Part of the unification order in the UI sweep issue (step d, first of three). Twenty files hand-rolled the same effect: a cancelled flag, a fetch, the problem body on a bad status, a catch that wraps the error. useResource does it once on top of the poller's request discipline: it aborts the request in flight when the inputs change or the page goes away, keeps the last good answer under a failed read and clears the error on the next good one. The agent details move to it (limits, linked accounts, ssh CA, permission catalogue, allowed and denied domains). Hint drops its HintTone alias for the shared Tone.
124 lines
3.9 KiB
JavaScript
124 lines
3.9 KiB
JavaScript
// The agent details' allowed-domains editor: which entries one agent sees and
|
|
// the bodies it sends. Run by `npm test` with Node's type stripping.
|
|
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import {
|
|
allowedSummary,
|
|
entryGroups,
|
|
swarmWideEntries,
|
|
behindNote,
|
|
entriesFor,
|
|
entryBody,
|
|
shownError,
|
|
} from "../src/agent/detail/allowed-domains.ts";
|
|
|
|
const all = [
|
|
{ domain: "crates.io", agent: "atlas" },
|
|
{ domain: "docs.rs", agent: "argus" },
|
|
{ domain: "github.com" },
|
|
{ domain: "pypi.org", agent: "atlas" },
|
|
];
|
|
|
|
test("an agent sees the swarm-wide entries first, then its own, and not another agent's", () => {
|
|
assert.deepEqual(entriesFor(all, "atlas"), [
|
|
{ domain: "github.com" },
|
|
{ domain: "crates.io", agent: "atlas" },
|
|
{ domain: "pypi.org", agent: "atlas" },
|
|
]);
|
|
// Control: the other agent's entry is there to be found.
|
|
assert.deepEqual(entriesFor(all, "argus"), [
|
|
{ domain: "github.com" },
|
|
{ domain: "docs.rs", agent: "argus" },
|
|
]);
|
|
assert.deepEqual(entriesFor(all, "iris"), [{ domain: "github.com" }]);
|
|
assert.deepEqual(entriesFor([], "atlas"), []);
|
|
});
|
|
|
|
test("the summary counts each scope", () => {
|
|
assert.equal(allowedSummary([]), "none added");
|
|
assert.equal(
|
|
allowedSummary(entriesFor(all, "atlas")),
|
|
"1 swarm-wide, 2 for this agent",
|
|
);
|
|
assert.equal(allowedSummary(entriesFor(all, "iris")), "1 swarm-wide");
|
|
assert.equal(
|
|
allowedSummary([{ domain: "a.io", agent: "atlas" }]),
|
|
"1 for this agent",
|
|
);
|
|
});
|
|
|
|
test("the body is swarm-wide or for the agent, with the name trimmed", () => {
|
|
assert.deepEqual(entryBody(" github.com ", true, "atlas"), {
|
|
domain: "github.com",
|
|
});
|
|
assert.deepEqual(entryBody("github.com", false, "atlas"), {
|
|
domain: "github.com",
|
|
agent: "atlas",
|
|
});
|
|
});
|
|
|
|
test("a derived entry is counted as automatic, not as the operator's own", () => {
|
|
const derived = { domain: "llm.example.com", agent: "atlas", derived: true };
|
|
assert.equal(
|
|
allowedSummary([...entriesFor(all, "atlas"), derived]),
|
|
"1 swarm-wide, 2 for this agent, 1 automatic",
|
|
);
|
|
assert.equal(allowedSummary([derived]), "1 automatic");
|
|
assert.deepEqual(entriesFor([derived], "atlas"), [derived]);
|
|
});
|
|
|
|
test("entries are grouped by source, empty sources left out", () => {
|
|
const derived = { domain: "auto.io", agent: "atlas", derived: true };
|
|
const groups = entryGroups([
|
|
{ domain: "a.io" },
|
|
{ domain: "b.io", agent: "atlas" },
|
|
derived,
|
|
]);
|
|
assert.deepEqual(
|
|
groups.map((g) => [g.source, g.entries.length]),
|
|
[
|
|
["swarm-wide", 1],
|
|
["own", 1],
|
|
["automatic", 1],
|
|
],
|
|
);
|
|
assert.deepEqual(
|
|
entryGroups([{ domain: "a.io" }]).map((g) => g.source),
|
|
["swarm-wide"],
|
|
);
|
|
assert.deepEqual(entryGroups([]), []);
|
|
});
|
|
|
|
test("the egress card lists only the entries that hold for every agent", () => {
|
|
const entries = [
|
|
{ domain: "crates.io" },
|
|
{ domain: "docs.rs", agent: "iris" },
|
|
{ domain: "api.example.com", derived: true },
|
|
{ domain: "github.com" },
|
|
];
|
|
assert.deepEqual(
|
|
swarmWideEntries(entries).map((e) => e.domain),
|
|
["crates.io", "github.com"],
|
|
);
|
|
assert.deepEqual(swarmWideEntries([]), []);
|
|
});
|
|
|
|
test("an add from the swarm page, with no agent, is a swarm-wide entry", () => {
|
|
assert.deepEqual(entryBody("github.com", true, ""), { domain: "github.com" });
|
|
});
|
|
|
|
test("the deny list names the hives that have not applied it, and says nothing when none is behind", () => {
|
|
assert.equal(behindNote([]), null);
|
|
assert.match(behindNote(["pr1ma"]), /^pr1ma has not applied this list yet/);
|
|
assert.match(
|
|
behindNote(["pr1ma", "mu3de"]),
|
|
/^pr1ma, mu3de have not applied this list yet/,
|
|
);
|
|
});
|
|
|
|
test("a failed removal shows before a failed read, and a read shows alone", () => {
|
|
assert.equal(shownError("remove", "read"), "remove");
|
|
assert.equal(shownError(null, "read"), "read");
|
|
assert.equal(shownError("remove", null), "remove");
|
|
assert.equal(shownError(null, null), null);
|
|
});
|