Files
archie/ui/test/task-tabs.test.js
T
sam d31c279658 feat(webui): add the per-run task detail page
A per-task page at #/tasks/{id} with tabs for the attempt's stages and log, changed
files, configuration and a raw debug view. Reachable from the task list, deep
linkable via ?tab= and ?attempt=, and reload safe. Existing URLs (#/tasks?task=N
and #/tasks?status=...) are unchanged.

- A stage rail per attempt: name, duration, terminal status and error text, with
  unattributed events surfaced and the agent's own verdict shown separately.
- No pass/fail badge and no exit code anywhere: the backend has neither, and a stage
  that returned nil after producing a poor diff is a success. Status word, duration
  and error text are shown instead.
- The log pane filters by attempt, stage and level, states the coverage caveat for
  stage filters (agent and tool output records no stage), and keeps the three read
  outcomes distinct: no log reader in this deployment, no file for this attempt, and
  no entries matching the filter.
- Retry is labelled as a new run and its confirm says the previous attempt's commits
  are discarded, because it hard-resets the branch onto the base.
- An absent capture reads "not captured for this run" rather than implying nothing
  changed, and no elapsed-run figure is shown since only per-stage durations exist.
- The events cache is invalidated on retry (it previously kept the ended attempt's
  events) and the log cache is keyed by attempt, so two attempts cannot be conflated.
- ui/dist is rebuilt and committed: the gate runs the node tests but never rebuilds
  the bundle, so a stale one would otherwise ship behind a green gate.
- docs/prds/task-run-detail.md records the surface and its limits, and
  docs/architecture/observability.md describes it alongside the read endpoints.

Both new vocabularies are pinned by tests on each side (config schema, change
statuses) so a one-sided rename fails a test instead of silently degrading the page.
2026-09-18 18:33:03 +10:00

116 lines
4.3 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { render, cleanup, fireEvent } from "@testing-library/preact";
import { TabBar, panelId, tabId } from "../src/tasks/tab-bar.jsx";
const TABS = [
{ id: "stages", label: "Stages" },
{ id: "log", label: "Log" },
{ id: "changes", label: "Changed files" },
];
import { useState } from "preact/hooks";
function Harness({ initial = "stages", onSelect }) {
const [active, setActive] = useState(initial);
return (
<TabBar
tabs={TABS}
active={active}
onSelect={(id) => {
onSelect?.(id);
setActive(id);
}}
prefix="run"
/>
);
}
function mount(active = "stages", onSelect) {
const { container, unmount } = render(<Harness initial={active} onSelect={onSelect} />);
return { root: container, unmount };
}
test("the tab list is a tablist of tabs with the active one selected", () => {
const { root, unmount } = mount("log");
const list = root.querySelector('[role="tablist"]');
assert.ok(list, "a tablist should render");
const tabs = [...root.querySelectorAll('[role="tab"]')];
assert.equal(tabs.length, 3);
assert.equal(tabs[0].getAttribute("aria-selected"), "false");
assert.equal(tabs[1].getAttribute("aria-selected"), "true");
assert.equal(tabs[0].textContent, "Stages");
unmount();
});
// The panel is a separate element in the page, so the relationship has to be
// declared explicitly or assistive technology cannot connect them.
test("each tab points at the panel it controls", () => {
const { root, unmount } = mount("stages");
const tabs = [...root.querySelectorAll('[role="tab"]')];
const expected = ["stages", "log", "changes"].map((id) => panelId("run", id));
assert.deepEqual(tabs.map((tab) => tab.getAttribute("aria-controls")), expected);
assert.deepEqual(tabs.map((tab) => tab.id), ["stages", "log", "changes"].map((id) => tabId("run", id)));
unmount();
});
// Roving tabindex: the tab list is one stop in the page's tab order, not three.
test("only the active tab is in the page tab order", () => {
const { root, unmount } = mount("changes");
const tabs = [...root.querySelectorAll('[role="tab"]')];
assert.deepEqual(tabs.map((tab) => tab.getAttribute("tabindex")), ["-1", "-1", "0"]);
unmount();
});
test("clicking a tab selects it", () => {
const selected = [];
const { root, unmount } = mount("stages", (id) => selected.push(id));
fireEvent.click(root.querySelectorAll('[role="tab"]')[2]);
assert.deepEqual(selected, ["changes"]);
unmount();
});
test("arrow keys move between tabs, wrap around, and select as they go", () => {
const selected = [];
const { root, unmount } = mount("stages", (id) => selected.push(id));
const first = root.querySelectorAll('[role="tab"]')[0];
first.focus();
fireEvent.keyDown(first, { key: "ArrowRight" });
fireEvent.keyDown(root.querySelectorAll('[role="tab"]')[1], { key: "ArrowRight" });
fireEvent.keyDown(root.querySelectorAll('[role="tab"]')[2], { key: "ArrowRight" });
assert.deepEqual(selected, ["log", "changes", "stages"], "arrow-right wraps to the first tab");
unmount();
});
test("Home and End jump to the ends of the tab list", () => {
const selected = [];
const { root, unmount } = mount("log", (id) => selected.push(id));
const active = root.querySelectorAll('[role="tab"]')[1];
fireEvent.keyDown(active, { key: "End" });
fireEvent.keyDown(root.querySelectorAll('[role="tab"]')[2], { key: "Home" });
assert.deepEqual(selected, ["changes", "stages"]);
unmount();
});
// Keyboard focus must follow selection: a roving-tabindex widget that moves the
// selection but leaves focus behind loses the keyboard user.
test("an arrow key moves keyboard focus with the selection", () => {
const { root, unmount } = mount("stages");
const first = root.querySelectorAll('[role="tab"]')[0];
first.focus();
fireEvent.keyDown(first, { key: "ArrowRight" });
const tabs = [...root.querySelectorAll('[role="tab"]')];
assert.equal(document.activeElement, tabs[1]);
unmount();
});
test("an unrelated key does nothing", () => {
const selected = [];
const { root, unmount } = mount("stages", (id) => selected.push(id));
fireEvent.keyDown(root.querySelectorAll('[role="tab"]')[0], { key: "a" });
assert.deepEqual(selected, []);
unmount();
});
test.after(() => cleanup());