Files
archie/ui/test/settings-apply-status.test.ts
T
sam 26004e4dac feat(webui): a live-apply setting reads as applied, never as a restart
The per-process apply rows labelled every older applied version "Restart
pending", including a live-apply kind that needs no restart at all: the lag is
in reporting. The wording now follows the resource's apply mode. A live kind
reads "Applied" at the stored version and "Behind" on an older one, neutrally
rather than as a warning, while a restart-required kind keeps "Restart
pending".

The restart banner's condition is lifted out of the component into a plain
module so it can be tested: only a restart-required resource with a process on
an older version earns the banner, and a live-apply kind never does. The
per-process rows are wired onto the Plugins page, where a live kind's lag is
meant to show.
2026-10-02 09:37:44 +10:00

67 lines
2.2 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
applyStateLabel,
applyStateTone,
restartPendingTitles,
} from "../src/settings/apply-status.ts";
import type { ApplyStatusRow } from "../src/stores/control-plane.ts";
const resource = (
kind: string,
title: string,
apply_mode: "live" | "restart-required" | "domain-managed",
) => ({ kind, title, apply_mode });
const behind: ApplyStatusRow[] = [
{ process: "archie-gateway", state: "pending-restart", version: 6, error: "" },
];
const current: ApplyStatusRow[] = [
{ process: "archied", state: "running", version: 7, error: "" },
];
test("the restart banner names a process-binding change but never a live one", () => {
const rowsFor = (kind: string) =>
kind === "plugin-settings" ? behind : kind === "tool-settings" ? behind : current;
// Both resources are behind; only the restart-required one is a restart.
assert.deepEqual(
restartPendingTitles(
[
resource("plugin-settings", "Plugin settings", "live"),
resource("tool-settings", "Tool and MCP settings", "restart-required"),
],
rowsFor,
),
["Tool and MCP settings"],
);
// A live-apply kind behind on a process never earns the banner at all.
assert.deepEqual(
restartPendingTitles(
[resource("plugin-settings", "Plugin settings", "live")],
() => behind,
),
[],
);
});
test("a live kind reads as applied, and a process-binding change as a restart", () => {
assert.equal(applyStateLabel("running", "live"), "Applied");
assert.equal(applyStateLabel("pending-restart", "restart-required"), "Restart pending");
});
test("a live kind's lag never reads as a restart and is not a warning", () => {
const liveLag = applyStateLabel("pending-restart", "live");
assert.ok(
!liveLag.toLowerCase().includes("restart"),
`a live kind must not be told to restart, got "${liveLag}"`,
);
// A live kind that is behind is not a warning: nothing is broken and no
// restart is owed, so the row stays neutral.
assert.equal(applyStateTone("pending-restart", "live"), "idle");
assert.equal(applyStateTone("pending-restart", "restart-required"), "warn");
});