Files
archie/ui/test/control-plane.test.ts
T
sam dcdaa9f451 feat(webui): show which process is running which settings version
The settings page now reads apply status beside each resource: every known
process with the version it applied, its error if it rejected the edit, and
whether it is still reporting at all. It re-reads after each save, so the page
reflects what the processes did with an edit rather than what was stored.

The server derives liveness only, because it knows whether a record went stale
but not which version the page is showing. The client compares against the
resource it is rendering, which is what turns a live record on an older
version into a pending restart.

A process that stopped re-stamping and one that never reported are separate
rows with separate wording, and neither is an error: the setting may be fine
and the process simply absent, which an operator acts on differently. A failed
apply-status read leaves the previous rows rather than taking the settings
page down with it.

state-store-contract.md gains the pair in its inventory and its count moves
from 45 to 47, with the note that this read is a list rather than the
config-snapshot pair's found=false singleton.

Closes archie-core-pskb.
2026-09-21 15:57:46 +10:00

87 lines
4.0 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
commandBody,
resourcesForPage,
upsertWorkflowDefinition,
removeWorkflowDefinition,
applyStatusForKind,
} from "../src/stores/control-plane.ts";
test("control-plane commands keep the edited version and typed values", () => {
assert.deepEqual(JSON.parse(commandBody({
max_model_tool_steps: 12,
max_runtime_seconds: 900,
max_consecutive_gate_failures: 3,
}, 7)), {
value: {
max_model_tool_steps: 12,
max_runtime_seconds: 900,
max_consecutive_gate_failures: 3,
},
expected_version: 7,
});
});
test("control-plane resources belong to one settings narrative", () => {
const catalog = [
"workflow-execution-settings", "provider-settings", "model-role-assignments",
"repository-policies", "channel-settings", "scheduling-policy", "tool-settings",
"plugin-settings", "container-runtime-policies", "workflow-definitions",
].map((kind) => ({ kind, title: kind, schema_json: "{}", commands: ["replace"] }));
assert.deepEqual(resourcesForPage(catalog, "tasks").map(({ kind }) => kind), ["workflow-execution-settings"]);
assert.deepEqual(resourcesForPage(catalog, "models").map(({ kind }) => kind), ["provider-settings", "model-role-assignments"]);
assert.deepEqual(resourcesForPage(catalog, "repositories").map(({ kind }) => kind), ["repository-policies"]);
assert.deepEqual(resourcesForPage(catalog, "channels").map(({ kind }) => kind), ["channel-settings"]);
assert.deepEqual(resourcesForPage(catalog, "advanced").map(({ kind }) => kind), [
"scheduling-policy", "tool-settings", "plugin-settings", "container-runtime-policies",
]);
assert.deepEqual(resourcesForPage(catalog, "workflows").map(({ kind }) => kind), ["workflow-definitions"]);
});
test("workflow edits replace by id without dropping sibling definitions", () => {
const original = { definitions: [
{ id: "implement", yaml: "id: implement\nsteps: []\n" },
{ id: "tdd", yaml: "id: tdd\nsteps: []\n" },
] };
assert.deepEqual(upsertWorkflowDefinition(original, { id: "implement", yaml: "id: implement\nsteps:\n - type: implement.code\n" }), {
definitions: [
{ id: "implement", yaml: "id: implement\nsteps:\n - type: implement.code\n" },
{ id: "tdd", yaml: "id: tdd\nsteps: []\n" },
],
});
assert.deepEqual(removeWorkflowDefinition(original, "implement"), {
definitions: [{ id: "tdd", yaml: "id: tdd\nsteps: []\n" }],
});
});
test("apply status names a process behind the stored version and one that stopped reporting", () => {
const records = [
{ process: "archied", kind: "tool-settings", applied_version: 7, reported_at: "", state: "current" },
{ process: "archie-gateway", kind: "tool-settings", applied_version: 6, reported_at: "", state: "current" },
{ process: "archie-messaging", kind: "tool-settings", applied_version: 7, reported_at: "", state: "unknown" },
{ process: "archied", kind: "plugin-settings", applied_version: 2, reported_at: "", state: "current" },
];
const processes = ["archied", "archie-gateway", "archie-messaging"];
assert.deepEqual(applyStatusForKind(records, processes, "tool-settings", 7), [
{ process: "archied", state: "running", version: 7, error: "" },
{ process: "archie-gateway", state: "pending-restart", version: 6, error: "" },
{ process: "archie-messaging", state: "unknown", version: 7, error: "" },
]);
});
test("apply status shows a process that has never reported, and one that rejected the edit", () => {
const processes = ["archied", "archie-gateway"];
const records = [
{ process: "archied", kind: "tool-settings", applied_version: 6, reported_at: "", state: "failed", error: "validate database settings: bad policy" },
];
assert.deepEqual(applyStatusForKind(records, processes, "tool-settings", 7), [
{ process: "archied", state: "failed", version: 6, error: "validate database settings: bad policy" },
{ process: "archie-gateway", state: "not-reporting", version: 0, error: "" },
]);
});