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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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.

Notes

shipped production is serving it deploy 4ec2c16

opened this

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 invalid_limit. The message names the maximum and the hint says to page through the rest with page, so a client that sent limit=9999 to mean "all" can fix itself.
  • page: it is a whole number from 1 to 1000 (the owned-repo cap). 0, -1, abc and 1001 answer 422 invalid_page, with the same {error, field, message, hint} shape. The refusal and parser are new in src/contract/page_query.ts; the old whole() helper is removed.
  • Unchanged: absent parameters still give limit 50 and page 1, and valid limit/page values behave as before.
  • OpenAPI: the route's entry in src/contract/openapi/routes/getApiV1UserRepos.ts now lists the limit and page query parameters and names both 422s.
  • Tests: in test/forge-origin-edges.test.ts I replaced the old test that expected limit=5000 to clamp to 100 and limit=-3&page=abc to 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.ts said 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.

Closes #14418

commented

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 invalid_limit. The message names the maximum and the hint says to page through the rest with page, so a client that sent limit=9999 to mean "all" can fix itself.
  • page: it is a whole number from 1 to 1000 (the owned-repo cap). 0, -1, abc and 1001 answer 422 invalid_page, with the same {error, field, message, hint} shape. The refusal and parser are new in src/contract/page_query.ts; the old whole() helper is removed.
  • Unchanged: absent parameters still give limit 50 and page 1, and valid limit/page values behave as before.
  • OpenAPI: the route's entry in src/contract/openapi/routes/getApiV1UserRepos.ts now lists the limit and page query parameters and names both 422s.
  • Tests: in test/forge-origin-edges.test.ts I replaced the old test that expected limit=5000 to clamp to 100 and limit=-3&page=abc to 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.ts said 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.

commented

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.ts and test/invalid-json-readers.test.ts all pass in my sandbox.
  • Where they failed: the crawl-budget tests were in shard 27, which did not run in isolation. looks-owner took 90 s against a 2 s budget. The log says invalid-json-readers is 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.

Approved

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs