Files
archie/ui/test/tasks-focus.test.js
T
sam 7414713d61 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

74 lines
2.7 KiB
JavaScript

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");
});