An agent card shows its freshness (stale with the last report's age, never reported, not in swarm identity) when it is not fresh, so the status filter has a visible reason. A failed state change shows its reason in a panel under the card, and a failed cancel shows its reason in the badge, instead of a hover title. Pages can set their title (usePageTitle) and the flow editor does, so several editor tabs differ; the 404 links home. The claude login dialog offers try again after a failure, announces its wait, and has a per-agent field id. The create-agent tabs go forward again as far as the operator has been, but not past a step that is invalid now (lastReachableStep, tested), and the disabled next and create buttons say why in a hint they are described by. usePolled reports when the last live answer arrived, and StaleNote says how old a list is under a failed refresh, or that it is the answer saved from the last visit, on the alerts, builds, review runs, hives, schedules and flows lists.
115 lines
4 KiB
JavaScript
115 lines
4 KiB
JavaScript
// The create-agent dialog's steps: order, what gates next, and the summary.
|
|
// Run by `npm test` with Node's type stripping.
|
|
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import {
|
|
lastReachableStep,
|
|
nameProblem,
|
|
nextStep,
|
|
previousStep,
|
|
STEPS,
|
|
stepProblem,
|
|
summaryRows,
|
|
} from "../src/pages/CreateAgentSteps.ts";
|
|
|
|
const ready = {
|
|
name: "ruth",
|
|
hive: "h1",
|
|
permissionsReady: true,
|
|
inferenceProblem: null,
|
|
};
|
|
|
|
test("the steps run in order and stop at both ends", () => {
|
|
assert.deepEqual(STEPS, [
|
|
"identity",
|
|
"instructions",
|
|
"permissions",
|
|
"resources",
|
|
"summary",
|
|
]);
|
|
assert.equal(nextStep("identity"), "instructions");
|
|
assert.equal(nextStep("resources"), "summary");
|
|
assert.equal(nextStep("summary"), "summary");
|
|
assert.equal(previousStep("summary"), "resources");
|
|
assert.equal(previousStep("identity"), "identity");
|
|
});
|
|
|
|
test("a name is 1-63 lowercase letters, digits and hyphens", () => {
|
|
assert.equal(nameProblem("ruth-2"), null);
|
|
assert.equal(nameProblem("a".repeat(63)), null);
|
|
assert.notEqual(nameProblem(""), null);
|
|
assert.notEqual(nameProblem("a".repeat(64)), null);
|
|
assert.notEqual(nameProblem("Ruth"), null);
|
|
assert.notEqual(nameProblem("ru th"), null);
|
|
});
|
|
|
|
test("identity needs a valid name and a hive before next", () => {
|
|
assert.equal(stepProblem("identity", ready), null);
|
|
assert.notEqual(stepProblem("identity", { ...ready, name: "" }), null);
|
|
assert.notEqual(stepProblem("identity", { ...ready, name: "No Way" }), null);
|
|
assert.equal(stepProblem("identity", { ...ready, hive: "" }), "pick a hive");
|
|
});
|
|
|
|
test("permissions waits for the list, resources for a valid inference", () => {
|
|
assert.notEqual(
|
|
stepProblem("permissions", { ...ready, permissionsReady: false }),
|
|
null,
|
|
);
|
|
assert.equal(stepProblem("permissions", ready), null);
|
|
assert.equal(
|
|
stepProblem("resources", { ...ready, inferenceProblem: "bad model" }),
|
|
"bad model",
|
|
);
|
|
assert.equal(stepProblem("instructions", { ...ready, name: "" }), null);
|
|
});
|
|
|
|
test("the summary lists what is sent and what stays at its default", () => {
|
|
const rows = (over) =>
|
|
Object.fromEntries(
|
|
summaryRows({
|
|
name: "ruth",
|
|
hive: "h1",
|
|
archetype: undefined,
|
|
permissions: undefined,
|
|
caps: {},
|
|
inference: {},
|
|
agentsMd: "",
|
|
...over,
|
|
}).map((r) => [r.label, r.value]),
|
|
);
|
|
const plain = rows({});
|
|
assert.equal(plain.name, "ruth");
|
|
assert.equal(plain.archetype, "none: a custom agent");
|
|
assert.equal(plain.permissions, "the default set");
|
|
assert.equal(plain["resource caps"], "none set");
|
|
assert.equal(plain.inference, "none set");
|
|
assert.equal(plain.instructions, "none");
|
|
|
|
const set = rows({
|
|
archetype: "reviewer",
|
|
permissions: ["meta", "inbox"],
|
|
caps: { cpu_quota: "200%", memory_max: "2G" },
|
|
inference: { model: "opus", subagent_models: ["haiku", "sonnet"] },
|
|
agentsMd: " Be brief.\n",
|
|
});
|
|
assert.equal(set.archetype, "reviewer");
|
|
assert.equal(set.permissions, "meta, inbox");
|
|
assert.equal(set["resource caps"], "cpu quota 200%; memory max 2G");
|
|
assert.equal(set.inference, "model opus; subagent models haiku, sonnet");
|
|
assert.equal(set.instructions, "AGENTS.md, 2 words");
|
|
assert.equal(rows({ permissions: [] }).permissions, "none");
|
|
assert.equal(rows({ agentsMd: "x" }).instructions, "AGENTS.md, 1 word");
|
|
});
|
|
|
|
test("the tabs go forward as far as the operator has been, not past a bad step", () => {
|
|
// On the summary (4) having been there: every step is open.
|
|
assert.equal(lastReachableStep(4, -1, 4), 4);
|
|
// Back on the identity step (0) after reaching the summary: still open to 4.
|
|
assert.equal(lastReachableStep(4, -1, 0), 4);
|
|
// The name went bad (step 0): only the current step is open.
|
|
assert.equal(lastReachableStep(4, 0, 0), 0);
|
|
// A bad permissions step (2) stops the tabs there.
|
|
assert.equal(lastReachableStep(4, 2, 0), 2);
|
|
// Never behind the current step.
|
|
assert.equal(lastReachableStep(1, 0, 3), 3);
|
|
});
|