Repository navigation
test(build): one source walker for the nine specs that inventory src/ - #288
Conversation
Nine specs assert that a list of call sites under `src/` is CLOSED — the JSX
anchors, the viewport reads, the Radix poppers, the SahajCloud reads, the
lucide glyphs, the translation keys, the `announceEmbed` site, the drawer-width
fallbacks, the live-preview graph. Each walked the tree itself, and the walks
had already drifted into three shapes that were not interchangeable: two
yielded the OS separator where the spec's own lists were written POSIX-style,
one yielded absolute paths, and two re-entered every directory by hand. A tenth
spec would inherit whichever one its author copied.
`src/test-support/source-tree.ts` is the one walk now, with `readSource` and
`readSourceWithoutComments` beside it — the comment stripper was three verbatim
copies, and it is load-bearing for two of the closed lists, since a docblock
naming `useIsWideViewport` or a Radix package read as a call site once.
`parseSource` is split into `source-ast.ts` so importing the walk never loads
`typescript`: seven of the nine read raw text and have no parse to pay for.
The scopes did NOT merge, and the helper is built so they cannot. The nine cover
seven different file sets and every difference is load-bearing — a story IS one
of the two sanctioned viewport callers, a story is NOT the app using a lucide
glyph, a generated declaration has no call sites and is the slowest thing under
`src/` to parse. So each spec passes its own `sourceFiles({…})` options, beside
the assertions they serve, and `source-tree.test.ts` pins every option as biting
in both directions: a scope that silently stopped matching would make all nine
pass by vacuum.
Equivalence was proven rather than argued. A throwaway spec reimplemented all
seven original predicates and asserted set equality against the new options:
same files in, same files out, on the current tree. Then each spec's own defect
was reintroduced at its causing site — a fourth JSX anchor, a fifth popper, a
second `768px`, an unlimited `sdk.find`, a disagreeing `--sy-drawer-w`, an
unlisted glyph, an unanswerable `t()` key, a second `announceEmbed`, `boot.ts`
reaching the widget graph — and all nine turn their own spec red. So do six
mutations of the walker against its own spec.
This changed one walk implementation, not nine walks, and the lane cost is
unchanged: vitest gives each spec file its own module registry, so the memos are
per-file and the tree is still read once per spec. Median of three on 4 cores,
same worktree: 28.6s before, 28.8s after. #285 owns the lane's total.
Closes #286
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cnyvtf1CEB5M3dGqFZEQLH
A tenth closed-list spec is the failure this guards against, and nothing but prose tells its author where the walk lives. So the testing guide names `src/test-support/`, gives `grep -rln readdirSync src/` as the check that a walk has not grown back, and states the part a shared helper invites getting wrong: the seven scopes are deliberate, and flattening one changes what a spec asserts in the passing direction. It also records the measurement, because the obvious reading of "one walk" is a faster lane and that is not what happened — vitest isolates each spec file's module registry, so the tree is still read once per spec. 28.6s before, 28.8s after. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cnyvtf1CEB5M3dGqFZEQLH
…walk Four cleanup lenses over the branch. The three findings that mattered all said the same thing: a shared module that leaves a second copy behind, or states its contract in prose only, has not finished the job. - **`Widget.standalone.test.ts` still declared the comment stripper**, identical to the one it imported, because `specifiers()` takes a string and `importGraph` feeds it absolute paths. So the regex pair this branch centralised had four copies on arrival, not three. `stripComments` is a pure export now, and that spec imports it. Its one double-strip went with it: `specifiers` strips for itself, so all three call sites pass raw source. - **Nothing stopped an app module importing `src/test-support/`.** It is the first non-spec module under `src/` to import a node builtin, the bundler and `pnpm size` are both blind to it, and `Widget.standalone.test.ts`'s graph walk cannot see it either — `resolveModule` returns null for a bare `node:` specifier by design. One comment in `AGENTS.md` was the whole contract. It is four lines in `source-tree.test.ts` instead, watched red by importing the walk into `lib/scope.ts`. - **The memo preamble was pasted three times, and had already diverged** — two copies tested `cached !== undefined`, the third was truthy. That is the slight-variation-on-copy-paste this branch exists to remove, so one `memo()` owns it and the divergence cannot recur. The rest was weight: the module's history and its ⚠ scopes rule were stated four times over two modules, a doc and `AGENTS.md`; three docblocks claimed the memos last "once per process" when vitest gives each spec file its own registry, which is the opposite of the fact stated two paragraphs away in `docs/testing.md`; and `SourceScope` and `SRC_DIR` were exported with no importer — `SRC_DIR` only so one spec could `..` back out of the scope system to read `scripts/`. That read is a local `new URL` again. The strip is now tested as a pure function on literals, including the `[^:]` guard that spares a `https://`. It used to assert that a sentence inside `source-tree.ts`'s own docblock disappeared, so rewording a comment broke a test and the failure pointed at the stripper. Rejected, with reasons in the PR body: folding `includeDeclarations` and `includeGeneratedTypes` away as unconditional exclusions (it narrows six specs' scopes, which is the one thing #286's criteria forbid), moving three specs' closing direction to `no-restricted-syntax` (a lint rule cannot carry the positive half, so each rule would have two homes), and rewriting `importGraph` onto src-relative paths for ~10ms. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cnyvtf1CEB5M3dGqFZEQLH
…te it The reason for the two-module split now lives in `source-ast.ts`, where a reader reaches it, and the ⚠ scopes rule in `source-tree.ts`. The layout block says what the directory holds, and that a spec enforces the boundary rather than prose. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cnyvtf1CEB5M3dGqFZEQLH
Deploying sahajatlas with
|
| Latest commit: |
02fc583
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9590431c.sahajatlas.pages.dev |
| Branch Preview URL: | https://claude-test-286-one-source-w.sahajatlas.pages.dev |
Deploying sahajatlas-design with
|
| Latest commit: |
718bc9b
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://11cd5e8f.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://claude-test-286-one-source-w.sahajatlas-design.pages.dev |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff matches #286 and is not bigger than it. I re-derived all nine original predicates from main and ran them beside the new sourceFiles({…}) calls over the branch's 458-file tree: all nine scopes are identical, at the counts the body claims (257, 84, 261, 311, 309, 259, 449). Where the port is not literally equivalent — three specs matched .test./.stories. on the basename, the walk matches a path suffix — it errs toward including more files, so a closed list fails loudly rather than passing by vacuum.
Nine callers is well past the single-caller bar, so the options object earns its keep. The one piece #286 did not ask for is the import-boundary spec, and it is the weakest thing here.
Findings
- should-fix —
docs/testing.md:379: the regrowth rule is a grep nothing runs, while the new guard covers a harm with no occurrences. Oneno-restricted-importsentry gates both. - consider —
src/test-support/source-tree.test.ts:73: that guard encodes a policysrc/mocks/←src/views/story-harness.tsxalready breaks, and it misses stories.
What was checked
The nine were set-diffed by script, not read. Every option asserted to bite against the real tree, and its anchor files exist, so none is vacuous. grep -rln readdirSync src/ names only the walker. Only the nine specs name test-support, which is what makes the unchanged pnpm size credible. eslint.config.js carries no no-restricted-imports. No contract surface is touched — test-only modules plus two docs.
⚠ ## Preview's "same build as main" is unverifiable as written. Both previews deployed, but the branch alias and sahajatlas.pages.dev differ on 3 of 6 eager chunk hashes: Pages builds Preview and Production from separate environments (docs/testing.md, #244), and no preview of main exists to compare against.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The regrowth rule #286 left behind was a grep nothing runs. One `no-restricted-imports` entry turns it into a `pnpm lint` failure, at the import, in the editor. `importNames: ['readdirSync']` is what keeps the single-file readers out of it — `translations.test.ts` keeps `readFileSync`, `Widget.standalone.test.ts` keeps `existsSync` and `statSync`. Both specifiers are listed because `from 'fs'` would otherwise walk straight past a rule naming only `node:fs`. Watched red at four sites and green at two: the named import from each specifier, the namespace import (ESLint reports `* as fs` when `importNames` is set), against `readFileSync` and against the walker itself. #286 rejected the lint route for the nine closed lists, correctly — lint cannot carry their positive half. This rule has no positive half. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_013unzZj5MVQxnjXPfa5d2FB
The `describe` claimed nothing but a spec imports the walk, while the scope
left stories out — so a story importing it passed. Watched both ways against
the same probe in `Drawer.stories.tsx`: green under `sourceFiles()`, red under
`sourceFiles({ includeStories: true })`. A story ships to the Ladle build, so
it belongs in the claim.
The docblock also read as a policy the repo does not hold: test-only code
under `src/` has no app importer. `src/mocks/` is browser-safe data and
`src/views/story-harness.tsx` imports it deliberately. The real distinction is
the `node:fs` import, and the docblock now says so where the next reader meets
the question.
The note about keeping `readdirSync` out of this file went with the grep it
served.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013unzZj5MVQxnjXPfa5d2FB
|
Both review threads answered, two commits pushed. Adopted — the regrowth rule nothing enforced. Adopted in part — the import-boundary guard. Body — the ⚠ was right that Lean gate green: 140 files, 1709 tests. Both gates watched red at their causing sites first. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#288 (#286) moved the nine `src/` inventories onto `src/test-support/source-tree.ts`, so they stopped calling `readdirSync(` and the walker detector lost all nine. The closed list in `select-unit-specs.test.ts` failed the merge-queue run, as designed. A spec that imports the shared walk is a walker now, found through the reference index, which already resolves `@/`, relative and quoted-path specifiers. That also picks up `source-tree.test.ts`, whose import boundary check reads the whole tree. `wrangler-config.test.ts`, which landed with #300, matches `readdirSync(` on the repo root. It is over-included on purpose, the way the detector is meant to err. Twelve walkers instead of ten, so the widest selection is 24 (`src/config/i18n.ts`, `src/lib/shape/index.ts`). On the same machine the 24-spec run measured no slower than the 22-spec one (~2.0s vs ~2.1s, 11 cores), so the ceiling moves to 26 to keep the same headroom. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
src/share one walk instead of each rolling its ownreaddirSync.Change outline
The nine each assert that a list of call sites is CLOSED. The walk was the duplicated part; the scope never was.
Files
Contract — the scope each spec now declares for itself
Nine callers, seven scopes. Each difference is load-bearing, so each spec states its own beside the assertions it serves.
Flow — what each of the nine dropped
Behaviour — two gates, in opposite directions
src/test-support/is the first non-spec code undersrc/to import a node builtin, and both the bundler andpnpm sizeare blind to who imports it.Preview
Nothing a preview can show: the diff is specs, test-only modules, a lint rule and docs, so no module in either bundle changed.
pnpm sizereportsstandalone309.1 KiB,loader2.8 KiB,embed310.9 KiB — all three unchanged frommain, measured in this checkout againstmain's own numbers.⚠ Comparing the two deployed previews cannot show this, and the first revision of this section claimed it could. Pages builds Preview and Production from separate dashboard environments (
docs/testing.md, #244), so the branch alias andsahajatlas.pages.devdiffer on eager chunk hashes whatever the diff is, and no preview ofmainexists to compare against. The byte-identical claim rests on the localpnpm sizenumbers above, not on the preview.Test results
pnpm lint && pnpm typecheck && pnpm test:run— 140 files, 1709 testspnpm build(incl.assert:css,assert:maps),pnpm size✓ all three graphs,pnpm ladle:build✓no-restricted-imports, watched red at four sites and green at two — see Detailcomment-lint.mjs --base origin/main→ no banned comment addedManual verification
Nothing by hand. Both claims a reviewer would otherwise take on trust were measured — see Detail.
Notes for reviewer
.filter()predicates at the call sites — fewer concepts, but the drift this ticket is about would be free to come back. The options name real distinctions (a story IS one of the two sanctioned viewport callers; a story is NOT the app using a lucide glyph), not nine callers' preferences.src/#286 proposed, and the two do not conflict. test(build): one source walker for the nine specs that inventorysrc/#286 asked whether the nine closed lists could become lint rules; they cannot, because lint carries no positive half (isSafeHrefis called,frameCollision()is spread), and that rejection stands below.no-restricted-importsonreaddirSynchas no positive half to carry, so the reason does not reach it.includeDeclarations/includeGeneratedTypesaway and exclude.d.tsandtypes/payload/unconditionally — it narrows six specs' scopes, which is the one thing test(build): one source walker for the nine specs that inventorysrc/#286's criteria forbid. The argument for it is that those five files cannot hold a scanned token, and that is a claim about content, not scope:translations.test.tsexcludestypes/payload/precisely BECAUSE the generated types name every translation key as a property, so the file is not inert.no-restricted-imports/no-restricted-syntax— a real proposal, and the analysis holds for the Radix poppers, the JSX anchors andannounceEmbed. It is rejected here because lint cannot carry the positive half of any of the three (isSafeHrefis called,frameCollision()is spread), so each rule would end up with two homes and the spec would stay. Worth deciding separately; not worth widening this PR.importGraphonto src-relative paths so its 231 reads hit the memo — measured at ~10ms, against rewriting the one intricate module-resolution routine in the repo's live-preview seam spec.src/mocks/is browser-safe data, andsrc/views/story-harness.tsximports it on purpose — app-named, inside the default scope. So the distinction the guard draws is thenode:fsimport, not "test-only code undersrc/", and the docblock says that where the next reader meets the question.readRepoSourcesupersedes #289 — six other specs carry private per-filesrc/readers thatreadSourcenow supersedes (views/MapFrame.test.tsxandWidget.theme-root.test.tsxare byte-identical to it). Outside this ticket's walk, and past the direct-fix bound, so it is its own issue rather than a wider diff here.Detail
Equivalence was proven twice, independently. A throwaway spec reimplemented all seven original predicates — including the
withFileTypesbasename.includes('.test.')form and both hand-rolled recursions — and asserted set equality against the new options; all seven matched, and it was deleted. A review lens then replayed the same nine predicates against the real 455-entry tree and reported 0 files either way on all nine:reads.inventory257,href84,overlay.popper261,responsive/Widget.standalone/announce-site311,translations309,Icons.usage259,use-map-controller449.Every spec was watched red at its own causing site, per
docs/testing.md's rule that a new assertion is not finished until it has failed:Widget.standaloneimport './config/live-preview/boot'inWidget.tsxconfig/responsive'768px'literal in an atomhooks/use-map-controllervar(--sy-drawer-w, 999px)instyles/base.csslib/overlay.popperlib/shape/hrefconfig/api/reads.inventorysdk.find({ collection: 'regions' })with nolimitIcons/Icons.usageconfig/translationst('mutant.missing.key')lib/announce-siteannounceEmbed()call siteTen mutations of the walker against
source-tree.test.tswent red too: each of the four defaults flipped,extensionsignored, each half of the comment strip removed, the[^:]URL guard broken, the stripped reader made raw, andlib/scope.tsimporting the walk. All 19 red, run one at a time with the mutation reverted after each.The two gates added in review were watched the same way. The lint rule, against a probe module under
src/lib/: red onimport { readdirSync } from 'node:fs', red on the same import from'fs', red onimport * as fs from 'node:fs'(ESLint reports a namespace import onceimportNamesis set), green onreadFileSync, and green onsrc/test-support/source-tree.tsitself. The import boundary, against one probe appended toDrawer.stories.tsx: green undersourceFiles()— the gap the review named — and red undersourceFiles({ includeStories: true }). Both probes were deleted.The lane cost did not change, and that is expected. Vitest gives each spec file its own module registry, so the module-level walk and the memos are per-file: the tree is still read once per spec, as before. Median of three
pnpm test:runruns in one worktree on 4 cores, with the branch applied and then with the nine originals restored fromHEAD: 28.6s before, 28.8s after, with ~1s spread inside each triple. #285 owns the lane's total. The win is one walk implementation and one comment stripper, not fewer walks.The two-module split is neutral against
main, not a win.require('typescript')measures 244ms and 20.3MB heap, and the seven non-parsing specs did not pay it before either. The split is what stops a single-module design introducing that regression.Rejected simplifications are only three of fifteen findings. The rest were applied in
f5ebd1d: the fourth copy of the comment stripper (left behind inWidget.standalone.test.tsbecausespecifiers()takes a string), a double strip at one of its three call sites, three pasted memo preambles that had already diverged oncached !== undefinedvs truthy, three docblocks claiming the memos last "once per process", the ⚠ scopes rule stated four times,SourceScopeandSRC_DIRexported with no importer, a.cssassertion pinned to an exhaustive four-file list, and a strip test that asserted on a sentence insidesource-tree.ts's own docblock — so rewording a comment broke a test and the failure pointed at the stripper.Closes #286