Skip to content

test(build): one source walker for the nine specs that inventory src/ - #288

Merged
sydevs-bot merged 6 commits into
mainfrom
claude/test-286-one-source-walker
Oct 13, 2026
Merged

sydevs-bot merged 6 commits into
mainfrom
claude/test-286-one-source-walker

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Nine specs that inventory src/ share one walk instead of each rolling its own readdirSync.
  • Their seven file scopes are unchanged and stay at the specs; a new spec asserts each option still bites.

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

 src/test-support/              # NEW — imported by specs only, and a spec asserts that
+├── source-tree.ts             # the ONE walk of src/, the memoised reads, the comment strip
+├── source-ast.ts              # memoised ts.SourceFile, split so the walk never loads `typescript`
+└── source-tree.test.ts        # every option biting both ways, the strip, the import boundary

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.

sourceFiles()                                             lib/overlay.popper
sourceFiles({ includeStories: true })                     Widget.standalone, config/responsive,
                                                          lib/announce-site
sourceFiles({ extensions: ['.tsx'] })                     lib/shape/href
sourceFiles({ includeDeclarations: false })               components/atoms/Icons/Icons.usage
sourceFiles({ includeDeclarations: false,                 config/api/reads.inventory
              includeGeneratedTypes: false })
sourceFiles({ includeStories: true,                       config/translations
              includeGeneratedTypes: false })
sourceFiles({ extensions: ['.ts', '.tsx', '.css'],        hooks/use-map-controller
              includeSpecs: true, includeStories: true })

Flow — what each of the nine dropped

 <spec>
-  readdirSync(SRC, …)                 # recursive+utf8 (4), recursive+withFileTypes (2), hand-rolled (3)
-  .map(p => p.split(sep).join('/'))   # present in 5 of the 9, absent from the rest
-  stripComments(source)               # four verbatim copies, counting the one left behind at first
-  readFileSync(join(SRC, path))       # re-read per assertion
-  ts.createSourceFile(…)              # two copies, two different ScriptKind rules
+  sourceFiles({ …its own scope })
+  readSource(path) / readSourceWithoutComments(path)
+  parseSource(path)

Behaviour — two gates, in opposite directions

src/test-support/ is the first non-spec code under src/ to import a node builtin, and both the bundler and pnpm size are blind to who imports it.

 eslint.config.js                       # NO SECOND WALK may be written
+  no-restricted-imports: node:fs + fs, importNames: ['readdirSync']
+    files: src/**/*.{ts,tsx}, ignores: src/test-support/**
+    # importNames leaves the single-file readers alone: readFileSync, existsSync, statSync
+    # this replaces a `grep -rln readdirSync src/` line in docs/testing.md that nothing ran

 source-tree.test.ts                    # THE ONE WALK may not be imported by the app
+  nothing outside `test-support/` imports the test support
+    every file in sourceFiles({ includeStories: true }) outside test-support/
+      → must not name `test-support`
+    # an app module importing the walk would ship a node:fs directory walk to every host page
+    # Widget.standalone's graph walk cannot see this: resolveModule returns null for `node:`
+    # lint cannot see it either — the importer writes no readdirSync of its own

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 size reports standalone 309.1 KiB, loader 2.8 KiB, embed 310.9 KiB — all three unchanged from main, measured in this checkout against main'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 and sahajatlas.pages.dev differ on eager chunk hashes whatever the diff is, and no preview of main exists to compare against. The byte-identical claim rests on the local pnpm size numbers above, not on the preview.

Test results

  • Lean gate: ✓ pnpm lint && pnpm typecheck && pnpm test:run — 140 files, 1709 tests
  • Build: ✓ pnpm build (incl. assert:css, assert:maps), pnpm size ✓ all three graphs, pnpm ladle:build ✓
  • The regrowth gate is no-restricted-imports, watched red at four sites and green at two — see Detail
  • comment-lint.mjs --base origin/main → no banned comment added

Manual verification

Nothing by hand. Both claims a reviewer would otherwise take on trust were measured — see Detail.

Notes for reviewer

  • The one judgement to check is the options object. It is the seam that lets seven scopes share one walk. The alternative was exporting the raw file list and leaving nine .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.
  • The lint rule is not the lint route test(build): one source walker for the nine specs that inventory src/ #286 proposed, and the two do not conflict. test(build): one source walker for the nine specs that inventory src/ #286 asked whether the nine closed lists could become lint rules; they cannot, because lint carries no positive half (isSafeHref is called, frameCollision() is spread), and that rejection stands below. no-restricted-imports on readdirSync has no positive half to carry, so the reason does not reach it.
  • Three review findings were rejected, each for a stated reason:
    • Fold includeDeclarations / includeGeneratedTypes away and exclude .d.ts and types/payload/ unconditionally — it narrows six specs' scopes, which is the one thing test(build): one source walker for the nine specs that inventory src/ #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.ts excludes types/payload/ precisely BECAUSE the generated types name every translation key as a property, so the file is not inert.
    • Move three specs' closing direction to no-restricted-imports / no-restricted-syntax — a real proposal, and the analysis holds for the Radix poppers, the JSX anchors and announceEmbed. It is rejected here because lint cannot carry the positive half of any of the three (isSafeHref is 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.
    • Rewrite importGraph onto 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.
  • The import boundary covers stories, and its docblock no longer claims a policy the repo does not hold. src/mocks/ is browser-safe data, and src/views/story-harness.tsx imports it on purpose — app-named, inside the default scope. So the distinction the guard draws is the node:fs import, not "test-only code under src/", and the docblock says that where the next reader meets the question.
  • Filed on the way: test(build): the private spec readers readRepoSource supersedes #289 — six other specs carry private per-file src/ readers that readSource now supersedes (views/MapFrame.test.tsx and Widget.theme-root.test.tsx are 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 withFileTypes basename .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.inventory 257, href 84, overlay.popper 261, responsive/Widget.standalone/announce-site 311, translations 309, Icons.usage 259, use-map-controller 449.

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:

Spec Defect reintroduced
Widget.standalone import './config/live-preview/boot' in Widget.tsx
config/responsive a second '768px' literal in an atom
hooks/use-map-controller var(--sy-drawer-w, 999px) in styles/base.css
lib/overlay.popper a fifth Radix popper import
lib/shape/href a fourth JSX anchor
config/api/reads.inventory sdk.find({ collection: 'regions' }) with no limit
Icons/Icons.usage a lucide glyph the gallery does not list
config/translations t('mutant.missing.key')
lib/announce-site a second announceEmbed() call site

Ten mutations of the walker against source-tree.test.ts went red too: each of the four defaults flipped, extensions ignored, each half of the comment strip removed, the [^:] URL guard broken, the stripped reader made raw, and lib/scope.ts importing 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 on import { readdirSync } from 'node:fs', red on the same import from 'fs', red on import * as fs from 'node:fs' (ESLint reports a namespace import once importNames is set), green on readFileSync, and green on src/test-support/source-tree.ts itself. The import boundary, against one probe appended to Drawer.stories.tsx: green under sourceFiles() — the gap the review named — and red under sourceFiles({ 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:run runs in one worktree on 4 cores, with the branch applied and then with the nine originals restored from HEAD: 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 in Widget.standalone.test.ts because specifiers() takes a string), a double strip at one of its three call sites, three pasted memo preambles that had already diverged on cached !== undefined vs truthy, three docblocks claiming the memos last "once per process", the ⚠ scopes rule stated four times, SourceScope and SRC_DIR exported with no importer, a .css assertion pinned to an exhaustive four-file list, and a strip test that asserted on a sentence inside source-tree.ts's own docblock — so rewording a comment broke a test and the failure pointed at the stripper.

Closes #286

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
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

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

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 13, 2026
@sydevs-bot

sydevs-bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 08:53Z address-review · attempt 1 · session · done
  • 08:53Z address-review · attempt 1 · session
  • 08:38Z review-pr · attempt 1 · session · done
  • 08:38Z review-pr · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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. One no-restricted-imports entry gates both.
  • consider — src/test-support/source-tree.test.ts:73: that guard encodes a policy src/mocks/ ← src/views/story-harness.tsx already 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

Comment thread docs/testing.md Resolved
Comment thread src/test-support/source-tree.test.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 13, 2026
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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Both review threads answered, two commits pushed.

Adopted — the regrowth rule nothing enforced. 3501042 adds no-restricted-imports on readdirSync from node:fs and fs, scoped to src/** outside test-support/. docs/testing.md names the rule where it published the grep.

Adopted in part — the import-boundary guard. 02fc583 puts stories in scope, and drops the docblock's wider policy: src/mocks/ is browser-safe data story-harness.tsx imports on purpose. Rebutted: the guard stays. Lint bans a second walk; the spec bans importing the one walk, which writes no readdirSync.

Body — the ⚠ was right that ## Preview's "same build as main" was unverifiable from two previews. It now rests on the local pnpm size numbers.

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

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 13, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 13, 2026 09:07
@sydevs-bot
sydevs-bot requested a review from Ardnived October 13, 2026 09:07
@sydevs-bot
sydevs-bot enabled auto-merge October 13, 2026 09:07
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Oct 13, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 13, 2026
Merged via the queue into main with commit a5565b6 Oct 13, 2026
51 of 53 checks passed
@sydevs-bot
sydevs-bot deleted the claude/test-286-one-source-walker branch October 13, 2026 13:32
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Oct 13, 2026
Ardnived added a commit that referenced this pull request Oct 14, 2026
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

test(build): one source walker for the nine specs that inventory src/

3 participants