Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: the setup assistant shows when ruth is declared destroyed

This commit is contained in:
iris 2026-10-28 22:14:52 +01:00
commit 1ee481c0b1
2 changed files with 25 additions and 6 deletions

View file

@ -1,8 +1,10 @@
// Whether the swarm has no agent named `ruth`, from `GET /api/agents/status`.
// The start page's setup assistant shows only then. It is a nudge, so
// anything short of a clear "ruth is not in the roster" answers `false`: a
// failed request or an unreadable list must not tell the operator to set
// up an agent that may already exist.
// The start page's setup assistant shows only then: when the roster has no
// `ruth`, or has one its hive declares `destroyed` (the declaration stays in
// the roster for good, though the agent is gone). Offline and paused still
// count as an agent. It is a nudge, so anything short of a clear answer
// is `false`: a failed request or an unreadable list must not tell the
// operator to set up an agent that may already exist.
type Fetch = (url: string) => Promise<{
ok: boolean;
@ -15,7 +17,10 @@ export async function ruthIsMissing(fetchImpl: Fetch): Promise<boolean> {
if (!r.ok) return false;
const rows = await r.json();
if (!Array.isArray(rows)) return false;
return !rows.some((row) => (row as { name?: unknown }).name === "ruth");
return !rows.some((row) => {
const { name, wanted } = row as { name?: unknown; wanted?: unknown };
return name === "ruth" && wanted !== "destroyed";
});
} catch {
return false;
}

View file

@ -33,6 +33,20 @@ test("a roster with ruth means she is not missing", async () => {
);
});
test("a ruth declared destroyed is missing; a stopped or paused one is not", async () => {
assert.equal(
await ruthIsMissing(answering([{ name: "ruth", wanted: "destroyed" }])),
true,
);
for (const wanted of ["up", "offline", "paused", null, undefined]) {
assert.equal(
await ruthIsMissing(answering([{ name: "ruth", wanted }])),
false,
String(wanted),
);
}
});
test("anything but a clear answer is not missing", async () => {
assert.equal(await ruthIsMissing(answering([], false)), false);
assert.equal(await ruthIsMissing(answering({ not: "a list" })), false);