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

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

Parked opened this
Closed without merging

scout/forge:scout/5063-the-admin-s-capacity-and-limits-reads-an → main 4 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +51 −9
README.md +3
@@ -1558,6 +1558,9 @@ button (in the row's own form, beside Save) restores the default through
15581558 until the value is back at the default; nothing else reminds anyone. The
15591559 JSON API and MCP carry the same fact: a setting away from its default has a
15601560 `changed` field (`at`, `by`) in the capacity listing (`listCapacity`).
1561 `GET /api/v1/admin/capacity` and `/api/v1/admin/limits`, and the MCP `capacity` and
1562 `limits` tools without a `key`, answer `{ items, changes, next_cursor: null }`: one
1563 fixed page, the rows in `items`, the change log in `changes`.
15611564
15621565 The `setting:<key>` findings filed before that are all closed; none raises an
15631566 ask, and the capacity page's Put back is the one answer. The `sentinel_kept`
src/http/api.ts +12 −2
@@ -1670,7 +1670,12 @@ export function apiRoutes(router: Router<Handler>): void {
16701670 const denied = accountAdmin(ctx, "ro");
16711671 if (denied) return denied;
16721672 const listed = timePhase(ctx.request, "capacity", () => listCapacity(ctx.app, ctx.auth.user));
1673 return timePhase(ctx.request, "render", () => (listed.ok ? json(listed.value) : notFound()));
1673 // A small, fixed list: one page, so no cursor.
1674 return timePhase(ctx.request, "render", () =>
1675 listed.ok
1676 ? json({ items: listed.value.settings, changes: listed.value.changes, next_cursor: null })
1677 : notFound(),
1678 );
16741679 });
16751680
16761681 router.add("PUT", "/api/v1/admin/capacity/:key", async (ctx) => {
@@ -1696,7 +1701,12 @@ export function apiRoutes(router: Router<Handler>): void {
16961701 const denied = accountAdmin(ctx, "ro");
16971702 if (denied) return denied;
16981703 const listed = timePhase(ctx.request, "limits", () => listLimits(ctx.app, ctx.auth.user));
1699 return timePhase(ctx.request, "render", () => (listed.ok ? json(listed.value) : notFound()));
1704 // A small, fixed list: one page, so no cursor.
1705 return timePhase(ctx.request, "render", () =>
1706 listed.ok
1707 ? json({ items: listed.value.limits, changes: listed.value.changes, next_cursor: null })
1708 : notFound(),
1709 );
17001710 });
17011711
17021712 router.add("PUT", "/api/v1/admin/limits/:key", async (ctx) => {
src/http/mcp.ts +2 −2
@@ -3855,7 +3855,7 @@ const TOOLS: readonly Tool[] = [
38553855 const listed = listCapacity(ctx.app, user);
38563856 if (!listed.ok) return bad("not_found", "no such tool here");
38573857 const key = typeof args["key"] === "string" ? args["key"] : undefined;
3858 if (key === undefined) return good(listed.value);
3858 if (key === undefined) return good({ items: listed.value.settings, changes: listed.value.changes, next_cursor: null });
38593859 const value = typeof args["value"] === "string" ? args["value"] : "";
38603860 const now = listed.value.settings.find((s) => s.key === key);
38613861 if (now === undefined) return bad("no_such_setting", `no capacity setting ${key}`);
@@ -3939,7 +3939,7 @@ const TOOLS: readonly Tool[] = [
39393939 const listed = listLimits(ctx.app, user);
39403940 if (!listed.ok) return bad("not_found", "no such tool here");
39413941 const key = typeof args["key"] === "string" ? args["key"] : undefined;
3942 if (key === undefined) return good(listed.value);
3942 if (key === undefined) return good({ items: listed.value.limits, changes: listed.value.changes, next_cursor: null });
39433943 const value = typeof args["value"] === "string" ? args["value"] : "";
39443944 const now = listed.value.limits.find((l) => l.key === key);
39453945 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);
test/mcp.test.ts +3 −1
@@ -981,7 +981,9 @@ describe("the forge over MCP", () => {
981981
982982 const before = limitValue(app.db, key);
983983 const listed = await tool(ro, "limits");
984 expect(listed.value.limits.map((l: any) => l.key)).toContain(key);
984 expect(listed.value.items.map((l: any) => l.key)).toContain(key);
985 expect(listed.value.next_cursor).toBeNull();
986 expect(listed.value.limits).toBeUndefined();
985987
986988 // The default is a dry run: nothing changes, even with an admin token.
987989 const dry = await tool(admin, "limits", { key, value: "13" });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs