Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/ruth-missing.test.mjs

100 lines
3 KiB
JavaScript

// The setup assistant: its "is ruth missing" check and the archetype it
// creates her from. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import { RUTH_ARCHETYPE, ruthIsMissing } from "../src/shell/ruth-missing.ts";
import {
findArchetype,
prefill,
requestArchetype,
} from "../src/pages/CreateAgentArchetype.ts";
import { requestPermissions } from "../src/pages/CreateAgentPermissions.ts";
const answering =
(body, ok = true) =>
async () => ({
ok,
json: async () => body,
});
test("a roster without ruth means ruth is missing", async () => {
assert.equal(
await ruthIsMissing(answering([{ name: "atlas" }, { name: "argus" }])),
true,
);
assert.equal(await ruthIsMissing(answering([])), true);
});
test("a roster with ruth means she is not missing", async () => {
assert.equal(
await ruthIsMissing(answering([{ name: "atlas" }, { name: "ruth" }])),
false,
);
});
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);
assert.equal(
await ruthIsMissing(async () => {
throw new Error("offline");
}),
false,
);
});
const defaults = ["messaging", "meta", "inbox", "execution"];
const listed = [
{ source: "hyperhive", name: "reviewer", description: "reviews" },
{
source: "hyperhive",
name: "ruth",
description: "manager",
permissions: [...defaults, "manage_root_agent", "logs", "metrics"],
inference: { model: "sonnet" },
},
];
// The assistant's form opens on the `ruth` archetype, so a new ruth is sent
// with the archetype's permissions and model; the default alone has no
// `manage_root_agent`.
test("the assistant creates ruth from the ruth archetype", () => {
const ruth = findArchetype(listed, RUTH_ARCHETYPE);
assert.equal(ruth?.name, "ruth");
const filled = prefill(ruth, defaults);
assert.deepEqual(requestPermissions(filled.permissions, defaults), [
...defaults,
"manage_root_agent",
"logs",
"metrics",
]);
assert.equal(filled.inference.model, "sonnet");
assert.deepEqual(requestArchetype(ruth), {
source: "hyperhive",
name: "ruth",
});
});
test("a swarm that does not list the ruth archetype gives none to pick", () => {
assert.equal(findArchetype([listed[0]], RUTH_ARCHETYPE), undefined);
assert.equal(findArchetype([], RUTH_ARCHETYPE), undefined);
// Same name from another source is not hers.
assert.equal(
findArchetype([{ ...listed[1], source: "elsewhere" }], RUTH_ARCHETYPE),
undefined,
);
});