diff --git a/web/PARITY.md b/web/PARITY.md index 3274dbb8..d6e78f9f 100644 --- a/web/PARITY.md +++ b/web/PARITY.md @@ -34,7 +34,7 @@ Status legend: `todo` · `partial` (some of it works) · `done` (working + captu | R1 | Run history list with status roll-up | `list_runs` | done | | R2 | Filter by status, sort, "needs you" markers | client-side | done — status/pipeline/time filter + sort implemented and captured (`captures/09-runs-day-groups.png`–`captures/15-runs-sorted.png`); the "needs you" requirement is delivered exactly as the app does it: a bell/badge + sheet (R15), not a per-row mark. No other R2 work is outstanding | | R3 | Run detail: run fields, steps/visits, targets, sessions | `get_run` | done — tabbed Summary / Graph / Input / Output / Timeline; the Timeline opens a per-visit stage pane with the headline rows (Status, Outcome, Duration, Visit `{v} / {max}`, Model target, Target, Session), the Verdict block (option chip + reason with inline artifact links) and the visit sections Artifacts / Session / Output / Input / This run / Stage definition. Captured 2026-10-19: `captures/20-run-430-summary.png`, `captures/23-run-430-timeline.png`, `captures/24-run-430-stage-artifacts.png`, `captures/25-run-440-verdict.png` | -| R4 | Summary tab incl. collapsible **Changes** viewer (raw + rendered diff) | `get_run` file changes | done — a collapsed-by-default **Changes** section in the Summary tab (`{N} file(s) changed · ±stat · partial capture`; the empty variants read `Changes · capture unavailable` / `capture pending` / `partial capture` / `not recorded for this run` / `capture incomplete` / `no changes observed`) whose rows open a full-screen diff viewer with **Rendered** (each `@@` hunk header on a raised surface, old/new gutter numbers, the shared `+`/`-`/space line language) and **Raw patch** forms, Previous/Next file paging (disabled at the ends), a raw-patch copy control, Escape/backdrop/Close close, and honest binary/truncated/no-patch messages instead of a fabricated diff. Pure logic in `src/changes.js`. Captured 2026-10-19: `captures/28-run-438-changes-collapsed.png`, `captures/29-run-438-changes-expanded.png`, `captures/30-run-438-changes-diff-rendered.png`, `captures/31-run-438-changes-diff-raw.png`, `captures/32-run-442-changes-binary.png`, `captures/33-run-450-changes-truncated.png`, `captures/34-run-455-changes-pending.png` | +| R4 | Summary tab incl. collapsible **Changes** viewer (raw + rendered diff), plus each visit's own file-change record | `get_run` file changes | done — the Summary's collapsed-by-default **Changes** section describes the run's **final state**, not a sum: steps are read in numeric sequence order, each path keeps first-seen order and reports its **last recorded step's** kind, patch, `+A -D` stat, binary/truncated flags and before/after modes, while `changed by A → B` still lists every stage that touched it in run order. Header wording is unchanged (`{N} file(s) changed · ±stat · partial capture`; empty variants `Changes · capture unavailable` / `partial capture` / `not recorded for this run` / `capture incomplete` / `no changes observed`). The aggregate is rendered **only when the run status is `succeeded`**; a failed or running run has no settled final state and shows no Summary Changes section at all. This is a **deliberate divergence from Android**, which shows the aggregate for failed runs too — the browser keeps the evidence in each visit's pane instead. That pane's existing **This run** section now shows the selected visit's own capture: a `File changes` line with the honest status word, file count, skipped/omitted counts and diagnostic; a `Changed files` list of `{kind} {path}` plus the parseable `+A -D` stat and `(binary)`/`(truncated)` markers; and neither row when the step recorded no capture. Each visit therefore shows its own set even when a stage ran three times. Summary rows still open the full-screen diff viewer with **Rendered** (each `@@` hunk header on a raised surface, old/new gutter numbers, the shared `+`/`-`/space line language) and **Raw patch** forms, Previous/Next file paging (disabled at the ends), a raw-patch copy control, Escape/backdrop/Close close, and honest binary/truncated/no-patch messages instead of a fabricated diff. Pure logic in `src/changes.js` and `src/runDetail.js`; `showRunChangesSummary` gates the aggregate. Captured 2026-10-19: `captures/28-run-438-changes-collapsed.png`, `captures/29-run-438-changes-expanded.png` (final-state `+42 -12` for the twice-edited `internal/server/retry_test.go`, header `+934 -156`), `captures/30-run-438-changes-diff-rendered.png`, `captures/31-run-438-changes-diff-raw.png`, `captures/32-run-449-changes-binary.png`, `captures/33-run-450-changes-truncated.png`, `captures/78-run-438-implementer-visit-changes.png` (that visit's own `partial (1 files)` and one Changed files line), `captures/79-run-440-no-summary-changes.png` (failed run: no aggregate), `captures/80-run-440-visit-changes.png` (its visit's `File changes`, no recorded rows), `captures/81-run-442-failed-visit-changes.png` (a failed run's implementer visit keeps its own Changed files) and `captures/82-run--no-summary-changes.png` (a running run: no aggregate) | | R5 | Graph tab (per-stage panes, verdicts) | `get_run` | done — the run detail's Graph tab (between Summary and Input) mounts the shared `src/graph.js` renderer in run mode with the app's run note: a visited stage is executed (solid fill + border), an unvisited one hollow with a dashed muted border, a terminal executed only when a visit resolved to it, a route executed only when a visit produced that outcome (solid with an arrowhead; success first, error last, others alphabetical, `error*` for a fallback error route), the Executed / Not executed legend (runs only, never the definition view), and — while executing — the current stage's pulsing halo + elapsed badge (a static ring under `prefers-reduced-motion`; nothing for a finished run). Clicking a stage opens the existing visit pane at that stage's latest visit with its Verdict; Back/Escape close it and restore focus. The empty state is the exact `This server did not include the run graph.` (unit-tested; no live run currently carries a graph-less payload). Captured 2026-10-19: `captures/28-run-438-graph.png` (finished run 438: legend + executed styling + dashed untaken routes), `captures/29-run-438-graph-pane.png` (a graph-opened stage pane showing a Verdict), `captures/30-run-440-graph.png` (failed run 440: hollow/dashed not-executed stages) | | R6 | Input / Output field sections per stage | `get_run` | done — one collapsed section per recorded entry, expanded as a monospace block (primitives verbatim, arrays `, `-joined, objects `k=v` `, `-joined), empty states "No input recorded." / "No output recorded.". Captured 2026-10-19: `captures/21-run-430-input.png`, `captures/22-run-430-output.png`, `captures/27-run-output-empty.png` | | R7 | Timeline | `get_run` | done — one compact row per visit (`{stage} · visit {n}`, stage-outcome chip, paperclip when artifacts recorded, duration, description = first non-blank diagnostic line else `→ {target}`); empty state "No visits recorded.". Captured 2026-10-19: `captures/23-run-430-timeline.png`, `captures/26-run-428-timeline-empty.png` | diff --git a/web/src/changes.js b/web/src/changes.js index 82ae9603..728d8d5b 100644 --- a/web/src/changes.js +++ b/web/src/changes.js @@ -1,6 +1,6 @@ -// Pure, DOM-free logic for the run summary's Changes section and its diff -// viewer, ported from the Android client so the browser says and shows exactly -// the same things: +// Pure, DOM-free logic for the run summary's final-state Changes section and its +// diff viewer, ported from the Android client so the browser says and shows +// exactly the same things (the aggregate is last-visit-wins rather than a sum): // ui/changes/RunChanges.kt changeKind, changeKindLabel, parseUnifiedPatch, // runChanges, runChangesHeader, runChangesNote, // changesListSummary, noChangeDetail, @@ -249,14 +249,27 @@ export function gutterText(value, width) { // --------------------------------------------------------------------------- /** - * Aggregates a run's stage steps into its Changes state. Pure and total over its - * input: a null `file_changes` on a step is a historical (or non-capturing) step - * and contributes nothing (it is never "no changes"); a present capture with no - * files is a real, observed no-change. Files are keyed by path and keep + * Whether the Summary tab may present the run-wide aggregated Changes section. + * The operator decision is final-state-only: a failed run has no settled final + * workspace, so its evidence stays in each visit's own recorded capture. The + * Android client shows the aggregate for failed runs too; this is a deliberate + * browser divergence, recorded in PARITY.md R4. Pure. + */ +export function showRunChangesSummary(status) { + return str(status).trim().toLowerCase() === "succeeded"; +} + +/** + * Aggregates a run's stage steps into its final-state Changes view. Pure and + * total over its input: a null `file_changes` on a step is a historical (or + * non-capturing) step and contributes nothing (it is never "no changes"); a + * present capture with no files is a real, observed no-change. Steps are read in + * numeric sequence order (stable for ties), and files are keyed by path and keep * first-seen order, so a path several steps changed is one entry naming all of - * them. Later steps win the kind unless they only say "other", added/removed - * line counts sum, binary/truncated are OR'd, before_mode is first-seen and - * after_mode last-seen. + * them. The last recorded step for a path supplies its kind, patch, added/removed + * counts, binary/truncated flags and modes: the summary describes the state the + * run left, never a sum of intermediate visits. Run-wide capture counters and + * caveats still describe every contributing step. */ export function runChanges(steps) { const entries = new Map(); @@ -267,9 +280,14 @@ export function runChanges(steps) { let missingCaptures = 0; let skipped = 0; let omitted = 0; + let truncatedSeen = false; const diagnostics = new Set(); + const orderedSteps = (steps ?? []) + .map((step, index) => ({ step, index })) + .sort((a, b) => sequenceOf(a.step) - sequenceOf(b.step) || a.index - b.index) + .map((entry) => entry.step); - for (const step of steps ?? []) { + for (const step of orderedSteps) { const changes = step?.file_changes; if (changes == null) { if (step?.status === "running" || step?.status === "waiting") stepsPending++; @@ -287,47 +305,39 @@ export function runChanges(steps) { for (const file of changes.files ?? []) { const path = str(file?.path); if (path.trim() === "") continue; + if (file?.truncated === true) truncatedSeen = true; const kind = changeKind(file?.kind); const parsed = parseUnifiedPatch(file?.patch); const existing = entries.get(path); const mergedSteps = existing ? [...existing.steps] : []; if (!mergedSteps.includes(stage)) mergedSteps.push(stage); - const patchParts = []; - if (existing && existing.patch != null) patchParts.push(existing.patch); - if (typeof file?.patch === "string" && file.patch.trim() !== "") patchParts.push(file.patch); - const joinedPatch = patchParts.join("\n"); + // The last recorded step wins every per-file fact: the summary is the + // final state, not an accumulation of the visits on the way there. entries.set(path, { path, - // A later step wins the kind: it is the observed state the run left. - kind: existing == null || kind !== ChangeKind.Other ? kind : existing.kind, - added: (existing?.added ?? 0) + parsed.added, - removed: (existing?.removed ?? 0) + parsed.removed, - binary: existing?.binary === true || file?.binary === true, - truncated: existing?.truncated === true || file?.truncated === true, - // Keep the first-seen before-mode and the last-seen after-mode, so the - // pair describes the run's net effect on the file. - beforeMode: existing && existing.beforeMode != null ? existing.beforeMode : nullable(file?.before_mode), - afterMode: file?.after_mode != null ? file.after_mode : existing?.afterMode ?? null, + kind, + added: parsed.added, + removed: parsed.removed, + binary: file?.binary === true, + truncated: file?.truncated === true, + beforeMode: nullable(file?.before_mode), + afterMode: nullable(file?.after_mode), otherModeChange: - existing?.otherModeChange === true || - (file?.before_mode != null && - file?.after_mode != null && - file.before_mode !== file.after_mode && - !file.binary && - parsed.added === 0 && - parsed.removed === 0), + file?.before_mode != null && + file?.after_mode != null && + file.before_mode !== file.after_mode && + !file.binary && + parsed.added === 0 && + parsed.removed === 0, steps: mergedSteps, - // Preserve every recorded textual patch for a path. A file may be - // changed by several stages, and retaining only the first one would - // make the displayed hunks disagree with the aggregate stat. - patch: joinedPatch.trim() !== "" ? joinedPatch : null, + patch: typeof file?.patch === "string" && file.patch.trim() !== "" ? file.patch : null, }); } } const files = [...entries.values()]; const pending = stepsWithChanges === 0 && stepsPending > 0; - const totalPartial = partial || files.some((file) => file.truncated) || omitted > 0; + const totalPartial = partial || truncatedSeen || omitted > 0; return { files, stepsWithChanges, @@ -538,6 +548,12 @@ export function diffLineClass(kind) { // Internals // --------------------------------------------------------------------------- +/** A step's numeric sequence for ordering, with a missing/invalid value as 0. */ +function sequenceOf(step) { + const value = Number(step?.sequence); + return Number.isFinite(value) ? value : 0; +} + /** An integer parsed from a strictly-numeric string, or null. */ function intOrNull(text) { return /^[+-]?\d+$/.test(text) ? Number.parseInt(text, 10) : null; diff --git a/web/src/runDetail.js b/web/src/runDetail.js index e22c4384..3ccd8b35 100644 --- a/web/src/runDetail.js +++ b/web/src/runDetail.js @@ -28,6 +28,7 @@ import { runStateOf, } from "./runs.js"; import { presentedArtifacts, sessionExportArtifact, displayVisit } from "./artifacts.js"; +import { changeStat, parseUnifiedPatch } from "./changes.js"; import { effectiveStageType } from "./templates.js"; // --------------------------------------------------------------------------- @@ -696,14 +697,25 @@ export function artifactBaseName(name) { // --------------------------------------------------------------------------- /** - * One changed-file line, e.g. `modified src/a.kt (binary) (truncated)`. Mirrors - * Format.kt fileChangeLine. + * One changed-file line, e.g. `modified src/a.kt +3 -2 (truncated)`. The kind, + * path and binary/truncated markers are Format.kt's exact spelling; the `+N -M` + * stat is added when the recorded patch is readable (not binary) and parses to + * at least one hunk, so a line never claims a line count it could not read. A + * binary file keeps its marker and never gets a text stat. */ export function fileChangeLine(file) { const base = `${str(file?.kind)} ${str(file?.path)}`; const binary = file?.binary ? " (binary)" : ""; const truncated = file?.truncated ? " (truncated)" : ""; - return base + binary + truncated; + let stat = ""; + if (!file?.binary) { + const patch = str(file?.patch); + if (patch.trim() !== "") { + const parsed = parseUnifiedPatch(patch); + if (parsed.hunks.length > 0) stat = changeStat(parsed.added, parsed.removed); + } + } + return base + (stat !== "" ? ` ${stat}` : "") + binary + truncated; } /** One notification receipt, e.g. `delivered → ntfy · ok`, skipping a blank diagnostic. */ @@ -714,12 +726,16 @@ export function notificationLine(receipt) { } /** - * A compact file-change summary, e.g. `partial (2 files), 1 skipped`. Blank - * parts are omitted; an entirely blank change set renders as "". + * A compact file-change summary, e.g. + * `partial (2 files), 1 skipped, 3 omitted · Excluded protected files.`. + * The status word, file count, skipped and omitted counts are the capture's own + * honest facts; the trimmed diagnostic follows after ` · ` when present. Blank + * parts are omitted, and an entirely blank change set renders as "". */ export function fileChangesSummary(changes) { let text = ""; - if (str(changes?.status).trim() !== "") text += str(changes.status); + const status = str(changes?.status).trim(); + if (status !== "") text += status; const files = changes?.files ?? []; if (files.length > 0) { if (text !== "") text += " "; @@ -729,6 +745,15 @@ export function fileChangesSummary(changes) { if (text !== "") text += ", "; text += `${changes.skipped} skipped`; } + if (Number(changes?.omitted) > 0) { + if (text !== "") text += ", "; + text += `${changes.omitted} omitted`; + } + const diagnostic = str(changes?.diagnostic).trim(); + if (diagnostic !== "") { + if (text !== "") text += " · "; + text += diagnostic; + } return text; } diff --git a/web/src/views/runDetail.js b/web/src/views/runDetail.js index c6bdfcf0..e309c664 100644 --- a/web/src/views/runDetail.js +++ b/web/src/views/runDetail.js @@ -71,6 +71,7 @@ import { runChanges, runChangesHeader, runChangesNote, + showRunChangesSummary, } from "../changes.js"; import { DECISION_ACTION, @@ -225,12 +226,15 @@ function renderRunSummaryTab(d, now) { ); // The run-level Changes (parity R4), collapsed by default like the Android - // summary: the observed workspace diff. Its header alone states the file count - // and aggregate stat until expanded, and every file row opens the diff viewer. - const changes = runChanges(d.steps ?? []); - wrap.append( - renderCollapsible("summary-changes", runChangesHeader(changes), () => renderChangesBody(changes)), - ); + // summary: the observed final-state workspace diff. Only a succeeded run has a + // settled final state to present; a failed run keeps its evidence in each + // visit's own capture (a deliberate divergence from Android, see PARITY R4). + if (showRunChangesSummary(d.status)) { + const changes = runChanges(d.steps ?? []); + wrap.append( + renderCollapsible("summary-changes", runChangesHeader(changes), () => renderChangesBody(changes)), + ); + } return wrap; } diff --git a/web/test/changes.test.mjs b/web/test/changes.test.mjs index a15c3f96..69d84ac0 100644 --- a/web/test/changes.test.mjs +++ b/web/test/changes.test.mjs @@ -1,8 +1,9 @@ // Pure unit tests for the run summary's Changes section and its diff viewer: // the kind mapping and labels, the unified-patch parser (hunks, line numbers, // stat counts, the `\ No newline` marker and header closing), the cross-step -// aggregation (kind merge, stat sums, binary/truncated OR, mode first/last), -// every header/note/detail wording variant and the row/viewer helpers. +// final-state aggregation (last sequence wins every per-file fact, every +// touching stage retained), every header/note/detail wording variant and the +// row/viewer helpers. // No server, no DOM. import { test } from "node:test"; import assert from "node:assert/strict"; @@ -33,6 +34,7 @@ import { runChanges, runChangesHeader, runChangesNote, + showRunChangesSummary, } from "../src/changes.js"; // A step file-change with sane defaults, overridable per test. @@ -224,7 +226,7 @@ test("a present capture with no files is a captured no-change", () => { assert.equal(noChangeDetail(changes), "The captured snapshots were identical: the workspace was unchanged."); }); -test("the later step wins the kind, but `other` never downgrades it", () => { +test("a later step's kind wins, including an unrecognised later kind", () => { const changes = runChanges([ step({ stage: "a", file_changes: { status: "complete", files: [file({ path: "x", kind: "modified" })] } }), step({ stage: "b", file_changes: { status: "complete", files: [file({ path: "x", kind: "added" })] } }), @@ -233,14 +235,84 @@ test("the later step wins the kind, but `other` never downgrades it", () => { assert.equal(changes.files[0].kind, ChangeKind.Added); assert.deepEqual(changes.files[0].steps, ["a", "b"]); - const downgrade = runChanges([ + const unknown = runChanges([ step({ stage: "a", file_changes: { status: "complete", files: [file({ path: "x", kind: "added" })] } }), step({ stage: "b", file_changes: { status: "complete", files: [file({ path: "x", kind: "copied" })] } }), ]); - assert.equal(downgrade.files[0].kind, ChangeKind.Added); + // No downgrade heuristic: the final visit recorded an unrecognised kind, so + // the row says `changed` rather than guessing from the earlier visit. + assert.equal(unknown.files[0].kind, ChangeKind.Other); }); -test("stat sums, binary/truncated OR and mode first/last-seen across steps", () => { +test("a path changed in three visits reports only the last visit's facts", () => { + const changes = runChanges([ + step({ + stage: "a", + sequence: 1, + file_changes: { + status: "complete", + files: [ + file({ + path: "x", + kind: "modified", + patch: "@@ -1 +1 @@\n-old\n+one", + before_mode: "0644", + after_mode: "0644", + }), + ], + }, + }), + step({ + stage: "b", + sequence: 2, + file_changes: { + status: "complete", + files: [ + file({ + path: "x", + kind: "modified", + patch: "@@ -1 +1 @@\n-one\n+two", + before_mode: "0644", + after_mode: "0644", + }), + ], + }, + }), + step({ + stage: "c", + sequence: 3, + file_changes: { + status: "complete", + files: [ + file({ + path: "x", + kind: "added", + patch: "@@ -1 +2 @@\n-two\n+three\n+four", + before_mode: "0755", + after_mode: "0600", + }), + ], + }, + }), + ]); + const entry = changes.files[0]; + assert.equal(entry.kind, ChangeKind.Added); + assert.equal(entry.added, 2); + assert.equal(entry.removed, 1); + assert.equal(entry.patch, "@@ -1 +2 @@\n-two\n+three\n+four"); + assert.equal(entry.binary, false); + assert.equal(entry.truncated, false); + assert.equal(entry.beforeMode, "0755"); + assert.equal(entry.afterMode, "0600"); + assert.equal(entryModeChanged(entry), true); + assert.deepEqual(entry.steps, ["a", "b", "c"]); + assert.equal(changeRowMeta(entry), "changed by a → b → c · mode 0755→0600"); + // The run total is the final state's stat, not the three visits summed. + assert.equal(changes.added, 2); + assert.equal(changes.removed, 1); +}); + +test("later binary/truncated flags and modes replace the earlier rows", () => { const changes = runChanges([ step({ stage: "a", @@ -251,8 +323,10 @@ test("stat sums, binary/truncated OR and mode first/last-seen across steps", () path: "x", kind: "modified", patch: "@@ -1 +1 @@\n-old\n+new", + binary: true, + truncated: true, before_mode: "0644", - after_mode: "0644", + after_mode: "0755", }), ], }, @@ -265,9 +339,9 @@ test("stat sums, binary/truncated OR and mode first/last-seen across steps", () file({ path: "x", kind: "modified", - patch: "@@ -1 +1 @@\n-gone\n+kept", - binary: true, - truncated: true, + patch: "", + binary: false, + truncated: false, before_mode: "0755", after_mode: "0755", }), @@ -276,16 +350,55 @@ test("stat sums, binary/truncated OR and mode first/last-seen across steps", () }), ]); const entry = changes.files[0]; - assert.equal(entry.added, 2); - assert.equal(entry.removed, 2); - assert.equal(entry.binary, true); - assert.equal(entry.truncated, true); - assert.equal(entry.beforeMode, "0644"); // first-seen - assert.equal(entry.afterMode, "0755"); // last-seen - assert.equal(entryModeChanged(entry), true); - assert.equal(entryHasPatch(entry), false); // binary hides the patch - assert.equal(changes.added, 2); - assert.equal(changes.removed, 2); + assert.equal(entry.binary, false); + assert.equal(entry.truncated, false); + assert.equal(entry.patch, null); + assert.equal(entry.beforeMode, "0755"); + assert.equal(entry.afterMode, "0755"); + assert.equal(entryModeChanged(entry), false); + assert.equal(entry.added, 0); + assert.equal(entry.removed, 0); + // A truncated row anywhere in the run still makes the capture partial. + assert.equal(changes.partial, true); +}); + +test("an earlier-only path keeps its own values", () => { + const changes = runChanges([ + step({ + stage: "a", + file_changes: { + status: "complete", + files: [file({ path: "x", kind: "added", patch: "@@ -0,0 +1 @@\n+x" })], + }, + }), + step({ + stage: "b", + file_changes: { + status: "complete", + files: [file({ path: "y", kind: "deleted", patch: "@@ -1 +0,0 @@\n-y" })], + }, + }), + ]); + assert.deepEqual(changes.files.map((entry) => entry.path), ["x", "y"]); + assert.equal(changes.files[0].kind, ChangeKind.Added); + assert.equal(changes.files[0].added, 1); + assert.equal(changes.files[0].removed, 0); + assert.equal(changes.files[1].kind, ChangeKind.Deleted); + assert.equal(changes.files[1].added, 0); + assert.equal(changes.files[1].removed, 1); +}); + +test("ordering follows numeric sequence, not input order", () => { + const outOfOrder = runChanges([ + step({ stage: "c", sequence: 3, file_changes: { status: "complete", files: [file({ path: "y", kind: "added" })] } }), + step({ stage: "a", sequence: 1, file_changes: { status: "complete", files: [file({ path: "y", kind: "modified" })] } }), + step({ stage: "b", sequence: 2, file_changes: { status: "complete", files: [file({ path: "x", kind: "added" })] } }), + ]); + assert.deepEqual(outOfOrder.files.map((entry) => entry.path), ["y", "x"]); + const y = outOfOrder.files.find((entry) => entry.path === "y"); + assert.equal(y.kind, ChangeKind.Added); + assert.deepEqual(y.steps, ["a", "c"]); + assert.equal(changeRowMeta(y), "changed by a → c"); }); test("changed-by lists the stage names in run order, deduped", () => { @@ -330,6 +443,16 @@ test("diagnostics from several captures are joined with a space, deduped", () => assert.equal(changes.diagnostic, "why one why two"); }); +test("showRunChangesSummary is true only for a settled succeeded run", () => { + assert.equal(showRunChangesSummary("succeeded"), true); + assert.equal(showRunChangesSummary(" Succeeded "), true); + for (const status of ["failed", "running", "waiting", "canceled", "interrupted", "blocked", ""]) { + assert.equal(showRunChangesSummary(status), false, `${status} must not show an aggregate`); + } + assert.equal(showRunChangesSummary(null), false); + assert.equal(showRunChangesSummary(undefined), false); +}); + // --------------------------------------------------------------------------- // Header, note and detail wording // --------------------------------------------------------------------------- @@ -552,10 +675,15 @@ test("runChanges derives run 438's shape: 22 files, partial, one missing capture assert.equal(changes.unavailable, false); assert.equal(changes.pending, false); assert.equal(changes.skipped, 10); - assert.equal(changes.files.find((f) => f.path === "internal/server/retry_test.go").added, 2); + // The retry test was modified by two implementer visits; only the last one's + // stat counts (the earlier patch must not be added to it). + assert.equal(changes.files.find((f) => f.path === "internal/server/retry_test.go").added, 1); + assert.equal(changes.files.find((f) => f.path === "internal/server/retry_test.go").removed, 1); + assert.equal(changes.added, 22); + assert.equal(changes.removed, 22); assert.equal( runChangesHeader(changes), - `22 files changed · +23 -23 · partial capture`, + `22 files changed · +22 -22 · partial capture`, ); assert.ok(runChangesNote(changes).startsWith("Partial capture: some changes may be missing. (10 files skipped)")); assert.ok(runChangesNote(changes).endsWith("Missing capture: 1 stage did not record changes.")); diff --git a/web/test/runDetail.test.mjs b/web/test/runDetail.test.mjs index 76f40c7a..290e4085 100644 --- a/web/test/runDetail.test.mjs +++ b/web/test/runDetail.test.mjs @@ -47,6 +47,7 @@ import { outcomeColorToken, stateGlyph, } from "../src/runDetail.js"; +import { showRunChangesSummary } from "../src/changes.js"; function step(overrides = {}) { return { @@ -315,6 +316,68 @@ test("runStepFields carries every evidence kind the timeline dropped", () => { assert.equal(fields.find((f) => f.label === "Input").block, true); }); +test("each visit's pane formats its own capture, never the run aggregate", () => { + const first = step({ + sequence: 1, + file_changes: { + status: "partial", + skipped: 2, + diagnostic: "Excluded protected files.", + files: [ + { kind: "added", path: "docs/one.md", patch: "@@ -0,0 +1 @@\n+one" }, + { kind: "modified", path: "src/runner.go", patch: "@@ -1 +1 @@\n-old\n+new" }, + ], + }, + }); + const second = step({ + sequence: 2, + file_changes: { + status: "complete", + files: [{ kind: "modified", path: "src/retry_test.go", patch: "@@ -1 +3 @@\n-old\n+a\n+b\n+c" }], + }, + }); + const third = step({ + sequence: 3, + file_changes: { status: "complete", files: [] }, + }); + + const firstFields = runStepFields(first); + assert.equal( + firstFields.find((field) => field.label === "File changes").value, + "partial (2 files), 2 skipped · Excluded protected files.", + ); + assert.equal( + firstFields.find((field) => field.label === "Changed files").value, + "added docs/one.md +1\nmodified src/runner.go +1 -1", + ); + + const secondFields = runStepFields(second); + assert.equal(secondFields.find((field) => field.label === "File changes").value, "complete (1 files)"); + assert.equal( + secondFields.find((field) => field.label === "Changed files").value, + "modified src/retry_test.go +3 -1", + ); + + // A captured no-change still shows its honest summary but has no file rows. + const thirdFields = runStepFields(third); + assert.equal(thirdFields.find((field) => field.label === "File changes").value, "complete"); + assert.equal(thirdFields.find((field) => field.label === "Changed files"), undefined); +}); + +test("a step that recorded no capture shows neither File changes nor Changed files", () => { + const fields = runStepFields(step({ file_changes: null })); + assert.ok(!fields.some((field) => field.label === "File changes")); + assert.ok(!fields.some((field) => field.label === "Changed files")); +}); + +test("showRunChangesSummary gates the Summary aggregate to succeeded only", () => { + assert.equal(showRunChangesSummary("succeeded"), true); + assert.equal(showRunChangesSummary(" SUCCEEDED "), true); + for (const status of ["failed", "running", "waiting", "canceled", "interrupted", ""]) { + assert.equal(showRunChangesSummary(status), false); + } +}); + test("headline and evidence split the visit's facts without duplication", () => { const fields = runStepFields({ status: "completed", @@ -473,12 +536,37 @@ test("referencedVerdictArtifacts resolves names to recorded files in recorded or // Formatters and colours // --------------------------------------------------------------------------- -test("fileChangeLine adds the binary and truncated markers", () => { +test("fileChangeLine adds a parseable stat, never a fabricated one", () => { assert.equal(fileChangeLine({ kind: "modified", path: "src/a.kt" }), "modified src/a.kt"); assert.equal( fileChangeLine({ kind: "modified", path: "src/a.kt", binary: true, truncated: true }), "modified src/a.kt (binary) (truncated)", ); + // A binary file keeps its marker and never gets a text stat, even if a patch + // string was recorded alongside it. + assert.equal( + fileChangeLine({ kind: "added", path: "shot.png", binary: true, patch: "@@ -1 +1 @@\n-a\n+b" }), + "added shot.png (binary)", + ); + assert.equal( + fileChangeLine({ + kind: "modified", + path: "src/a.kt", + patch: "@@ -1,2 +1,3 @@\n ctx\n-old\n+new\n+more", + }), + "modified src/a.kt +2 -1", + ); + assert.equal( + fileChangeLine({ + kind: "modified", + path: "src/a.kt", + truncated: true, + patch: "@@ -1 +1 @@\n-old\n+new", + }), + "modified src/a.kt +1 -1 (truncated)", + ); + // Header-only/unparseable text is not a diff and earns no stat. + assert.equal(fileChangeLine({ kind: "modified", path: "src/a.kt", patch: "not a patch" }), "modified src/a.kt"); }); test("notificationLine appends a non-blank diagnostic only", () => { @@ -489,8 +577,23 @@ test("notificationLine appends a non-blank diagnostic only", () => { ); }); -test("fileChangesSummary omits blank parts", () => { +test("fileChangesSummary carries status, count, skipped, omitted and diagnostic", () => { assert.equal(fileChangesSummary({ status: "partial", files: [{}, {}], skipped: 1 }), "partial (2 files), 1 skipped"); + assert.equal( + fileChangesSummary({ + status: "partial", + files: [{}, {}], + skipped: 1, + omitted: 3, + diagnostic: " Excluded protected files. ", + }), + "partial (2 files), 1 skipped, 3 omitted · Excluded protected files.", + ); + assert.equal( + fileChangesSummary({ status: "unavailable", files: [], diagnostic: "snapshot unreadable" }), + "unavailable · snapshot unreadable", + ); + assert.equal(fileChangesSummary({ status: "complete", files: [] }), "complete"); assert.equal(fileChangesSummary({}), ""); assert.equal(fileChangesSummary(null), ""); }); diff --git a/web/test/ui-smoke.mjs b/web/test/ui-smoke.mjs index abcd12b4..c5bff20a 100644 --- a/web/test/ui-smoke.mjs +++ b/web/test/ui-smoke.mjs @@ -2612,6 +2612,29 @@ try { console.log(` expanded: ${expanded.summary} — ${expanded.rows} row(s)`); console.log(` note: ${expanded.note}`); console.log(` kinds: ${[...new Set(expanded.kinds)].join(", ")}`); + // The summary is the final state: retry_test.go was modified in two + // implementer visits (+30 -12, then +42 -12). The row must show the last + // visit's +42 -12, not their +72 -24 sum, and only the one stage name. + const finalState = await page.evaluate(`(() => { + const row = [...document.querySelectorAll(".run-detail .changes-list .change-row")] + .find((n) => n.querySelector(".change-path")?.textContent === "internal/server/retry_test.go"); + if (!row) return null; + return { + stat: [...row.querySelectorAll(".change-stat span")].map((n) => n.textContent).join(" "), + meta: row.querySelector(".change-meta")?.textContent ?? "", + }; + })()`); + if (!finalState) throw new Error("run 438's Changes list lost internal/server/retry_test.go"); + if (finalState.stat !== "+42 -12") { + throw new Error(`run 438 did not show retry_test.go's final-visit stat: ${finalState.stat}`); + } + if (finalState.meta !== "changed by implementer") { + throw new Error(`run 438's retry_test.go stage list is wrong: ${finalState.meta}`); + } + if (!collapsed.title.includes("+934 -156")) { + throw new Error(`run 438's header is not the final-state stat: ${collapsed.title}`); + } + console.log(` final state: retry_test.go ${finalState.stat} — ${finalState.meta}`); await page.evaluate(`document.querySelector(".run-detail .changes-list .change-row")?.scrollIntoView({ block: "center" })`); shots.push(await page.screenshot(`${out}/29-run-438-changes-expanded.png`)); @@ -2710,13 +2733,64 @@ try { await page.waitForSelector(".change-viewer", { timeout: 15000 }); await closeChangeViewer("backdrop"); + // Part 1: each visit's "This run" carries its own capture. Run 438's second + // implementer visit changed only retry_test.go and must not show the run-wide + // aggregate (or the first visit's docs/runner rows). + step("opening run 438's second implementer visit: its own File changes"); + await page.clickText(".detail .detail-tabs .detail-tab", "Timeline"); + await page.waitForSelector(".detail .timeline-row", { timeout: 15000 }); + await page.click('.detail .timeline-row[data-stage-key="implementer"][data-visit-index="1"]'); + await page.waitForSelector(".stage-pane", { timeout: 15000 }); + await page.clickText(".stage-pane .section-toggle", "This run"); + await page.waitForSelector(".stage-pane .codeblock", { timeout: 15000 }); + const visitChanges = await page.evaluate(`(() => { + const row = [...document.querySelectorAll(".stage-pane .kv-row")] + .find((n) => n.querySelector(".kv-key")?.textContent === "File changes"); + const block = [...document.querySelectorAll(".stage-pane .codeblock")] + .find((n) => n.querySelector(".codeblock-label")?.textContent === "Changed files"); + return { + summary: row?.querySelector(".kv-val")?.textContent ?? "", + files: block?.querySelector(".codeblock-body")?.textContent ?? "", + labels: [...document.querySelectorAll(".stage-pane .codeblock-label")].map((n) => n.textContent), + }; + })()`); + if (!visitChanges.summary.startsWith("partial (1 files), 2 skipped · Excluded protected")) { + throw new Error(`the implementer visit's File changes is wrong: ${visitChanges.summary}`); + } + if (visitChanges.files !== "modified internal/server/retry_test.go +42 -12") { + throw new Error(`the implementer visit's Changed files is wrong: ${visitChanges.files}`); + } + if (visitChanges.files.includes("docs/notes") || visitChanges.files.includes("runner.go")) { + throw new Error(`the visit pane leaked another visit's files: ${visitChanges.files}`); + } + console.log(` implementer visit 2: ${visitChanges.summary}`); + console.log(` changed files: ${visitChanges.files}`); + await page.evaluate(`(() => { + const row = [...document.querySelectorAll(".stage-pane .kv-row")] + .find((n) => n.querySelector(".kv-key")?.textContent === "File changes"); + row?.scrollIntoView({ block: "center" }); + })()`); + shots.push(await page.screenshot(`${out}/78-run-438-implementer-visit-changes.png`)); + await page.click(".stage-pane-back"); + await eventually(() => page.evaluate(`!document.querySelector(".stage-pane")`), { + timeout: 5000, + what: "the implementer visit pane to close", + }); + // A binary capture: the honest message in place of a diff, and Raw disabled. - step("opening a binary capture (run 442): the honest message and a disabled Raw patch"); - await page.click('.list.runs .run-row-meta[data-run-id="442"]'); - await page.waitForText("run 442 ·", { timeout: 25000 }); - await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 }); + // Run 449 succeeded and recorded binary captures; choose its binary row (its + // first row is a text file). + step("opening a binary capture (run 449): the honest message and a disabled Raw patch"); + await openRunDetail(449); await expandChanges(); - await page.click(".run-detail .changes-list .change-row"); + const openedBinary = await page.evaluate(`(() => { + const row = [...document.querySelectorAll(".run-detail .changes-list .change-row")] + .find((n) => (n.querySelector(".change-meta")?.textContent ?? "").includes("binary")); + if (!row) return false; + row.click(); + return true; + })()`); + if (!openedBinary) throw new Error("run 449's Changes list showed no binary row"); await page.waitForSelector(".change-viewer .change-honest", { timeout: 15000 }); const binary = await page.evaluate(`(() => ({ message: document.querySelector(".change-viewer .change-honest")?.textContent ?? "", @@ -2732,7 +2806,7 @@ try { if (binary.rawDisabled !== true) throw new Error("Raw patch should be disabled for a binary file"); if (binary.hunks !== 0) throw new Error("a binary file must not render a fabricated diff"); console.log(` binary: ${binary.message}`); - shots.push(await page.screenshot(`${out}/32-run-442-changes-binary.png`)); + shots.push(await page.screenshot(`${out}/32-run-449-changes-binary.png`)); await closeChangeViewer("close"); // A truncated capture: the truncation reason, still no fabricated diff. @@ -2763,38 +2837,118 @@ try { shots.push(await page.screenshot(`${out}/33-run-450-changes-truncated.png`)); await closeChangeViewer("close"); - // A still-running run: its Changes header must be one of the two valid shapes - // for an in-flight capture (the empty `Changes · …` variant, or a file-count - // header), never a fabricated complete diff. Its live state decides which, so - // the probe accepts either rather than pinning one. - step("opening a running run's Changes header"); - const pendingRunId = await page.evaluate(`(() => { + // Part 3: a failed run has no settled final state, so its Summary carries no + // aggregate Changes section at all. The visit pane still carries that visit's + // own capture. + step("opening failed run 440: no Summary Changes section"); + await openRunDetail(440); + const failedSummaryTitles = await page.evaluate( + `[...document.querySelectorAll(".run-detail .collapsible .section-title")].map((n) => n.textContent ?? "")`, + ); + const leakedAggregate = failedSummaryTitles.find( + (title) => /^Changes · /.test(title) || /^\d+ files? changed/.test(title), + ); + if (leakedAggregate) { + throw new Error(`failed run 440 still shows an aggregate Changes section: ${leakedAggregate}`); + } + console.log(` run 440 summary sections: ${failedSummaryTitles.join(" | ")}`); + shots.push(await page.screenshot(`${out}/79-run-440-no-summary-changes.png`)); + + step("run 440's visit pane keeps that visit's own File changes"); + await page.clickText(".detail .detail-tabs .detail-tab", "Timeline"); + await page.waitForSelector(".detail .timeline-row", { timeout: 15000 }); + await page.click(".detail .timeline-row"); + await page.waitForSelector(".stage-pane", { timeout: 15000 }); + await page.clickText(".stage-pane .section-toggle", "This run"); + await page.waitForSelector(".stage-pane .kv-row", { timeout: 15000 }); + const failedVisit = await page.evaluate(`(() => { + const row = [...document.querySelectorAll(".stage-pane .kv-row")] + .find((n) => n.querySelector(".kv-key")?.textContent === "File changes"); + const block = [...document.querySelectorAll(".stage-pane .codeblock")] + .find((n) => n.querySelector(".codeblock-label")?.textContent === "Changed files"); + return { + summary: row?.querySelector(".kv-val")?.textContent ?? "", + files: block?.querySelector(".codeblock-body")?.textContent ?? "", + }; + })()`); + // This visit's capture recorded no file rows (0 files, 2 skipped), so the + // honest summary is shown and Changed files is correctly absent. + if (!failedVisit.summary.startsWith("partial, 2 skipped · Excluded protected")) { + throw new Error(`run 440's visit File changes is wrong: ${failedVisit.summary}`); + } + if (failedVisit.files !== "") { + throw new Error(`run 440's visit invented Changed files with no recorded rows: ${failedVisit.files}`); + } + console.log(` run 440 visit: ${failedVisit.summary} (no recorded file rows)`); + await page.evaluate(`(() => { + const row = [...document.querySelectorAll(".stage-pane .kv-row")] + .find((n) => n.querySelector(".kv-key")?.textContent === "File changes"); + row?.scrollIntoView({ block: "center" }); + })()`); + shots.push(await page.screenshot(`${out}/80-run-440-visit-changes.png`)); + await page.click(".stage-pane-back"); + await eventually(() => page.evaluate(`!document.querySelector(".stage-pane")`), { + timeout: 5000, + what: "the run 440 visit pane to close", + }); + + // A failed run that did record file rows: run 442's implementer visit keeps + // its own Changed files even though the Summary aggregate is suppressed. + step("run 442's failed implementer visit keeps its Changed files"); + await openRunDetail(442); + await page.clickText(".detail .detail-tabs .detail-tab", "Timeline"); + await page.waitForSelector(".detail .timeline-row", { timeout: 15000 }); + await page.click('.detail .timeline-row[data-stage-key="implementer"][data-visit-index="0"]'); + await page.waitForSelector(".stage-pane", { timeout: 15000 }); + await page.clickText(".stage-pane .section-toggle", "This run"); + await page.waitForSelector(".stage-pane .codeblock", { timeout: 15000 }); + const failedFiles = await page.evaluate(`(() => { + const block = [...document.querySelectorAll(".stage-pane .codeblock")] + .find((n) => n.querySelector(".codeblock-label")?.textContent === "Changed files"); + return block?.querySelector(".codeblock-body")?.textContent ?? ""; + })()`); + if (!failedFiles.includes("web/src/")) { + throw new Error(`run 442's implementer visit lost its Changed files: ${failedFiles}`); + } + console.log(` run 442 implementer visit changed files: ${failedFiles.split("\n").length} rows`); + await page.evaluate(`(() => { + const block = [...document.querySelectorAll(".stage-pane .codeblock")] + .find((n) => n.querySelector(".codeblock-label")?.textContent === "Changed files"); + block?.scrollIntoView({ block: "center" }); + })()`); + shots.push(await page.screenshot(`${out}/81-run-442-failed-visit-changes.png`)); + await page.click(".stage-pane-back"); + await eventually(() => page.evaluate(`!document.querySelector(".stage-pane")`), { + timeout: 5000, + what: "the run 442 visit pane to close", + }); + + // A running run has no settled final state either: invert the old pending- + // header probe and assert the aggregate is absent while it executes. + step("a running run's Summary has no Changes section"); + await page.clickText("nav.tabs button.tab", "Runs"); + await page.waitForSelector(".list.runs .run-row", { timeout: 25000 }); + const runningRunId = await page.evaluate(`(() => { const row = [...document.querySelectorAll(".list.runs .run-row")] .find((n) => n.querySelector(".chip-running")); const meta = row?.querySelector(".run-row-meta[data-run-id]"); return meta ? Number(meta.getAttribute("data-run-id")) : null; })()`); - if (pendingRunId == null) { - console.log(" -- no running run available; skipped the pending Changes header"); + if (runningRunId == null) { + console.log(" -- no running run available; skipped the no-aggregate check"); } else { - await page.click(`.list.runs .run-row-meta[data-run-id="${pendingRunId}"]`); - await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 }); - const pendingToggle = await page.evaluate(`(() => { - // A running run's Changes header has one of two valid shapes: the - // empty-capture form (Changes · capture pending / partial capture / - // capture incomplete) before any step has recorded files, or the - // file-count form ({N} file(s) changed · ±stat · …) once one has. Which - // one appears depends on how far the live capture has progressed, so the - // probe accepts either rather than assuming the empty variant. - return [...document.querySelectorAll(".run-detail .collapsible .section-toggle .section-title")] - .map((n) => n.textContent ?? "") - .find((t) => /^Changes · /.test(t) || /^\\d+ files? changed/.test(t)) ?? ""; - })()`); - if (!/^Changes · /.test(pendingToggle) && !/^\d+ files? changed/.test(pendingToggle)) { - throw new Error(`a running run's Changes header is wrong: ${pendingToggle}`); + await openRunDetail(runningRunId); + const runningTitles = await page.evaluate( + `[...document.querySelectorAll(".run-detail .collapsible .section-title")].map((n) => n.textContent ?? "")`, + ); + const runningAggregate = runningTitles.find( + (title) => /^Changes · /.test(title) || /^\d+ files? changed/.test(title), + ); + if (runningAggregate) { + throw new Error(`running run ${runningRunId} shows an aggregate Changes section: ${runningAggregate}`); } - console.log(` running run ${pendingRunId} changes header: ${pendingToggle}`); - shots.push(await page.screenshot(`${out}/34-run-${pendingRunId}-changes-pending.png`)); + console.log(` running run ${runningRunId}: no Summary Changes section`); + shots.push(await page.screenshot(`${out}/82-run-${runningRunId}-no-summary-changes.png`)); } // S1/S2: omni-search over the real server. The panel is opened from the top