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

GET /api/v1/admin/limits answers `{ items, next_cursor: null }` #5164

Merged opened this

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

Merged

`GET /api/v1/admin/limits` now answers `{ items, next_cursor: null }`, where `items` is the array of limit rows. `bun x tsc --noEmit` is clean, and the touched tests pass, including `test/mcp.test.ts`, `test/limits.test.ts`, `test/admin_refused.test.ts` and the OpenAPI tests.

shipped production is serving it deploy 9105665

opened this

GET /api/v1/admin/limits now answers { items, next_cursor: null }, where items is the array of limit rows. bun x tsc --noEmit is clean, and the touched tests pass, including test/mcp.test.ts, test/limits.test.ts, test/admin_refused.test.ts and the OpenAPI tests.

  • Handler: only the HTTP handler in src/http/api.ts changed. listLimits in src/actions/limits.ts still returns { limits, changes }, so the MCP limits tool, the pages and the terminal are untouched.
  • OpenAPI: the row's summary in src/contract/openapi.ts now says { items: [{ key, value, isSet, defaultValue, ... }], next_cursor }.
  • Test: the API test in test/limits.test.ts now asserts that items has one entry per limit key and that next_cursor is null.
  • Callers: the terminal screens (quotas.ts, invites.ts, forge.ts) never call the HTTP route, so none needed a fix. The only test that read the body was the one in test/limits.test.ts.

Left out: the old response also carried the changes history of limit edits, and it is gone from the HTTP route. The issue's { items, next_cursor: null } shape has no place for it. Say if you want it back as an extra field.

To try it, call GET /api/v1/admin/limits with an admin token.

🤖 Generated with Claude Code

Closes #5146

Changes requested — before the latest push

The shape change is right and safe: auth is still accountAdmin(ctx, "ro"), the handler stays thin, listLimits is untouched so the MCP tool, the page and the terminal keep their reads, and test/limits.test.ts passes. The preview answers 404 to a request with no token, as it should.

One miss blocks it: the response drops changes, the history of who changed which limit and when. That is the audit trail of an admin control. After this pull the JSON API cannot reach it at all, even though the page and MCP still show it. The issue did not ask for that. Its own code, json({ items: listed.value, ... }), would have kept the field inside a nested object. This file already has the pattern for a list that carries history: the egress grants route answers json({ items: view.value.rows, changes: view.value.changes, next_cursor: null }) (src/http/api.ts around line 5722).

What to fix first: answer json({ items: listed.value.limits, changes: listed.value.changes, next_cursor: null }). Then add a test assertion that would fail without it: make a PUT and expect body.changes to be an array whose first entry is that key. Also update the OpenAPI summary to { items: [...], changes, next_cursor }.

commented

GET /api/v1/admin/limits now answers { items, changes, next_cursor: null }. items is the array of limit rows and changes is the limit-change history. That is the same shape the egress grants route uses.

I took all three of sentinel's points:

  • Handler: src/http/api.ts returns changes: listed.value.changes as a sibling field. listLimits is still untouched.
  • OpenAPI summary: the row for this route in src/contract/openapi.ts now reads { items: [...], changes, next_cursor }.
  • Test: test/limits.test.ts now reads the list after a PUT of share.daily_max. It asserts changes is an array and its first entry has that key. It fails if changes is dropped.

bun x tsc --noEmit is clean. test/limits.test.ts, test/mcp.test.ts and the OpenAPI tests pass. I did not re-run test/admin_refused.test.ts this round. It passed on the first push and this change doesn't touch its routes.

No callers needed changes. The terminal screens never call this route.

To try it, call GET /api/v1/admin/limits with an admin token.

🤖 Generated with Claude Code

Approved

Clean. GET /api/v1/admin/limits now answers { items, changes, next_cursor: null }. That is the same envelope the egress grants route uses (src/http/api.ts ~5722), so the limit-change history from the last round is back.

  • Security: auth is unchanged. accountAdmin(ctx, "ro") still gates the route, and the response is json(), not user text. On the preview, an anonymous call and a junk-bearer call both get the documented 404 not_found.
  • Scope: only the HTTP handler changed. listLimits keeps { limits, changes }, so the MCP limits tool, the page and the terminal are untouched, as #5146 asked. No caller of the HTTP route reads the body, and the OpenAPI summary matches the new shape.
  • Tests: I applied the diff locally. bun test test/limits.test.ts gives 6 pass, 0 fail. The new assertions on items, next_cursor and changes[0].key would each fail against the old body or with changes dropped.
  • Both doors: no new capability, so there is nothing to add to the tty or the README.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs