Repository navigation
Description
Summary
docs/rules/data-layer.md now requires every SahajCloud collection read to send an explicit
limit and page and to walk pages through readAllPages. Nothing enforces it, and the failure
mode is the quietest one in the rule: an absent limit is not a refusal — Payload defaults it
to 10, so the read silently returns ten rows while lint, typecheck and the unit lane all stay
green. This repo already has the right shape of gate for a rule like this, twice.
Approach
#253 added the rule and converted the three wholesale reads. It enforced the rule by example, with
per-call-site assertions in src/config/api/fetch.test.ts — which say nothing about the next read
somebody adds. Replace that with a source-walking spec, the pattern
src/lib/shape/href.test.ts:132 ("the JSX anchor inventory") already uses for the isSafeHref
rule, and src/components/atoms/Icons/Icons.usage.test.tsx uses in both directions.
⚠ Parse, do not grep. href.test.ts:156 records why: a regex over raw text has to strip
comments first, and every cheap way of doing that has a false pass in it — an unpaired /* or a
line comment swallows everything up to the next docblock and hides the very call site the spec
exists to find. It uses the typescript compiler API (already a devDependency) to walk the AST.
Copy that mechanism.
The exemptions are the whole design problem, and the inventory is small enough to close. Every
SahajCloud read in src/config/api/ today:
| Call site | Needs limit |
Why |
|---|---|---|
fetch.ts:177 sdk.find regions |
yes | walked, carries it |
fetch.ts:267 sdk.find events |
yes | walked, carries it |
fetch.ts:219 requestJson /events/geojson |
yes | a collection list read behind a custom endpoint; walked, carries it |
fetch.ts:644, :791 sdk.findByID |
no | one document by id |
fetch.ts:768, :815 sdk.findGlobal |
no | a global |
fetch.ts:701 requestJson /clients/me |
no | an API-key self-read, one record |
mutate.ts:176, :359, :420 requestJson |
no | POSTs |
So the gate is: every sdk.find call site carries a numeric limit and a page, and mentions
neither pagination nor limit: 0. findByID, findGlobal and the mutations are out of scope by
construction. The one read the AST cannot classify is a requestJson GET — only /events/geojson
is a list read — so hold those as a named inventory the way GATED_ANCHORS is held, and fail on an
unlisted one with instructions rather than guessing.
Decide while writing it whether the spec also requires the call to sit inside a readAllPages
callback. It is the stronger claim and the one the rule actually makes, but it is harder to see
from one call expression's AST than the presence of limit is.
Acceptance criteria
- A new
sdk.findcall site with nolimit, or nopage, fails the unit lane. - A new
sdk.findcall site sendingpagination: falseorlimit: 0fails the unit lane. -
findByID,findGlobaland the threemutate.tswrites do not fail it. - A
requestJsonGET not in the spec's inventory fails the lane, with a message naming what to
do about it. - The failure message names the file, the call site and the rule, so a cold run can act on it.
- The spec parses the source through the
typescriptAPI, with no regex over raw file text. - The three per-call-site
limit/paginationassertions infetch.test.tsstay — they pin
what each read sends on the wire, which is a different claim from the inventory's.
Verification checklist
-
pnpm test:runpasses. - Add a throwaway
sdk.find({ collection: 'regions', select: { slug: true } })somewhere under
src/, watch the lane go red naming that file, then remove it. A spec written against the
current source is the easy one to get vacuously green (docs/testing.md, "A regression spec
is not finished until it has FAILED"). - Repeat with
pagination: false, and with arequestJsonGET to a new path. - Comment out
limitingetRegionsand watch the lane namefetch.ts. -
pnpm lint && pnpm typecheckpass. - The lane stays under ~5s — a PostToolUse hook runs it after every
src/**edit
(docs/testing.md). Parsing every file undersrc/config/api/is cheap; parsing all of
src/is whathref.test.tsalready pays for, so measure before widening the glob.
Notes
Found while implementing #253 and recorded there rather than built, because a correct exemption
list is a judgement call about which reads legitimately send no limit — not something to settle
inside a PR about pagination.
The rule it enforces is in docs/rules/data-layer.md, under "SahajCloud query rules (enforced —
400 on violation)". The bounds themselves are SahajCloud's MAX_CLIENT_LIMIT (2000) and
MAX_CLIENT_PAGE (10000), live since sydevs/SahajCloud#890.
🤖 Written by the sydevs autonomous loop — see what this is
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Hold Until
Projects
- StatusShow more project fieldsDone
Activity
Ardnived commentedon Oct 11, 2026
@sydevs-bot implement
sydevs-bot commentedon Oct 11, 2026
🤖 no session running
recent dispatches
Written by the sydevs dispatcher. Sessions never edit this comment.
test(api): fail the lane when a collection read ships without an expl…
docs(testing): re-measure the unit lane, which is ~28s and not ~1.5s
fix(api): close the three holes a review pass found in the read inven…