Skip to content

test(api): fail the lane when a collection read ships without an explicit limit #275

Closed

Description

@sydevs-bot

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.find call site with no limit, or no page, fails the unit lane.
  • A new sdk.find call site sending pagination: false or limit: 0 fails the unit lane.
  • findByID, findGlobal and the three mutate.ts writes do not fail it.
  • A requestJson GET 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 typescript API, with no regex over raw file text.
  • The three per-call-site limit / pagination assertions in fetch.test.ts stay — they pin
    what each read sends on the wire, which is a different claim from the inventory's.

Verification checklist

  • pnpm test:run passes.
  • 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 a requestJson GET to a new path.
  • Comment out limit in getRegions and watch the lane name fetch.ts.
  • pnpm lint && pnpm typecheck pass.
  • The lane stays under ~5s — a PostToolUse hook runs it after every src/** edit
    (docs/testing.md). Parsing every file under src/config/api/ is cheap; parsing all of
    src/ is what href.test.ts already 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

Activity

  1. added theissue type on Oct 11, 2026
  2. moved this from Revising to Proposed in SYDevelopers Technical Roadmapon Oct 11, 2026
  3. added
    proposal
    on Oct 11, 2026
  4. Ardnived commented on Oct 11, 2026

    @Ardnived
    Contributor

    @sydevs-bot implement

  5. removed
    proposal
    on Oct 11, 2026
  6. moved this from Proposed to Approved in SYDevelopers Technical Roadmapon Oct 11, 2026
  7. added
    bot:working
    on Oct 11, 2026
  8. sydevs-bot commented on Oct 11, 2026

    @sydevs-bot
    ContributorAuthor

    🤖 no session running

    recent dispatches
    • 19:34Z implement · attempt 1 · session · done
    • 19:34Z implement · attempt 1 · session

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

  9. removed
    bot:working
    on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    Medium

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions