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

77 lines
2.2 KiB
JavaScript

// The setup assistant: its "is ruth missing" check and the permissions it
// creates her with. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
RUTH_EXTRA_PERMISSIONS,
ruthIsMissing,
} from "../src/shell/ruth-missing.ts";
import {
initialSelection,
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,
);
});
// The assistant's create form sends `manage_root_agent` with the default
// set, so a new ruth holds it from her first start; the default alone does not.
test("the assistant creates ruth with manage_root_agent", () => {
const defaults = ["messaging", "meta", "inbox", "execution"];
const all = [...defaults, "web_tools", "manage_root_agent"];
assert.deepEqual(
requestPermissions(
initialSelection(all, defaults, RUTH_EXTRA_PERMISSIONS),
defaults,
),
[...defaults, "manage_root_agent"],
);
assert.equal(
requestPermissions(initialSelection(all, defaults, []), defaults),
undefined,
);
});