Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/routes.test.mjs
iris 79f2d4bd4d swarm-ui: open the terminal, group and flow pages for a malformed address
A name or id that isn't valid percent-encoding (for example /agents/%E0%A4%A/terminal)
made decodeURIComponent throw while the page rendered, leaving a blank page. The
segment now stays as typed, as the agents page already did, so the page opens
(a terminal for that name, disconnected). A tested helper does the decoding.
2026-11-25 20:48:10 +01:00

122 lines
3.9 KiB
JavaScript

// The shell's per-route layout: which paths are full-bleed. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
MOVED_ROUTES,
agentPath,
isFullBleedRoute,
movedHref,
pageOf,
safeDecode,
selectedAgent,
visibleNavItems,
} from "../src/shell/routes.ts";
test("the start page is full-bleed", () => {
assert.equal(isFullBleedRoute("/"), true);
});
test("the hive directory moved off / and is not full-bleed", () => {
assert.equal(isFullBleedRoute("/agents"), false);
});
test("an agent's terminal and a subagent's are full-bleed", () => {
assert.equal(isFullBleedRoute("/agents/iris/terminal"), true);
assert.equal(
isFullBleedRoute("/agents/iris/subagents/scout-1/terminal"),
true,
);
});
test("the agents page and other routes are not full-bleed", () => {
for (const path of ["/agents", "/agents/iris", "/jobs", "/issues"]) {
assert.equal(isFullBleedRoute(path), false, path);
}
});
test("a terminal path with extra segments is not full-bleed", () => {
assert.equal(isFullBleedRoute("/agents/iris/terminal/extra"), false);
assert.equal(isFullBleedRoute("/agents//terminal"), false);
});
const NAV = [{ href: "/agents" }, { href: "/components" }, { href: "/jobs" }];
test("hide developer details takes the components tab out of the nav", () => {
assert.deepEqual(
visibleNavItems(NAV, true).map((i) => i.href),
["/agents", "/jobs"],
);
});
test("with it off the nav is whole again", () => {
assert.deepEqual(visibleNavItems(NAV, false), NAV);
});
test("an old address goes to the tab that holds its page, query kept", () => {
assert.equal(movedHref("/alerts", ""), "/reports");
assert.equal(movedHref("/issues", ""), "/reports");
assert.equal(movedHref("/review", ""), "/jobs");
assert.equal(movedHref("/schedules", ""), "/swarm");
assert.equal(movedHref("/messages", ""), "/swarm");
assert.equal(
movedHref("/builds", "run=atlas-abc-1"),
"/jobs?run=atlas-abc-1",
);
});
test("a current tab is not moved", () => {
assert.equal(movedHref("/jobs", ""), null);
assert.equal(movedHref("/agents", "x=1"), null);
});
test("no old address leads to another old address", () => {
for (const to of Object.values(MOVED_ROUTES)) {
assert.equal(to in MOVED_ROUTES, false, to);
}
});
test("the old notifications list goes to the swarm tab, the editor pages stay", () => {
assert.equal(movedHref("/notifications", ""), "/swarm");
assert.equal(movedHref("/notifications/some-flow", ""), null);
});
test("a group of agent terminals is full-bleed", () => {
assert.equal(isFullBleedRoute("/agents/group/ab12cd34"), true);
assert.equal(isFullBleedRoute("/agents/group"), false);
});
test("one segment after /agents selects that agent on the agents page", () => {
assert.equal(selectedAgent("/agents/iris"), "iris");
assert.equal(selectedAgent("/agents/a%20b"), "a b");
assert.equal(agentPath("a b"), "/agents/a%20b");
assert.equal(selectedAgent(agentPath("a/b")), "a/b");
});
test("the agents list, a group and a terminal select no agent", () => {
for (const path of [
"/agents",
"/agents/",
"/agents/group",
"/agents/group/g1",
"/agents/iris/terminal",
"/agents/iris/subagents/s/terminal",
"/jobs",
]) {
assert.equal(selectedAgent(path), null, path);
}
assert.equal(selectedAgent("/agents/%E0%A4%A"), null);
});
test("an agent selected on the agents page is still the agents page", () => {
assert.equal(pageOf("/agents/iris"), "/agents");
assert.equal(pageOf("/agents"), "/agents");
assert.equal(pageOf("/agents/iris/terminal"), "/agents/iris/terminal");
assert.equal(pageOf("/agents/group/g1"), "/agents/group/g1");
assert.equal(pageOf("/jobs"), "/jobs");
});
test("a path segment decodes, and a malformed one comes back as typed", () => {
assert.equal(safeDecode("my%20agent"), "my agent");
assert.equal(safeDecode("plain"), "plain");
assert.equal(safeDecode("%E0%A4%A"), "%E0%A4%A");
});