Repository navigation
test(api): fail the lane when a collection read ships without an explicit limit - #284
Conversation
…icit limit #253 enforced the explicit-`limit` rule by example, with per-call-site assertions in `fetch.test.ts`. Those pin what each of the three reads sends on the wire, which is a different claim from "and nothing else reads any other way" — they say nothing about the next read somebody adds, and the failure mode is the quietest one in the rule: an absent `limit` is not a refusal, it is ten rows, with lint, typecheck and the unit lane all green. So the inventory is executable here instead, on the shape `href.test.ts` already uses for the `isSafeHref` rule: walk `src/**` through the `typescript` API and fail any `sdk.find` that sends no `limit` or `page`, sends `pagination` or `limit: 0`, sits outside a `readAllPages` callback, or sorts without `walkSort`. Parsed rather than grepped because commenting out a `limit` is exactly the edit it has to catch, and a regex has to strip comments first. `findByID`, `findGlobal` and `mutate.ts`'s POSTs are out by construction — none takes a `limit`. A custom endpoint is the read an AST cannot classify, so the GET paths are two named inventories and an unlisted one fails with the instruction to decide which it is, rather than being guessed at. The same goes for a `method` or a `path` that is not a literal: unreadable fails, so a read cannot leave the inventory by being opaque. Two checks go past the ticket's criteria, because both are the claim the rule actually makes and both are visible from one call expression: a read sending `limit: 2000, page: 1` and never walking truncates silently above one page, and a walk sorted by a non-unique key repeats and drops rows at every boundary. Refs #275 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GN284jC2KsJ2yCLRQJgx8g
This ticket's own verification checklist asked whether the new spec keeps the lane "under ~5s", citing this file. Measuring it to answer that found the premise stale in both halves: the jsdom note has said "about 1s against the whole lane's ~1.5s" since there were a handful of specs, and there are now 25 jsdom files among 133. Measured on 4 cores: 113 node-only files take ~16s, the 25 jsdom files add ~12s, for ~28s over 1698 tests. The per-file opt-in is still what keeps the first number from becoming the second, so the structural point stands and only the numbers were wrong. The PostToolUse hook note carried the same figure as a target. A budget nobody has been under for months reads as satisfied rather than as broken, so it now says what the hook actually costs per edit and asks for a new spec's own cost to stay small — which is the part a contributor controls. Refs #275 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GN284jC2KsJ2yCLRQJgx8g
…tory
A fixed `page` passed. `page: 1` is present and in range, so the check waved
through the one shape that duplicates rows instead of paginating: the walk asks
for page one `totalPages` times and concatenates it. Only a value that varies
per call can be the page the walk is on, so a resolvable number is now the
defect rather than the pass.
A namespace import hid every read in its file, which contradicted this file's
own blind-spot note. It fails the lane now instead of being documented, and
`import { default as x }` binds like the default import it is.
The wrapper-count message named `client.ts` while the count came from every
scanned file, so an opaque `requestJson(opts)` added in `mutate.ts` would have
pointed at the wrong file with no site named. It lists the sites it found.
`MAX_CLIENT_PAGE` went with the `page` range check. No assertion on it could
fail: a page must vary to pass at all, and `MAX_PAGE_WALK` bounds the walk two
orders of magnitude under that ceiling — the same reason `paginate.ts` dropped
its own copy in 08b62da.
Refs #275
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GN284jC2KsJ2yCLRQJgx8g
Deploying sahajatlas with
|
| Latest commit: |
6be0e2f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1abd9cf5.sahajatlas.pages.dev |
| Branch Preview URL: | https://claude-test-275-explicit-lim.sahajatlas.pages.dev |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff matches the ticket: one spec, two doc edits, no production code. Its size is in proportion to the failure it catches, and the two checks past the criteria (readAllPages, walkSort) are the claim the rule actually makes, visible from the same call expression. No contract surface moves. One aggregate question is not this PR's to answer: src/ now holds nine specs that each roll their own readdirSync walk, this being the ninth. A shared test helper, or a no-restricted-syntax rule, is a ticket rather than a change here.
On the getGeojson sort you asked about — nothing to file. main sent no sort, so the prior order was Payload's unspecified default and never a contract; walkSort() makes it defined. If the online tail needs a chosen order, that is its own ticket, not a regression in #277.
Findings
should-fix—reads.inventory.test.ts:369: a POST list read escapes both inventories. Confirmed green against a probe.should-fix—reads.inventory.test.ts:465: the walker self-check pinsCLIENT_PAGE_LIMIT's value, so a tuning change goes red under the wrong message. Confirmed.consider—docs/testing.md: the lane budget is removed rather than replaced.
What was checked. Read whole: the new spec, config/api/{client,paginate}.ts, fetch.ts's three walked reads and two custom GETs, href.test.ts's anchor inventory (the cited precedent), eslint.config.js. #275 against the diff — every criterion met, plus two. Ran the spec in a throwaway worktree: 5 passed, 1.33s. Probed two defects there: the POST read above stayed green, CLIENT_PAGE_LIMIT = 1000 went red. Counted the source walkers with grep -rln readdirSync src/. The SDK types method as a five-literal union, which is what closes the lowercase-method hole.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The inventory kept only `method: 'GET'`, and a non-literal method was the only other way out of it. So a `requestJson` list read sent as POST was in neither set: it passed every spec with no `limit`, no `page` and no walk. `data-layer.md` names POST-as-GET as a shape this API has, and the SDK sends `args` as the query string whatever the verb, so the method never classified anything. What separates a read from a write is the body. A `json` or `file` option is a write — which is what keeps `mutate.ts`'s three POSTs out — and everything else is a read, checked against the two path inventories. Watched red at the causing site: a POST read of an unlisted path fails the inventory check naming the file and line; the same read at `/events/geojson` fails all four page checks; adding a `json` body to it goes green again. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TMw3HFBzr1ay1WnXPCQ9Jy
The walker self-check compared `fetch.ts`'s resolved `CLIENT_PAGE_LIMIT` against `MAX_CLIENT_LIMIT`, so lowering the page size — a tuning choice `paginate.ts` owns — failed with `expected 1000 to be 2000` under "the walk itself must not silently break". The claim is that the resolver still follows the import hop to a number, so compare against the imported constant. Watched red at the causing site: `export const CLIENT_PAGE_LIMIT = 1000 + 1000` fails with `expected undefined to be 2000`, while `= 1000` now stays green. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TMw3HFBzr1ay1WnXPCQ9Jy
Re-measuring the lane removed the only stated bound on it and left nobody owning ~28s per `src/**` edit. #285 owns the total now, and the hook note cites it rather than restating a number nothing checks. The jsdom paragraph keeps the warning and the measurement, and drops the account of how the old figure went stale — its replacements will go the same way. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TMw3HFBzr1ay1WnXPCQ9Jy
The rule pointed at the spec's old GET filter. The spec classifies a custom call by whether it carries a `json` or `file` body, so this records what actually puts `mutate.ts`'s POSTs out of scope — and why the method could not do that job. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TMw3HFBzr1ay1WnXPCQ9Jy
|
Adopted all three review findings, one commit each, plus the rule they changed.
6be0e2f carries the read/write mark into Filed from the review body: #285 (lane cost) and #286 (nine specs, nine 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
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
#442's doc commits re-counted the lane, re-timed the hook and re-measured the bundle into prose, and copied lists the code already holds. Each would need the same edit at the next change. Kept every ⚠ and its reason; dropped: - figures: lane, spec and source counts, hook timings, KiB savings, budget percentages, advisory counts, the six FallbackKinds - copied lists: the loader's parameters (docs/embedding.md owns them), the factory and wholesale-key lists, the zoom constants' values, the coverage excludes, another repo's action list, the _headers max-ages - restatements: the zod-shape and eager-shell explanations their own homes hold - the hook re-measurement chain, collapsed to its conclusion (drops #389) Rule: sydevs/claude-workflow docs/documentation.md (#284, #289). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
limitrule.pagination: falseSahajCloud reads #253 enforced that rule by example. This asserts it over the source, so the next read is covered.Change outline
Behaviour — what the gate decides, per call site
The
methoddecides nothing: the SDK sendsargsas the query string at any verb, so aPOST-as-GET is a read.
Files
src/config/api/ ├── client.ts # unchanged ├── paginate.ts # unchanged — this spec asserts its contract is reached ├── fetch.ts # unchanged ├── fetch.test.ts # unchanged: its three per-call-site assertions are a different claim +└── reads.inventory.test.ts docs/rules/data-layer.md # the rule now points at its enforcement docs/testing.md # a stale lane measurement this ticket's checklist rested onPreview
change, and no story changed, so the Ladle playground is unaffected.
Test results
pnpm lint+pnpm typecheck+pnpm test:run(1701 passed, 139 files)reads.inventory.test.tsManual verification
Notes for reviewer
inside a
readAllPagescallback and must sort throughwalkSort. Both are the claim the ruleactually makes rather than a proxy for it, and both are visible from one call expression. A read
sending
limit: 2000, page: 1and never walking satisfies the ticket's criteria exactly andstill truncates silently at 2001 rows. One line removes either if you disagree.
pagination: falseSahajCloud reads #277's merged code, not this PR's, for you to judge.getGeojsonsendssort: walkSort()wheremainsent nosortat all, soidascending becomes the feed'sprimary order.
byDistancereturns 0 for two distance-less events andArray#sortis stable, sothe online tail of the results list reorders — it inherits feed order, which was the server's
default and is now
id. The review's verdict was that the prior order was Payload's unspecifieddefault and never a contract, so there is nothing to file; a chosen order for the online tail
would be its own ticket. Say the word if you read it differently.
per-edit cost, and test(build): one source walker for the nine specs that inventory
src/#286 owns the nine specs that each roll their ownreaddirSyncwalk ofsrc/— this spec being the ninth.pagination: falseSahajCloud reads #277 and then rebased ontomain. refactor(api): paginate the threepagination: falseSahajCloud reads #277 merged at 19:38Z,four minutes into that session, and the spec cannot exist without its
readAllPages/walkSortseam — on the
mainthat existed at dispatch, the three reads still sentpagination: falseandthis spec would have been red on arrival. The rebase was clean:
comm -12over the two filelists found zero overlapping files, and the gate above ran after it.
/simplifydid not run as a skill. While the branch was stacked, its diff range was refactor(api): paginate the threepagination: falseSahajCloud reads #277'scode, so it would have been reviewing and editing another PR's diff; by the time of the rebase
the review pass was already done.
/code-review highran scoped to this branch's own files, andthe
/simplifylenses I applied by hand are in the Detail block.src/config/api/is on this repo'strigger paths, so it ran. The diff is one unit-test file and two Markdown files: no network,
shell,
evalor deserialization, and the only reads are of our ownsrc/tree from areaddirSyncwalk.ts.createSourceFileparses without executing, whichhref.test.tsalreadyrelies on.
comment-lint.mjs: clean.Detail
Every assertion was watched red before it was kept, each defect reintroduced at the site that
would actually cause it:
sdk.findinsrc/views/limitcommented out ingetRegionslimitcheck, namingfetch.ts:177limit: 0page: 1hard-coded ingetRegionspagination: falsewith everything else correctpaginationcheck alonesort: 'name'andsort: undefinedwalkSortcheck at bothsdk.findsitesrequestJsonGET to/regions/treerequestJsonPOST read of an unlisted path/events/geojsonCLIENT_PAGE_LIMIT = 1000 + 1000expected undefined to be 2000sdk.requestinclient.tsimport * as client from '@/config/api/client'Two cases were also watched green, because a check that fired on them would be a false
positive: the POST read once it carries a
jsonbody (a write), andCLIENT_PAGE_LIMIT = 1000(atuning change, which used to fail under a walker-health label).
The commented-out
limitis the case the ticket's ⚠ is about: a regex over raw text has to stripcomments first, and every cheap way of doing that has a false pass in it. The AST ignores the
comment correctly.
Why the glob is all of
src/, measured rather than assumed. The ticket asked for this.Scanning 255 files costs ~0.7s (28.5s → 29.2s over the whole lane).
src/types/payload/isexcluded: generated declarations, no call sites, and the slowest thing under
src/to parse. Asdk.findadded anywhere undersrc/is caught — verified in both a.tsand a.tsxfile.limitresolves through one import hop.limit: CLIENT_PAGE_LIMITis an identifier, so thespec resolves it to a module-level numeric literal in its own file or the module it was imported
from. Keyed by file, not by name:
src/loader/literals.tsduplicates values across the loaderseam on purpose, and a repo-wide name map collided immediately on
IDLE_DEADLINE_MSat two values.An unresolvable value fails rather than passes, which is what stops the check being satisfied by
anything opaque.
MAX_CLIENT_PAGEis deliberately not checked. Apagemust vary per call to pass at all, andMAX_PAGE_WALKbounds the walk two orders of magnitude under that ceiling, so no assertion on itcould ever fail — the same reason 08b62da dropped
CLIENT_MAX_PAGEfrompaginate.ts.The first review's four findings. Three were real and are fixed in the third commit: a
hard-coded
page: 1passed (verified — it kept all four specs green); a namespace import hid everyread in its file, contradicting the file's own blind-spot note; and the wrapper-count message named
client.tswhile the count came from every scanned file. The fourth was thegetGeojsonsortquestion above.
The second review's three findings, all adopted, one commit each:
limit,pageor walkCLIENT_PAGE_LIMIT's value, so a tuning change went redThe first is why the inventory now reads a
jsonorfilebody as the read/write mark instead offiltering on
method: 'GET':argsis the query string at any verb, so the method classifiednothing, and a POST-as-GET is a shape
data-layer.mdnames. 6be0e2f carries that into the rule.Why
docs/testing.mdis in this diff. The ticket's verification checklist asked whether thenew spec keeps the lane "under ~5s", citing that file. Measuring it to answer found the premise
stale in both halves: the jsdom note has said "about 1s against the whole lane's ~1.5s" since there
were a handful of specs, and there are now 25 jsdom files among 133. Measured on 4 cores: 113
node-only files take ~16s, the 25 jsdom files add ~12s, ~28s in total. The per-file opt-in still
does the work the line credits it with, so only the numbers were wrong. #285 owns the total,
and the hook note cites that ticket rather than a bound this PR would have had to invent — a
figure nothing checks is how the old one went stale.
/simplifylenses applied by hand, on this branch's own file: the per-module constantresolution replaced a repo-wide map; a redundant
&& bindings.requestJsonconjunct went; theunused
MAX_CLIENT_PAGEwent with the range check it served; andpropertyOf/valueOfnow takeundefinedinstead of each caller passing?? ({} as never). The second review's first commitdropped
methodfrom theReadtype for the same reason — nothing branched on it any more.Blind spots are stated in the file, since a guard that oversells itself is worse than none. A
re-export under another name and a dynamic import are both invisible; a namespace import was too,
until the first review found it, and now fails.
selectandpopulateare a different clause ofthe same rule and are not checked here.
Closes #275
🤖 Generated with Claude Code
https://claude.ai/code/session_01GN284jC2KsJ2yCLRQJgx8g
Generated by Claude Code