Files
archie/ui/test/events-counts.test.ts
T
sam 5e1e365c05 feat(webui): events counts, YAML reading, log rows and dashboard filters
Four findings from the ui-redesign verification pass, each with the module that
owns the rule and the test that pins it.

- events: the three-step strip's and the tab chips' counts move out of the SFC
  into events/counts.ts -- one read per step, an unreadable count stays blank
  rather than reading as zero (events-counts.test.ts).
- workflows: workflows/workflow-yaml.ts reads the editor's YAML with a real
  parser (the yaml package, not a line scanner) to drive the read-only Steps
  preview and a live validity indicator; the editor gains a line-number gutter
  and light syntax colouring behind the textarea. Step types and their settings
  are not served to the dashboard, so those remain the server's to check on
  save, and a save it refuses still reports its own reason.
- tasks: an ERROR log row is a block rather than only red text (lib/log.ts), the
  log pane ends with "End of attempt N - M lines", and the task head offers
  Archive when the server's own action list offers it (task-actions.ts, and
  TaskRowActions' new `only` narrows the list without inventing a control).
- dashboard: the live activity feed gains the All/Tasks/System filter
  (activity-filter.ts) and every quality-gate row gains a pass bar
  (pass-bar.ts) that is red when the gate is failing.

ui/dist regenerated; ui/package.json carries yaml ^2.9.1.
2026-09-30 11:41:33 +10:00

76 lines
2.2 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import type { EventsCountReaders } from "../src/events/counts.ts";
const { COUNT_SOURCES, loadEventCounts } = await import(
"../src/events/counts.ts"
);
const { EVENTS_TABS } = await import("../src/events/tab-selection.ts");
/** Readers standing in for api.captures / api.mappings / api.bindings. */
function readers(overrides: Partial<EventsCountReaders> = {}): EventsCountReaders {
return {
captures: async () => ({ captures: [{}, {}] }),
mappings: async () => ({ mappings: [{}] }),
bindings: async () => ({ bindings: [] }),
...overrides,
};
}
test("each count is the length of what its own read answered with", async () => {
assert.deepEqual(await loadEventCounts(readers()), {
inspector: 2,
mappings: 1,
bindings: 0,
});
});
test("a load reads each list once", async () => {
const called: string[] = [];
const record = (name: string, response: unknown) => async () => {
called.push(name);
return response;
};
await loadEventCounts(
readers({
captures: record("captures", { captures: [] }),
mappings: record("mappings", { mappings: [] }),
bindings: record("bindings", { bindings: [] }),
}),
);
assert.deepEqual(called.sort(), ["bindings", "captures", "mappings"]);
});
test("a count that could not be read stays blank, not zero", async () => {
const counts = await loadEventCounts(
readers({
mappings: async () => {
throw new Error("offline");
},
}),
);
assert.equal(counts.mappings, undefined);
assert.equal(counts.inspector, 2, "a failed sibling read blanked its count");
assert.equal(counts.bindings, 0);
});
test("a response without its list counts as an empty list", async () => {
const counts = await loadEventCounts(
readers({
captures: async () => null,
mappings: async () => ({}),
}),
);
assert.equal(counts.inspector, 0);
assert.equal(counts.mappings, 0);
});
test("every tab of the chain has one source, and the strip reads them in order", () => {
assert.deepEqual(
COUNT_SOURCES.map((source) => source.tab),
EVENTS_TABS.map((tab) => tab.id),
"a tab whose count nothing reads shows a chip that can never fill",
);
});