Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/create-agents-md.test.mjs
iris 30ba34f411 swarm-ui: let the create-agent form set the new agent's initial AGENTS.md
The form gets a collapsed "instructions" section with a plain text box. Its
text goes in the optional agents_md field of the create request, and is left
out while the box is empty or only whitespace. The controller's size refusal
shows under the box instead of in the form's general error panel. The text
box empties after a successful create.

The send and refusal logic sits in its own module with tests, and
docs/swarm/ui.md describes the field.
2026-10-18 15:59:19 +02:00

43 lines
1.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 {
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);
});