Skip to content

test(build): a repo-root reader, so the new URL(…, import.meta.url) trap can be linted - #303

Merged
sydevs-bot merged 5 commits into
mainfrom
claude/test-302-repo-source-reader
Oct 16, 2026
Merged

sydevs-bot merged 5 commits into
mainfrom
claude/test-302-repo-source-reader

Conversation

@sydevs-bot

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

Copy link
Copy Markdown
Contributor

Summary

  • Decision recorded: yes, the repo wants a second rooted reader. readRepoSource owns the repo root; readSource keeps src/ and now reads through it.
  • eslint.config.js fails any spec, anything in test-support/, and any scripts/**/*.mjs that writes new URL(…, import.meta.url), so the trap is a rule instead of prose.
  • The ticket's proposed root carried the trap itself. Measured, and replaced with one that does not.

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.

 under `environment: 'node'`            — every form yields a file: URL
 under `// @vitest-environment jsdom`   — Vite's WEB transform
-  new URL('.', import.meta.url)        → http://localhost:3000/src/test-support
-    fileURLToPath(…)                   → THROWS "The URL must be of scheme file", at IMPORT
+  import.meta.url                      → file:///…/src/test-support/<spec>   # left alone
+    dirname(fileURLToPath(…))          → /…/src/test-support

Files — src/test-support/ gains the lower half

 src/test-support/
+├── repo-source.ts    # REPO_ROOT + readRepoSource(<repo-relative path>) — the one root a
+│                     # spec reads a repo FILE through
 ├── source-tree.ts    # the ONE walk of `src/`; SRC_DIR and readSource now go through it
 └── source-ast.ts     # unchanged

Nine specs stop resolving their own root. Two reads reached outside src/ where readSource cannot follow (vite.config.ts, docs/embedding.md, two build scripts, public/_headers); the rest are inside src/ 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.js

 eslint.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/**/*.mjs

test-support/ is in scope because source-tree.ts is the file the defect actually killed, and it is no spec — a spec-only rule would not have caught the original. scripts/**/*.mjs is 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, and select-unit-specs.mjs was resolving its root the banned way while a spec imported it. A .mjs cannot import the .ts reader, so its root is dirname(fileURLToPath(import.meta.url)), which the lint message now names beside readRepoSource. Shipped code and the build configs stay out: src/styles/fonts.ts and .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.mjs takes resolve rather than join, because its path comes from process.argv[2] and new URL resolves an absolute argument against the root where join would append it — pnpm ladle:build's ../build and 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:maps and pnpm size were run as a check, not because anything ships.

Test results

  • Lean gate: ✓ pnpm lint && pnpm typecheck && pnpm test:run — 145 files, 1754 tests
  • Build: ✓ pnpm build (both rewritten gates ran: assert:css over 1176 rules, assert:maps over 23 files) + pnpm size (standalone 309.1/318, loader 2.8/3.5, embed 310.9/318 KiB)
  • Comment lint: ✓ no banned phrasing added across 21 changed files

Each new failure was watched, at the site that causes it:

  • Resolve REPO_ROOT the banned way → repo-source.jsdom.test.ts dies at collection with TypeError: The URL must be of scheme file. Restored, green.
  • Add the form back to sheet.test.ts and to source-tree.ts → pnpm lint red in both, and silent on fonts.ts. Removed, green.
  • Add the form back to scripts/sync-translations.mjs → pnpm lint red there, and silent on src/styles/fonts.ts, .ladle/config.mjs and .ladle/vite.config.ts. Removed, green.

Manual verification

  1. The ticket's grep returns only prose: grep -rn "new URL(.*import.meta.url" src/ --include='*.test.ts' --include='*.test.tsx'.
  2. The per-edit budget is unmoved — walker set still 12, widest selection still 24 (src/config/i18n.ts), measured through selectFrom against this tree. An edit to repo-source.ts itself selects 20.
  3. Every rewritten script constant printed beside the expression it replaces, including process.argv[2] as ../dist, ../build, dist, /tmp/out and ./x/../y. All identical; join is the one that would have differed, on the absolute argument.
  4. node --check over every scripts/*.mjs, and each resolved constant confirmed to point at a file that exists (openapi.json excepted — the script writes it, and it is gitignored).

Notes for reviewer

Three judgement calls, each a deviation from the ticket's letter:

  • The ticket proposed resolving the new reader "off the same SRC_DIR-derived root". That root is new 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 is dirname(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 .mjs modules 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.ts takes REPO_ROOT for its root enumeration; postcss-scope-widget.test.ts also had one read resolved off the cwd, which the same reader settles.
  • Acceptance criterion 5 asks to drop the "four live sites" warning test(build): the private spec readers readRepoSource supersedes #289 left in docs/testing.md. No such warning is on main — grep -n "live sites" docs/testing.md is empty. Nothing to drop; the rest of that criterion is done.

Dismissed review findings:

  • Widen the ban to fileURLToPath(import.meta.url), which five specs write — measured false. MapFrame.test.tsx and Widget.theme-root.test.tsx are both jsdom, both write that form, and both pass: bare import.meta.url survives the web transform. Those five specs are untouched because they are not carrying the defect.
  • Collapse the three copies of the match assertion 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.
  • Key walker detection on the named import rather than the module specifier — would change a mechanism docs/testing.md prices and select-unit-specs.test.ts pins; it needs its own measurement.
  • Hand the root down from vitest.config.ts via test.env — unnecessary once the root stopped needing a fallback, and it would tie the module to the vitest pipeline.
Detail

Why repo-source.ts is not part of source-tree.ts. Importing source-tree.ts is what marks a spec a tree-walker in scripts/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.ts is also simply the lower half: it owns the root that source-tree.ts derives src/ from, and readSource is now one line over readRepoSource, 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.mjs resolves its own, because a .mjs cannot import the .ts reader, and five specs read bare import.meta.url for 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 through source-tree.ts's memo, which forced memo out into a third module. Across every call site exactly one path is read twice in a single module registry, so the cache bought one readFileSync and cost a module; readSource keeps 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; the pr-review-toolkit plugin 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 by source-tree.test.ts's "nothing outside test-support/ imports the test support"), and every readRepoSource call site is a literal but one, which comes from a readdirSync dirent matched against an anchored regex. The re-run over the script rewrites checked the thing worth checking — that a moved root cannot make assert-no-sourcemaps scan the wrong directory and pass vacuously. It cannot: the path is identical, and both the existsSync(OUT_DIR) and the scanned === 0 guards are untouched, with a live run reading 23 real files.

Closes #302

🤖 Generated with Claude Code

https://claude.ai/code/session_01EQRZC9QxrLdsYQSfJnDFPp

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

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

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
sahajatlas-design d112dd1 Oct 16 2026, 08:11 AM

@sydevs-bot

sydevs-bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 07:43Z address-review · attempt 1 · session · done
  • 07:43Z address-review · attempt 1 · session
  • 07:35Z review-pr · attempt 1 · session · done
  • 07:35Z review-pr · attempt 1 · session

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

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

@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 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.md carries no "four live sites" warning and no prose naming the trap. The claim is correct.
  • eslint.config.js whole — the new block is the only no-restricted-syntax, so it shadows nothing.
  • SRC_DIR moving to join(REPO_ROOT, 'src') from a trailing-slash URL path: every use is relative/join, so nothing weakens silently. Same for ROOT.
  • SHARED_WALK keys on source-tree.ts alone, 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

Comment thread scripts/select-unit-specs.test.ts Resolved
Comment thread AGENTS.md 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 16, 2026
`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
@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

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

View logs

@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Both review threads adopted, two commits pushed (d112dd1).

  • should-fix: the root a spec imports → fad5311. The lint rule's third scope is now scripts/**/*.mjs — five of them are imported by a spec, so the trap had the same reach there that killed source-tree.ts. Six constants moved with it, each measured identical to the form it replaces.
  • consider: "the ONE module" → d112dd1. AGENTS.md now claims what the module holds: the one root a spec reads a repo file through. The five specs with their own root stay out.

Nothing rebutted. Lean gate green (145 files, 1754 tests), pnpm build + pnpm size green, security pass clean. The ban was watched failing in scripts/, and silent on fonts.ts and .ladle/. PR body refreshed: this push made its reader line and rule table false.

🤖 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 16, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 16, 2026 08:14
@sydevs-bot
sydevs-bot requested a review from Ardnived October 16, 2026 08:14
@sydevs-bot
sydevs-bot enabled auto-merge October 16, 2026 08:14
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Oct 16, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 16, 2026
Merged via the queue into main with commit f09ac88 Oct 16, 2026
52 of 54 checks passed
@sydevs-bot
sydevs-bot deleted the claude/test-302-repo-source-reader branch October 16, 2026 17:15
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Oct 16, 2026
sydevs-bot pushed a commit that referenced this pull request Oct 16, 2026
#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
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): a repo-root reader, so the new URL(…, import.meta.url) trap can be linted

3 participants