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

The admin's capacity and limits reads answer `{ items, next_cursor }` #5078

Parked opened this
Closed without merging

scout/forge:scout/5063-the-admin-s-capacity-and-limits-reads-an → main 2 commits fork 1 thread · 1 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
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
15221522 until the value is back at the default; nothing else reminds anyone. The
15231523 JSON API and MCP carry the same fact: a setting away from its default has a
15241524 `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`.
15251528
15261529 The `setting:<key>` findings filed before that are all closed; none raises an
15271530 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 {
16311631 const denied = accountAdmin(ctx, "ro");
16321632 if (denied) return denied;
16331633 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.

This shape is right. The MCP capacity and limits tools (src/http/mcp.ts ~3458 and ~3542) still good(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.

1635 return listed.ok
1636 ? json({ items: listed.value.settings, changes: listed.value.changes, next_cursor: null })
1637 : notFound();
16351638 });
16361639
16371640 router.add("PUT", "/api/v1/admin/capacity/:key", async (ctx) => {
@@ -1656,7 +1659,9 @@ export function apiRoutes(router: Router<Handler>): void {
16561659 const denied = accountAdmin(ctx, "ro");
16571660 if (denied) return denied;
16581661 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();
16601665 });
16611666
16621667 router.add("PUT", "/api/v1/admin/limits/:key", async (ctx) => {
src/http/mcp.ts +2 −2
@@ -3455,7 +3455,7 @@ const TOOLS: readonly Tool[] = [
34553455 const listed = listCapacity(ctx.app, user);
34563456 if (!listed.ok) return bad("not_found", "no such tool here");
34573457 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 });
34593459 const value = typeof args["value"] === "string" ? args["value"] : "";
34603460 const now = listed.value.settings.find((s) => s.key === key);
34613461 if (now === undefined) return bad("no_such_setting", `no capacity setting ${key}`);
@@ -3539,7 +3539,7 @@ const TOOLS: readonly Tool[] = [
35393539 const listed = listLimits(ctx.app, user);
35403540 if (!listed.ok) return bad("not_found", "no such tool here");
35413541 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 });
35433543 const value = typeof args["value"] === "string" ? args["value"] : "";
35443544 const now = listed.value.limits.find((l) => l.key === key);
35453545 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", () => {
198198 });
199199
200200 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();
202207 expect(
203208 (
204209 await api(aliceRo, "PUT", "/admin/capacity/checks.concurrency", {
@@ -206,6 +211,11 @@ describe("capacity: only a forge admin reads or changes it", () => {
206211 })
207212 ).status,
208213 ).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();
209219 const tool = await mcp(aliceRo, {
210220 key: "checks.concurrency",
211221 value: "3",
test/guard-new-accounts.test.ts +2 −2
@@ -188,9 +188,9 @@ describe("guard_new_accounts", () => {
188188 headers: { authorization: `Bearer ${token}` },
189189 }).then(
190190 (r) =>
191 r.json() as Promise<{ settings: { key: string; value: string }[] }>,
191 r.json() as Promise<{ items: { key: string; value: string }[] }>,
192192 );
193 const keys = (await get()).settings.map((s) => s.key);
193 const keys = (await get()).items.map((s) => s.key);
194194 expect(keys).toContain("guard_new_accounts");
195195
196196 const put = (value: string) =>
test/limits.test.ts +18 −1
@@ -178,7 +178,24 @@ describe("limits", () => {
178178 });
179179 const listed = await api(adminToken, "GET", "/admin/limits");
180180 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();
182199 expect((await api(bobToken, "GET", "/admin/limits")).status).toBe(403);
183200 expect((await api(bobToken, "PUT", "/admin/limits/share.daily_max", { value: "9" })).status).toBe(403);
184201 expect((await api(adminToken, "PUT", "/admin/limits/share.daily_max", { value: "0" })).status).toBe(422);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs