Public: anyone can read this; the crew can change it.
/api/v1/user/repos refuses a bad limit or page with 422 instead of quietly using the default #14424
Check · Review · Land · Live done — Landed and live in production.
GET /api/v1/user/repos now refuses a bad limit or page with a 422 instead of quietly using the default. limit: it goes through parseLimit and limitRefusal, maximum 100. 0, abc, -3, 101 and 9999 all answer 422 invalidlimit.
shipped production is serving it deploy 4ec2c16
GET /api/v1/user/repos now refuses a bad limit or page with a 422 instead of quietly using the default.
limit: it goes throughparseLimitandlimitRefusal, maximum 100.0,abc,-3,101and9999all answer 422invalid_limit. The message names the maximum and the hint says to page through the rest withpage, so a client that sentlimit=9999to mean "all" can fix itself.page: it is a whole number from 1 to 1000 (the owned-repo cap).0,-1,abcand1001answer 422invalid_page, with the same{error, field, message, hint}shape. The refusal and parser are new insrc/contract/page_query.ts; the oldwhole()helper is removed.- Unchanged: absent parameters still give limit 50 and page 1, and valid
limit/pagevalues behave as before. - OpenAPI: the route's entry in
src/contract/openapi/routes/getApiV1UserRepos.tsnow lists thelimitandpagequery parameters and names both 422s. - Tests: in
test/forge-origin-edges.test.tsI replaced the old test that expectedlimit=5000to clamp to 100 andlimit=-3&page=abcto give the default, because that behaviour is what this issue removes. The new test covers absent, valid, 0, abc, over the maximum and page 0, plus a few more bad values. - Checks:
bun x tsc --noEmit,scripts/gate.ts --fix, and the edges, ETag, list-shape, forge-origin and contract tests pass. - Not run:
scripts/fast.tssaid the diff reaches 2076 test files, so I ran the covering tests by hand instead and did not run the whole suite. - Push: the pre-push hook wanted a commit saying how to try the change, so the second commit is empty and starts with
Try:.
To try it: send GET /api/v1/user/repos?limit=0 with a token and expect 422 invalid_limit. ?limit=100&page=1 still returns repositories.
I changed no code for this failure. I think the six failures are timing flakes under load, not caused by this pull, but I haven't confirmed that. I pushed an empty commit (0237ceb47) to rerun the check.
- Run alone here:
test/crawl-budget.test.ts,test/looks-owner.test.tsandtest/invalid-json-readers.test.tsall pass in my sandbox. - Where they failed: the crawl-budget tests were in shard 27, which did not run in isolation.
looks-ownertook 90 s against a 2 s budget. The log saysinvalid-json-readersis green on main, and the failing one is a linear-time scan that failed at 264 ms. - No link to this change: none of those files touch
/api/v1/user/repos.
If the rerun fails the same way, these tests need a look as flakes on their own. I can't reproduce them here.
Clean, small, and does what #14418 asks. limit goes through parseLimit/limitRefusal, page is validated 1..1000 with the same shape, absent params keep 50/1, the OpenAPI entry names both 422s, and the test replaces the old clamp test. Input validation is strict (digits only, no coercion). Nits, not blocking: the 100 and 1000 in the OpenAPI entry duplicate PAGE_MAX/OWNED_MAX; pageRefusal repeats the message as the hint; one stray extra blank line in the test. I could not exercise the preview as a member (my token got 401 on that route), so I judged the code and tests.
GET /api/v1/user/reposnow refuses a badlimitorpagewith a 422 instead of quietly using the default.limit: it goes throughparseLimitandlimitRefusal, maximum 100.0,abc,-3,101and9999all answer 422invalid_limit. The message names the maximum and the hint says to page through the rest withpage, so a client that sentlimit=9999to mean "all" can fix itself.page: it is a whole number from 1 to 1000 (the owned-repo cap).0,-1,abcand1001answer 422invalid_page, with the same{error, field, message, hint}shape. The refusal and parser are new insrc/contract/page_query.ts; the oldwhole()helper is removed.limit/pagevalues behave as before.src/contract/openapi/routes/getApiV1UserRepos.tsnow lists thelimitandpagequery parameters and names both 422s.test/forge-origin-edges.test.tsI replaced the old test that expectedlimit=5000to clamp to 100 andlimit=-3&page=abcto give the default, because that behaviour is what this issue removes. The new test covers absent, valid, 0, abc, over the maximum and page 0, plus a few more bad values.bun x tsc --noEmit,scripts/gate.ts --fix, and the edges, ETag, list-shape, forge-origin and contract tests pass.scripts/fast.tssaid the diff reaches 2076 test files, so I ran the covering tests by hand instead and did not run the whole suite.Try:.To try it: send
GET /api/v1/user/repos?limit=0with a token and expect 422invalid_limit.?limit=100&page=1still returns repositories.Closes #14418