Files
archie/ui/test/changed-files.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

170 lines
7.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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(<ChangedFiles {...props} />);
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());