Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions .github/workflows/mcpx-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ name: mcpx docs

# Build the mcpx book (#1941, Approach C) and publish it to GitHub Pages.
#
# Pull requests build .#mcpx-docs and upload the rendered site as an
# ordinary build artifact — no deploy, no PR previews (reviewers download
# the artifact). Pushes to main and manual dispatches deploy the same
# build to Pages via the Actions artifact flow: Pages source for this
# repository is "GitHub Actions" (build_type=workflow), no generated
# HTML is ever committed, and no extra repository or secret is needed.
# Builds run on pushes to main and on manual dispatch — there is no
# pull-request build (the sibling docs workflows, fleet-docs.yml,
# atlas-docs.yml and id-docs.yml, are shaped the same way). Pushes and
# dispatches deploy the build to Pages via the Actions artifact flow:
# Pages source for this repository is "GitHub Actions"
# (build_type=workflow), no generated HTML is ever committed, and no
# extra repository or secret is needed.
#
# The build is the flake output .#mcpx-docs (pkgs/mcpx/docs.nix, from
# #1939 / PR #2629): the same `nix build` locally and in CI. The
# derivation takes the base URL as its `siteUrl` argument, baked in as
# mdBook's site-url: PR/local builds use the default "/", the Pages
# mdBook's site-url: plain builds use the default "/", the Pages
# deploy overrides it with "/code/" (the project site's path) — builds
# differ only in that one value (#1941).

Expand Down Expand Up @@ -65,14 +66,6 @@ jobs:
test -f site/index.html.md
grep -q 'rel="alternate" type="text/markdown"' site/index.html

- name: Upload site artifact (PR builds only)
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v7
with:
name: mcpx-docs-site
path: site
if-no-files-found: error

deploy:
name: "stage: build + upload Pages artifact"
# Deploys only from main: pushes to main and manual dispatches
Expand All @@ -99,7 +92,7 @@ jobs:
# (https://developing-today.github.io/code/), and mdBook needs
# that path as its site-url: with "/" the generated 404 page
# points its CSS/JS and navigation at the domain root and breaks.
# Same derivation as the PR build, differing only in the siteUrl
# Same derivation as the build job, differing only in the siteUrl
# argument (#1941).
- name: Nix build (deploy variant, siteUrl /code/)
run: |
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/docs/spec/conformance-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Generated by `internal/conformance` (`MCPX_UPDATE_MATRIX=1 go test ./internal/conformance -run TestMatrix`); do not edit.

Generated from inputs `e9412930e5a01e78` (sha256 of docs/spec/requirements.md, internal/conformance/overrides/*.json, internal/conformance/coverage*.go, internal/conformance/authsplit.json). `TestMatrix` regenerates this file and fails when it differs, so it describes the tree it is committed in.
Generated from inputs `6b1cdc606dd5e28c` (sha256 of docs/spec/requirements.md, internal/conformance/overrides/*.json, internal/conformance/coverage*.go, internal/conformance/authsplit.json). `TestMatrix` regenerates this file and fails when it differs, so it describes the tree it is committed in.

Every normative requirement of every revision (catalogue: `docs/spec/requirements.md`), for mcpx as a server and as a client. A requirement is *tested* when a named test verifies it in that revision, *n/a* when it does not bind mcpx in that role, and a *gap* when it binds mcpx and mcpx does not meet it yet, with the issue that tracks it. Run exactly the covering tests with `go run ./internal/conformance/cmd/covering`.

Expand Down
8 changes: 8 additions & 0 deletions pkgs/mcpx/internal/conformance/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"regexp"
"sort"
"strings"

"github.com/developing-today/code/pkgs/mcpx/internal/refdoc"
)

var issueRe = regexp.MustCompile(`^#[0-9]+$`)
Expand Down Expand Up @@ -176,7 +178,13 @@ func Summary(reqs []Requirement, st map[Cell]Status) map[string]map[string]map[s
return out
}

// mdEscape makes a coverage detail safe for a matrix table cell:
// angle-bracket placeholders become entities (via refdoc.EscapeAngles,
// so the book renderer shows <id> instead of eating it as a tag),
// newlines fold to spaces, and pipes are normalised to the escaped
// form so a cell can never break the table's shape.
func mdEscape(s string) string {
s = refdoc.EscapeAngles(s)
s = strings.ReplaceAll(s, "\n", " ")
return strings.ReplaceAll(strings.ReplaceAll(s, `\|`, "|"), "|", `\|`)
}
Expand Down
22 changes: 22 additions & 0 deletions pkgs/mcpx/internal/conformance/mdescape_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package conformance

import "testing"

// The matrix's gap and n/a details are prose written in the coverage
// files, and they name commands with placeholder arguments
// ("mcpx elicit result <id>"). mdEscape must turn those placeholders
// into entities the book renderer shows instead of eating them as
// HTML tags (#13422), while leaving code spans — the house style for
// a placeholder that must stay literal — untouched.
func TestMdEscapeAngles(t *testing.T) {
cases := []struct{ in, want string }{
{"visible via mcpx elicit result <id>", "visible via mcpx elicit result &lt;id&gt;"},
{"host, or `flake:<ref>` for a devshell", "host, or `flake:<ref>` for a devshell"},
{"pipes | stay escaped", `pipes \| stay escaped`},
}
for _, c := range cases {
if got := mdEscape(c.in); got != c.want {
t.Errorf("mdEscape(%q) = %q, want %q", c.in, got, c.want)
}
}
}
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/conformance/requirements.json
Original file line number Diff line number Diff line change
Expand Up @@ -14461,7 +14461,7 @@
},
"notes": {
"client": "yes — broker records `Server`",
"server": "yes — message rewritten \"\u003cserver\u003e (via mcpx) asks:\" so the downstream can meet it"
"server": "yes — message rewritten \"\u0026lt;server\u0026gt; (via mcpx) asks:\" so the downstream can meet it"
}
},
{
Expand Down
80 changes: 78 additions & 2 deletions pkgs/mcpx/internal/refdoc/md.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package refdoc
import "strings"

// Table renders a Markdown table with the given headers and rows.
// Cells are escaped: a "|" becomes "\|" and a newline becomes "<br>",
// so a cell can never break the table's shape. Rows shorter than the
// Cells are escaped: a "|" becomes "\|", angle brackets in prose
// become "&lt;"/"&gt;" (see EscapeAngles) and a newline becomes
// "<br>", so a cell can never break the table's shape or lose a
// placeholder token to the HTML renderer. Rows shorter than the
// header are padded with empty cells.
func Table(headers []string, rows [][]string) string {
var b strings.Builder
Expand Down Expand Up @@ -49,13 +51,87 @@ func Table(headers []string, rows [][]string) string {
}

func escapeCell(s string) string {
s = EscapeAngles(s)
s = strings.ReplaceAll(s, "|", `\|`)
s = strings.ReplaceAll(s, "\r\n", "<br>")
s = strings.ReplaceAll(s, "\n", "<br>")
s = strings.ReplaceAll(s, "\r", "<br>")
return s
}

// EscapeAngles escapes "<" and ">" as the HTML entities &lt; and
// &gt; in prose, so a placeholder token like <id> survives rendering
// instead of being eaten as an HTML tag (an mdBook build warns about
// the unclosed tag, and the placeholder vanishes from the published
// page). Text inside a backtick code span is already literal, so it
// passes through untouched: a source that writes `flake:<ref>` keeps
// exactly that text. Existing entities are not special-cased --
// "&lt;" contains no angle bracket and passes through as written.
// A backtick run with no matching closing run is literal text
// (CommonMark), so it does not switch the rest of the string to code.
func EscapeAngles(s string) string {
if !strings.ContainsAny(s, "<>") {
return s
}
var b strings.Builder
b.Grow(len(s))
span := 0 // backtick run length of the code span we are inside; 0 = prose
for i := 0; i < len(s); {
c := s[i]
if c == '`' {
j := i
for j < len(s) && s[j] == '`' {
j++
}
run := j - i
switch {
case span == 0 && hasClosingRun(s[j:], run):
span = run
case span != 0 && run == span:
span = 0
}
b.WriteString(s[i:j])
i = j
continue
}
if span == 0 {
switch c {
case '<':
b.WriteString("&lt;")
i++
continue
case '>':
b.WriteString("&gt;")
i++
continue
}
}
b.WriteByte(c)
i++
}
return b.String()
}

// hasClosingRun reports whether s contains a backtick run of exactly
// n backticks, which is what closes a code span opened by n backticks.
func hasClosingRun(s string, n int) bool {
for i := 0; i < len(s); {
if s[i] != '`' {
i++
continue
}
j := i
for j < len(s) && s[j] == '`' {
j++
}
if j-i == n {
return true
}
i = j
}
return false
}

// Code renders s as a fenced code block. The fence is one backtick
// longer than the longest backtick run inside s (and at least three),
// so code that itself contains fences cannot break out of the block.
Expand Down
33 changes: 33 additions & 0 deletions pkgs/mcpx/internal/refdoc/md_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,36 @@ func TestRenderingIsDeterministic(t *testing.T) {
t.Error("same input rendered different bytes across runs")
}
}

func TestTableEscapesAnglePlaceholdersInProse(t *testing.T) {
got := refdoc.Table(
[]string{"setting", "governs"},
[][]string{
{"`a.b`", "visible via mcpx elicit result <id>"},
{"`c.d`", "host, or `flake:<ref>` for a Nix flake devshell"},
},
)
want := "| setting | governs |\n" +
"| --- | --- |\n" +
"| `a.b` | visible via mcpx elicit result &lt;id&gt; |\n" +
"| `c.d` | host, or `flake:<ref>` for a Nix flake devshell |\n"
if got != want {
t.Errorf("Table mismatch:\n got: %q\nwant: %q", got, want)
}
}

func TestEscapeAngles(t *testing.T) {
cases := []struct{ in, want string }{
{"plain text", "plain text"},
{"a <server> b", "a &lt;server&gt; b"},
{"`<server>` in code", "`<server>` in code"},
{"``a ` <b>`` and <c>", "``a ` <b>`` and &lt;c&gt;"},
{"already &lt;escaped&gt;", "already &lt;escaped&gt;"},
{"a lone ` backtick, then <x>", "a lone ` backtick, then &lt;x&gt;"},
}
for _, c := range cases {
if got := refdoc.EscapeAngles(c.in); got != c.want {
t.Errorf("EscapeAngles(%q) = %q, want %q", c.in, got, c.want)
}
}
}
5 changes: 5 additions & 0 deletions pkgs/mcpx/internal/settings/configuration_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"sort"
"strings"

"github.com/developing-today/code/pkgs/mcpx/internal/refdoc"
)

// ConfigurationTable is the generated inventory inside
Expand Down Expand Up @@ -60,6 +62,9 @@ func ConfigurationTable(all []Setting) string {
if set.Plumbing {
governs = "*(plumbing)* " + governs
}
// A Short is prose: a bare <placeholder> in it would be
// eaten as an HTML tag by the book renderer (#13422).
governs = refdoc.EscapeAngles(governs)
fmt.Fprintf(&b, "| `%s` | %s | %s | %s | %s | %s | %s | %s |\n",
set.Path, set.Kind, def, set.Scope, yesNo(set.Hot),
strings.Join(flags, ", "), strings.Join(envs, ", "),
Expand Down