Skip to content

Show the MCP replay on port builds and accept Ruby's indented require - #246

Merged
tony merged 5 commits into
mainfrom
fix/mcp-replay-ruby-require-20261102
Nov 3, 2026
Merged

tony merged 5 commits into
mainfrom
fix/mcp-replay-ruby-require-20261102

Conversation

@tony

@tony tony commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Why

Two features from #232 pass every docs-side check but break in a port's own docs build. That build regenerates its data at the port's head (gen-mcp-protocol.mjs --source-bound, gen-example-sources.mjs in build-site.sh), while docs CI and previews read the committed copies.

  • MCP replay: on the live site after r11, the worked example shows "Requests only: no recorded results" with no tmux preview on every port but Python, for example C++. buildShowcase accepted a recording only when transcript.revision === snapshot.revision. A port build's snapshot is always at the port head, so that never held.
  • Ruby: libtmux-ruby#89's docs build failed with core-capabilities: ruby/send-keys has no import lines. programProblems required require at column 0, and Ruby master's examples/api/capture.rb indents it inside begin so README excerpts carry it.

What changes

  • A recording counts while every tool it calls is still advertised with the schemas it was recorded against. Each transcript stores those schemas in contracts (mcp-contract.ts). The nine committed transcripts are backfilled from the committed snapshot at their own revision. A changed or missing schema, a missing tool, or a transcript without contracts still falls back to requests-only. The provenance line still names the revision the results were recorded at, and says when the page documents a different revision.
  • Ruby's completeness rule accepts an indented require (/^[ \t]*require ["']/m). A commented require and require_relative are still refused.
  • The recorder's host-name check reads a backslash before a name as a pattern escape (^%\d+$ held the user name d).

Verification

  • A test regenerates each recorded port's snapshot at a later revision, exactly as build-site.sh does. It fails on main for all nine recorded ports and passes here. Its controls cover a changed input or output schema, a missing tool, no contracts, an unrelated tool change and key order.
  • A byte-exact copy of Ruby master's capture.rb (20744401e) passes the completeness rule; three cases fail without the fix.
  • The six focused suites pass on this branch (core-capabilities, mcp-showcase, mcp-transcript-checks, mcp-replay, port-landing-page, product-copy). No build was run here; this PR's CI is the first full run.

Schema comparison is strict, descriptions included, so a reworded parameter description at a port's head sends that port back to requests-only until it is re-recorded.

The same three commits are on #245, which drops them when it rebases.

Review follow-ups

An independent review approved this PR. Its findings 1, 2, 3 and 5 are fixed in two commits on top of the first three; the rest are listed below.

  • The provenance no longer implies equal values. Equal schemas fix the shape of a call and its result, not the values. When the page documents a revision other than the one recorded, the line now says the results were recorded at one revision, this page documents a different one, the calls have the same input and output schemas there, and the results at that revision may differ from the recorded ones. It names no direction: a tag or a pinned build can document an older revision, and a snapshot's revision does not say which is newer. The documentedRevision doc comment and the recorder header use the same neutral wording.
  • A recording that lists tools must list the advertised ones. Ruby's recorded tmux_capabilities result lists data.enabled_tools, and a snapshot advertising another set still passed on the two called tools' schemas. A recording now shows only when every list of strings in a result that names all the tools the session called is the set the snapshot advertises, in either direction; otherwise the page falls back to requests only. The check does not assume the key name, and Ruby is the only committed recording whose results name any tool. A server that lists only a subset on purpose would fall back to requests only until someone looks at it.
  • An absent output schema is not claimed. When a called tool was recorded without an output schema, the page says "the same input schemas" and does not mention output schemas. All committed recordings carry output schemas, so their text is unchanged.
  • The host-name check no longer exempts a backslash. The exemption let C:\Users\d\AppData, \\wsl-box\share\file and USERPROFILE=C:\Users\tony through leaks() and sanitize(). It is reverted. The recorder and the test over the committed recordings scan the transcript without its contracts key, because those schemas are copied from the committed tools/list snapshot and never carry session data (^%\d+$ is the pattern that needed the exemption).

Verification

  • The new tests failed before the change and pass after it. Against the previous commit, seven tests in mcp-showcase failed (the provenance wording for a documented revision that looks newer and one that looks older, the input-only claim, outputsChecked, Ruby with a tool removed, Ruby with a tool added, and a list under another key). Against the restored exemption, the three constructed leaks fail; with contracts scanned, the pattern case and the committed-recordings test fail.
  • The six focused suites pass: core-capabilities, mcp-showcase, mcp-transcript-checks, mcp-replay, port-landing-page, product-copy. oxlint is clean on the touched sources, and tsc reports nothing in them (it reports unrelated errors elsewhere in this checkout).
  • Not run: a site build, the outer test loop, and scripts/gen-mcp-transcript.mjs itself, which needs each port's checkout. The recorder reaches the scan through withoutContracts, which the tests cover.

Left for later

  • Finding 4: the Ruby completeness rule's false accepts on heredocs.
  • Finding 6: gaps in the recorder's tests.
  • Finding 7: the repository comparison.

tony added 5 commits November 2, 2026 18:43
why: libtmux-ruby's own docs build failed with "core-capabilities:
ruby/send-keys has no import lines" while rendering /demo/home. Ruby
master's examples/api/capture.rb and examples/api/new_window.rb put
`require "libtmux"` inside the begin block, two spaces in, after the
`# docs:begin main` marker, so README excerpts of that region carry the
require. The Ruby completeness rule only accepted `require` at column 0.
Docs CI stayed green because it reads the revision-bound example cache,
where both files still had the require at column 0; the port's build
reads the live files and fails.

what:
- Ruby `imports` rule matches `require` after leading spaces or tabs.
  A commented require still does not count, `require_relative` and
  `Example.` still trip the `local` rule, and a program with no require
  still reports "has no import lines".
- Add examples/api/capture.rb as a fixture, taken from
  libtmux/libtmux-ruby master 20744401ee9f (git blob f070fac,
  last changed by 2156612), and test that the begin-wrapped program has
  no problems, that dropping its require reports the missing imports,
  that a helper stays refused, and that the entry rule still matches
  the wrapped shape.
- Go, Rust and TypeScript rules are unchanged. Go and TypeScript
  imports are top-level by spec and every formatter leaves them at
  column 0. Rust `use` inside `fn main` is legal but unusual, and the
  Rust showcase files on libtmux-rs master all keep it at column 0.

The example cache is not refreshed: the generator reads the revision the
Ruby API model pins (9b1545562), so a cache refresh to master needs a
model revision bump and a Ruby checkout, not this fix.
… check

why: The host-name check matches a one-letter user name such as `d` as a
token. A backslash was not a word boundary for it, so the `\d` in a
tool's input pattern (`^%\d+$`) read as the name and refused a file that
only holds public schema text. The next change stores those schemas in
each transcript, and the recorder and the committed-recording test both
run this check.

what:
- Treat a backslash before a name as an escape, not a token boundary,
  for both leaks() and sanitize().
- Test that a pattern's escape is neither reported nor rewritten, and
  that a name beside it still is.
why: A port's own docs build runs gen-mcp-protocol.mjs --source-bound,
which regenerates the tools/list snapshot at the port's head. The
snapshot's revision is then that commit and never the one a recording
was made at, and buildShowcase required the two to be equal. Every port
built that way printed "Requests only" for the worked example; only
Python, whose MCP product has its own pinned checkout, kept its replay.
Docs CI and local previews read the committed snapshot, whose revision
equals the recording's, so no test saw it.

A recording stays true while the calls it replays are the same contract
on the server being documented, whatever the commit.

what:
- Store the input and output schemas of each tool a transcript calls,
  taken from the snapshot the recorder already verifies against the
  checkout; the recorder's --check compares them too.
- Backfill the committed transcripts from the committed snapshot at
  each transcript's own revision. The diff only adds the key.
- Show a recording when its steps equal the example's, none failed, and
  every tool it called is still advertised with the recorded schemas,
  compared without regard to key order. A changed or missing schema, a
  missing tool, or a transcript without schemas gives requests only.
- Keep naming the revision the results were recorded at, and when the
  page documents a later one, say the tools take and return the same
  schemas there.
- Test a snapshot rewritten at another revision the way build-site.sh
  does for each port, a changed input or output schema for each recorded
  tool, a tool that is gone, and the page's provenance line. Replace the
  test that required equal revisions with one that checks the stored
  schemas against the snapshot.
why: The earlier exemption for a backslash before a name let
`C:\Users\d\AppData`, `\\wsl-box\share\file` and
`USERPROFILE=C:\Users\tony` through leaks() and sanitize(), so a
Windows host's user or machine name could reach a committed recording.
It was added only because `contracts` (JSON Schema patterns such as
`^%\d+$`) now sits inside the scanned text.

The contracts are copied from the committed tools/list snapshot and
never carry session data, so the host check has no reason to read them.

what:
- Restore the token boundary as it was before the exemption.
- Add withoutContracts() and scan the transcript without that key, in
  the recorder and in the test over the committed recordings.
- Test that the three constructed names are found and rewritten again,
  and that a contract pattern with `\d` does not trip the scan while a
  name in a recorded step still does.
- The tests fail with the exemption restored, and fail when contracts
  are scanned.
why: The page said a recorded tool takes and returns "the same schemas"
at the documented revision, which reads as if the shown values are what
that server returns. Equal schemas fix the shape of a call and its
result, not the values. The earlier wording also called the documented
revision "later", and a tag or a pinned build can document an older
one; a snapshot's revision does not say which is newer.

Two gaps let a recording stand when it should not. Ruby's recorded
tmux_capabilities result lists the tools the server enabled, and a
snapshot that advertises another set still passed on the two called
tools' schemas. A tool recorded without an output schema compared equal
to one without, so "same schemas" claimed a return shape nobody had
checked.

what:
- State the provenance plainly: the results were recorded at one
  revision, the page documents a different one, the calls have the same
  input and output schemas there, and the values may differ. Name no
  direction.
- Say "input schemas" alone when a called tool has no recorded output
  schema (Recording.outputsChecked, from statesOutputs()).
- Show no recording when a result lists tools and the list is not the
  set the snapshot advertises, in either direction. A list is any
  array of strings, at any depth, that names every tool the session
  called, so no key name such as enabled_tools is assumed.
- Test the Ruby additions and removals, a list on another port under a
  different key, lists that must be ignored, direction-neutral wording
  for a documented revision that looks newer and one that looks older,
  and the input-only claim. Seven of the new tests fail on the previous
  commit and pass here; the committed recordings of the other ports
  name no tool in their results and are unaffected.
@tony
tony marked this pull request as ready for review November 3, 2026 04:57
@tony
tony merged commit ae091e4 into main Nov 3, 2026
3 checks passed
@tony
tony temporarily deployed to docs-preview-cleanup November 3, 2026 05:05 — with GitHub Actions Inactive

This branch was previously deployed

2 inactive deployments
docs-preview-cleanup — a2e2bc1a Deployed Nov 3, 2026 by tony via cleanup #206
docs-preview — a2e2bc1a Deployed Nov 3, 2026 by tony via publish-preview / publish #1147
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant