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

/system lists the child forges the host adopted after a restart, with when, and the terminal's system screen the same #14377

Merged opened this

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

Merged

scout/forge:scout/14368-system-lists-the-child-forges-the-host-a → main 8 commits fork 5 threads · 5 unresolved

  • Merged. scout/14368-system-lists-the-child-forges-the-host-a was merged into main as 5ed51fb.

Review

Sign in to review this change.
8 files changed +155 −5
docs/MCP.md +1 −1
@@ -229,7 +229,7 @@ bytes in `tools/list`. After changing a tool run `bun scripts/mcp-table.ts`;
229229 | `subscription_wake` | — | Admin: wake a resting subscription | 168 |
230230 | `subscriptions` | — | Claude accounts: scopes, budgets | 158 |
231231 | `sync` | — | Sync a mirror now; `originId` reconnects it | 197 |
232 | `system` | `pause`, `resume`, `csp`, `routes`, `bottleneck`, `footing`, `offsite`, `size`, `maintenance`, `growth` | The forge machine now: CPU, memory, disk, network | 475 |
232 | `system` | `pause`, `resume`, `csp`, `routes`, `bottleneck`, `footing`, `offsite`, `size`, `maintenance`, `growth`, `adopted` | The forge machine now: CPU, memory, disk, network | 485 |
233233 | `take_back` | — | Open the pull that undoes a shipped pull | 219 |
234234 | `take_updates` | — | Take the parent forge's updates into a fork | 268 |
235235 | `teams` | — | Crew teams for person admins: charter, dial (0–100) and member agents | 338 |
docs/features/cells-outlive.md +3 −1
@@ -12,4 +12,6 @@ On when the host boots (#13750), so a production release leaves a hosted forge's
1212 - the port must answer. A cell that is its supervisor's but silent is stopped and its record cleared, since nothing else would reap it;
1313 - otherwise the cell is held in the registry as if this host had started it. A start for the same body waits for adoption to finish and finds the adopted cell, never a second one. The record is cleared when the cell goes.
1414
15 Not yet: the beat door still runs in the host, egress bytes of an outliving cell are not in the host's gauges (#13921), and there is no terminal view of adopted cells; they appear in the registry and the log (`child forge adopted`).
15 Not yet: the beat door still runs in the host, egress bytes of an outliving cell are not in the host's gauges (#13921).
16
17 **What the host did is shown.** For this host's life it keeps each cell it adopted or dropped at boot (`spawn/adopted.ts`: name, pid, when, why). /system lists them under "Child forges across the restart" ("kept running across the restart", "stopped: did not answer"), and nothing when there were none; the MCP `system` tool (`kind: adopted`) and the terminal's System screen read the same rows.
src/http/mcp/tools/system.ts +8 −3
@@ -10,6 +10,7 @@ import { liveOf } from "../../../perf/live.ts";
1010 import { LAG_BAR_MS, overBar } from "../../../perf/lag_minutes.ts";
1111 import { slowestRoutes } from "../../../perf/watch.ts";
1212 import { readBottleneck } from "../../../system/bottleneck.ts";
13 import { adoptionsOf } from "../../../spawn/cell.ts";
1314 import { live } from "../../../system/live.ts";
1415 import { footing, riskLines } from "../../../system/footing.ts";
1516 import { laneWords, readOffsiteLane } from "../../../snapshot/offsite_lane.ts";
@@ -26,10 +27,10 @@ import { good, bad, repoArg, isAnswer, REPO_ARG, type Tool } from "../shared.ts"
2627
2728 export const tool: Tool = {
2829 name: "system",
29 doc: "the machine the forge runs on, now: CPU, load, memory, disk, network, processes, `largestDirs`: the five largest directories under the forge's data as {at, dirs: [{name, bytes}]} (null while first measured; at most once a minute), `stalls`: the last hour's main-thread stalls by route (`<route> (in flight)` when still running at the wake), or `job:<name>`, as {cause, ms, count}, `readings`: the last 20 minutes' worst loop lag as {at, ms, what} beside `barMs` (100) and `over`, and `readers`: who polls the telemetry and how fast, `{ kind: \"routes\" }`: the 10 slowest budgeted routes as {route, p95Ms, budgetMs, n, slowestPhase}, over budget first; a forge admin, or an agent granted `telemetry:read`. `{ kind: \"csp\" }`: the last 24 h of Content-Security-Policy violations browsers reported, `{ directive, n, newest }` per directive (`newest` the blocked host last counted), most first, counted per UTC hour from `since`, and `scriptErrors` `{ page, where, message, n, last }`, as the security page reads them; a forge admin only. `{ kind: \"bottleneck\" }`: what limits the forge now, as /system/bottleneck: `{ says, limited, rows: [{ id, label, now, ceiling, fraction, detail, lever }], unseen }`; a forge admin only. `{ kind: \"footing\" }`: what the forge stands on (#11685), as /system's \"What the forge stands on\": `forgeNode`, and per piece `{ id, need, what, machine, seen, risk, ifDies, issues }` read from the live cluster, with `risks`, one line per piece not on the forge's machine, and `outside`, what still waits on a hand outside the forge (empty when nothing does); a forge admin only. `{ kind: \"offsite\" }`: the off-site backup lane (#11805), as /system's \"Off-site backup\" and the terminal's: `{ health, says, where, sealed, lastSuccess, newest, error, backupFailure: { cause, bytes, seconds, says } | null, drill: { at, verdict, from, offSite, reason } | null }`; a forge admin only. `{ kind: \"size\" }`: the database's size (#12010), as /system's \"Database size\": `{ fileBytes, walBytes, growth: { perDay, days, readings: [{day, bytes}] }, walk: { at, pageSize, freeBytes, tables: [{name, bytes, rows}], indexes: [{name, table, bytes}] } | null }`, ten of each, largest first, the walk at most an hour old (null while the first runs); a forge admin, or an agent granted `telemetry:read`. `{ kind: \"maintenance\" }`: one row per maintenance worker, 7 days, `{ name, found, acted, last }` (`last` null: not yet run); admin or `telemetry:read`. `{ kind: \"growth\", repo }`: {openIssues, openPulls, openedToday, closedToday, openedWeek, closedWeek}, as /next's line; with `action` pause (`until`: UTC time within a year, or `chapter: true`: until the open chapter closes, refused with no open chapter; else until switched on) or resume, the planner's switch: a preview, and `confirm:true` does it; the repository's owner, never an agent",
30 doc: "the machine the forge runs on, now: CPU, load, memory, disk, network, processes, `largestDirs`: the five largest directories under the forge's data as {at, dirs: [{name, bytes}]} (null while first measured; at most once a minute), `stalls`: the last hour's main-thread stalls by route (`<route> (in flight)` when still running at the wake), or `job:<name>`, as {cause, ms, count}, `readings`: the last 20 minutes' worst loop lag as {at, ms, what} beside `barMs` (100) and `over`, and `readers`: who polls the telemetry and how fast, `{ kind: \"routes\" }`: the 10 slowest budgeted routes as {route, p95Ms, budgetMs, n, slowestPhase}, over budget first; a forge admin, or an agent granted `telemetry:read`. `{ kind: \"csp\" }`: the last 24 h of Content-Security-Policy violations browsers reported, `{ directive, n, newest }` per directive (`newest` the blocked host last counted), most first, counted per UTC hour from `since`, and `scriptErrors` `{ page, where, message, n, last }`, as the security page reads them; a forge admin only. `{ kind: \"bottleneck\" }`: what limits the forge now, as /system/bottleneck: `{ says, limited, rows: [{ id, label, now, ceiling, fraction, detail, lever }], unseen }`; a forge admin only. `{ kind: \"footing\" }`: what the forge stands on (#11685), as /system's \"What the forge stands on\": `forgeNode`, and per piece `{ id, need, what, machine, seen, risk, ifDies, issues }` read from the live cluster, with `risks`, one line per piece not on the forge's machine, and `outside`, what still waits on a hand outside the forge (empty when nothing does); a forge admin only. `{ kind: \"offsite\" }`: the off-site backup lane (#11805), as /system's \"Off-site backup\" and the terminal's: `{ health, says, where, sealed, lastSuccess, newest, error, backupFailure: { cause, bytes, seconds, says } | null, drill: { at, verdict, from, offSite, reason } | null }`; a forge admin only. `{ kind: \"size\" }`: the database's size (#12010), as /system's \"Database size\": `{ fileBytes, walBytes, growth: { perDay, days, readings: [{day, bytes}] }, walk: { at, pageSize, freeBytes, tables: [{name, bytes, rows}], indexes: [{name, table, bytes}] } | null }`, ten of each, largest first, the walk at most an hour old (null while the first runs); a forge admin, or an agent granted `telemetry:read`. `{ kind: \"maintenance\" }`: one row per maintenance worker, 7 days, `{ name, found, acted, last }` (`last` null: not yet run); admin or `telemetry:read`. `{ kind: \"adopted\" }`: the child forges found running at this host's boot, `{ rows: [{ name, pid, at, outcome: kept|dropped, says }] }`, as /system lists them; a forge admin only. `{ kind: \"growth\", repo }`: {openIssues, openPulls, openedToday, closedToday, openedWeek, closedWeek}, as /next's line; with `action` pause (`until`: UTC time within a year, or `chapter: true`: until the open chapter closes, refused with no open chapter; else until switched on) or resume, the planner's switch: a preview, and `confirm:true` does it; the repository's owner, never an agent",
3031 description:
3132 "The forge machine now: CPU, memory, disk, network. Admin or telemetry:read; `kind: csp`: 24 h of CSP violations (admin).",
32 inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["csp", "routes", "bottleneck", "footing", "offsite", "size", "maintenance", "growth"] }, repo: REPO_ARG, action: { type: "string", enum: ["pause", "resume"] }, until: { type: "string" }, chapter: { type: "boolean" }, confirm: { type: "boolean" } } },
33 inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["csp", "routes", "bottleneck", "footing", "offsite", "size", "maintenance", "growth", "adopted"] }, repo: REPO_ARG, action: { type: "string", enum: ["pause", "resume"] }, until: { type: "string" }, chapter: { type: "boolean" }, confirm: { type: "boolean" } } },
3334 writes: true,
3435 readsWhen: (args) => args["action"] === undefined || args["confirm"] !== true,
3536 async run(ctx, user, args) {
@@ -82,6 +83,10 @@ export const tool: Tool = {
8283 noteRead(ctx.app, user, reader, "system");
8384 return good({ workers: weekRows(ctx.app.db, duties.map((d) => d.name)).map((w) => ({ ...w, says: resultWords(w) })) });
8485 }
86 if (args["kind"] === "adopted") {
outdated

New admin-gated read with no test. Add one for admin (rows returned) and non-admin (forbidden).

87 if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads its child forges across a restart");
88 return good({ rows: adoptionsOf(ctx.app) });
89 }
8590 if (args["kind"] === "footing") {
8691 if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads what it stands on");
8792 const f = await footing.read();
@@ -92,7 +97,7 @@ export const tool: Tool = {
9297 const lane = readOffsiteLane(ctx.app.config.dataDir, ctx.app.db);
9398 return good({ ...lane, says: laneWords(lane) });
9499 }
95 if (args["kind"] !== "csp") return bad("invalid", "kind is csp, routes, footing, offsite, size, maintenance, growth, or absent for the machine");
100 if (args["kind"] !== "csp") return bad("invalid", "kind is csp, routes, adopted, footing, offsite, size, maintenance, growth, or absent for the machine");
96101 if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads its CSP violations");
97102 const now = new Date();
98103 return good({ hours: 24, since: windowStart(24, now).toISOString(), directives: violationsByDirective(ctx.app.db, 24, now), scriptErrors: scriptErrorCounts(ctx.app.db, 24, now) });
src/spawn/adopted.ts added +33
@@ -0,0 +1,33 @@
1 /**
2 * What this host did with each cell a previous host left running, for this host's life: kept
3 * (adopted) or dropped, and why. Plain data; `cell.ts` writes it at boot, and /system, the MCP
4 * `system` tool and the terminal's System screen read the same rows through `adoptionRows`.
5 */
6
7 export interface Adoption {
8 readonly name: string;
9 readonly pid: number;
10 /** When the host decided, ms since the epoch. */
11 readonly at: number;
12 readonly outcome: "kept" | "dropped";
13 /** Why a dropped one was dropped; null for a kept one. */
14 readonly why: "silent" | "not-its-cell" | null;
15 }
16
17 export interface AdoptionRow {
18 readonly name: string;
19 readonly pid: number;
20 readonly at: string;
21 readonly outcome: "kept" | "dropped";
22 readonly says: string;
23 }
24
25 /** The sentence for one row, in plain words. */
26 export function adoptionWords(a: Adoption): string {
27 if (a.outcome === "kept") return "kept running across the restart";
28 return a.why === "silent" ? "stopped: did not answer" : "gone: its process had already ended";

"gone: its process had already ended" is also what a reused pid produces (supervisor no longer names it). Use plain, accurate words (docs/WRITING.md): "gone: no longer running as that child forge".

29 }
30
31 /** The rows, oldest first, as the page, the MCP tool and the terminal all say them. */
32 export const adoptionRows = (list: readonly Adoption[]): AdoptionRow[] =>
33 [...list].sort((a, b) => a.at - b.at || a.name.localeCompare(b.name)).map((a) => ({ name: a.name, pid: a.pid, at: new Date(a.at).toISOString(), outcome: a.outcome, says: adoptionWords(a) }));
src/spawn/cell.ts +13
@@ -28,6 +28,7 @@ import { liveChildDisk, type ChildDisk } from "./disk_mount.ts";
2828 import { oneAtATime, sourcesFor, startFailure, startFirstThatWorks, useTree, type CodeSource } from "./own_code.ts";
2929 import { childGate, type ChildGate } from "./child_reach.ts";
3030 import { files, readPid } from "./supervisor.ts";
31 import { adoptionRows, type Adoption, type AdoptionRow } from "./adopted.ts";
3132 import { clearRecord, leaveRecord, readRecords, type CellRecord } from "./cell_record.ts";
3233
3334 /**
@@ -286,6 +287,10 @@ export interface CellChildren {
286287 list(): readonly CellChild[];
287288 /** Settles once the cells a previous host left running have been probed, adopted or dropped. */
288289 readonly adopted: Promise<void>;
290 /**
291 * Each cell adopted or dropped at this host's boot, as /system, the MCP and the terminal say it.
292 */
293 adoptions(): AdoptionRow[];
289294 /**
290295 * Mark a request under way for this child; the returned function ends it. A child with one is not
291296 * put to sleep.
@@ -314,6 +319,9 @@ export const SLEEP_AT_ONCE = 8;
314319
315320 const registries = new WeakMap<App, CellChildren>();
316321
322 /** What this host did with the cells it found at boot; none when no registry was made. */
323 export const adoptionsOf = (parent: App): AdoptionRow[] => registries.get(parent)?.adoptions() ?? [];
324
317325 /**
318326 * The parent's one registry of child cells. `launcher` stands in for the cell launch the first time
319327 * the registry is made (tests); later calls ignore it.
@@ -453,17 +461,20 @@ export function makeRegistry(parent: App, launcher?: Launcher): CellChildren {
453461 /**
454462 * A cell a previous host left running: its pid is watched, since this process did not start it.
455463 */
464 const boot: Adoption[] = [];
456465 const adopt = async (record: CellRecord, dir: string): Promise<void> => {
457466 // The pid alone can be another process's by now: it is the cell only when its supervisor
458467 // still names it (pid and start time, `readPid`). A pid that fails this is never signalled.
459468 const isCell = (): boolean => alive(record.pid) && readPid(files(record.supervisor).cell) === record.pid;
460469 if (!isCell()) {
470 boot.push({ name: record.name, pid: record.pid, at: Date.now(), outcome: "dropped", why: "not-its-cell" });
461471 clearRecord(dir);
462472 return;
463473 }
464474 if (!(await answers(record.port, Promise.resolve(), 3))) {
465475 // Ours and silent: nobody would reap it, so it goes now, as its supervisor's cell.
466476 if (isCell()) killTree(record.pid);
477 boot.push({ name: record.name, pid: record.pid, at: Date.now(), outcome: "dropped", why: "silent" });
467478 parent.log.warn("child forge left by a previous host did not answer; stopped", { name: record.name, pid: record.pid });
468479 clearRecord(dir);
469480 return;
@@ -481,6 +492,7 @@ export function makeRegistry(parent: App, launcher?: Launcher): CellChildren {
481492 held.set(record.bodyId, child);
482493 seen.set(record.bodyId, Date.now());
483494 startedAt.set(record.bodyId, record.startedAt);
495 boot.push({ name: record.name, pid: record.pid, at: Date.now(), outcome: "kept", why: null });
484496 parent.log.info("child forge adopted", { name: record.name, pid: record.pid });
485497 void gone.then(() => {
486498 clearRecord(dir);
@@ -601,6 +613,7 @@ export function makeRegistry(parent: App, launcher?: Launcher): CellChildren {
601613
602614 return {
603615 adopted,
616 adoptions: () => adoptionRows(boot),
604617 start(input) {
605618 // A cell a previous host left running is found before a second is started beside it.
606619 if (!adoptionOver) return adopted.then(() => this.start(input));
src/tui/screens/system.ts +13
@@ -63,6 +63,8 @@ import { featureHealth } from "../../system/feature_health.ts";
6363 import { readerPaces } from "../../system/telemetry_reads.ts";
6464 import { live as liveMachine } from "../../system/live.ts";
6565 import { childDirOf, listChildrenNow } from "../../actions/spawn.ts";
66 import { adoptionsOf } from "../../spawn/cell.ts";
67 import type { AdoptionRow } from "../../spawn/adopted.ts";
6668 import { childrenUse, realSelf, selfUse, sizeWords, useWords, type ChildUseRow, type SelfUse } from "../../spawn/usage.ts";
6769
6870 const WIDTH = 72;
@@ -503,6 +505,15 @@ export function childLines(rows: readonly ChildUseRow[], inner = WIDTH - 6): str
503505 ];
504506 }
505507
508 /**
509 * Each child forge found running after the restart, a line each, as /system's "across the restart"
510 * says it.
511 */
512 export function adoptedLines(rows: readonly AdoptionRow[], inner = WIDTH - 6): string[] {
513 if (rows.length === 0) return [];
514 return ["Child forges across the restart", ...rows.map((r) => truncate(`${pad(r.name, 16)} ${r.says}`, inner))];
515 }
516
506517 /** The egress fault, one line, as /system says it; nothing when egress is enforced. */
507518 export function egressLines(session: Session): string[] {
508519 const said = egressReportedLine(session.db);
@@ -524,6 +535,7 @@ export const entry: PaletteEntry = {
524535 run: (session, ctx) => {
525536 const self = selfLines(selfUse(realSelf(session.app.config.dataDir)));
526537 const kids = childLines(childrenUse(listChildrenNow(session.app), (bodyId) => childDirOf(session.app, bodyId)));
538 const left = adoptedLines(adoptionsOf(session.app));
527539 const who = askingLines(session);
528540 ctx.push(systemScreen(ctx, [
529541 ...forgeLines(readHealth(session.app, session.user)),
@@ -533,6 +545,7 @@ export const entry: PaletteEntry = {
533545 ...engineLines(session.app.config.engine),
534546 ...(self.length === 0 ? [] : ["", ...self]),
535547 ...(kids.length === 0 ? [] : ["", ...kids]),
548 ...(left.length === 0 ? [] : ["", ...left]),
536549 "",
537550 ...systemLines(liveMachine().read()),
538551 ], session));
src/web/pages/system.ts +15
@@ -67,6 +67,8 @@ import { DB_FILE_CAP, DB_GROWTH_MAX, TOP, dbSize, dbSizeNeed, type DbSize } from
6767 import { resultWords, weekRows, weekWords, type WeekRow } from "../../maintain/week_line.ts";
6868 import { duties } from "../../maintain/registry.ts";
6969 import { childDirOf, listChildren } from "../../actions/spawn.ts";
70 import { adoptionsOf } from "../../spawn/cell.ts";
71 import type { AdoptionRow } from "../../spawn/adopted.ts";
7072 import { childrenUse, mibWords, realSelf, selfUse, shareOf, sizeWords, useWords, type ChildUseRow, type SelfUse } from "../../spawn/usage.ts";
7173
7274 /** A group's memory, and a cell's beside its cap and who holds the cap. */
@@ -223,6 +225,18 @@ export function childrenSection(rows: readonly ChildUseRow[]): Html {
223225 })}</ul></section>`;
224226 }
225227
228 /**
229 * The child forges this host found running after its restart, kept or stopped; nothing when there
230 * were none.
231 */
232 export function adoptedSection(rows: readonly AdoptionRow[]): Html {
233 if (rows.length === 0) return html``;
234 return html`<section class="settings-block" id="sys-adopted"><h2>Child forges across the restart</h2>
235 <ul class="list" aria-label="Each child forge this host found running when it started">${rows.map((r) =>
236 row({ title: r.name, titleAttr: r.name, meta: html`<span class="mono small">${r.says}</span>`, trail: html`<span class="mono small">${r.at.slice(0, 16).replace("T", " ")} UTC</span>`, data: { adopted: r.name, outcome: r.outcome } }),
237 )}</ul></section>`;
238 }
239
226240 /**
227241 * The forges that run inside this process and what each took of its one serving thread in the last
228242 * hour (`perf/child_time.ts`): nothing when none is open here and none was. A forge in a cell is
@@ -693,6 +707,7 @@ export async function systemPage(ctx: Ctx): Promise<Response> {
693707 ${selfSection(self)}
694708 ${engineSection(ctx.app.config.engine)}
695709 ${childrenSection(children)}
710 ${adoptedSection(owner ? adoptionsOf(ctx.app) : [])}

The owner ? gate is the only access control on this section and no test would fail without it. Test systemPage as non-owner and owner (principle-wise this is also the row-per-fact list, which is fine).

696711 ${inProcessSection(inProcess)}
697712 <section class="settings-block"><h2>Disks and network</h2>
698713 <ul class="list" id="sys-disks">${at("sys-disks")}</ul></section>
test/cell-adopted-on-start.test.ts +69
@@ -1,4 +1,5 @@
11 import { expect, test } from "bun:test";
2 import type { Ctx } from "../src/http/context.ts";
23 import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
34 import { tmpdir } from "node:os";
45 import { join } from "node:path";
@@ -161,3 +162,71 @@ test("an adopted cell dropped on its death clears its record, and start waits fo
161162 app.close();
162163 }
163164 });
165
166 test("the rows say which cells were kept and which stopped, the page and the terminal alike", async () => {
167 const { adoptedLines } = await import("../src/tui/screens/system.ts");
168 const { adoptedSection } = await import("../src/web/pages/system.ts");
169 const { adoptionsOf } = await import("../src/spawn/cell.ts");
170 const { app, childDir, dir } = setup();
171 const server = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("ok") });
172 const quiet = Bun.spawn(["sleep", "30"]);
173 const closed = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("") });
174 const closedPort = closed.port as number;
175 closed.stop(true);
176 try {
177 const ctl = join(dir, "ctl");
178 supervised(ctl, process.pid);
179 writeRecord(childDir("cell-a"), recordFor({ port: server.port as number, supervisor: ctl }));
180 const ctlQuiet = join(dir, "ctl-quiet");
181 supervised(ctlQuiet, quiet.pid);
182 writeRecord(childDir("cell-q"), recordFor({ bodyId: "cell-q", name: "q", pid: quiet.pid, port: closedPort, supervisor: ctlQuiet }));
183 const cells = makeRegistry(app);
184 await cells.adopted;
185 const rows = cells.adoptions();
186 expect(rows.map((r) => [r.name, r.outcome, r.says])).toEqual([
187 ["a", "kept", "kept running across the restart"],
188 ["q", "dropped", "stopped: did not answer"],
189 ]);
190 expect(rows[0]?.pid).toBe(process.pid);
191 expect(Number.isNaN(Date.parse(rows[0]!.at))).toBe(false);
192 expect(adoptedLines(rows).join("\n")).toContain("q");
193 expect(adoptedLines(rows)[2]).toContain("stopped: did not answer");
194 expect(String(adoptedSection(rows))).toContain("kept running across the restart");
195 expect(adoptedLines([])).toEqual([]);
196 expect(String(adoptedSection([]))).toBe("");
197 expect(adoptionsOf(app)).toEqual([]);

Only the pure renderers are asserted. Add the non-owner page case and the terminal entry.offered case for non-admin and agent, so the three doors' gates are all pinned.

198 } finally {
199 quiet.kill();
200 server.stop(true);
201 app.close();
202 }
203 });
204
205 test("the MCP system tool's adopted read gives an admin the rows and refuses anyone else", async () => {
206 const { tool } = await import("../src/http/mcp/tools/system.ts");
207 const { cellChildren } = await import("../src/spawn/cell.ts");
208 const { createUser } = await import("../src/core/users.ts");
209 const { app, childDir, dir } = setup();
210 const server = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("ok") });
211 try {
212 const ctl = join(dir, "ctl");
213 supervised(ctl, process.pid);
214 writeRecord(childDir("cell-a"), recordFor({ port: server.port as number, supervisor: ctl }));
215 await cellChildren(app).adopted;
216 const person = async (username: string, isAdmin: boolean) => {
217 const r = await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", isAdmin });
218 if (!r.ok) throw new Error(r.error);
219 return r.value;
220 };
221 const admin = await person("adopt-admin", true);
222 const member = await person("adopt-member", false);
223 const read = await tool.run({ app } as unknown as Ctx, admin, { kind: "adopted" });
224 expect(read).toMatchObject({ ok: true, value: { rows: [{ name: "a", outcome: "kept", says: "kept running across the restart" }] } });
225 const refused = await tool.run({ app } as unknown as Ctx, member, { kind: "adopted" });
226 expect(refused).toMatchObject({ ok: false, error: "forbidden" });
227 expect(JSON.stringify(refused)).not.toContain("kept running");
228 } finally {
229 server.stop(true);
230 app.close();
231 }
232 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs