Public: anyone can read this; the crew can change it.

The admin's accounts, people and invites lists answer `{ items, next_cursor }` #5052

opened this

Merged 45d 10h ago, live in production

GET /api/v1/admin/accounts, /api/v1/admin/people and /api/v1/admin/invites now answer { items, nextcursor }. The shape of /admin/people changed: it answered { people: [...] }, and the other two answered { items } with no cursor.

Notes

opened this

GET /api/v1/admin/accounts, /api/v1/admin/people and /api/v1/admin/invites now answer { items, next_cursor }. The shape of /admin/people changed: it answered { people: [...] }, and the other two answered { items } with no cursor.

I ran the new paging test plus the roles, invites, accounts, MCP and admin-refused suites, and they pass. I did not get a type check: bun x tsc --noEmit stopped on a missing bun type definition, and I did not chase it.

  • Paging: each route takes limit (default 50, max 200) and cursor. A bad limit (0, 201, negative, non-numeric, empty) or a bad cursor is a 422 (invalid_limit / invalid_cursor), never clamped.
  • Permissions and filters: unchanged on all three routes.
  • Code: the paging lives in a new module, src/http/offset_page.ts. The routes in src/http/api.ts use it.
  • Cursor: it is an offset into the list as read at that moment. A row added or removed between pages can shift later pages by one.
  • Callers: nothing else in src/ read these three API responses. The pages, terminal UI and MCP call the actions directly, so only the API shape and test/roles.test.ts (which read .people) needed updating. The README line for /admin/people now describes the new shape.
  • Tests: test/admin-lists-paged.test.ts covers, for each route, the shape, paging with limit=2 until next_cursor is null (the pages add up to the unpaged list), and bad limits and cursors refused.

I did not add an SQL-level cursor. These lists are small and held whole in memory, so slicing is enough. I touched no other route in src/http/api.ts.

Closes #5042

3 earlier comments
commented

GET /api/v1/admin/accounts, /api/v1/admin/people and /api/v1/admin/invites now answer { items, next_cursor }. The shape of /admin/people changed: it answered { people: [...] }, and the other two answered { items } with no cursor.

I ran the new paging test plus the roles, invites, accounts, MCP and admin-refused suites, and they pass. I did not get a type check: bun x tsc --noEmit stopped on a missing bun type definition, and I did not chase it.

  • Paging: each route takes limit (default 50, max 200) and cursor. A bad limit (0, 201, negative, non-numeric, empty) or a bad cursor is a 422 (invalid_limit / invalid_cursor), never clamped.
  • Permissions and filters: unchanged on all three routes.
  • Code: the paging lives in a new module, src/http/offset_page.ts. The routes in src/http/api.ts use it.
  • Cursor: it is an offset into the list as read at that moment. A row added or removed between pages can shift later pages by one.
  • Callers: nothing else in src/ read these three API responses. The pages, terminal UI and MCP call the actions directly, so only the API shape and test/roles.test.ts (which read .people) needed updating. The README line for /admin/people now describes the new shape.
  • Tests: test/admin-lists-paged.test.ts covers, for each route, the shape, paging with limit=2 until next_cursor is null (the pages add up to the unpaged list), and bad limits and cursors refused.

I did not add an SQL-level cursor. These lists are small and held whole in memory, so slicing is enough. I touched no other route in src/http/api.ts.

commented

I merged main into the branch and pushed it. The conflict was in src/http/api.ts and is resolved.

  • The conflict: main had added keyedWindow and keyedPage, name-cursor paging helpers. This branch had offsetRefused, the 422 helper for the admin lists. They are independent, so I kept both and made no other changes.
  • Type check: bun x tsc --noEmit is clean.
  • Tests: the three suites that touch this change pass (16 pass, 0 fail): admin-lists-paged, api-errors and admin_refused. The full bun test run had 10 failures: three merge-queue tests, the two tests about bringing a conflicted pull up to date and handing it to a person, the SSH-port-taken test, the chromium look tests, and the one-tap conflict-resolution test. They look like sandbox limits (no chromium, ssh or outbound network) rather than anything from this merge. I didn't run them against main to confirm. The forge's check will run them in full.
commented

The admin accounts, people and invites lists now answer { items, next_cursor }, and the published contract now says so.

What changed

  • The three GET /api/v1/admin/{accounts,people,invites} entries in src/contract/openapi.ts now say they answer { items, next_cursor }. Each states limit 1 to 200 (default 50), cursor taken from next_cursor, and a 422 for a bad limit or cursor, worded like the ${REPO}/events entry.
  • Each of the three declares query: { limit: "integer", cursor: "string" }.
  • /admin/people used to publish { people: [...] }. It now publishes items, which matches what the route returns.

Testing

  • I ran the 47 tests under test/ that cover the contract and OpenAPI, and they pass.
  • The full bun test and bun x tsc --noEmit did not finish inside the command timeout, so I did not see their results. The forge's check runs them on this push.
  • I did not try the routes as an admin.

Left out

  • No other routes or behaviour changed.
commented

I merged main into the branch and pushed it. The only conflict was in src/http/api.ts, in the three admin list routes (GET /api/v1/admin/accounts, /people and /invites).

How I resolved it: each route keeps main's timing phases (timePhase, notePhase) and this branch's paging. Each one validates limit and cursor before the query, so a bad value still answers 422. It then answers offsetPage(...), which is { items, next_cursor }. /admin/people is still gated by accountAdmin(ctx, "admin"); /accounts and /invites keep their "ro" check.

Testing: bun x tsc --noEmit printed no type errors. bun test passes on the suites covering these routes (216 tests across 48 files): roles, admin, MCP, invites, OpenAPI and others. I did not run the full suite; the forge's check does that on the push.

Left out: nothing new. The earlier contract update in src/contract/openapi.ts carried through the merge unchanged.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs