diff --git a/.github/workflows/mcpx-docs.yml b/.github/workflows/mcpx-docs.yml index 7892ca7c1f..041155d50e 100644 --- a/.github/workflows/mcpx-docs.yml +++ b/.github/workflows/mcpx-docs.yml @@ -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). @@ -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 @@ -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: | diff --git a/pkgs/mcpx/docs/spec/conformance-matrix.md b/pkgs/mcpx/docs/spec/conformance-matrix.md index 4be4c4ad83..48a85b8d0c 100644 --- a/pkgs/mcpx/docs/spec/conformance-matrix.md +++ b/pkgs/mcpx/docs/spec/conformance-matrix.md @@ -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`. diff --git a/pkgs/mcpx/internal/conformance/matrix.go b/pkgs/mcpx/internal/conformance/matrix.go index 059b46340a..a2e6c87fcd 100644 --- a/pkgs/mcpx/internal/conformance/matrix.go +++ b/pkgs/mcpx/internal/conformance/matrix.go @@ -5,6 +5,8 @@ import ( "regexp" "sort" "strings" + + "github.com/developing-today/code/pkgs/mcpx/internal/refdoc" ) var issueRe = regexp.MustCompile(`^#[0-9]+$`) @@ -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 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, `\|`, "|"), "|", `\|`) } diff --git a/pkgs/mcpx/internal/conformance/mdescape_test.go b/pkgs/mcpx/internal/conformance/mdescape_test.go new file mode 100644 index 0000000000..d29260d122 --- /dev/null +++ b/pkgs/mcpx/internal/conformance/mdescape_test.go @@ -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 "). 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 ", "visible via mcpx elicit result <id>"}, + {"host, or `flake:` for a devshell", "host, or `flake:` 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) + } + } +} diff --git a/pkgs/mcpx/internal/conformance/requirements.json b/pkgs/mcpx/internal/conformance/requirements.json index 1a41ac78e5..54c5769a00 100644 --- a/pkgs/mcpx/internal/conformance/requirements.json +++ b/pkgs/mcpx/internal/conformance/requirements.json @@ -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" } }, { diff --git a/pkgs/mcpx/internal/refdoc/md.go b/pkgs/mcpx/internal/refdoc/md.go index 9fe925cfdb..aa8b669f8f 100644 --- a/pkgs/mcpx/internal/refdoc/md.go +++ b/pkgs/mcpx/internal/refdoc/md.go @@ -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 "
", -// so a cell can never break the table's shape. Rows shorter than the +// Cells are escaped: a "|" becomes "\|", angle brackets in prose +// become "<"/">" (see EscapeAngles) and a newline becomes +// "
", 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 @@ -49,6 +51,7 @@ 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", "
") s = strings.ReplaceAll(s, "\n", "
") @@ -56,6 +59,79 @@ func escapeCell(s string) string { return s } +// EscapeAngles escapes "<" and ">" as the HTML entities < and +// > in prose, so a placeholder token like 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:` keeps +// exactly that text. Existing entities are not special-cased -- +// "<" 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("<") + i++ + continue + case '>': + b.WriteString(">") + 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. diff --git a/pkgs/mcpx/internal/refdoc/md_test.go b/pkgs/mcpx/internal/refdoc/md_test.go index f6a47f547c..d72b0955c6 100644 --- a/pkgs/mcpx/internal/refdoc/md_test.go +++ b/pkgs/mcpx/internal/refdoc/md_test.go @@ -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 "}, + {"`c.d`", "host, or `flake:` for a Nix flake devshell"}, + }, + ) + want := "| setting | governs |\n" + + "| --- | --- |\n" + + "| `a.b` | visible via mcpx elicit result <id> |\n" + + "| `c.d` | host, or `flake:` 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 b", "a <server> b"}, + {"`` in code", "`` in code"}, + {"``a ` `` and ", "``a ` `` and <c>"}, + {"already <escaped>", "already <escaped>"}, + {"a lone ` backtick, then ", "a lone ` backtick, then <x>"}, + } + 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) + } + } +} diff --git a/pkgs/mcpx/internal/settings/configuration_table.go b/pkgs/mcpx/internal/settings/configuration_table.go index dab9494b77..cbdea203ad 100644 --- a/pkgs/mcpx/internal/settings/configuration_table.go +++ b/pkgs/mcpx/internal/settings/configuration_table.go @@ -4,6 +4,8 @@ import ( "fmt" "sort" "strings" + + "github.com/developing-today/code/pkgs/mcpx/internal/refdoc" ) // ConfigurationTable is the generated inventory inside @@ -60,6 +62,9 @@ func ConfigurationTable(all []Setting) string { if set.Plumbing { governs = "*(plumbing)* " + governs } + // A Short is prose: a bare 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, ", "),