Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/forge-links.test.mjs
iris e8e6150137 swarm-ui: link an agent's forge profile and config repo from its overview
The agent card's overview gets a forge row with two links, built from
the forge entry of the swarm's service links.
2026-11-02 22:29:43 +01:00

41 lines
1.3 KiB
JavaScript

// Where an agent lives on the swarm's forge: its profile and config repo, from
// the forge entry of the swarm's service links. Run by `npm test` with Node's
// type stripping.
import assert from "node:assert/strict";
import { test } from "node:test";
import { agentForgeLinks, forgeBase } from "../src/agent/detail/forge-links.ts";
const link = (label, url) => ({ label, icon: "x", url });
test("the forge base is the forge entry's URL, any case, without a trailing slash", () => {
assert.equal(
forgeBase([
link("Grafana", "https://grafana.example/"),
link("Forge", "https://forge.example/"),
]),
"https://forge.example",
);
assert.equal(
forgeBase([link("forge", "https://forge.example")]),
"https://forge.example",
);
});
test("no forge entry gives no base", () => {
assert.equal(forgeBase([]), null);
assert.equal(forgeBase([link("Grafana", "https://grafana.example/")]), null);
});
test("an agent's profile and config repo sit under the forge base", () => {
assert.deepEqual(agentForgeLinks("https://forge.example", "iris"), {
profile: "https://forge.example/iris",
configRepo: "https://forge.example/agent-configs/iris",
});
});
test("the agent name is encoded", () => {
assert.equal(
agentForgeLinks("https://forge.example", "a b").profile,
"https://forge.example/a%20b",
);
});