Files
archie/ui/test/timeline-event.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

131 lines
5.0 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { describeTimelineEvent } from "../src/tasks/timeline-event.js";
test("stage events name the stage, workflow, duration, and failure", () => {
assert.deepEqual(
describeTimelineEvent({
kind: "stage_finish",
workflow: "implement",
stage: "baseline",
data: { duration_ms: 1250, error: "task check failed" },
}),
{
title: "Stage failed: baseline",
detail: "implement workflow · ran for 1.3 s — task check failed",
},
);
});
test("retry events explain which failure caused the retry", () => {
assert.deepEqual(
describeTimelineEvent({
kind: "task_retried",
detail: "retried via the dashboard",
data: { retry_count: 2, previous_stage: "baseline", previous_reason: "task check failed" },
}),
{ title: "Retry 2", detail: "after baseline: task check failed" },
);
});
test("agent events expose stage efficiency and cache usage as fresh vs cached", () => {
// prompt_tokens (280,000) INCLUDES the 240,000 cache hits -- showing it
// next to "cached" reads as two separate charges when only 40,000 of it
// was billed at full price. The fresh figure is the disclosed remainder.
assert.deepEqual(
describeTimelineEvent({
kind: "agent_finish",
stage: "analyse",
data: {
status: "passed",
iterations: 7,
tokens: 282066,
prompt_tokens: 280000,
completion_tokens: 2066,
cached_tokens: 240000,
model: "openai/gpt-5.6-luna",
},
}),
{
title: "Agent passed: analyse",
detail:
"7 iterations · 282,066 tokens · 40,000 fresh prompt · 2,066 completion · 240,000 cached · openai/gpt-5.6-luna",
},
);
});
test("agent events with zero-valued usage fields omit them entirely", () => {
// Pre-v0.1.24 persisted events lack the breakdown fields, and a
// failed run still publishes agent_finish with the zero Result. Either
// shape must not render "0 prompt · 0 completion · 0 cached".
const result = describeTimelineEvent({
kind: "agent_finish",
stage: "baseline-fix",
data: {
status: "",
iterations: 0,
tokens: 0,
prompt_tokens: 0,
completion_tokens: 0,
cached_tokens: 0,
model: "openai/gpt-5.6-luna",
},
});
assert.equal(result.title, "Agent finished: baseline-fix");
assert.equal(result.detail.includes("0 "), false, `detail should not mention zero counts: ${result.detail}`);
assert.equal(result.detail, "openai/gpt-5.6-luna");
});
test("stage durations render minutes and hours, not raw seconds", () => {
const r1 = describeTimelineEvent({ kind: "stage_finish", stage: "analyse", data: { duration_ms: 8_500 } });
assert.equal(r1.detail, "ran for 8.5 s");
const r2 = describeTimelineEvent({ kind: "stage_finish", stage: "analyse", data: { duration_ms: 40_600 } });
assert.equal(r2.detail, "ran for 41 s");
const r3 = describeTimelineEvent({ kind: "stage_finish", stage: "fix", data: { duration_ms: 5 * 60_000 + 12_000 } });
assert.equal(r3.detail, "ran for 5 min 12 s");
const r4 = describeTimelineEvent({ kind: "stage_finish", stage: "tdd", data: { duration_ms: 1 * 3_600_000 } });
assert.equal(r4.detail, "ran for 1 h");
const r5 = describeTimelineEvent({ kind: "stage_finish", stage: "analyse", data: { duration_ms: 90_000 } });
assert.equal(r5.detail, "ran for 1 min 30 s");
const r6 = describeTimelineEvent({ kind: "stage_finish", stage: "analyse", data: { duration_ms: 3_599_600 } });
assert.equal(r6.detail, "ran for 1 h");
});
test("cancelled stages are described as interrupted rather than failed", () => {
assert.deepEqual(
describeTimelineEvent({
kind: "stage_finish",
stage: "implement",
data: { error: "context canceled", interrupted: true },
}),
{ title: "Stage interrupted: implement", detail: "context canceled" },
);
});
// 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",
detail: "approved via dashboard",
});
});