Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: show the notification router's flows and switch built-ins off

This commit is contained in:
atlas 2026-10-24 03:51:33 +02:00 • committed by mara
commit 0512862b3d
6 changed files with 368 additions and 0 deletions

View file

@ -0,0 +1,80 @@
// The notifications page's tree and wording helpers. Run by `npm test`.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
describeNode,
treeRows,
withBuiltin,
} from "../src/pages/notifications/FlowTypes.ts";
const flow = {
id: "f",
name: "f",
enabled: true,
nodes: [
{ id: "s", kind: "source", events: ["issues", "issue_assign"] },
{ id: "m", kind: "match", when: [{ field: "action", equals: "closed" }] },
{ id: "m2", kind: "match", when: [] },
{
id: "t",
kind: "todo",
to: { field: "todo_holders" },
op: "clear",
key: "forge:{repo}#{number}:",
prefix: true,
text: "",
},
{
id: "u",
kind: "todo",
to: { agent: "triage" },
op: "upsert",
key: "k",
prefix: false,
text: "look",
},
],
edges: [
{ from: "s", to: "m" },
{ from: "m", to: "t" },
{ from: "s", to: "m2" },
{ from: "m2", to: "u" },
],
};
test("treeRows: each subtree follows its parent, with its depth", () => {
assert.deepEqual(
treeRows(flow).map((r) => [r.node.id, r.depth]),
[
["s", 0],
["m", 1],
["t", 2],
["m2", 1],
["u", 2],
],
);
});
test("treeRows: a cycle ends the walk and a flow with no source is empty", () => {
const cyclic = { ...flow, edges: [...flow.edges, { from: "t", to: "s" }] };
assert.equal(treeRows(cyclic).length, 5);
assert.deepEqual(treeRows({ ...flow, nodes: [] }), []);
});
test("describeNode: says what each kind does", () => {
assert.equal(describeNode(flow.nodes[0]), "forge issues, issue_assign");
assert.equal(describeNode(flow.nodes[1]), "action = closed");
assert.equal(describeNode(flow.nodes[2]), "match anything");
assert.equal(
describeNode(flow.nodes[3]),
"clear todos forge:{repo}#{number}:* of {todo_holders}",
);
assert.equal(describeNode(flow.nodes[4]), "todo to triage, key k: look");
});
test("withBuiltin: switching off adds once, switching on removes", () => {
assert.deepEqual(withBuiltin([], "b", false), ["b"]);
assert.deepEqual(withBuiltin(["b"], "b", false), ["b"]);
assert.deepEqual(withBuiltin(["c"], "a", false), ["a", "c"]);
assert.deepEqual(withBuiltin(["a", "b"], "a", true), ["b"]);
});