Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: an agent's named ssh connections show in its ssh popover, with add, replace and remove

The ssh popover of an opened agent card gets a folded connections section: a table of the agent's named connections (name, user@host:port) with edit and remove, and a form that saves one. The list is read on the first open; a save is a PUT that replaces a connection of the same name, so the button reads replace and a line names the connection when the name exists; remove asks first. The controller's refusal shows under the form as it comes, and the section says the connections are inactive while ssh is off. The request building is in ssh-connections.ts with a test; swarm-ui.md describes the section.
This commit is contained in:
iris 2026-11-20 04:05:25 +01:00 • committed by mara
commit 62551e004e

View file

@ -0,0 +1,75 @@
// The named SSH connections of an agent card: URLs, the save body and the
// replace check. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
connectionBody,
connectionUrl,
connectionsUrl,
parsePort,
replaces,
sortedConnections,
} from "../src/agent/detail/ssh-connections.ts";
const conn = (name, host = "box", port = 22, user = "root") => ({
name,
user,
host,
port,
});
test("the routes carry the agent and the connection name", () => {
assert.equal(connectionsUrl("iris"), "/api/agents/iris/ssh-connections");
assert.equal(
connectionUrl("iris", "k8s-lab-vm"),
"/api/agents/iris/ssh-connections/k8s-lab-vm",
);
});
test("a name is escaped in the URL", () => {
assert.equal(
connectionUrl("iris", "a/b c"),
"/api/agents/iris/ssh-connections/a%2Fb%20c",
);
});
test("the table lists connections by name", () => {
const list = [conn("zeta"), conn("alpha"), conn("mid")];
assert.deepEqual(
sortedConnections(list).map((c) => c.name),
["alpha", "mid", "zeta"],
);
assert.deepEqual(
list.map((c) => c.name),
["zeta", "alpha", "mid"],
"the list given is not reordered",
);
});
test("a save replaces a connection with the same name, ignoring spaces typed", () => {
const list = [conn("lab"), conn("prod")];
assert.equal(replaces(list, "lab"), true);
assert.equal(replaces(list, " lab "), true);
assert.equal(replaces(list, "other"), false);
assert.equal(replaces([], "lab"), false);
});
test("a port is a whole number or nothing", () => {
assert.equal(parsePort("2222"), 2222);
assert.equal(parsePort(" 22 "), 22);
assert.equal(parsePort(""), null);
assert.equal(parsePort("22a"), null);
assert.equal(parsePort("-1"), null);
assert.equal(parsePort("2.5"), null);
});
test("the body trims the fields and needs all of them", () => {
assert.deepEqual(connectionBody(" root ", " muede-pc2 ", "2222"), {
user: "root",
host: "muede-pc2",
port: 2222,
});
assert.equal(connectionBody("", "host", "22"), null);
assert.equal(connectionBody("root", " ", "22"), null);
assert.equal(connectionBody("root", "host", "ssh"), null);
});