Repository navigation
test(build): a repo-root reader, so the new URL(…, import.meta.url) trap can be linted - #303
Conversation
`readSource` is `src/`-relative by contract, so nine specs resolved a path beside `src/` themselves, each writing `new URL(<path>, import.meta.url)`. Vite REWRITES that expression under its web transform, which vitest picks for every jsdom spec, so it yields `http://localhost:3000/…` and `fileURLToPath` throws AT IMPORT — the file dies before one assertion runs. It cost `source-tree.ts` exactly that (#289). `readRepoSource` (`src/test-support/repo-source.ts`) owns the root now. `source-tree.ts` derives `src/` from it and `readSource` reads through it, so one module resolves a root and one function reaches the disk. Measured on this tree, under jsdom: `new URL('.', import.meta.url)` gives `http://localhost:3000/src/test-support`, while bare `import.meta.url` is left alone and stays a `file:` URL. So the root is `dirname(fileURLToPath(import.meta.url))` — correct under both transforms and from any working directory, with no fallback to caveat. `repo-source.jsdom.test.ts` holds it, watched failing at collection when the root is resolved the banned way. It is a separate module from the walk on purpose: `repo-source.ts` is the lower half, and importing `source-tree.ts` is also what marks a spec a tree-walker, which runs on every edit. The walker set stays 12 and the widest selection 24, both measured. `scripts/` is in scope: the hazard does not depend on the directory, and four specs there wrote the same form. `postcss-scope-widget.test.ts` also read one path off the cwd, which the same reader settles. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011jq8gunEGvEnXy3syY3VAP
The reader rule was prose, where #286's sibling hazard is a lint rule — `no-restricted-imports` bans a second `readdirSync`, "caught at the import instead of by a grep nobody runs". This closes the other half. `no-restricted-syntax` fails any spec, and anything under `src/test-support/`, that writes the form. `test-support/` is in scope because `source-tree.ts` is the file the defect actually killed and it is no spec, so a spec-only rule would not have caught the original. Watched failing from both scopes, and not on `src/styles/fonts.ts`. Shipped code stays out: `fonts.ts` writes the same form as Vite's asset-URL idiom, which is what the form is for. The ban is on that one expression and not on `import.meta.url`, because bare `import.meta.url` is measured to survive the web transform intact. `sheet.adopt.test.ts` had recorded the wrong root cause for its sibling's node-only environment since the comment was written: jsdom's `import.meta.url` was blamed for what Vite's rewrite does. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011jq8gunEGvEnXy3syY3VAP
`docs/testing.md`'s `src/test-support/` section had the walk's lint rule and the reader rule as prose beside it. It now carries both, plus the measurement that decides the rule's shape: Vite rewrites the expression, not the property. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011jq8gunEGvEnXy3syY3VAP
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
sahajatlas-design | d112dd1 | Oct 16 2026, 08:11 AM |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the size of #302: a recorded decision, a reader, a rule, docs. The three new files are the reader and its two specs, and the jsdom half is the only place the property can be asserted, so none is spare. The separate module earns itself on a number, not a preference — importing source-tree.ts marks a spec a tree-walker, and the walkers run on every edit.
Replacing the ticket's proposed SRC_DIR-derived root with dirname(fileURLToPath(…)) is the right reversal: the ticket's root carried the trap it was meant to remove. Rewiring palette.defaults.test.ts, which the ticket's list of seven missed, is forced by the rule, not smuggled in.
One gap, below: the rule stops short of scripts/*.mjs, and this PR routes a root through one.
Findings
- should-fix —
scripts/select-unit-specs.test.ts:19: the root it imports is resolved the banned way, in a module the new rule does not cover. - consider —
AGENTS.md:196: "the ONE module resolving the REPO root" is not true as shipped.
What was checked
- Full diff from the attached checkout, against
origin/main, with #302 beside it. grep -rn 'import\.meta\.url'over the tree:select-unit-specs.mjs:25,.ladle/and the build scripts remain. The five specs the body dismisses read the bare property, so that dismissal holds.- Criterion 5 against
main:docs/testing.mdcarries no "four live sites" warning and no prose naming the trap. The claim is correct. eslint.config.jswhole — the new block is the onlyno-restricted-syntax, so it shadows nothing.SRC_DIRmoving tojoin(REPO_ROOT, 'src')from a trailing-slash URL path: every use isrelative/join, so nothing weakens silently. Same forROOT.SHARED_WALKkeys onsource-tree.tsalone, so "walker set still 12" holds by construction.- No contract surface touched.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`select-unit-specs.mjs` resolved the repo root the banned way, and a spec imports it — the position `source-tree.ts` was in when the defect killed it. Node-only today, so nothing crashed, but prose was again the only thing holding it. The rule's third scope is `scripts/**/*.mjs`, because five of them are imported by a spec and so sit in the lane's module graph. A `.mjs` cannot import the `.ts` reader, so each root is `dirname(fileURLToPath(import.meta.url))` and the lint message now names that form beside `readRepoSource`. Every rewritten constant was measured against the form it replaces, and all eight resolve identically. `assert-no-sourcemaps.mjs` takes `resolve` rather than `join`: its path comes from `process.argv[2]`, and `new URL` resolves an absolute argument against the root where `join` would append it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EQRZC9QxrLdsYQSfJnDFPp
`AGENTS.md` called `repo-source.ts` "the ONE module resolving the REPO root". It is not: `select-unit-specs.mjs` resolves its own, because a `.mjs` cannot import the `.ts` reader, and five specs read the bare property for a root of their own. It is the one root a spec reads a repo FILE through, which is the claim the module actually holds. `docs/testing.md` gains the rule's `scripts/**/*.mjs` scope and why the module graph, not the directory, is what decides it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EQRZC9QxrLdsYQSfJnDFPp
Deploying sahajatlas with
|
| Latest commit: |
d112dd1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://4fbb7c6e.sahajatlas.pages.dev |
| Branch Preview URL: | https://claude-test-302-repo-source.sahajatlas.pages.dev |
|
Both review threads adopted, two commits pushed (
Nothing rebutted. Lean gate green (145 files, 1754 tests), 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#303 moved this selector's repo root off `new URL(…, import.meta.url)` and lifted the spec's header comment above its imports, where this branch had rewritten that comment in place. Kept #303's structure and this branch's wording, since the sentence about walkers staying out of the selection is what #293 changes. `repo-source.ts`'s rationale in docs/testing.md rested on walkers running on every edit, which this branch ends. Restated against the new behaviour: a reader importing the walk would now take its callers off the inner loop instead of onto every edit. The module split stands either way. Re-measured the two totals the merge moved: 420 lane sources, not 417, and `translations.test.ts` reaches 7 of them. 117 selecting nothing and the widest at 14 are unchanged. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GSuT7wgPRVBUbR9bRgHwEP
Summary
readRepoSourceowns the repo root;readSourcekeepssrc/and now reads through it.eslint.config.jsfails any spec, anything intest-support/, and anyscripts/**/*.mjsthat writesnew URL(…, import.meta.url), so the trap is a rule instead of prose.Change outline
Behaviour — what each form resolves to under vitest's two transforms
Measured on this tree, with a throwaway jsdom spec. This is what decides the whole change: Vite rewrites the expression, not the property.
Files —
src/test-support/gains the lower halfNine specs stop resolving their own root. Two reads reached outside
src/wherereadSourcecannot follow (vite.config.ts,docs/embedding.md, two build scripts,public/_headers); the rest are insidesrc/and deliberately come here anyway — see the note below on why they do not take the walk.Files — the two lane rules in
eslint.config.jseslint.config.js ├── src/**/*.{ts,tsx}, not test-support/ no-restricted-imports: readdirSync (#286) +└── **/*.{test,spec}.{ts,tsx}, test-support/, no-restricted-syntax: new URL(…, i.m.url) (#302) + scripts/**/*.mjstest-support/is in scope becausesource-tree.tsis the file the defect actually killed, and it is no spec — a spec-only rule would not have caught the original.scripts/**/*.mjsis in scope for the same reason one directory over: five of them are imported by a spec, so they sit in the lane's module graph too, andselect-unit-specs.mjswas resolving its root the banned way while a spec imported it. A.mjscannot import the.tsreader, so its root isdirname(fileURLToPath(import.meta.url)), which the lint message now names besidereadRepoSource. Shipped code and the build configs stay out:src/styles/fonts.tsand.ladle/write the same form as Vite's asset-URL idiom, which is what the form is for.Six script constants moved with the rule. Each was measured against the form it replaces and resolves identically.
assert-no-sourcemaps.mjstakesresolverather thanjoin, because its path comes fromprocess.argv[2]andnew URLresolves an absolute argument against the root wherejoinwould append it —pnpm ladle:build's../buildand an absolute path both land where they did.Preview
Nothing to preview. The branch changes specs,
eslint.config.js, six build scripts and two Markdown files, so the deployed output is unchanged —pnpm build,pnpm assert:css,pnpm assert:mapsandpnpm sizewere run as a check, not because anything ships.Test results
pnpm lint && pnpm typecheck && pnpm test:run— 145 files, 1754 testspnpm build(both rewritten gates ran:assert:cssover 1176 rules,assert:mapsover 23 files) +pnpm size(standalone 309.1/318, loader 2.8/3.5, embed 310.9/318 KiB)Each new failure was watched, at the site that causes it:
REPO_ROOTthe banned way →repo-source.jsdom.test.tsdies at collection withTypeError: The URL must be of scheme file. Restored, green.sheet.test.tsand tosource-tree.ts→pnpm lintred in both, and silent onfonts.ts. Removed, green.scripts/sync-translations.mjs→pnpm lintred there, and silent onsrc/styles/fonts.ts,.ladle/config.mjsand.ladle/vite.config.ts. Removed, green.Manual verification
grep -rn "new URL(.*import.meta.url" src/ --include='*.test.ts' --include='*.test.tsx'.src/config/i18n.ts), measured throughselectFromagainst this tree. An edit torepo-source.tsitself selects 20.process.argv[2]as../dist,../build,dist,/tmp/outand./x/../y. All identical;joinis the one that would have differed, on the absolute argument.node --checkover everyscripts/*.mjs, and each resolved constant confirmed to point at a file that exists (openapi.jsonexcepted — the script writes it, and it is gitignored).Notes for reviewer
Three judgement calls, each a deviation from the ticket's letter:
SRC_DIR-derived root". That root isnew URL('..', import.meta.url)— the trap. A reader built that way centralises the crash without removing it, and a jsdom spec importing it still dies. The measurement above is why the root isdirname(fileURLToPath(import.meta.url))instead: no fallback, no cwd assumption, correct from any directory.scripts/is in scope (the ticket asked for a decision rather than an assumption), its.mjsmodules included after review. The hazard does not depend on the directory, and leaving known instances of the banned form would be the "prose is the only enforcement" failure again.wrangler-config.test.tstakesREPO_ROOTfor its root enumeration;postcss-scope-widget.test.tsalso had one read resolved off the cwd, which the same reader settles.readRepoSourcesupersedes #289 left indocs/testing.md. No such warning is onmain—grep -n "live sites" docs/testing.mdis empty. Nothing to drop; the rest of that criterion is done.Dismissed review findings:
fileURLToPath(import.meta.url), which five specs write — measured false.MapFrame.test.tsxandWidget.theme-root.test.tsxare both jsdom, both write that form, and both pass: bareimport.meta.urlsurvives the web transform. Those five specs are untouched because they are not carrying the defect.matchassertion helper (ci-workflows,select-unit-specs,host-reset) — real duplication, but a separate concern with a diverged signature and its own home question. Not folded in.docs/testing.mdprices andselect-unit-specs.test.tspins; it needs its own measurement.vitest.config.tsviatest.env— unnecessary once the root stopped needing a fallback, and it would tie the module to the vitest pipeline.Detail
Why
repo-source.tsis not part ofsource-tree.ts. Importingsource-tree.tsis what marks a spec a tree-walker inscripts/select-unit-specs.mjs, and the walkers run on every edit in the lane. Folding the reader in there would have moved four single-file readers into that set.repo-source.tsis also simply the lower half: it owns the root thatsource-tree.tsderivessrc/from, andreadSourceis now one line overreadRepoSource, so one function reaches the disk.It is the one root a spec reads a repo FILE through, not the only root in the repo.
select-unit-specs.mjsresolves its own, because a.mjscannot import the.tsreader, and five specs read bareimport.meta.urlfor a root of their own (Widget.standalone,MapFrame,Widget.theme-root,Widget.translate,DynamicEventsList). Those five are safe under both transforms and stay as they are; what the lint rule removes is the one expression that is not.No memoisation on
readRepoSource. An earlier revision memoised it throughsource-tree.ts'smemo, which forcedmemoout into a third module. Across every call site exactly one path is read twice in a single module registry, so the cache bought onereadFileSyncand cost a module;readSourcekeeps its own memo, where hundreds of reads make it pay.Why the jsdom spec earns an extra environment. It is the only place the property can be asserted — every rewired reader is node-only, so nothing else in the lane would go red if the root regressed. It fails at collection rather than on an assertion, which its docblock says, because an ordinary failing expectation there would mean something else.
Reviewed with
/simplify(four lenses) and the built-in/security-review; thepr-review-toolkitplugin is not installed in a routine. The security pass found nothing, twice: the module does not reach the production bundle (vite.config.ts's three entries, pinned bysource-tree.test.ts's "nothing outsidetest-support/imports the test support"), and everyreadRepoSourcecall site is a literal but one, which comes from areaddirSyncdirent matched against an anchored regex. The re-run over the script rewrites checked the thing worth checking — that a moved root cannot makeassert-no-sourcemapsscan the wrong directory and pass vacuously. It cannot: the path is identical, and both theexistsSync(OUT_DIR)and thescanned === 0guards are untouched, with a live run reading 23 real files.Closes #302
🤖 Generated with Claude Code
https://claude.ai/code/session_01EQRZC9QxrLdsYQSfJnDFPp