Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/create-agents-md.test.mjs

70 lines
2.4 KiB
JavaScript

// What the create-agent form sends for the initial AGENTS.md, and which error
// it shows beside the box. Run by `npm test`, which Node runs with its
// built-in test runner and type stripping, so the `.ts` module is imported as
// it is.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
agentsMdAfterPick,
agentsMdBody,
agentsMdRefusal,
} from "../src/pages/CreateAgentAgentsMd.ts";
test("an empty or whitespace-only box sends no agents_md", () => {
assert.deepEqual(agentsMdBody(""), {});
assert.deepEqual(agentsMdBody(" \n\t \n"), {});
});
test("text is sent as typed, whitespace and all", () => {
assert.deepEqual(agentsMdBody("# me\n\nDo the thing.\n"), {
agents_md: "# me\n\nDo the thing.\n",
});
assert.deepEqual(agentsMdBody(" indented"), { agents_md: " indented" });
});
test("the size refusal shows beside the box", () => {
const detail = "agents_md is 70000 bytes; the limit is 65536";
assert.equal(agentsMdRefusal({ status: 400, detail }), detail);
});
test("other failures stay with the general error", () => {
assert.equal(
agentsMdRefusal({ status: 400, detail: "name is not a valid identifier" }),
null,
);
assert.equal(
agentsMdRefusal({
status: 500,
detail: "agents_md is 70000 bytes; the limit is 65536",
}),
null,
);
assert.equal(agentsMdRefusal({ status: 400 }), null);
assert.equal(agentsMdRefusal({ detail: "agents_md is too long" }), null);
});
test("a pick fills an empty box with the archetype's prompt", () => {
assert.equal(agentsMdAfterPick("", "", "Review only."), "Review only.");
assert.equal(agentsMdAfterPick(" \n", "", "Review only."), "Review only.");
});
test("a pick keeps text the operator typed or edited", () => {
assert.equal(agentsMdAfterPick("# mine", "", "Review only."), "# mine");
assert.equal(
agentsMdAfterPick("Review only. Also x.", "Review only.", "Triage."),
"Review only. Also x.",
);
});
test("a pick over an unedited prefill swaps it, and none clears it", () => {
assert.equal(
agentsMdAfterPick("Review only.", "Review only.", "Triage."),
"Triage.",
);
assert.equal(agentsMdAfterPick("Review only.", "Review only.", ""), "");
});
test("an archetype without a prompt leaves the box as it is", () => {
assert.equal(agentsMdAfterPick("# mine", "", ""), "# mine");
assert.equal(agentsMdAfterPick("", "", ""), "");
});