web: show per-visit changes and last-visit summary

Each visit's This run pane reports its own recorded capture: the File
changes status line (with skipped/omitted counts and diagnostic) and its
Changed files list with parseable stats. The Summary aggregate now keeps
each path's last recorded step rather than summing visits, and is only
rendered for a succeeded run; a failed run keeps its evidence in the
visit panes. This is a deliberate divergence from Android, noted in R4.
This commit is contained in:
2026-10-19 18:27:39 +01:00
parent 2503a38f50
commit b011f4ada4
7 changed files with 535 additions and 105 deletions
+150 -22
View File
@@ -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."));