loadTaskLogs(t.id, t.attempt)}
+ onRetry={() => loadTaskLogs(t.id, t.attempt, { force: true })}
+ />
)}
@@ -448,7 +512,15 @@ function TasksApp({ query }) {
{issueLink(t) ?? `#${t.issue_number}`}
|
- {t.title || "(untitled)"}
+ e.stopPropagation()}
+ onKeyDown={(e) => e.stopPropagation()}
+ >
+ {t.title || "(untitled)"}
+
|
diff --git a/ui/src/tasks/timeline-event.jsx b/ui/src/tasks/timeline-event.jsx
index 635675be5..9818c693b 100644
--- a/ui/src/tasks/timeline-event.jsx
+++ b/ui/src/tasks/timeline-event.jsx
@@ -4,7 +4,9 @@ function words(value) {
.replace(/\b\w/g, (letter) => letter.toUpperCase());
}
-function duration(milliseconds) {
+// Exported so the stage rail renders a duration exactly the way the timeline
+// does; a second formatter would eventually disagree with this one.
+export function duration(milliseconds) {
const ms = Number(milliseconds);
if (!Number.isFinite(ms) || ms < 0) return "";
if (ms < 1000) return `${Math.round(ms)} ms`;
@@ -79,5 +81,21 @@ export function describeTimelineEvent(ev = {}) {
};
}
+ // Condition (d): the two provenance kinds render as one human line. The
+ // captured payload is rendered by its own panel, never dumped into the
+ // timeline, so these cases name what was recorded and nothing more.
+ if (ev.kind === "config_captured") {
+ return {
+ title: "Configuration captured",
+ detail: "The effective task-runtime configuration for this run.",
+ };
+ }
+ if (ev.kind === "changes_captured") {
+ const fileCount = Number(data.totals?.files);
+ const files = Number.isFinite(fileCount) && fileCount > 0 ? `${fileCount} file${fileCount === 1 ? "" : "s"} changed` : "";
+ const after = data.captured_after ? `captured after ${data.captured_after}` : "";
+ return { title: "Change capture recorded", detail: [files, after].filter(Boolean).join(" · ") };
+ }
+
return { title: words(ev.kind || ev.type), detail: ev.detail || "" };
}
diff --git a/ui/test/api-client.test.js b/ui/test/api-client.test.js
index 63adfed89..70759389a 100644
--- a/ui/test/api-client.test.js
+++ b/ui/test/api-client.test.js
@@ -44,6 +44,9 @@ const READS = [
["tasks", []],
["taskMeta", []],
["task", [1]],
+ ["taskAttempts", [1]],
+ ["taskChanges", [1, { attempt: 2 }]],
+ ["taskDebug", [1, { attempt: 2 }]],
["setup", []],
["capabilities", []],
["workflows", []],
@@ -191,6 +194,28 @@ test("a 415 keeps the server's explanation and reads as refused", async () => {
);
});
+// The run detail page's reads. `qs` drops empty values, so an attempt the page
+// has not resolved yet must not be sent as an empty string: the server treats an
+// absent attempt as "the task's current attempt", and `attempt=` would be a
+// different, malformed request.
+test("the run detail reads build their URLs with absent filters absent", async () => {
+ stubFetch(okResponse);
+ await api.taskAttempts(42);
+ await api.taskChanges(42, { attempt: 2 });
+ await api.taskDebug(42, { attempt: 0 });
+ await api.taskChanges(42, {});
+
+ assert.deepEqual(
+ calls.map((call) => call.path),
+ [
+ "/api/tasks/42/attempts",
+ "/api/tasks/42/changes?attempt=2",
+ "/api/tasks/42/debug?attempt=0",
+ "/api/tasks/42/changes",
+ ],
+ );
+});
+
test("every api method is classified by this suite", () => {
const classified = new Set([
...MUTATIONS.map(([name]) => name),
diff --git a/ui/test/attempt-config.test.js b/ui/test/attempt-config.test.js
new file mode 100644
index 000000000..e6bbe314e
--- /dev/null
+++ b/ui/test/attempt-config.test.js
@@ -0,0 +1,111 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { render, cleanup } from "@testing-library/preact";
+import { AttemptConfig, CONFIG_SCHEMA, selectConfigEvent } from "../src/tasks/attempt-config.jsx";
+
+const EVENTS = [
+ {
+ kind: "config_captured",
+ attempt: 1,
+ at: "2026-09-18T07:00:00.100Z",
+ stage: "",
+ data: { schema: CONFIG_SCHEMA, document: { BotUser: "archie-attempt-one", Models: { main: "openai/gpt" } } },
+ },
+ {
+ kind: "config_captured",
+ attempt: 2,
+ at: "2026-09-18T07:05:00.100Z",
+ stage: "",
+ data: { schema: CONFIG_SCHEMA, document: { BotUser: "archie-attempt-two", Models: { main: "openai/gpt" } } },
+ },
+];
+
+function mount(props) {
+ const { container, unmount } = render();
+ return { root: container, unmount };
+}
+
+// Selecting by kind alone would show the newest attempt's configuration on
+// every attempt -- the merge-attempts bug the attempt column exists to prevent.
+test("the configuration is selected by kind and attempt together", () => {
+ const { root, unmount } = mount({ events: EVENTS, attempt: 1 });
+ assert.match(root.textContent, /archie-attempt-one/);
+ assert.doesNotMatch(root.textContent, /archie-attempt-two/);
+ assert.match(root.textContent, /attempt 1's effective task-runtime configuration/);
+ unmount();
+});
+
+test("an attempt with no config event of its own says so, never another attempt's", () => {
+ const { root, unmount } = mount({ events: EVENTS, attempt: 3 });
+ assert.equal(root.querySelector(".empty-title").textContent, "Not captured for this run");
+ assert.doesNotMatch(root.textContent, /archie-attempt-one|archie-attempt-two/);
+ assert.match(root.textContent, /Nothing here says the run used the defaults/);
+ unmount();
+});
+
+test("the document is passed through verbatim, pretty-printed", () => {
+ const { root, unmount } = mount({ events: EVENTS, attempt: 2 });
+ const json = root.querySelector(".run-json").textContent;
+ assert.match(json, /"BotUser": "archie-attempt-two"/);
+ assert.match(json, /"Models"/);
+ unmount();
+});
+
+// The page must not imply this document is the whole configuration: it is the
+// non-secret task-runtime subset.
+test("the panel states the scope of what was captured", () => {
+ const { root, unmount } = mount({ events: EVENTS, attempt: 1 });
+ assert.match(root.textContent, /non-secret subset/);
+ assert.match(root.textContent, /not the dashboard configuration view/);
+ assert.match(root.textContent, /providers, repositories, identities, credentials and lock state/);
+ unmount();
+});
+
+test("an unrecognised schema is named and its payload is still shown", () => {
+ const events = [
+ { kind: "config_captured", attempt: 2, at: "2026-09-18T07:05:00.100Z", data: { schema: "archie/task-config@9", document: { future: true } } },
+ ];
+ const { root, unmount } = mount({ events, attempt: 2 });
+ assert.match(root.textContent, /unknown schema \(archie\/task-config@9\)/);
+ assert.match(root.querySelector(".run-json").textContent, /"future": true/);
+ unmount();
+});
+
+test("a config event with no data at all renders the raw payload rather than guessing", () => {
+ const events = [{ kind: "config_captured", attempt: 2, at: "2026-09-18T07:05:00.100Z" }];
+ const { root, unmount } = mount({ events, attempt: 2 });
+ assert.match(root.textContent, /unknown schema/);
+ assert.ok(root.querySelector(".run-json"));
+ unmount();
+});
+
+test("loading and failure states are distinct, and the failure offers a retry", () => {
+ const loading = mount({ events: undefined, attempt: 1 });
+ assert.match(loading.root.textContent, /Loading this task's events/);
+ loading.unmount();
+
+ const failed = mount({ events: null, attempt: 1, onRetry: () => {} });
+ assert.match(failed.root.textContent, /Could not load this task's events/);
+ assert.equal(failed.root.querySelector("button").textContent, "Retry");
+ failed.unmount();
+});
+
+test("selectConfigEvent ignores other kinds and other attempts", () => {
+ const events = [
+ { kind: "stage_finish", attempt: 2, data: {} },
+ ...EVENTS,
+ ];
+ assert.equal(selectConfigEvent(events, 2).attempt, 2);
+ assert.equal(selectConfigEvent(events, 3), null);
+ assert.equal(selectConfigEvent(undefined, 1), null);
+});
+
+// CONFIG_SCHEMA mirrors events.ConfigCapturedSchema (internal/events/events.go),
+// which the Go suite pins by the same literal. Pinning both sides is what makes
+// a one-sided rename a failing test rather than every attempt rendering as
+// "unknown schema".
+test("the config schema is the one the producer stamps", () => {
+ assert.equal(CONFIG_SCHEMA, "archie/task-config@1");
+});
+
+test.after(() => cleanup());
diff --git a/ui/test/changed-files.test.js b/ui/test/changed-files.test.js
new file mode 100644
index 000000000..d799d29a1
--- /dev/null
+++ b/ui/test/changed-files.test.js
@@ -0,0 +1,169 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { render, cleanup } from "@testing-library/preact";
+import { ChangedFiles, fileStatusLabel } from "../src/tasks/changed-files.jsx";
+
+const CAPTURE = {
+ captured_at: "2026-09-18T07:03:00.000Z",
+ captured_after: "commit",
+ stage: "commit",
+ owner: "o",
+ repo: "r",
+ base: "main",
+ branch: "feat/42-x",
+ head_sha: "abcdef1234567890",
+ base_sha: "0987654321fedcba",
+ pr_number: 7,
+ totals: { files: 3, additions: 40, deletions: 5 },
+ truncated: false,
+ files: [
+ { path: "internal/x.go", old_path: "", status: "modified", additions: 12, deletions: 3, binary: false },
+ { path: "bin/app", old_path: "", status: "added", additions: 0, deletions: 0, binary: true },
+ { path: "internal/new.go", old_path: "internal/old.go", status: "renamed", additions: 1, deletions: 1, binary: false },
+ ],
+};
+
+const TASK = {
+ id: 42,
+ repo_url: "https://forge.example.internal/o/r",
+ pr_number: 7,
+ pr_url: "https://forge.example.internal/o/r/pull/7",
+};
+
+function mount(props) {
+ const { container, unmount } = render();
+ return { root: container, unmount };
+}
+
+function rowFor(root, path) {
+ return [...root.querySelectorAll(".run-changes-table tbody tr")].find((row) =>
+ row.querySelector(".run-changes-path")?.textContent.includes(path),
+ );
+}
+
+// F5: nothing predating the capture has one, and the forge cannot supply one, so
+// an empty view must not read as "this run changed nothing".
+test("no capture recorded is not reported as no files changed", () => {
+ const { root, unmount } = mount({ state: { task_id: 42, attempt: 2, found: false, captures: [] } });
+ assert.equal(root.querySelector(".empty-title").textContent, "No change capture was recorded for this attempt");
+ assert.match(root.textContent, /not the same as "no files changed"/);
+ assert.doesNotMatch(root.textContent, /Nothing changed/);
+ unmount();
+});
+
+test("a capture renders its per-file counts and statuses", () => {
+ const { root, unmount } = mount({ state: { task_id: 42, attempt: 2, found: true, captures: [CAPTURE] }, task: TASK });
+ const modified = rowFor(root, "internal/x.go");
+ assert.match(modified.textContent, /Modified/);
+ assert.doesNotMatch(modified.textContent, /modified/, "the raw status code must not be shown as a word");
+ assert.match(modified.textContent, /\+12/);
+ assert.equal(root.querySelector(".run-capture-totals").textContent, "3 files · +40 · −5");
+ unmount();
+});
+
+// found:true with no readable capture is a READ failure, not "nothing was
+// captured": the server reports found from the capture event's existence, so
+// conflating the two tells the operator no capture was recorded when one
+// demonstrably was.
+test("a capture that was recorded but could not be read is not reported as missing", () => {
+ const { root, unmount } = mount({ state: { task_id: 42, attempt: 2, found: true, captures: [] } });
+ assert.match(root.textContent, /could not be read/i);
+ assert.doesNotMatch(root.textContent, /No change capture was recorded/);
+ unmount();
+});
+
+test("a renamed file shows the path it came from", () => {
+ const { root, unmount } = mount({ state: { task_id: 42, attempt: 2, found: true, captures: [CAPTURE] } });
+ const renamed = rowFor(root, "internal/new.go");
+ assert.match(renamed.textContent, /Renamed/);
+ assert.match(renamed.textContent, /internal\/old\.go → internal\/new\.go/);
+ unmount();
+});
+
+// A zero-hunk file is "no textual hunks", which is what the capture actually
+// recorded -- not a claim about the file's type on disk.
+test("a file with no textual hunks is described that way, not as a binary", () => {
+ const { root, unmount } = mount({ state: { task_id: 42, attempt: 2, found: true, captures: [CAPTURE] } });
+ const binary = rowFor(root, "bin/app");
+ assert.match(binary.textContent, /no textual hunks/);
+ assert.match(binary.textContent, /Added/);
+ assert.doesNotMatch(binary.textContent, /binary/i);
+ unmount();
+});
+
+test("a truncated capture says so while still reporting complete totals", () => {
+ const truncated = { ...CAPTURE, truncated: true, totals: { files: 210, additions: 900, deletions: 40 } };
+ const { root, unmount } = mount({ state: { task_id: 42, attempt: 2, found: true, captures: [truncated] } });
+ assert.match(root.textContent, /Showing the first 3 of 210 files/);
+ assert.match(root.textContent, /210 files · \+900 · −40/);
+ unmount();
+});
+
+test("the capture links to the repository and the pull request", () => {
+ const { root, unmount } = mount({ state: { task_id: 42, attempt: 2, found: true, captures: [CAPTURE] }, task: TASK });
+ const hrefs = [...root.querySelectorAll("a")].map((a) => a.getAttribute("href"));
+ assert.ok(hrefs.includes("https://forge.example.internal/o/r"));
+ assert.ok(hrefs.includes("https://forge.example.internal/o/r/pull/7"));
+ assert.match(root.textContent, /feat\/42-x → main/);
+ assert.match(root.textContent, /abcdef12/);
+ unmount();
+});
+
+// A link is only rendered when there is a URL behind it: a capture with no forge
+// coordinates shows its owner/repo and PR number as text rather than a dead link.
+test("a capture with no forge URL shows plain text instead of a dead link", () => {
+ const bare = { ...CAPTURE, pr_number: 9 };
+ const { root, unmount } = mount({ state: { task_id: 42, attempt: 2, found: true, captures: [bare] } });
+ assert.match(root.textContent, /PR #9/);
+ assert.equal(root.querySelectorAll("a").length, 0);
+ unmount();
+});
+
+test("multiple captures in one attempt all render, oldest first", () => {
+ const second = {
+ ...CAPTURE,
+ captured_at: "2026-09-18T07:06:00.000Z",
+ captured_after: "commit-push",
+ stage: "push",
+ };
+ const { root, unmount } = mount({ state: { task_id: 42, attempt: 2, found: true, captures: [CAPTURE, second] } });
+ const heads = [...root.querySelectorAll(".run-capture-when")].map((n) => n.textContent);
+ assert.deepEqual(heads, ["Captured after commit in stage commit", "Captured after commit-push in stage push"]);
+ unmount();
+});
+
+test("loading and failure states are distinct, and the failure offers a retry", () => {
+ const loading = mount({ state: undefined });
+ assert.match(loading.root.textContent, /Loading changed files/);
+ loading.unmount();
+
+ const failed = mount({ state: null, onRetry: () => {} });
+ assert.match(failed.root.textContent, /Could not load this attempt's changed files/);
+ assert.equal(failed.root.querySelector("button").textContent, "Retry");
+ failed.unmount();
+});
+
+test("the status vocabulary is words, and an unknown status is passed through", () => {
+ assert.equal(fileStatusLabel("added"), "Added");
+ assert.equal(fileStatusLabel("typechange"), "Type changed");
+ assert.equal(fileStatusLabel("submodule"), "submodule");
+});
+
+// The five statuses are the producer's own vocabulary
+// (internal/domain/workflow/task/changes.go), pinned by literal in the Go suite.
+// This pins the dashboard half to the same five strings: without it, a rename on
+// one side renders raw status codes beside words and both suites stay green.
+test("the status vocabulary matches the strings the producer persists", () => {
+ const persisted = {
+ added: "Added",
+ modified: "Modified",
+ deleted: "Deleted",
+ renamed: "Renamed",
+ typechange: "Type changed",
+ };
+ for (const [status, label] of Object.entries(persisted)) {
+ assert.equal(fileStatusLabel(status), label, `${status} must be a known status, not passed through`);
+ }
+});
+
+test.after(() => cleanup());
diff --git a/ui/test/main-routing.test.js b/ui/test/main-routing.test.js
new file mode 100644
index 000000000..367a03c96
--- /dev/null
+++ b/ui/test/main-routing.test.js
@@ -0,0 +1,93 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { waitFor } from "@testing-library/preact";
+
+// The router as the browser actually uses it: main.jsx is imported once (it
+// starts on import), and every step below navigates by changing the hash and
+// waiting for the app to follow. This is the only place the wiring between the
+// route table, the matcher and the navigation highlight is exercised -- the
+// matcher's own unit tests cannot see whether `show` hands the nav the section
+// path or the detail path.
+//
+// archied is absent on purpose: every request fails, which is itself a state
+// these pages must render honestly rather than blankly.
+globalThis.fetch = async () => {
+ throw new Error("no daemon in this test");
+};
+
+// jsdom has no EventSource, and the dashboard subscribes to the daemon's event
+// stream the moment it mounts. An inert stand-in keeps this test about routing
+// rather than about the stream.
+class InertEventSource {
+ close() {}
+}
+globalThis.EventSource = InertEventSource;
+
+function navCurrent(path) {
+ return document.querySelector(`a.nav-item[href="#${path}"]`)?.getAttribute("aria-current");
+}
+
+function title() {
+ return document.querySelector(".page-title")?.textContent;
+}
+
+async function navigate(hash) {
+ location.hash = hash;
+ // jsdom queues its own hashchange for the assignment; waitFor lets it land.
+ await new Promise((resolve) => setTimeout(resolve, 0));
+}
+
+test("the app routes deep links and keeps the navigation highlight honest", async (t) => {
+ document.body.innerHTML = '';
+ location.hash = "#/tasks/42";
+ await import("../src/main.jsx");
+ await waitFor(() => assert.equal(title(), "Task #42"));
+
+ await t.test("a per-task route renders the run page and keeps Tasks current", () => {
+ assert.equal(title(), "Task #42");
+ assert.ok(document.querySelector(".run-restart"), "the run controls should render");
+ assert.equal(
+ navCurrent("/tasks"),
+ "page",
+ "W9: a detail route must hand the nav its section, or Tasks silently loses aria-current",
+ );
+ });
+
+ await t.test("the tasks list route still works", async () => {
+ await navigate("#/tasks");
+ await waitFor(() => assert.equal(title(), "Tasks"));
+ assert.equal(navCurrent("/tasks"), "page");
+ assert.equal(document.querySelector(".tab-bar"), null, "the run page is no longer mounted");
+ });
+
+ // W10: #/tasks?task=N and #/tasks?status=... are pinned deep links. The steps
+ // below enter this route from the run page on purpose: the query string is an
+ // entry state, so a navigation that only changes the query of the page already
+ // mounted keeps the operator's own filter selection instead.
+ await t.test("a tab and attempt in the query string open that panel", async () => {
+ await navigate("#/tasks/7?tab=log&attempt=1");
+ await waitFor(() => assert.equal(title(), "Task #7"));
+ const selected = [...document.querySelectorAll('[role="tab"]')].find(
+ (tab) => tab.getAttribute("aria-selected") === "true",
+ );
+ assert.equal(selected.textContent, "Log");
+ // The panels read one attempt, and this deployment answered no reads at
+ // all -- so the panel says that rather than claiming there is no attempt.
+ await waitFor(() => assert.match(document.body.textContent, /Could not load this task's attempts/));
+ assert.equal(navCurrent("/tasks"), "page");
+ });
+
+ await t.test("the existing task deep links keep working", async () => {
+ await navigate("#/tasks?task=7&status=needs_you");
+ await waitFor(() => assert.equal(title(), "Tasks"));
+ assert.equal(document.querySelector(".task-filter").value, "needs_you");
+ assert.equal(navCurrent("/tasks"), "page");
+ });
+
+ await t.test("an unmatched path falls back to the dashboard", async () => {
+ await navigate("#/nope/deep");
+ await waitFor(() => assert.ok(document.querySelector(".hero-title"), "the dashboard should render"));
+ assert.equal(document.querySelector(".tab-bar"), null);
+ assert.equal(navCurrent("/"), "page");
+ });
+});
diff --git a/ui/test/routing.test.js b/ui/test/routing.test.js
new file mode 100644
index 000000000..c9cdcf245
--- /dev/null
+++ b/ui/test/routing.test.js
@@ -0,0 +1,57 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { matchRoute, navPath } from "../src/routing.jsx";
+
+// The route table mirrors main.jsx's: a literal section and the parameterised
+// detail page declared after it, which is the ordering that stops /tasks/:id
+// from swallowing /tasks.
+const routes = [
+ { path: "/", label: "Dashboard" },
+ { path: "/tasks", label: "Tasks", view: () => null },
+ { path: "/tasks/:id", label: "Task run", view: () => null, nav: false, navPath: "/tasks" },
+ { path: "/logs", label: "Logs", view: () => null },
+];
+
+test("a literal path matches its own route, not a parameterised one", () => {
+ const match = matchRoute(routes, "/tasks");
+ assert.equal(match.route.path, "/tasks");
+ assert.deepEqual(match.params, {});
+});
+
+test("a path segment is captured as a route param", () => {
+ const match = matchRoute(routes, "/tasks/42");
+ assert.equal(match.route.path, "/tasks/:id");
+ assert.deepEqual(match.params, { id: "42" });
+});
+
+test("the query string is not part of the path", () => {
+ const match = matchRoute(routes, "/tasks/42?tab=changes&attempt=2");
+ assert.equal(match.route.path, "/tasks/:id");
+ assert.equal(match.params.id, "42");
+});
+
+test("a trailing slash names the same route", () => {
+ assert.equal(matchRoute(routes, "/tasks/").route.path, "/tasks");
+ assert.equal(matchRoute(routes, "/tasks/42/").params.id, "42");
+});
+
+// A prefix rule would send every unknown path under a section to that section's
+// page, so a typo would render something plausible instead of the dashboard.
+test("an unmatched path matches nothing rather than the nearest prefix", () => {
+ assert.equal(matchRoute(routes, "/nope"), null);
+ assert.equal(matchRoute(routes, "/tasks/42/extra"), null);
+ assert.equal(matchRoute(routes, "/task"), null);
+});
+
+test("an encoded segment is decoded into the param", () => {
+ assert.equal(matchRoute(routes, "/tasks/a%20b").params.id, "a b");
+});
+
+// W9: a detail route is not a nav entry, so it names the section it belongs to.
+// Without this the Tasks item loses aria-current the moment the operator opens
+// a run, and the whole nav reads as "nothing is current".
+test("a parameterised route reports the section it keeps current", () => {
+ assert.equal(navPath(routes[2]), "/tasks");
+ assert.equal(navPath(routes[1]), "/tasks");
+ assert.equal(navPath(undefined), "/");
+});
diff --git a/ui/test/stage-rail.test.js b/ui/test/stage-rail.test.js
new file mode 100644
index 000000000..56b5de388
--- /dev/null
+++ b/ui/test/stage-rail.test.js
@@ -0,0 +1,229 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { render, cleanup } from "@testing-library/preact";
+import { StageRail } from "../src/tasks/stage-rail.jsx";
+
+// The frozen shape of GET /api/tasks/{id}/attempts. Attempt 1 failed on
+// `implement`; attempt 2 is still running. The attempt-level duration_ms is
+// present on purpose: the rail must not render it.
+const ATTEMPTS = {
+ task_id: 42,
+ current_attempt: 2,
+ unattributed_events: 3,
+ attempts: [
+ {
+ attempt: 1,
+ status: "failed",
+ started_at: "2026-09-18T07:00:00.000Z",
+ finished_at: "2026-09-18T07:04:00.000Z",
+ duration_ms: 1_000_000,
+ event_count: 14,
+ stages: [
+ { name: "prepare", seq: 0, status: "ok", started_at: "2026-09-18T07:00:00.123Z", duration_ms: 1200, error: "" },
+ {
+ name: "implement",
+ seq: 1,
+ status: "failed",
+ started_at: "2026-09-18T07:00:01.323Z",
+ duration_ms: 230000,
+ error: "stage implement: builder exited 1",
+ },
+ ],
+ },
+ {
+ attempt: 2,
+ status: "running",
+ started_at: "2026-09-18T07:05:00.000Z",
+ event_count: 2,
+ stages: [{ name: "analyse", seq: 0, status: "running", started_at: "2026-09-18T07:05:00.000Z" }],
+ },
+ ],
+};
+
+function mount(props) {
+ const { container, unmount } = render();
+ return { root: container, unmount };
+}
+
+function stageRow(root, name) {
+ return [...root.querySelectorAll(".run-stage")].find(
+ (row) => row.querySelector(".run-stage-name")?.textContent === name,
+ );
+}
+
+test("each stage renders its name, duration and terminal status", () => {
+ const { root, unmount } = mount({ state: ATTEMPTS, attemptNumber: 1, events: [] });
+ const prepare = stageRow(root, "prepare");
+ assert.ok(prepare, "the prepare stage should render");
+ assert.match(prepare.textContent, /prepare/);
+ assert.match(prepare.textContent, /ok/);
+ assert.match(prepare.textContent, /ran for 1\.2 s/);
+ const implement = stageRow(root, "implement");
+ assert.match(implement.textContent, /ran for 3 min 50 s/);
+ assert.match(implement.textContent, /stage implement: builder exited 1/);
+ unmount();
+});
+
+// W2: merging attempts by stage name is the failure this whole feature exists to
+// prevent.
+test("the rail shows only the selected attempt's stages", () => {
+ const { root, unmount } = mount({ state: ATTEMPTS, attemptNumber: 1, events: [] });
+ assert.ok(stageRow(root, "prepare"));
+ assert.ok(stageRow(root, "implement"));
+ assert.equal(stageRow(root, "analyse"), undefined, "attempt 2's stages must not appear in attempt 1's rail");
+ assert.match(root.textContent, /Attempt 1/);
+ unmount();
+});
+
+test("an interrupted stage is not labelled failed", () => {
+ const state = {
+ ...ATTEMPTS,
+ attempts: [
+ {
+ attempt: 1,
+ status: "interrupted",
+ started_at: "2026-09-18T07:00:00.000Z",
+ stages: [{ name: "implement", seq: 0, status: "interrupted", duration_ms: 4200, error: "context canceled" }],
+ },
+ ],
+ };
+ const { root, unmount } = mount({ state, attemptNumber: 1, events: [] });
+ const row = stageRow(root, "implement");
+ assert.match(row.textContent, /interrupted/);
+ assert.doesNotMatch(row.textContent, /failed/);
+ unmount();
+});
+
+test("a stage with no recorded start shows no invented duration", () => {
+ const state = {
+ ...ATTEMPTS,
+ attempts: [
+ {
+ attempt: 1,
+ status: "ok",
+ stages: [{ name: "commit", seq: 0, status: "ok" }],
+ },
+ ],
+ };
+ const { root, unmount } = mount({ state, attemptNumber: 1, events: [] });
+ const row = stageRow(root, "commit");
+ assert.match(row.textContent, /duration not recorded/);
+ assert.doesNotMatch(row.textContent, /ran for/);
+ unmount();
+});
+
+// F3: waiting_human can span days, so an attempt's wall time is not a duration
+// of work and the page must not present it as one.
+test("the attempt's own duration is never rendered", () => {
+ const { root, unmount } = mount({ state: ATTEMPTS, attemptNumber: 1, events: [] });
+ assert.doesNotMatch(root.textContent, /ran for 16 min/);
+ assert.doesNotMatch(root.textContent, /1,000,000|1000000/);
+ unmount();
+});
+
+test("events with no attempt are reported rather than guessed at", () => {
+ const { root, unmount } = mount({ state: ATTEMPTS, attemptNumber: 1, events: [] });
+ assert.match(root.textContent, /3 events on this task predate attempt attribution/);
+ unmount();
+});
+
+// F1: a stage is `ok` when its function returned without error. There is no
+// exit code and no verification, and the agent's own verdict is a separate
+// claim -- neither may be presented as a check result.
+test("the agent's own verdict is shown separately from the stage's status", () => {
+ const events = [
+ {
+ kind: "agent_finish",
+ attempt: 1,
+ stage: "implement",
+ data: { status: "passed", iterations: 7, tokens: 1234, model: "openai/gpt-5.6-luna" },
+ },
+ ];
+ const { root, unmount } = mount({ state: ATTEMPTS, attemptNumber: 1, events });
+ const row = stageRow(root, "implement");
+ assert.match(row.textContent, /Agent's own report, not verified by archie/);
+ assert.match(row.textContent, /Agent passed: implement/);
+ assert.match(row.textContent, /failed/, "the stage keeps its own terminal status");
+ assert.doesNotMatch(row.textContent, /exit code|exit status/i);
+ unmount();
+});
+
+test("an agent report for another attempt is not attached to this attempt's stage", () => {
+ const events = [
+ { kind: "agent_finish", attempt: 2, stage: "implement", data: { status: "passed" } },
+ ];
+ const { root, unmount } = mount({ state: ATTEMPTS, attemptNumber: 1, events });
+ assert.doesNotMatch(root.textContent, /Agent's own report/);
+ unmount();
+});
+
+test("the rail says what ok means instead of implying a gate ran", () => {
+ const { root, unmount } = mount({ state: ATTEMPTS, attemptNumber: 1, events: [] });
+ assert.match(root.textContent, /ok means the stage returned without error/);
+ assert.match(root.textContent, /does not verify/);
+ unmount();
+});
+
+test("an attempt with no stages says so instead of showing an empty rail", () => {
+ const state = {
+ task_id: 42,
+ current_attempt: 1,
+ unattributed_events: 0,
+ attempts: [{ attempt: 1, status: "unknown", stages: [] }],
+ };
+ const { root, unmount } = mount({ state, attemptNumber: 1, events: [] });
+ assert.match(root.textContent, /No stages recorded for this attempt/);
+ unmount();
+});
+
+test("a task with no attempts says so", () => {
+ const { root, unmount } = mount({
+ state: { task_id: 42, current_attempt: 0, unattributed_events: 0, attempts: [] },
+ attemptNumber: null,
+ events: [],
+ });
+ assert.match(root.textContent, /No attempts recorded/);
+ unmount();
+});
+
+test("a selected attempt that was never recorded is reported, not faked", () => {
+ const { root, unmount } = mount({ state: ATTEMPTS, attemptNumber: 9, events: [] });
+ assert.match(root.textContent, /Attempt 9 is not recorded for this task/);
+ assert.match(root.textContent, /attempt 1, 2/);
+ unmount();
+});
+
+// A deployment where every event predates the attempt column answers with no
+// attempts at all -- but the events are still there, unattributed. The count
+// must be surfaced in the EMPTY rail too, not only beside a populated one, or
+// the page presents unattributable history as "nothing happened".
+test("unattributed events are surfaced even when no attempt is recorded", () => {
+ const { root, unmount } = mount({
+ state: { task_id: 42, current_attempt: 0, unattributed_events: 4, attempts: [] },
+ attemptNumber: null,
+ events: [],
+ });
+ assert.match(root.textContent, /No attempts recorded/);
+ assert.match(root.textContent, /4 events on this task predate attempt attribution/);
+ unmount();
+});
+
+test("unattributed events are surfaced when the selected attempt is not recorded", () => {
+ const { root, unmount } = mount({ state: ATTEMPTS, attemptNumber: 9, events: [] });
+ assert.match(root.textContent, /Attempt 9 is not recorded/);
+ assert.match(root.textContent, /3 events on this task predate attempt attribution/);
+ unmount();
+});
+
+test("loading and failure states are distinct, and the failure offers a retry", () => {
+ const loading = mount({ state: undefined, attemptNumber: null, events: [] });
+ assert.match(loading.root.textContent, /Loading/);
+ loading.unmount();
+
+ const failed = mount({ state: null, attemptNumber: null, events: [], onRetry: () => {} });
+ assert.match(failed.root.textContent, /Could not load this task's attempts/);
+ assert.equal(failed.root.querySelector("button").textContent, "Retry");
+ failed.unmount();
+});
+
+test.after(() => cleanup());
diff --git a/ui/test/task-detail.test.js b/ui/test/task-detail.test.js
new file mode 100644
index 000000000..6088b16a8
--- /dev/null
+++ b/ui/test/task-detail.test.js
@@ -0,0 +1,401 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { render, cleanup, fireEvent, waitFor } from "@testing-library/preact";
+import { api, ApiError } from "../src/base/api.jsx";
+import { taskDetailPage } from "../src/tasks/task-detail.jsx";
+
+const CONFIG_SCHEMA = "archie/task-config@1";
+
+const TASK = {
+ id: 42,
+ title: "Fix the flaky test",
+ status: "parked",
+ owner: "o",
+ repo: "r",
+ workflow: "tdd",
+ attempt: 2,
+ actions: ["retry", "abandon", "reject"],
+ repo_url: "https://forge.example.internal/o/r",
+ issue_url: "https://forge.example.internal/o/r/issues/5",
+ issue_number: 5,
+ pr_number: 7,
+ pr_url: "https://forge.example.internal/o/r/pull/7",
+};
+
+const ATTEMPTS = {
+ task_id: 42,
+ current_attempt: 2,
+ unattributed_events: 0,
+ attempts: [
+ {
+ attempt: 1,
+ status: "failed",
+ started_at: "2026-09-18T07:00:00.000Z",
+ finished_at: "2026-09-18T07:04:00.000Z",
+ duration_ms: 240333,
+ event_count: 3,
+ stages: [
+ { name: "prepare", seq: 0, status: "ok", started_at: "2026-09-18T07:00:00.123Z", duration_ms: 1200, error: "" },
+ { name: "implement", seq: 1, status: "failed", duration_ms: 230000, error: "stage implement: builder exited 1" },
+ ],
+ },
+ {
+ attempt: 2,
+ status: "running",
+ started_at: "2026-09-18T07:05:00.000Z",
+ event_count: 1,
+ stages: [{ name: "analyse", seq: 0, status: "running", started_at: "2026-09-18T07:05:00.000Z" }],
+ },
+ ],
+};
+
+const EVENTS = [
+ {
+ kind: "config_captured",
+ attempt: 2,
+ at: "2026-09-18T07:05:00.100Z",
+ stage: "",
+ data: { schema: CONFIG_SCHEMA, document: { BotUser: "archie", Models: { main: "openai/gpt" } } },
+ },
+ { kind: "stage_start", attempt: 2, stage: "analyse", at: "2026-09-18T07:05:00.000Z", data: {} },
+];
+
+function install(overrides = {}) {
+ const original = {
+ tasks: api.tasks,
+ task: api.task,
+ taskAttempts: api.taskAttempts,
+ taskLogs: api.taskLogs,
+ taskChanges: api.taskChanges,
+ taskDebug: api.taskDebug,
+ taskAction: api.taskAction,
+ };
+ const calls = { tasks: 0, task: 0, attempts: 0, logs: [], changes: [], debug: [], actions: [] };
+ api.tasks = async () => {
+ calls.tasks += 1;
+ return [TASK];
+ };
+ api.task = async (id) => {
+ calls.task += 1;
+ return EVENTS;
+ };
+ api.taskAttempts = async (id) => {
+ calls.attempts += 1;
+ return ATTEMPTS;
+ };
+ api.taskLogs = async (id, params) => {
+ calls.logs.push(params);
+ return { found: true, attempt: params?.attempt ?? 2, disabled: false, entries: [{ level: "info", msg: "line", time: "2026-09-18T07:05:00Z" }] };
+ };
+ api.taskChanges = async (id, params) => {
+ calls.changes.push(params);
+ return { task_id: 42, attempt: params?.attempt ?? 2, found: false, captures: [] };
+ };
+ api.taskDebug = async (id, params) => {
+ calls.debug.push(params);
+ return { task_id: 42, attempt: params?.attempt ?? 2, task: TASK, events: EVENTS };
+ };
+ api.taskAction = async (id, action) => {
+ calls.actions.push({ id, action });
+ return {};
+ };
+ for (const [key, value] of Object.entries(overrides)) api[key] = value;
+ const restore = () => Object.assign(api, original);
+ return { calls, restore };
+}
+
+function mount(queryString, id = "42") {
+ const { container, unmount } = render(
+ taskDetailPage(new URLSearchParams(queryString), { id }),
+ );
+ return { root: container, unmount };
+}
+
+test("the page offers every panel as a tab and opens Stages by default", async () => {
+ const { restore } = install();
+ const { root, unmount } = mount("tab=");
+ await waitFor(() => assert.ok(root.querySelector(".run-stages"), "the rail should render"));
+ const tabs = [...root.querySelectorAll('[role="tab"]')].map((tab) => tab.textContent);
+ assert.deepEqual(tabs, ["Stages", "Log", "Changed files", "Configuration", "Debug"]);
+ assert.equal(root.querySelector('[role="tab"]').getAttribute("aria-selected"), "true");
+ // The panel is bound to the selected tab.
+ const panel = root.querySelector('[role="tabpanel"]');
+ assert.equal(panel.getAttribute("aria-labelledby"), root.querySelector('[role="tab"]').id);
+ unmount();
+ restore();
+});
+
+test("the panel element is the selected tab's panel", () => {
+ const { root, unmount } = mount("tab=changes");
+ const selected = [...root.querySelectorAll('[role="tab"]')].find(
+ (tab) => tab.getAttribute("aria-selected") === "true",
+ );
+ assert.equal(selected.textContent, "Changed files");
+ assert.equal(root.querySelector('[role="tabpanel"]').id, selected.getAttribute("aria-controls"));
+ unmount();
+});
+
+// R8: the tabs are deep-linkable, so the query string alone decides which panel
+// opens -- including on a reload with no client state.
+test("?tab= decides which panel opens", async () => {
+ const { restore, calls } = install();
+ const { root, unmount } = mount("tab=debug");
+ await waitFor(() => assert.ok(root.querySelector(".run-json"), "the debug view should render"));
+ const json = root.querySelector(".run-json").textContent;
+ assert.match(json, /"title": "Fix the flaky test"/);
+ assert.match(json, /"attempt": 2/);
+ assert.match(root.textContent, /Attempt 2 is the one selected above/);
+ assert.deepEqual(calls.debug, [{ attempt: 2 }]);
+ // The debug envelope is only fetched for the visible tab.
+ assert.equal(calls.changes.length, 0);
+ unmount();
+ restore();
+});
+
+test("the debug view states that its event list is unfiltered", async () => {
+ const { restore } = install();
+ const { root, unmount } = mount("tab=debug");
+ await waitFor(() => assert.ok(root.querySelector(".run-json")));
+ assert.match(root.textContent, /Events are unfiltered on purpose/);
+ unmount();
+ restore();
+});
+
+test("the default attempt is the task's current one", async () => {
+ const { restore } = install();
+ const { root, unmount } = mount("tab=stages");
+ await waitFor(() => assert.ok(root.querySelector(".run-stages")));
+ assert.match(root.textContent, /Attempt 2/);
+ assert.equal(
+ [...root.querySelectorAll(".run-stage-name")].map((n) => n.textContent).join(","),
+ "analyse",
+ "attempt 1's stages must not appear on the current attempt's rail",
+ );
+ const chips = [...root.querySelectorAll(".run-attempt")];
+ assert.equal(chips.length, 2);
+ assert.equal(chips[1].getAttribute("aria-pressed"), "true");
+ unmount();
+ restore();
+});
+
+test("?attempt= pins an earlier attempt and the rail follows it", async () => {
+ const { restore } = install();
+ const { root, unmount } = mount("tab=stages&attempt=1");
+ await waitFor(() => assert.ok(root.querySelector(".run-stages")));
+ assert.deepEqual(
+ [...root.querySelectorAll(".run-stage-name")].map((n) => n.textContent),
+ ["prepare", "implement"],
+ );
+ assert.equal(root.querySelectorAll(".run-attempt")[0].getAttribute("aria-pressed"), "true");
+ unmount();
+ restore();
+});
+
+test("selecting another attempt re-reads the panels for that attempt", async () => {
+ const { restore } = install();
+ const { root, unmount } = mount("tab=stages");
+ await waitFor(() => assert.ok(root.querySelector(".run-stages")));
+ fireEvent.click(root.querySelectorAll(".run-attempt")[0]);
+ await waitFor(() =>
+ assert.deepEqual(
+ [...root.querySelectorAll(".run-stage-name")].map((n) => n.textContent),
+ ["prepare", "implement"],
+ ),
+ );
+ unmount();
+ restore();
+});
+
+test("the log pane sends the selected attempt and the filters to the server", async () => {
+ const { restore, calls } = install();
+ const { root, unmount } = mount("tab=log&attempt=1");
+ await waitFor(() => assert.ok(root.querySelector(".log-list")));
+ assert.deepEqual(calls.logs, [{ attempt: 1, level: "", stage: "", limit: 500 }]);
+
+ const stageSelect = [...root.querySelectorAll(".task-log-filter select")][1];
+ fireEvent.change(stageSelect, { target: { value: "prepare" } });
+ await waitFor(() => assert.equal(calls.logs.length, 2));
+ assert.deepEqual(calls.logs[1], { attempt: 1, level: "", stage: "prepare", limit: 500 });
+ await waitFor(() => assert.match(root.textContent, /A stage filter matches only log lines that record a stage/));
+ unmount();
+ restore();
+});
+
+// R4: the Config tab consumes the events response the page already holds, so it
+// must issue no request of its own.
+test("the configuration tab reads the captured document from the fetched events", async () => {
+ const { restore, calls } = install();
+ const { root, unmount } = mount("tab=config");
+ await waitFor(() => assert.ok(root.querySelector(".run-json")));
+ assert.match(root.querySelector(".run-json").textContent, /"BotUser": "archie"/);
+ assert.equal(calls.task, 1, "the events are fetched once, by the page");
+ assert.equal(calls.changes.length, 0);
+ assert.equal(calls.debug.length, 0);
+ unmount();
+ restore();
+});
+
+test("the configuration tab says nothing was captured for an attempt with no record", async () => {
+ const { restore } = install();
+ const { root, unmount } = mount("tab=config&attempt=1");
+ await waitFor(() =>
+ assert.equal(root.querySelector(".empty-title").textContent, "Not captured for this run"),
+ );
+ unmount();
+ restore();
+});
+
+test("changed files are read for the selected attempt and say a capture is missing", async () => {
+ const { restore, calls } = install();
+ const { root, unmount } = mount("tab=changes&attempt=1");
+ await waitFor(() =>
+ assert.equal(root.querySelector(".empty-title").textContent, "No change capture was recorded for this attempt"),
+ );
+ assert.deepEqual(calls.changes, [{ attempt: 1 }]);
+ unmount();
+ restore();
+});
+
+// R6: the control is labelled as a new run, and the copy says what it destroys.
+test("the new-run control states that the previous attempt's commits are discarded", async () => {
+ const { restore } = install();
+ const { root, unmount } = mount("tab=stages");
+ await waitFor(() => assert.ok(root.querySelector(".run-restart")));
+ const button = root.querySelector(".run-restart button");
+ assert.equal(button.textContent, "Start a new run");
+ assert.match(root.textContent, /The previous attempt's commits are discarded/);
+ assert.match(root.textContent, /fresh worktree reset onto the base branch/);
+ unmount();
+ restore();
+});
+
+test("a declined confirmation starts no run", async () => {
+ const { restore, calls } = install();
+ const originalConfirm = window.confirm;
+ let asked = "";
+ window.confirm = (text) => {
+ asked = text;
+ return false;
+ };
+ const { root, unmount } = mount("tab=stages");
+ await waitFor(() => assert.ok(root.querySelector(".run-restart button")));
+ fireEvent.click(root.querySelector(".run-restart button"));
+ assert.match(asked, /previous attempt's commits are discarded/);
+ assert.deepEqual(calls.actions, []);
+ unmount();
+ window.confirm = originalConfirm;
+ restore();
+});
+
+test("a confirmed new run drops the old attempt's caches and selects the new run", async () => {
+ const NEW_ATTEMPTS = {
+ task_id: 42,
+ current_attempt: 3,
+ unattributed_events: 0,
+ attempts: [
+ ...ATTEMPTS.attempts,
+ { attempt: 3, status: "running", started_at: "2026-09-18T07:09:00.000Z", event_count: 1, stages: [{ name: "bootstrap", seq: 0, status: "ok", duration_ms: 500 }] },
+ ],
+ };
+ let attemptReads = 0;
+ const { restore, calls } = install({
+ taskAttempts: async () => {
+ attemptReads += 1;
+ return attemptReads === 1 ? ATTEMPTS : NEW_ATTEMPTS;
+ },
+ });
+ const originalConfirm = window.confirm;
+ window.confirm = () => true;
+ const { root, unmount } = mount("tab=stages");
+ await waitFor(() => assert.ok(root.querySelector(".run-stages")));
+ fireEvent.click(root.querySelector(".run-restart button"));
+ await waitFor(() => assert.equal(root.querySelectorAll(".run-attempt").length, 3));
+ await waitFor(() =>
+ assert.deepEqual(
+ [...root.querySelectorAll(".run-stage-name")].map((n) => n.textContent),
+ ["bootstrap"],
+ "the new run's stages are shown, not the previous attempt's",
+ ),
+ );
+ assert.deepEqual(calls.actions, [{ id: 42, action: "retry" }]);
+ assert.equal(root.querySelectorAll(".run-attempt")[2].getAttribute("aria-pressed"), "true");
+ assert.equal(calls.task, 2, "the ended attempt's events are refetched for the new run");
+ unmount();
+ window.confirm = originalConfirm;
+ restore();
+});
+
+test("a task outside the listed rows is reported honestly rather than blank", async () => {
+ const { restore } = install({ tasks: async () => [] });
+ const { root, unmount } = mount("tab=stages");
+ await waitFor(() => assert.ok(root.querySelector(".run-stages")));
+ assert.match(root.textContent, /not among the tasks this dashboard lists/);
+ assert.match(root.textContent, /Debug tab holds the stored record verbatim/);
+ assert.match(root.textContent, /operator controls could not be read/);
+ unmount();
+ restore();
+});
+
+test("a deployment that lists no tasks for this id still shows the recorded run", async () => {
+ const { restore } = install({ tasks: async () => [] });
+ const { root, unmount } = mount("tab=stages&attempt=1");
+ await waitFor(() => assert.ok(root.querySelector(".run-stages")));
+ assert.match(root.textContent, /Task #42/);
+ assert.match(root.textContent, /prepare/);
+ unmount();
+ restore();
+});
+
+test("an unknown task renders an honest failure, not an empty page", async () => {
+ const { restore } = install({
+ taskAttempts: async () => {
+ throw new ApiError("no such task", 404);
+ },
+ });
+ const { root, unmount } = mount("tab=stages");
+ await waitFor(() => assert.ok(root.querySelector(".page-title")));
+ assert.match(root.querySelector(".page-title").textContent, /Task not found/);
+ assert.match(root.textContent, /No task with id 42/);
+ unmount();
+ restore();
+});
+
+test("a non-numeric id is refused without asking the server anything", () => {
+ const { restore, calls } = install();
+ const { root, unmount } = mount("tab=stages", "not-an-id");
+ assert.match(root.textContent, /is not a task id/);
+ assert.deepEqual(calls, { tasks: 0, task: 0, attempts: 0, logs: [], changes: [], debug: [], actions: [] });
+ unmount();
+ restore();
+});
+
+test("a task with no attempts says so on every panel", async () => {
+ const { restore } = install({
+ taskAttempts: async () => ({ task_id: 42, current_attempt: 0, unattributed_events: 4, attempts: [] }),
+ });
+ const { root, unmount } = mount("tab=stages");
+ await waitFor(() => assert.match(root.textContent, /No attempts recorded/));
+ fireEvent.click([...root.querySelectorAll('[role="tab"]')][3]);
+ await waitFor(() => assert.match(root.textContent, /No attempt recorded/));
+ unmount();
+ restore();
+});
+
+test("a failure to load the attempts offers a retry", async () => {
+ let reads = 0;
+ const { restore } = install({
+ taskAttempts: async () => {
+ reads += 1;
+ if (reads === 1) throw new Error("boom");
+ return ATTEMPTS;
+ },
+ });
+ const { root, unmount } = mount("tab=stages");
+ await waitFor(() => assert.match(root.textContent, /Could not load this task's attempts/));
+ fireEvent.click([...root.querySelectorAll(".run-error button")][0]);
+ await waitFor(() => assert.ok(root.querySelector(".run-stages")));
+ unmount();
+ restore();
+});
+
+test.after(() => cleanup());
diff --git a/ui/test/task-logs.test.js b/ui/test/task-logs.test.js
index a97410851..69891c4dc 100644
--- a/ui/test/task-logs.test.js
+++ b/ui/test/task-logs.test.js
@@ -1,10 +1,20 @@
import { test } from "node:test";
import assert from "node:assert/strict";
-import { render, cleanup } from "@testing-library/preact";
-import { TaskLogPanel, taskLogDownloadURL } from "../src/tasks/task-logs.jsx";
+import { render, cleanup, fireEvent } from "@testing-library/preact";
+import { TaskLogPanel, logCacheKey, taskLogDownloadURL } from "../src/tasks/task-logs.jsx";
function renderPanel(state, opts = {}) {
- const { container, unmount } = render();
+ const { container, unmount } = render(
+ ,
+ );
return { root: container, unmount };
}
@@ -103,3 +113,136 @@ test("a panel for an attempt with no log offers no download", () => {
assert.equal(root.querySelector(".task-log-download"), null, "there is nothing to download");
unmount();
});
+
+// W7: the filter controls must sit ABOVE the three read outcomes. Below the
+// disabled early return they would replace the deployment-level message with an
+// empty filtered pane in exactly the deployment that cannot read logs.
+const FILTER_OPTS = { filters: { level: "", stage: "" }, onFilterChange: () => {}, stages: ["prepare"] };
+
+test("the three read outcomes survive with the filter bar rendered above them", () => {
+ const disabled = renderPanel({ disabled: true, entries: [] }, FILTER_OPTS);
+ assert.ok(disabled.root.querySelector(".task-log-filters"), "the filter bar renders first");
+ assert.match(disabled.root.textContent, /No persisted log for this attempt/);
+ assert.match(disabled.root.textContent, /cannot read task logs/);
+ disabled.unmount();
+
+ const absent = renderPanel({ found: false, entries: [], attempt: 0 }, FILTER_OPTS);
+ assert.match(absent.root.textContent, /No log recorded for this attempt/);
+ assert.doesNotMatch(absent.root.textContent, /cannot read task logs/);
+ absent.unmount();
+
+ const filtered = renderPanel({ disabled: false, found: true, entries: [], attempt: 0 }, FILTER_OPTS);
+ assert.equal(filtered.root.querySelector(".empty-title").textContent, "Nothing recorded");
+ filtered.unmount();
+});
+
+// W6: one cache entry per task could not represent two attempts, so a retry
+// served the previous run's log under the new run's id.
+test("the log cache key is keyed by task, attempt and filters", () => {
+ assert.equal(logCacheKey(7, 1), "7|1||");
+ assert.notEqual(logCacheKey(7, 1), logCacheKey(7, 2), "two attempts must not share a cache entry");
+ assert.notEqual(logCacheKey(7, 1), logCacheKey(71, 1), "two tasks must not share a cache entry");
+ assert.notEqual(
+ logCacheKey(7, 1, { level: "ERROR", stage: "" }),
+ logCacheKey(7, 1, { level: "", stage: "" }),
+ "a filtered read is a different response and needs its own entry",
+ );
+});
+
+// F2: a stage filter narrows to lines a stage tagged and nothing more. Agent and
+// tool output has no stage, so a sparse result must be explained next to the
+// control rather than left to look broken.
+test("a stage filter states its coverage limit beside the control", () => {
+ const { root, unmount } = renderPanel(
+ { found: true, entries: [], attempt: 1 },
+ { ...FILTER_OPTS, filters: { level: "", stage: "prepare" }, stages: ["prepare", "implement"] },
+ );
+ assert.match(root.textContent, /A stage filter matches only log lines that record a stage/);
+ assert.match(root.textContent, /Agent and tool output carries none/);
+ unmount();
+});
+
+test("an attempt with no recorded stage names says the stage filter has nothing to match", () => {
+ const { root, unmount } = renderPanel(
+ { found: true, entries: [], attempt: 1 },
+ { ...FILTER_OPTS, stages: [] },
+ );
+ assert.match(root.textContent, /recorded no stage names/);
+ unmount();
+});
+
+test("changing a filter reports the whole filter set to the page", () => {
+ const seen = [];
+ const { root, unmount } = renderPanel(
+ { found: true, entries: [], attempt: 1 },
+ { ...FILTER_OPTS, onFilterChange: (next) => seen.push(next) },
+ );
+ const level = root.querySelectorAll("select")[0];
+ const stage = root.querySelectorAll("select")[1];
+ fireEvent.change(level, { target: { value: "ERROR" } });
+ fireEvent.change(stage, { target: { value: "prepare" } });
+ assert.deepEqual(seen, [
+ { level: "ERROR", stage: "" },
+ { level: "", stage: "prepare" },
+ ]);
+ unmount();
+});
+
+// The pane names the attempt it is showing so it can never present attempt 1's
+// log as attempt 2's.
+test("the pane names the attempt it is showing", () => {
+ const explicit = renderPanel({ found: true, attempt: 1, entries: [] }, { attempt: 1 });
+ assert.match(explicit.root.textContent, /Attempt 1/);
+ explicit.unmount();
+
+ const resolved = renderPanel({ found: true, attempt: 4, entries: [] }, { attempt: null, taskId: 42 });
+ assert.match(resolved.root.textContent, /Attempt 4/);
+ assert.equal(
+ resolved.root.querySelector(".task-log-download").getAttribute("href"),
+ "/api/tasks/42/logs/download?attempt=4",
+ "a download follows the attempt the pane is showing, not whatever is current",
+ );
+ resolved.unmount();
+});
+
+test("a panel without a page to act on a filter renders no filter controls", () => {
+ const { root, unmount } = renderPanel({ found: true, entries: [], attempt: 1 });
+ assert.equal(root.querySelector("select"), null, "a control that filters nothing is worse than none");
+ assert.match(root.textContent, /Attempt 1/);
+ unmount();
+});
+
+// R9: the pane carries one live region announcing its STATE, never a line at a
+// time. A per-line live region would read the whole log aloud on every load,
+// and a pane that loads 500 entries would be unusable with a screen reader.
+test("the pane announces its state once, not every log line", () => {
+ const { root, unmount } = renderPanel({
+ found: true,
+ attempt: 2,
+ entries: [
+ { level: "info", msg: "one" },
+ { level: "info", msg: "two" },
+ ],
+ });
+ const live = root.querySelector("[aria-live]");
+ assert.ok(live, "the pane should carry a live region");
+ assert.equal(live.getAttribute("role"), "status");
+ assert.equal(live.getAttribute("aria-atomic"), "true");
+ assert.match(live.textContent, /2 log entries/);
+ assert.ok(live.className.includes("visually-hidden"), "the live text is for assistive technology only");
+ assert.equal(root.querySelector(".log-list").contains(live), false, "the live region is not the list itself");
+ unmount();
+});
+
+test("the live region says which of the log-unavailable cases applies", () => {
+ const disabled = renderPanel({ disabled: true, entries: [] });
+ assert.match(disabled.root.querySelector("[aria-live]").textContent, /cannot read task logs/);
+ disabled.unmount();
+
+ const absent = renderPanel({ found: false, entries: [], attempt: 0 });
+ assert.match(absent.root.querySelector("[aria-live]").textContent, /No log recorded for this attempt/);
+ assert.doesNotMatch(absent.root.querySelector("[aria-live]").textContent, /cannot read task logs/);
+ absent.unmount();
+});
+
+test.after(() => cleanup());
diff --git a/ui/test/task-tabs.test.js b/ui/test/task-tabs.test.js
new file mode 100644
index 000000000..9fd656690
--- /dev/null
+++ b/ui/test/task-tabs.test.js
@@ -0,0 +1,115 @@
+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 (
+ {
+ onSelect?.(id);
+ setActive(id);
+ }}
+ prefix="run"
+ />
+ );
+}
+
+function mount(active = "stages", onSelect) {
+ const { container, unmount } = render();
+ 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());
diff --git a/ui/test/tasks-actions.test.js b/ui/test/tasks-actions.test.js
index 9139eaadf..2f6361b44 100644
--- a/ui/test/tasks-actions.test.js
+++ b/ui/test/tasks-actions.test.js
@@ -1,7 +1,7 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { register } from "node:module";
-import { render, waitFor } from "@testing-library/preact";
+import { render, waitFor, fireEvent } from "@testing-library/preact";
const cssLoad = "data:text/javascript," + encodeURIComponent(`
export async function load(url, context, nextLoad) {
@@ -186,3 +186,107 @@ test("a link-kind action renders an anchor to the forge", async () => {
assert.equal(link.textContent, "Open PR");
assert.equal(link.getAttribute("href"), "https://forge.example.internal/sam/archie/pull/42");
});
+
+// The stuck-pane case: an open log pane whose row is collapsed while the task
+// is retried. If the pane only ever loaded from the click that opened it, the
+// new attempt's pane would sit on "Loading…" with nothing fetching it.
+test("a log pane left open across a retry loads the new attempt when the row is reopened", async () => {
+ const first = { id: 9, title: "Restart me", status: "parked", repo: "sam/archie", workflow: "tdd", attempt: 1, actions: ["retry"] };
+ const second = { ...first, attempt: 2, status: "running" };
+ const original = { tasks: api.tasks, task: api.task, taskAction: api.taskAction, taskLogs: api.taskLogs };
+ let listReads = 0;
+ const logReads = [];
+ api.tasks = async () => {
+ listReads += 1;
+ return [listReads === 1 ? first : second];
+ };
+ api.task = async () => [
+ { kind: "stage_start", attempt: listReads, stage: listReads === 1 ? "prepare" : "bootstrap", at: "2026-09-18T07:00:00Z" },
+ ];
+ api.taskLogs = async (id, params) => {
+ logReads.push(params);
+ return { found: true, attempt: params.attempt, disabled: false, entries: [{ level: "info", msg: "line" }] };
+ };
+ api.taskAction = async () => ({});
+ try {
+ const { container } = render(tasksPage(new URLSearchParams("task=9")));
+ await waitFor(() => assert.match(container.textContent, /Started stage: prepare/));
+ fireEvent.click(container.querySelector(".task-logs-section button"));
+ await waitFor(() => assert.equal(logReads.length, 1));
+
+ // Collapse the row, retry from the collapsed row, then reopen it.
+ fireEvent.click(container.querySelector(".task-expand"));
+ fireEvent.click(container.querySelector(".task-actions button"));
+ await waitFor(() => assert.equal(listReads, 2));
+ fireEvent.click(container.querySelector(".task-expand"));
+
+ await waitFor(() => assert.match(container.textContent, /Started stage: bootstrap/));
+ await waitFor(() => assert.equal(logReads.length, 2), { timeout: 2000 });
+ assert.deepEqual(logReads[1], { attempt: 2, limit: 500 });
+ assert.doesNotMatch(container.textContent, /Loading attempt log/);
+ } finally {
+ Object.assign(api, original);
+ }
+});
+
+// R8: the run detail page is a per-task route, and the list is how an operator
+// reaches it. The existing #/tasks?task=N deep link is a different affordance
+// and stays working (pinned in operator-controls.test.js).
+test("a task row links to its run detail page", async () => {
+ const root = await renderTask({ id: 7, title: "Fix the flaky test", status: "parked", repo: "sam/archie", actions: [] });
+ const link = root.querySelector(".task-detail-link");
+ assert.ok(link, "the title should link to the run detail page");
+ assert.equal(link.getAttribute("href"), "#/tasks/7");
+ assert.equal(link.textContent, "Fix the flaky test");
+});
+
+// W8: the per-task caches used to be written and never invalidated, so a retry
+// left the previous attempt's timeline (and, because the log cache was keyed by
+// task, its log) on screen under the new run.
+test("a retry drops the ended attempt's caches and reloads the new run", async () => {
+ const first = { id: 8, title: "Flaky", status: "parked", repo: "sam/archie", workflow: "tdd", attempt: 1, actions: ["retry"] };
+ const second = { ...first, attempt: 2, status: "running" };
+ const original = { tasks: api.tasks, task: api.task, taskAction: api.taskAction, taskLogs: api.taskLogs };
+ let listReads = 0;
+ const timelineReads = [];
+ const logReads = [];
+ api.tasks = async () => {
+ listReads += 1;
+ return [listReads === 1 ? first : second];
+ };
+ api.task = async () => {
+ timelineReads.push(timelineReads.length + 1);
+ const attempt = timelineReads.length;
+ return [
+ {
+ kind: "stage_start",
+ attempt,
+ stage: attempt === 1 ? "prepare" : "bootstrap",
+ at: "2026-09-18T07:00:00Z",
+ },
+ ];
+ };
+ api.taskLogs = async (id, params) => {
+ logReads.push(params);
+ return { found: true, attempt: params.attempt, disabled: false, entries: [{ level: "info", msg: "line" }] };
+ };
+ api.taskAction = async () => ({});
+ try {
+ const { container } = render(tasksPage(new URLSearchParams("task=8")));
+ await waitFor(() => assert.match(container.textContent, /Started stage: prepare/));
+
+ fireEvent.click(container.querySelector(".task-logs-section button"));
+ await waitFor(() => assert.equal(logReads.length, 1));
+ assert.deepEqual(logReads[0], { attempt: 1, limit: 500 });
+
+ fireEvent.click(container.querySelector(".task-actions button"));
+ await waitFor(() => assert.match(container.textContent, /Started stage: bootstrap/));
+ assert.equal(timelineReads.length, 2, "the timeline is refetched, not kept from the ended attempt");
+ assert.doesNotMatch(container.textContent, /Started stage: prepare/);
+
+ await waitFor(() => assert.equal(logReads.length, 2), { timeout: 2000 });
+ assert.deepEqual(logReads[1], { attempt: 2, limit: 500 }, "the log pane follows the new attempt");
+ } finally {
+ Object.assign(api, original);
+ }
+});
diff --git a/ui/test/tasks-focus.test.js b/ui/test/tasks-focus.test.js
new file mode 100644
index 000000000..e31abbf98
--- /dev/null
+++ b/ui/test/tasks-focus.test.js
@@ -0,0 +1,73 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { register } from "node:module";
+import { render, waitFor } from "@testing-library/preact";
+
+// tasks.jsx imports its feature CSS, which node cannot load; the same inline
+// loader the sibling tasks tests register lets the module be imported here.
+const cssLoad = "data:text/javascript," + encodeURIComponent(`
+ export async function load(url, context, nextLoad) {
+ if (url.endsWith(".css")) {
+ return { format: "module", shortCircuit: true, source: "export default {};" };
+ }
+ return nextLoad(url, context);
+ }
+`);
+register(cssLoad, import.meta.url);
+
+const { api } = await import("../src/base/api.jsx");
+const { tasksPage } = await import("../src/tasks/tasks.jsx");
+
+// jsdom implements neither matchMedia nor scrollIntoView, so both are provided
+// here to observe the one decision under test: which scroll behaviour a
+// deep-linked row is revealed with.
+function stubMotion(reduced) {
+ window.matchMedia = (query) => ({
+ matches: Boolean(reduced) && String(query).includes("prefers-reduced-motion: reduce"),
+ media: String(query),
+ onchange: null,
+ addEventListener() {},
+ removeEventListener() {},
+ addListener() {},
+ removeListener() {},
+ dispatchEvent() {
+ return false;
+ },
+ });
+}
+
+async function revealWithMotion(reduced) {
+ const seen = [];
+ const originalScroll = Element.prototype.scrollIntoView;
+ const originalMatchMedia = window.matchMedia;
+ const originalTasks = api.tasks;
+ Element.prototype.scrollIntoView = (opts) => seen.push(opts);
+ stubMotion(reduced);
+ api.tasks = async () => [
+ { id: 7, title: "Deep link", status: "running", repo: "o/r", workflow: "tdd", actions: [], attempt: 1 },
+ ];
+ try {
+ const { unmount } = render(tasksPage(new URLSearchParams("task=7")));
+ await waitFor(() => assert.ok(seen.length, "the deep-linked row should be revealed"));
+ unmount();
+ return seen[0];
+ } finally {
+ Element.prototype.scrollIntoView = originalScroll;
+ window.matchMedia = originalMatchMedia;
+ api.tasks = originalTasks;
+ }
+}
+
+// The global reduced-motion rule switches CSS transitions, NOT JS smooth
+// scrolling: a deep-linked row is revealed by scrollIntoView, so the behaviour
+// has to be chosen in JS or a reduced-motion user still gets an animated scroll.
+test("a revealed row scrolls smoothly only when motion is not reduced", async () => {
+ const opts = await revealWithMotion(false);
+ assert.equal(opts.behavior, "smooth");
+ assert.equal(opts.block, "center");
+});
+
+test("a revealed row scrolls instantly when motion is reduced", async () => {
+ const opts = await revealWithMotion(true);
+ assert.equal(opts.behavior, "auto");
+});
diff --git a/ui/test/timeline-event.test.js b/ui/test/timeline-event.test.js
index b5f0258e4..5045ca25a 100644
--- a/ui/test/timeline-event.test.js
+++ b/ui/test/timeline-event.test.js
@@ -102,6 +102,26 @@ test("cancelled stages are described as interrupted rather than failed", () => {
);
});
+// Condition (d): the two provenance events render as human timeline lines and
+// must never dump the captured payload inline -- the Configuration tab renders
+// the document; the timeline only says that it was captured.
+test("capture events describe themselves without dumping their payload", () => {
+ const config = describeTimelineEvent({
+ kind: "config_captured",
+ data: { schema: "archie/task-config@1", document: { BotUser: "archie" } },
+ });
+ assert.equal(config.title, "Configuration captured");
+ assert.doesNotMatch(config.detail, /BotUser/);
+
+ const changes = describeTimelineEvent({
+ kind: "changes_captured",
+ data: { captured_after: "commit", totals: { files: 3, additions: 40, deletions: 5 } },
+ });
+ assert.equal(changes.title, "Change capture recorded");
+ assert.match(changes.detail, /3 files changed/);
+ assert.match(changes.detail, /captured after commit/);
+});
+
test("unknown event kinds become readable labels", () => {
assert.deepEqual(describeTimelineEvent({ kind: "human_approved", detail: "approved via dashboard" }), {
title: "Human Approved",
|