Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

fix(scripts): read snippet imports from the AST in both gates - #7569

Merged
os-steve merged 2 commits into
mainfrom
claude/issue-7555-import-reader-ast
Sep 3, 2026
Merged

os-steve merged 2 commits into
mainfrom
claude/issue-7555-import-reader-ast

Conversation

@os-steve

@os-steve os-steve commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #7555

Both snippet gates carried a private importedSpecifiers(body) that found module
specifiers with three regexes over the raw block text. Documentation prose is part of
that corpus, so the pattern matched text that is not an import. Both copies are gone;
the one reader is now moduleSpecifiersOfBlock, exported from the shared harness — the
TSX parse plus the AST walk moduleSpecifiersOf that PR #7554 added — so the two gates
cannot answer the question differently.

Verification head: aa54aee (two commits: the reader swap 9f1a2ad, then the
corpus-agreement pin patch aa54aee asked for in review). Written by Claude Code in
session session_019RfFHiRCSs3JXLK4cwcfox — attribution kept as prose here because the
pull-request PATCH endpoint strips the footer block from this body (measured twice, see
the closing note).

The specimen, measured

content/docs/plugins/plugin-markdown.mdx:195 is a tsx block whose body assigns a
template literal holding a README sample. Inside that literal is the line
npm install project-name. Nothing in that block imports anything.

reader reports for that block
the private regex reader (before) ["project-name"]
moduleSpecifiersOfBlock (after) []

Over the whole corpus the two readers disagree on exactly that one block, and in one
direction only:

population blocks agree regex-only specifiers AST-only
docs gate, compiled blocks 455 454 1 (project-name) 0
skills gate, marked ts fences 17 17 0 0
skills gate, --measure ts fences 121 121 0 0

Population and behaviour: nothing moved

Both gates print byte-identical output before (e304a4e) and after (9f1a2ad) —
diff over the full stdout of each run is empty. The lines the card and the triage
name, quoted from both runs:

Scanned 227 document(s): 201 covered (99 of them hold a ts/tsx block), 26 ungated — declared in this script, NOT verified by it.
Covered blocks: 613 — 455 to compile, 158 declared fragment(s).
Root bound:     no block imports a specifier that resolves only through this repository's ROOT manifest.
Semantic phase: 455 of 455 block(s) judged, 0 failed.
Unmapped specifiers (covered by neither map, so the shared harness's ROOT BOUND refuses them — they would otherwise resolve from the repository ROOT's own node_modules, this workspace's devDependency set, NOT what a reader of the guide installs): @playwright/test, vitest
Marked: 17 ts fence(s) (floor 17), 39 json fence(s) (floor 39) — the floor is ⛔ SHRINK-ONLY. Unmarked fences are ignored by design (opt-in).
Root bound:     4 fence(s) refused (@playwright/test, vitest) and therefore NOT type-checked; 4 row(s) declared in KNOWN_ROOT_DEVDEP_EXAMPLES (⛔ SHRINK-ONLY, 4 row(s)), 0 NOT declared, 0 declared row(s) no longer refused.
Semantic phase: 13 of 17 ts fence(s) judged, 0 failed.

--build-filter is byte-identical for both gates too (26 workspace filter words for the
docs gate, 11 for the skills gate). No false specifier was moving it: a false name joins
the filter only when it happens to equal a workspace package, and project-name is not
one — luck, not construction, which is why the collision case is now pinned over a
throwaway tree with the real-import control beside it.

The Unmapped specifiers line is unchanged for the same reason in reverse: the false
name lives in the docs corpus, and that line is the skills gate's. What changed
is that the line and the refusals it reports are now one reader. Since PR #7554 the line
is the report of what the ROOT BOUND refuses, and the bound has always walked the AST —
a regex-derived report of an AST-derived refusal is two answers to one question, free to
name different sets over the same fences. The suite pins that the two sets agree over
this corpus, and that the line cannot name a specifier no fence imports.

What is pinned (3 new tests per suite)

scripts/__tests__/check-doc-snippet-types.test.ts (67 to 70 tests):

  • the corpus specimen itself — the block at plugin-markdown.mdx:195 still holds
    npm install project-name, moduleSpecifiersOfBlock reports [] for it, and the
    retired regex (kept in the test file, and only there, as the contrast) reports
    ["project-name"]. Without the contrast the pin would hold for any block that imports
    nothing;
  • the consumer with teeth: over a throwaway tree where the invented name does equal a
    workspace package, neededPackages and the build filter stay empty and no
    unbuilt-package precondition is raised — with the real-import control beside it, so
    an empty result cannot come from a tree that was never scanned.

scripts/__tests__/check-skill-examples.test.ts (81 to 84 tests):

  • the source-level "one reader" fact, added to the existing harness-not-forked pin:
    moduleSpecifiersOfBlock must be in the import block from the docs gate;
  • the same template-literal shape through this gate's own path: unmappedSpecifiers and
    neededPackages stay empty, with the real-import control naming some-runner;
  • the agreement itself, build-free, over the real corpus: the Unmapped specifiers set
    equals the set the bound refuses, specifier for specifier.

Patched in review (aa54aee). That last pin first closed with
expect(refused.size).toBeGreaterThan(0), which is not a fact about the two readers it
compares — it asserts the corpus still MARKS a fence importing a root-only specifier, and
today that set is exactly the four marked fences in skills/objectui/guides/testing.md.
PR #7568 (objectui#7557, governed, draft) unmarks them, so on the merge of both changes
refused is empty, the equality still holds, and the clause would have red over a change
that is not about it. The clause is now expect(read.size).toBeGreaterThan(0) — the
specifiers the reader actually produced over the selected fences, which is what this pin
owns. Nothing in that flight's region is touched (KNOWN_ROOT_DEVDEP_EXAMPLES,
MARKED_FLOOR, testing.md); git diff against main for those two identifiers is
empty.

The pin's comment also now records, as a measurement, why the equality is scoped to the
SELECTED population and must not widen to --measure: over all 121 candidate fences the
two sets legitimately differ, 12 names on the line against 6 refused, because a specifier
that is unmapped and NOT root-declared belongs on the line and is correctly left in the
program to fail there.

The two readings the patch is proved by

Both taken in this worktree, exit captured before any pipe, restore proved by state.

(a) skills/objectui/guides/testing.md taken from PR #7568's head f7de6dc, nothing
else changed
— applied blob 74382b9... over HEAD blob 0f68499..., os:check markers
4 to 0:

before the patch (9f1a2ad) after the patch (aa54aee)
agrees with the bound over the real corpus red — expected 0 to be greater than 0 green
the two suites 3 failed | 151 passed (154) 2 failed | 152 passed (154)

The two that stay red in both columns are pre-existing pins on MARKED_FLOOR and
KNOWN_ROOT_DEVDEP_EXAMPLES — PR #7568's own region, which its commit moves in the same
change; only its guide was applied here, so they red by construction and neither is
touched by this branch.

Restored after each reading: git hash-object back to 0f68499... = the HEAD blob,
git status --porcelain empty, markers back to 4.

(b) the real merge of both pull requests, built in a throwaway compare worktree at
f7de6dc with this branch's diff applied on top. git merge-tree --write-tree reports
ONE conflict, in the check-skill-examples.mjs header docblock — both changes add a
paragraph at the same place; resolved for the probe by keeping both paragraphs, which is
the whole resolution. On that merged tree, everything is green:

check-skill-examples EXIT=0   self-test EXIT=0   check-doc-snippets EXIT=0   vitest EXIT=0
Unmapped specifiers: none — every bare import of a selected fence is covered by the map above.
Marked: 13 ts fence(s) (floor 13), 39 json fence(s) (floor 39) — the floor is ⛔ SHRINK-ONLY. Unmarked fences are ignored by design (opt-in).
Root bound:     no selected fence imports a specifier that resolves only through the repository's ROOT manifest.
Semantic phase: 13 of 13 ts fence(s) judged, 0 failed.
Every marked skill example holds up against the built types.
Test Files 2 passed (2) · Tests 154 passed (154)

⚠️ For whoever lands second: the conflict above is textual, not just semantic. It is one
docblock paragraph and the resolution is to keep both.

Ablation

moduleSpecifiersOfBlock's body swapped back to the three regexes, at 9f1a2ad, under a
trap ... EXIT INT TERM restore with absolute paths. No rebuild leg: both suites import
their subject by relative path (../check-doc-snippet-types.mjs), so the mutated source
is what runs — no dist, no package exports, no vitest alias between them.

Mutation proved on disk before any reading was taken: injected marker present (3
occurrences), removed anchor absent (0), and the file's git hash-object moved from the
HEAD blob f1bb41e... to a0b7200....

Three tests red, each naming itself and the false specifier; every control stayed green:

× reports nothing for the corpus block that finding measured
  AssertionError: expected [ 'project-name' ] to deeply equal []
× does NOT add one named only inside a template literal
  AssertionError: expected [ '@fixture/pkg-a' ] to deeply equal []
× does NOT name one that appears only inside a template literal
  AssertionError: expected [ 'some-runner' ] to deeply equal []

Tests  3 failed | 151 passed (154)

The agreement pin cannot red under this ablation and did not: it mutates both sides of
the comparison at once. It is the standing assertion, not the ablation's target.

Restored, proved by state rather than by exit code: on-disk git hash-object back to
f1bb41e... (equal to the HEAD blob), git diff HEAD empty, git status --porcelain
empty, injected marker 0 occurrences.

Gates

All re-run at aa54aee, exit captured before any pipe.

command exit verdict line
pnpm check:doc-snippets 0 Every covered documentation snippet compiles against the built types.
pnpm check:skill-examples 0 Every marked skill example the root bound could reach holds up against the built types — 4 declared row(s) in KNOWN_ROOT_DEVDEP_EXAMPLES were NOT reached, and this line does not speak for them.
node scripts/check-skill-examples.mjs --self-test 0 ✓ check-skill-examples self-test: 52 cases pass (...)
pnpm exec vitest run scripts/__tests__/check-doc-snippet-types.test.ts scripts/__tests__/check-skill-examples.test.ts 0 Test Files 2 passed (2) · Tests 154 passed (154)
pnpm check:doc-fences 0 ✅ check:doc-fences — every TypeScript block in 227 document(s) is fenced ts/tsx/typescript, except 80 declared file(s) carrying 90 block(s) ... (⛔ SHRINK-ONLY).
pnpm check:control-bytes 0 ✅ check-control-bytes: OK (scanned 6237 tracked text file(s); skipped 85 binary).
node scripts/check-changeset-presence.mjs 0 ✅ No source or published contract of a released package changed in this range, so no changeset is owed.
pnpm type-check:scripts 0 tsc -p tsconfig.scripts.json clean
pnpm lint 0 Tasks: 47 successful, 47 total — 0 errors; none of the four files appears in the output

Derived beyond the dispatched list, because the diff is scripts/**: pnpm type-check:scripts (and tsc --listFiles confirms both edited test files and both
edited .mjs gates are in that program — 2 hits each, so "clean" really covers them),
plus check:esm-specifiers, check:pre-install-import-graph, lint:coverage,
type-check:coverage, check:skills-paths — all exit 0. The union of every test file
that names either gate (13 files, found by git grep) passes: 466 tests.

No changeset: check-changeset-presence.mjs decides, and it says none is owed —
scripts/** publishes nothing. No skip-changeset label applied.

Nothing under content/docs/, skills/** or .claude/** is touched; the bound, the
floors and the declared rows are unchanged. Not a governed surface, so this stays draft
for the seat to review, flip ready and arm auto-merge.

Platform note, measured on this body. create_pull_request stored the footer block
and normalised it to the session-URL form. The PATCH behind update_pull_request then
DELETED it: the body sent without a footer and the body sent with one both stored at
exactly 12317 bytes with zero footers, so this is removal, not the recorded downgrade and
not the recorded append. Attribution is therefore carried as prose at the top of this
body, which is the shape the repo's own guidance says survives an edit; it is not
re-posted as a block, to avoid a retry loop against a sanitizer.

`check-doc-snippet-types.mjs` and `check-skill-examples.mjs` each carried a
private `importedSpecifiers(body)` that found module specifiers with three
regexes over the raw block text. Documentation prose is part of that corpus, so
the pattern matched text that is not an import: `content/docs/plugins/
plugin-markdown.mdx:195` is a `tsx` block whose body assigns a template literal
holding a README sample, and the line `npm install project-name` inside that
literal was reported as an import of `project-name`. Nothing in that block
imports anything.

Both copies are replaced by `moduleSpecifiersOfBlock`, exported from the shared
harness — the parse and the AST walk `moduleSpecifiersOf` together, so the two
gates cannot answer the question differently. Measured over the whole corpus,
the readers disagree on exactly one block, the one above: 455 docs blocks, 121
skills fences under `--measure`, one regex-only specifier, zero AST-only.

Neither consumer moves, and both survived the over-match by luck rather than by
construction:

- `--build-filter` is byte-identical for both gates. A false specifier joins the
  build filter only when it happens to equal a workspace package, and
  `project-name` is not one. The suite now pins the collision case over a
  throwaway tree, with the real-import control beside it.
- The skills gate's `Unmapped specifiers` line is unchanged
  (`@playwright/test, vitest`). Since the root bound landed that line is the
  REPORT of what the bound refuses, and the bound has always walked the AST — a
  regex-derived report of an AST-derived refusal is two answers to one question.
  The suite pins that the two sets agree over this corpus, and that the line
  cannot name a specifier no fence imports.

Both gates print byte-identical output before and after: same `Covered blocks`,
same `Marked:`, same `Root bound:`, same `Semantic phase:`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019RfFHiRCSs3JXLK4cwcfox
…ces are marked

The pin `agrees with the bound over the real corpus, specifier for specifier`
closed with `expect(refused.size).toBeGreaterThan(0)`. That clause is not about
the two readers it exists to compare — it asserts that the corpus still MARKS a
fence importing a root-only specifier, and today that set is made of exactly the
four marked fences in `skills/objectui/guides/testing.md`. A flight that unmarks
them empties `refused`, leaves the equality true, and reds this pin over a change
that has nothing to do with it.

Measured, in this worktree, with `skills/objectui/guides/testing.md` taken from
objectui#7557's head (`f7de6dc`) and nothing else changed: the old clause failed
with `expected 0 to be greater than 0`. With the clause replaced it passes, and
the only remaining reds are the two pre-existing pins on `MARKED_FLOOR` and
`KNOWN_ROOT_DEVDEP_EXAMPLES` — that flight's own region, which its commit moves
in the same change and which this diff does not touch.

The non-vacuity clause now asserts what this pin actually owns: that the reader
produced specifiers over the selected fences at all, so an equality between two
sets nothing ever filled cannot pass for a measurement. Both readings are
recorded in the pull request body.

Also records, in the pin's own comment, why the equality is scoped to the
SELECTED population and must not widen to `--measure`: measured over all 121
candidate fences the two sets legitimately differ, 12 names on the line against 6
refused, because a specifier that is unmapped and NOT root-declared belongs on
the line and is correctly left in the program to fail there.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019RfFHiRCSs3JXLK4cwcfox
@os-steve
os-steve marked this pull request as ready for review September 3, 2026 23:42
@os-steve
os-steve added this pull request to the merge queue Sep 3, 2026
Merged via the queue into main with commit 78d592b Sep 3, 2026
30 checks passed
@os-steve
os-steve deleted the claude/issue-7555-import-reader-ast branch September 3, 2026 23:57
os-steve pushed a commit that referenced this pull request Sep 4, 2026
Brings in PR #7569 (objectui#7555), which moved both gates' import reading
onto the harness's moduleSpecifiersOfBlock. One textual conflict, in the
header docblock of scripts/check-skill-examples.mjs: both branches add a
paragraph at the same position.

Both paragraphs kept, and nothing else in the resolution. Order reads with
the prose above it: #7569's paragraph about the report OF the refusals comes
first, since the paragraph before it ends on the Unmapped specifiers line
that paragraph is about; this branch's paragraph about a refused fence not
being type-checked follows, in the updated form that records the four rows'
retirement. The other side's copy of that second paragraph is the pre-edit
original and is superseded, not dropped.

Verified across the merge: KNOWN_ROOT_DEVDEP_EXAMPLES stays an empty Set,
MARKED_FLOOR ts stays 13, skills/objectui/guides/testing.md is byte-identical
to this branch's commit, and the moduleSpecifiersOfBlock import and both of
its call sites from the other side survive.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019RfFHiRCSs3JXLK4cwcfox
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

importedSpecifiers is a regex, so an import-shaped line inside a template literal is read as an import by both snippet gates

2 participants