Public: anyone can read this; the crew can change it.
The admin's capacity and limits reads answer `{ items, next_cursor }` #5078
scout/forge:scout/5063-the-admin-s-capacity-and-limits-reads-an → main 2 commits fork 1 thread · 1 unresolved
6 files
changed +43
−8
README.md +3
| @@ -1522,6 +1522,9 @@ button (in the row's own form, beside Save) restores the default through | ||
| 1522 | 1522 | until the value is back at the default; nothing else reminds anyone. The |
| 1523 | 1523 | JSON API and MCP carry the same fact: a setting away from its default has a |
| 1524 | 1524 | `changed` field (`at`, `by`) in the capacity listing (`listCapacity`). |
| 1525 | `GET /api/v1/admin/capacity` and `/api/v1/admin/limits`, and the MCP `capacity` and | |
| 1526 | `limits` tools without a `key`, answer `{ items, changes, next_cursor: null }`: one | |
| 1527 | fixed page, the rows in `items`, the change log in `changes`. | |
| 1525 | 1528 | |
| 1526 | 1529 | The `setting:<key>` findings filed before that are all closed; none raises an |
| 1527 | 1530 | ask, and the capacity page's Put back is the one answer. The `sentinel_kept` |
src/http/api.ts +7 −2
| @@ -1631,7 +1631,10 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 1631 | 1631 | const denied = accountAdmin(ctx, "ro"); |
| 1632 | 1632 | if (denied) return denied; |
| 1633 | 1633 | const listed = listCapacity(ctx.app, ctx.auth.user); |
| 1634 | return listed.ok ? json(listed.value) : notFound(); | |
| 1634 | // A small, fixed list: one page, so no cursor. | |
| 1635 | return listed.ok | |
| 1636 | ? json({ items: listed.value.settings, changes: listed.value.changes, next_cursor: null }) | |
| 1637 | : notFound(); | |
| 1635 | 1638 | }); |
| 1636 | 1639 | |
| 1637 | 1640 | router.add("PUT", "/api/v1/admin/capacity/:key", async (ctx) => { |
| @@ -1656,7 +1659,9 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 1656 | 1659 | const denied = accountAdmin(ctx, "ro"); |
| 1657 | 1660 | if (denied) return denied; |
| 1658 | 1661 | const listed = listLimits(ctx.app, ctx.auth.user); |
| 1659 | return listed.ok ? json(listed.value) : notFound(); | |
| 1662 | return listed.ok | |
| 1663 | ? json({ items: listed.value.limits, changes: listed.value.changes, next_cursor: null }) | |
| 1664 | : notFound(); | |
| 1660 | 1665 | }); |
| 1661 | 1666 | |
| 1662 | 1667 | router.add("PUT", "/api/v1/admin/limits/:key", async (ctx) => { |
src/http/mcp.ts +2 −2
| @@ -3455,7 +3455,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 3455 | 3455 | const listed = listCapacity(ctx.app, user); |
| 3456 | 3456 | if (!listed.ok) return bad("not_found", "no such tool here"); |
| 3457 | 3457 | const key = typeof args["key"] === "string" ? args["key"] : undefined; |
| 3458 | if (key === undefined) return good(listed.value); | |
| 3458 | if (key === undefined) return good({ items: listed.value.settings, changes: listed.value.changes, next_cursor: null }); | |
| 3459 | 3459 | const value = typeof args["value"] === "string" ? args["value"] : ""; |
| 3460 | 3460 | const now = listed.value.settings.find((s) => s.key === key); |
| 3461 | 3461 | if (now === undefined) return bad("no_such_setting", `no capacity setting ${key}`); |
| @@ -3539,7 +3539,7 @@ const TOOLS: readonly Tool[] = [ | ||
| 3539 | 3539 | const listed = listLimits(ctx.app, user); |
| 3540 | 3540 | if (!listed.ok) return bad("not_found", "no such tool here"); |
| 3541 | 3541 | const key = typeof args["key"] === "string" ? args["key"] : undefined; |
| 3542 | if (key === undefined) return good(listed.value); | |
| 3542 | if (key === undefined) return good({ items: listed.value.limits, changes: listed.value.changes, next_cursor: null }); | |
| 3543 | 3543 | const value = typeof args["value"] === "string" ? args["value"] : ""; |
| 3544 | 3544 | const now = listed.value.limits.find((l) => l.key === key); |
| 3545 | 3545 | if (now === undefined) return bad("no_such_limit", `no limit ${key}`); |
test/capacity.test.ts +11 −1
| @@ -198,7 +198,12 @@ describe("capacity: only a forge admin reads or changes it", () => { | ||
| 198 | 198 | }); |
| 199 | 199 | |
| 200 | 200 | test("an admin with a read-only token may read, not change", async () => { |
| 201 | expect((await api(aliceRo, "GET", "/admin/capacity")).status).toBe(200); | |
| 201 | const read = await api(aliceRo, "GET", "/admin/capacity"); | |
| 202 | expect(read.status).toBe(200); | |
| 203 | const shape = (await read.json()) as { items: { key: string }[]; next_cursor: null; settings?: unknown }; | |
| 204 | expect(shape.items.map((s) => s.key)).toContain("checks.concurrency"); | |
| 205 | expect(shape.next_cursor).toBeNull(); | |
| 206 | expect(shape.settings).toBeUndefined(); | |
| 202 | 207 | expect( |
| 203 | 208 | ( |
| 204 | 209 | await api(aliceRo, "PUT", "/admin/capacity/checks.concurrency", { |
| @@ -206,6 +211,11 @@ describe("capacity: only a forge admin reads or changes it", () => { | ||
| 206 | 211 | }) |
| 207 | 212 | ).status, |
| 208 | 213 | ).toBe(403); |
| 214 | const listed = await mcp(aliceRo, {}); | |
| 215 | const mshape = JSON.parse(listed.text) as { items: { key: string }[]; next_cursor: null; settings?: unknown }; | |
| 216 | expect(mshape.items.map((s) => s.key)).toContain("checks.concurrency"); | |
| 217 | expect(mshape.next_cursor).toBeNull(); | |
| 218 | expect(mshape.settings).toBeUndefined(); | |
| 209 | 219 | const tool = await mcp(aliceRo, { |
| 210 | 220 | key: "checks.concurrency", |
| 211 | 221 | value: "3", |
test/guard-new-accounts.test.ts +2 −2
| @@ -188,9 +188,9 @@ describe("guard_new_accounts", () => { | ||
| 188 | 188 | headers: { authorization: `Bearer ${token}` }, |
| 189 | 189 | }).then( |
| 190 | 190 | (r) => |
| 191 | r.json() as Promise<{ settings: { key: string; value: string }[] }>, | |
| 191 | r.json() as Promise<{ items: { key: string; value: string }[] }>, | |
| 192 | 192 | ); |
| 193 | const keys = (await get()).settings.map((s) => s.key); | |
| 193 | const keys = (await get()).items.map((s) => s.key); | |
| 194 | 194 | expect(keys).toContain("guard_new_accounts"); |
| 195 | 195 | |
| 196 | 196 | const put = (value: string) => |
test/limits.test.ts +18 −1
| @@ -178,7 +178,24 @@ describe("limits", () => { | ||
| 178 | 178 | }); |
| 179 | 179 | const listed = await api(adminToken, "GET", "/admin/limits"); |
| 180 | 180 | expect(listed.status).toBe(200); |
| 181 | expect(((await listed.json()) as { limits: unknown[] }).limits).toHaveLength(LIMIT_KEYS.length); | |
| 181 | const shape = (await listed.json()) as { items: unknown[]; next_cursor: null; limits?: unknown }; | |
| 182 | expect(shape.items).toHaveLength(LIMIT_KEYS.length); | |
| 183 | expect(shape.next_cursor).toBeNull(); | |
| 184 | expect(shape.limits).toBeUndefined(); | |
| 185 | const rpc = await fetch(`${servers.url}/mcp`, { | |
| 186 | method: "POST", | |
| 187 | headers: { | |
| 188 | authorization: `Bearer ${adminToken}`, | |
| 189 | "content-type": "application/json", | |
| 190 | accept: "application/json, text/event-stream", | |
| 191 | }, | |
| 192 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "limits", arguments: {} } }), | |
| 193 | }); | |
| 194 | const tool = ((await rpc.json()) as { result: { content: { text: string }[] } }).result.content[0]!.text; | |
| 195 | const mshape = JSON.parse(tool) as { items: unknown[]; next_cursor: null; limits?: unknown }; | |
| 196 | expect(mshape.items).toHaveLength(LIMIT_KEYS.length); | |
| 197 | expect(mshape.next_cursor).toBeNull(); | |
| 198 | expect(mshape.limits).toBeUndefined(); | |
| 182 | 199 | expect((await api(bobToken, "GET", "/admin/limits")).status).toBe(403); |
| 183 | 200 | expect((await api(bobToken, "PUT", "/admin/limits/share.daily_max", { value: "9" })).status).toBe(403); |
| 184 | 201 | expect((await api(adminToken, "PUT", "/admin/limits/share.daily_max", { value: "0" })).status).toBe(422); |
new above
offline
This shape is right. The MCP
capacityandlimitstools (src/http/mcp.ts ~3458 and ~3542) stillgood(listed.value)on a keyless call, so they still answer{ settings, changes }/{ limits, changes }. Give them this same{ items, changes, next_cursor: null }and add a test for each.