Repository navigation
perf(test): give the unit lane a per-edit budget it is actually under - #290
Conversation
… budget The PostToolUse hook ran `pnpm test:run` on every `src/**` edit. That cost ~35s on 4 cores and failed nothing, because the hook reports non-blocking context — so the "under ~5s" `docs/testing.md` asked for stopped being true with every gate green. `scripts/select-unit-specs.mjs` selects from three sources instead, because none of them reaches the others' couplings: the stem's co-located siblings, specs that reference the module by `@/` alias or by repo-relative path in a literal list, and the nine specs whose fixture is `readdirSync` over `src/` and which therefore hold no reference to what breaks them. `vitest related` was the obvious alternative and is not viable here: it reaches a second-hop coupling the selection misses, but measured 22s on `src/lib/geo.ts` alone against the lane's 35s. The full lane still runs in the lean gate and CI, so this narrows the inner loop and no gate. The budget is one number in `docs/testing.md` — 10s on 4 cores, against a measured 4.9s typical and 8.9s widest. What holds it is the selection's width, which `scripts/select-unit-specs.test.ts` pins exhaustively, together with the walker set as a closed list: a tenth walker would otherwise stop running per edit silently. Closes #285 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fykc2h9oeU3kcq72LoWcuL
…ound Four review lenses over the branch. What changed: The walker detector was `readdirSync`-only, so a spec enumerating the tree any other way would drop out of the per-edit set with every assertion still green — the silent loss of coverage this ticket exists to end. It now matches four enumerating calls, and the doc says plainly that a walker reaching the tree through a shared helper is still invisible to it (#286 is that change). The spec now pins `vitest.config.ts`'s own `include` and fails on a spec outside the two directories the selector looks in, so a new spec location cannot go uncovered quietly. Each of those assertions was watched failing at its cause. Simplifications: one shared tree walk instead of two, a prefix comparison instead of a built regex for co-located siblings, one eager text map instead of a lazy cache, one alternation instead of ten substring scans, and the fixture built once. The width sweep that guards the budget went 652ms to 316ms, which matters because this spec is itself in the always-run floor. The hook spawns `node_modules/.bin/vitest` rather than `pnpm test:run`: pnpm's script indirection measures ~0.5s on every edit. Its root now comes from the module's own location instead of `process.cwd()`. The budget is 12s, not 10s. The widest edit measures 9.0s median-of-three, and 10s left no room for a slower machine to be noticed rather than just wrong. Every figure in the section is re-measured: the lane ~36s, `vitest related` 26s on one file, the floor ~4.5s and 131 of 393 sources paying only it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fykc2h9oeU3kcq72LoWcuL
…'s name The selector looked for the module's `@/` alias or its quoted repo-relative path, and one module is addressed three ways. Both misses were real and silent: `fetch.test.ts` is the only spec for `src/config/api/client.ts` and reaches it as `'./client'`, so breaking `interceptFetch` left the hook green; `Chip.test.tsx` imports its own folder as `'.'`, so editing a per-component barrel selected no spec of that component at all. 17 such sibling pairs exist in this tree, and `src/AGENTS.md` reserves `@/` for deep paths, which makes the relative form the repo's normal style rather than an exception. Every quoted specifier in every spec is now resolved to the module it addresses, once, into an index the selection reads. That is one pass instead of a scan per source, so the width sweep that guards the budget fell from 316ms to 21ms — and the sweep now calls the real `selectFrom`, where before it re-composed the three sources itself and would have gone vacuously green on a fourth. Each specifier form is pinned end to end against this tree, and each was watched failing with its own branch removed. The budget stays 12s: the widest edit moved to `src/config/i18n.ts`, whose 22 specs include four jsdom ones, and measures 9.7s median-of-three. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Fykc2h9oeU3kcq72LoWcuL
Deploying sahajatlas with
|
| Latest commit: |
2702dbd
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://76f5e477.sahajatlas.pages.dev |
| Branch Preview URL: | https://claude-perf-285-unit-lane-bu.sahajatlas.pages.dev |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff meets #285's criteria and is honest that the third holds vacuously. Its numbers hold: I re-derived 393 lane sources, width min 10 / p50 11 / p90 12 / max 22, the ten walkers, and 124 sources selecting nothing else. Those same numbers say the walkers are nearly the whole cost — the 4.5s floor sits above the 4.3s typical selection — so the two reference sources buy coverage, not time.
The selector still earns its keep: vitest related measures 26s, and the project split narrows the floor rather than replacing selection. But 392 lines and twelve exports arrive for a ticket that asked for one number, and the lever that moves the median most is owned by nothing.
Findings
should-fixscripts/select-unit-specs.mjs:68—LANE_DIRSindexesscripts/; this gate refuses it, so noscripts/edit selects anything, the selector's own included.should-fixdocs/testing.md:250— 114 node-only files / 1701 tests omit the file this PR adds. 115 and 1713.considerscripts/select-unit-specs.mjs:110—referenceIndexandtreeWalkingSpecsare exported and named nowhere.considerscripts/select-unit-specs.mjs:174—readLaneruns before the lane gate, so every edit of any file pays the read.considerdocs/testing.md:412— the project-split lever has no ticket behind it.
What was checked
#285 and its criteria. The body against the diff: ## Change outline matches, and no ## Preview link exists, correctly — no src/ file is touched. Read whole: the hook, the selector, its spec, vitest.config.ts, both doc hunks. Re-derived from the real tree: the width sweep, the walkers, 124/393, readLane's 27ms. Timings not re-measured — no node_modules here. The quote scanner misses no specifier in all 140 specs. SahajCloud's hook is the same shape, its lane unmeasured, so no finding.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`LANE_DIRS` collected specs from `src/` and `scripts/`, so the reference index and the walker set both held the six `scripts/` specs — while `isLaneSource` refused every `scripts/` path. Editing the selector itself therefore ran nothing, and its spec ran on every unrelated `src/` edit instead. One list now governs both halves. `SOURCE_EXT` gains `.mjs`, because `scripts/` ships its sources as modules and its specs as TypeScript, and `listLaneSources` walks both directories so the width sweep measures what the hook now acts on. Width is unchanged at the top: 22 against a ceiling of 24, now tied between `src/config/i18n.ts` and `src/lib/shape/index.ts`. The 19 `scripts/` sources select 10 or 11 each — the walker floor plus their own spec. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018P9kaAfuJERNv3GbQT1va4
`referenceIndex` and `treeWalkingSpecs` were exported and named nowhere — not by the hook, not by the spec. `readLane` is the one caller of both, and it is what the spec reaches for. Of twelve exports only `REPO_ROOT` and `selectSpecs` have a production consumer; narrowing these two costs no coverage. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018P9kaAfuJERNv3GbQT1va4
`selectSpecs` passed `readLane(root)` as an argument, so it ran before `selectFrom` reached its `isLaneSource` gate. The hook is wired to every Edit and Write, so a Markdown, JSON or story edit paid a recursive `readdir` of both lane directories plus 140 spec reads only to be told the path was outside the lane. Measured on this tree: 31.8ms cold and 18.5ms warm, now 0.09ms. `selectFrom` keeps its own gate, which is what the fixture specs drive. No spec pins this. The only assertion available is a timing one, and a 300x gap measured under no load is not a bound worth the flake. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018P9kaAfuJERNv3GbQT1va4
The jsdom trade quoted 114 node-only files and 1701 tests, both from before this branch added `scripts/select-unit-specs.test.ts`. The lane is 140 files and 1714 tests, 25 of the files jsdom, so the node-only half is 115. Re-derived rather than incremented — the old 114 was one short too. The hook's scope line and the width figures also moved with this branch's `scripts/` fix: 412 lane sources, 133 of them selecting the walker floor alone. The project-split lever now names #293, which owns it. The paragraph handed the next reader a measured 4.5s to 1.5s win with nothing behind it, which is how #285's own figure went unowned until #284's review noticed. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018P9kaAfuJERNv3GbQT1va4
|
All five findings adopted, one commit each, pushed as 912f925. Each reply names its commit.
Two new assertions, both watched failing with the old gate restored. The gate-first fix carries none: the only assertion available is a timing one. Lean gate green — 140 files, 1714 tests, 30.8s. The body's flow block, test results, "Filed on the way" and width figures are refreshed. 🤖 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]>
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
sahajatlas-design | 2702dbd | Oct 14 2026, 06:35 PM |
Summary
docs/testing.mdas one number, and what holds it — the selection's width — is pinned by a spec rather than restated as a figure nothing checks.Change outline
Flow — what one lane edit pays
Files — one new responsibility
Preview
Nothing deployed changes: the diff touches
.claude/,scripts/and docs only, so neither entry graph moves andpnpm sizereads the same bundle. There is no page to open.Test results
lint+typecheck+test:run(140 files, 1714 tests, 30.8s)scripts/select-unit-specs.test.ts)Manual verification
src/**/*.tsfile in a session with the hook enabled and confirm feedback arrives in a few seconds rather than ~36s.Notes for reviewer
The judgement call worth checking is the budget's number. 12s, not the 10s the first draft stated: the widest edit in the tree (
src/config/i18n.ts, 22 specs, four of them jsdom) measures 9.7s median-of-three, and 10s left no room for a slower machine to be noticed rather than just wrong. Typical is 4.3s.The hook now covers less, on purpose. It does not reach a spec coupled through a second module — editing
geo.tsrunsgeo.test.ts, nevercamera.test.ts. The full lane still runs in the lean gate and in CI, so a selection miss costs feedback latency, never a shipped regression.vitest relateddoes reach that coupling and measured 26s onsrc/lib/geo.tsalone (67 of 140 files), so the module graph here is too connected to select from.scripts/is in the lane on both sides now. The adversarial review foundLANE_DIRSindexing its six specs while the source gate refused everyscripts/path, so editing the selector ran nothing and its own spec ran on every unrelatedsrc/edit instead. One list governs both halves,SOURCE_EXTgains.mjs, and the width sweep measures 412 sources rather than 393. The top is unchanged at 22 against a ceiling of 24.Filed on the way: #293, for the project-split lever
docs/testing.mdnames. It was the one measured win in that file with nothing behind it.⚠ #286 is in flight and will break one assumption. It consolidates the nine
src/inventories onto one shared walker; a spec that reaches the tree through that helper stops matching the enumerating-call detector. The walker closed list fails loudly when that happens, which is the intended handoff, but the two PRs will conflict inscripts/and in the walker specs.Detail
The three defects the review pass found in the first draft, each fixed in its own commit and each watched failing with its cause restored:
fetch.test.tsis the only spec forsrc/config/api/client.ts(docs/testing.mdsays so) and reaches it as'./client';Chip.test.tsximports its own folder as'.'. So breakinginterceptFetchleft the hook green, and editing a per-component barrel selected no spec of that component. 17 sibling pairs exist in this tree, andsrc/AGENTS.mdreserves@/for deep paths. Fixed by resolving every quoted specifier to the module it addresses.readdirSync-only. A spec enumerating the tree any other way would drop out of the per-edit set with every assertion green — the silent loss this ticket exists to end. It now matches four enumerating calls, and the doc says plainly that a walker reaching the tree through a helper is still invisible to it.selectFromnow.The adversarial review's five points, each adopted:
bf9ef99— thescripts/gate above. Two new assertions, both watched failing with thesrc/-only gate restored.912f925—docs/testing.mdquoted 114 node-only files and 1701 tests, both from before this branch's own spec existed. 115 and 1714, re-derived rather than incremented.77a1f7c—referenceIndexandtreeWalkingSpecswere exported and named nowhere. Both module-private now;readLaneis the one caller of either.26a4327—readLane(root)was an argument, so it ran before the lane gate. Every Markdown or JSON edit paid 31.8ms cold to be told its path was outside the lane; 0.09ms now. No spec pins it — the only assertion available is a timing one, and a 300× gap measured under no load is not a bound worth the flake.912f925— the project-split lever now names perf(test): move the repo-wide inventory specs off the per-edit path #293.Rejected alternatives, with the measurement behind each:
projectssplit on node vs jsdom. Node-only is ~20s and jsdom-only ~15s, so neither half fits any useful budget.isolate: false. 20s for the full lane, and flaky — one of three runs failed a file.vitest relatedas the mechanism. 26s on one leaf module, 67 of 140 files.escapeRegExp.postcss-scope-widget.mjshas an identical one, unexported. Importing it would put a 500-line build script on the hook's startup path, and the duplicate disappeared anyway when the needle alternation did.selectSpecscall in the one real-tree assertion with the cached parts. It costs 72ms and buys the only end-to-end call against this repo, which is the one thing a test of the parts cannot give.The lever still on the table, now owned by #293: the ten tree-walking inventories are ~4.5s of every edit, and 133 of 412 source files select nothing else. Moving them into their own vitest project and pointing the hook at the unit one would land the median near 1.5s. It does not remove the selector — the other two sources are still needed — so it narrows the floor rather than replacing the design, and it is a mechanism change worth its own review.
Fixture pre-mortem. The tmp tree assumes the lane collects
src/**andscripts/**specs named*.test.ts(x), that an import is written@/…or relative, and that a spec reading source text off disk names it as a quoted repo-relative path. The first is now asserted againstvitest.config.ts's owninclude. The others were checked againstsrc/AGENTS.md("Imports") andsrc/lib/brand.test.ts'sCOPY_FILES.Measured 2026-10-13, 4 cores, median of three, wall clock of the whole hook command: floor (no spec of its own) 4.5s · typical
src/lib/geo.ts4.3s · widestsrc/config/i18n.ts9.7s, re-measured 9.2s after thescripts/change · ascripts/source 3.6s · full lane ~36s. Selection width across all 412 lane sources: min 10, p50 11, p90 12, max 22.Closes #285
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code