web: run Summary Changes section with rendered/raw diff viewer (R4)
Add a collapsed-by-default Changes section to the run Summary tab and a full-screen diff viewer, ported from the Android RunChanges/ChangeDiffViewer wording. Pure aggregation and unified-patch parsing live in src/changes.js; app.js wires the section/viewer and sets every server string with textContent. Unit tests cover the header variants, kind merge, stat sums and hunk parsing; ui-smoke captures the collapsed/expanded section, rendered and raw viewer, paging, Escape/backdrop close, binary, truncated and a running run's header.
This commit is contained in:
@@ -0,0 +1,562 @@
|
||||
// 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.
|
||||
// No server, no DOM.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
ChangeKind,
|
||||
ChangeLineKind,
|
||||
BINARY_DIFF_MESSAGE,
|
||||
NO_LINE_CHANGES_MESSAGE,
|
||||
TRUNCATED_PATCH_NOTE,
|
||||
changeEntryTags,
|
||||
changeKind,
|
||||
changeKindLabel,
|
||||
changeKindTitle,
|
||||
changePositionLabel,
|
||||
changeRowMeta,
|
||||
changeStat,
|
||||
changesListSummary,
|
||||
diffLineClass,
|
||||
diffLineSymbol,
|
||||
entryHasPatch,
|
||||
entryModeChanged,
|
||||
gutterText,
|
||||
gutterWidth,
|
||||
noChangeDetail,
|
||||
parseUnifiedPatch,
|
||||
patchUnavailableReason,
|
||||
runChanges,
|
||||
runChangesHeader,
|
||||
runChangesNote,
|
||||
} from "../src/changes.js";
|
||||
|
||||
// A step file-change with sane defaults, overridable per test.
|
||||
function file(overrides = {}) {
|
||||
return { path: "a.txt", kind: "modified", patch: "", ...overrides };
|
||||
}
|
||||
|
||||
// A run step with a file_changes capture, overridable per test.
|
||||
function step(overrides = {}) {
|
||||
return { stage: "s", status: "completed", sequence: 1, file_changes: null, ...overrides };
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Kind mapping
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("changeKind trims and lowercases, never inventing a kind", () => {
|
||||
assert.equal(changeKind("added"), ChangeKind.Added);
|
||||
assert.equal(changeKind(" Deleted "), ChangeKind.Deleted);
|
||||
assert.equal(changeKind("MODIFIED"), ChangeKind.Modified);
|
||||
assert.equal(changeKind("copied"), ChangeKind.Other);
|
||||
assert.equal(changeKind(""), ChangeKind.Other);
|
||||
assert.equal(changeKind(null), ChangeKind.Other);
|
||||
});
|
||||
|
||||
test("changeKindLabel and changeKindTitle spell the app's words", () => {
|
||||
assert.equal(changeKindLabel(ChangeKind.Added), "added");
|
||||
assert.equal(changeKindLabel(ChangeKind.Modified), "modified");
|
||||
assert.equal(changeKindLabel(ChangeKind.Deleted), "deleted");
|
||||
assert.equal(changeKindLabel(ChangeKind.Other), "changed");
|
||||
assert.equal(changeKindTitle(ChangeKind.Added), "Added");
|
||||
assert.equal(changeKindTitle(ChangeKind.Other), "Changed");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// changeStat and changesListSummary
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("changeStat omits a zero side and is blank when both are zero", () => {
|
||||
assert.equal(changeStat(3, 2), "+3 -2");
|
||||
assert.equal(changeStat(3, 0), "+3");
|
||||
assert.equal(changeStat(0, 2), "-2");
|
||||
assert.equal(changeStat(0, 0), "");
|
||||
});
|
||||
|
||||
test("changesListSummary keeps the file(s) wording and appends the stat", () => {
|
||||
const one = { files: [{}], added: 2, removed: 0 };
|
||||
assert.equal(changesListSummary(one), "1 file changed · +2");
|
||||
assert.equal(changesListSummary({ files: [{}, {}], added: 0, removed: 0 }), "2 files changed");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// parseUnifiedPatch
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("parseUnifiedPatch treats a blank patch as an empty diff", () => {
|
||||
for (const blank of ["", " ", "\n", null, undefined]) {
|
||||
assert.deepEqual(parseUnifiedPatch(blank), {
|
||||
raw: "",
|
||||
headerLines: [],
|
||||
hunks: [],
|
||||
added: 0,
|
||||
removed: 0,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("parseUnifiedPatch numbers a single hunk and counts the body", () => {
|
||||
const patch = [
|
||||
"--- a/x.txt",
|
||||
"+++ b/x.txt",
|
||||
"@@ -1,3 +1,3 @@",
|
||||
" ctx",
|
||||
"-old",
|
||||
"+new",
|
||||
" tail",
|
||||
].join("\n");
|
||||
const parsed = parseUnifiedPatch(patch);
|
||||
assert.equal(parsed.raw, patch);
|
||||
assert.deepEqual(parsed.headerLines, ["--- a/x.txt", "+++ b/x.txt"]);
|
||||
assert.equal(parsed.hunks.length, 1);
|
||||
const hunk = parsed.hunks[0];
|
||||
assert.equal(hunk.header, "@@ -1,3 +1,3 @@");
|
||||
assert.deepEqual([hunk.oldStart, hunk.oldCount, hunk.newStart, hunk.newCount], [1, 3, 1, 3]);
|
||||
assert.deepEqual(
|
||||
hunk.lines.map((line) => [line.kind, line.text, line.oldLine, line.newLine]),
|
||||
[
|
||||
[ChangeLineKind.Context, "ctx", 1, 1],
|
||||
[ChangeLineKind.Remove, "old", 2, 0],
|
||||
[ChangeLineKind.Add, "new", 0, 2],
|
||||
[ChangeLineKind.Context, "tail", 3, 3],
|
||||
],
|
||||
);
|
||||
assert.equal(parsed.added, 1);
|
||||
assert.equal(parsed.removed, 1);
|
||||
});
|
||||
|
||||
test("parseUnifiedPatch defaults a missing count to 1", () => {
|
||||
const parsed = parseUnifiedPatch("@@ -5 +7 @@\n-old\n+new");
|
||||
const hunk = parsed.hunks[0];
|
||||
assert.deepEqual([hunk.oldStart, hunk.oldCount, hunk.newStart, hunk.newCount], [5, 1, 7, 1]);
|
||||
assert.equal(parsed.added, 1);
|
||||
assert.equal(parsed.removed, 1);
|
||||
});
|
||||
|
||||
test("parseUnifiedPatch flags a `\\ No newline` marker without numbering it", () => {
|
||||
const parsed = parseUnifiedPatch(
|
||||
["@@ -1 +1 @@", "-one", "\\ No newline at end of file", "+two"].join("\n"),
|
||||
);
|
||||
const lines = parsed.hunks[0].lines;
|
||||
assert.equal(lines[1].noNewlineMarker, true);
|
||||
assert.equal(lines[1].text, "\\ No newline at end of file");
|
||||
assert.equal(lines[1].oldLine, 0);
|
||||
assert.equal(lines[1].newLine, 0);
|
||||
assert.equal(lines[1].kind, ChangeLineKind.Context);
|
||||
});
|
||||
|
||||
test("a `---`/`+++` header closes the current hunk instead of numbering into it", () => {
|
||||
const parsed = parseUnifiedPatch(
|
||||
[
|
||||
"--- a/x",
|
||||
"+++ b/x",
|
||||
"@@ -1 +1 @@",
|
||||
"-old",
|
||||
"+new",
|
||||
"--- a/y",
|
||||
"+++ b/y",
|
||||
"@@ -1 +1 @@",
|
||||
"-alt",
|
||||
"+neu",
|
||||
].join("\n"),
|
||||
);
|
||||
assert.equal(parsed.hunks.length, 2);
|
||||
assert.deepEqual(
|
||||
parsed.hunks[0].lines.map((line) => line.text),
|
||||
["old", "new"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
parsed.hunks[1].lines.map((line) => line.text),
|
||||
["alt", "neu"],
|
||||
);
|
||||
assert.equal(parsed.headerLines.filter((line) => line.startsWith("--- ")).length, 2);
|
||||
assert.equal(parsed.added, 2);
|
||||
assert.equal(parsed.removed, 2);
|
||||
});
|
||||
|
||||
test("an unrecognised tail is kept as unnumbered context and header lines before a hunk are kept", () => {
|
||||
const parsed = parseUnifiedPatch(
|
||||
["index abc..def 100644", "--- a/x", "+++ b/x", "@@ -1 +1 @@", "-old", "+new", "trailing junk"].join("\n"),
|
||||
);
|
||||
assert.equal(parsed.headerLines[0], "index abc..def 100644");
|
||||
const tail = parsed.hunks[0].lines.at(-1);
|
||||
assert.equal(tail.kind, ChangeLineKind.Context);
|
||||
assert.equal(tail.text, "trailing junk");
|
||||
assert.equal(tail.oldLine, 0);
|
||||
assert.equal(tail.newLine, 0);
|
||||
});
|
||||
|
||||
test("a trailing newline becomes a numbered empty context line", () => {
|
||||
const parsed = parseUnifiedPatch("@@ -1 +1 @@\n ctx\n");
|
||||
const lines = parsed.hunks[0].lines;
|
||||
assert.equal(lines.length, 2);
|
||||
assert.deepEqual([lines[1].text, lines[1].oldLine, lines[1].newLine], ["", 2, 2]);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Aggregation
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("a null capture that is running/waiting is pending, otherwise a missing capture", () => {
|
||||
const running = runChanges([step({ status: "running" }), step({ status: "waiting" })]);
|
||||
assert.equal(running.pending, true);
|
||||
assert.equal(running.missingCaptures, 0);
|
||||
assert.equal(running.stepsWithChanges, 0);
|
||||
|
||||
const missing = runChanges([step({ status: "completed" }), step({ status: "failed" })]);
|
||||
assert.equal(missing.pending, false);
|
||||
assert.equal(missing.missingCaptures, 2);
|
||||
});
|
||||
|
||||
test("a present capture with no files is a captured no-change", () => {
|
||||
const changes = runChanges([
|
||||
step({ stage: "a", file_changes: { status: "complete", files: [] } }),
|
||||
]);
|
||||
assert.equal(changes.stepsWithChanges, 1);
|
||||
assert.deepEqual(changes.files, []);
|
||||
assert.equal(changes.partial, false);
|
||||
assert.equal(runChangesHeader(changes), "Changes · no changes observed");
|
||||
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", () => {
|
||||
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" })] } }),
|
||||
]);
|
||||
assert.equal(changes.files.length, 1);
|
||||
assert.equal(changes.files[0].kind, ChangeKind.Added);
|
||||
assert.deepEqual(changes.files[0].steps, ["a", "b"]);
|
||||
|
||||
const downgrade = 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);
|
||||
});
|
||||
|
||||
test("stat sums, binary/truncated OR and mode first/last-seen across steps", () => {
|
||||
const changes = runChanges([
|
||||
step({
|
||||
stage: "a",
|
||||
file_changes: {
|
||||
status: "complete",
|
||||
files: [
|
||||
file({
|
||||
path: "x",
|
||||
kind: "modified",
|
||||
patch: "@@ -1 +1 @@\n-old\n+new",
|
||||
before_mode: "0644",
|
||||
after_mode: "0644",
|
||||
}),
|
||||
],
|
||||
},
|
||||
}),
|
||||
step({
|
||||
stage: "b",
|
||||
file_changes: {
|
||||
status: "complete",
|
||||
files: [
|
||||
file({
|
||||
path: "x",
|
||||
kind: "modified",
|
||||
patch: "@@ -1 +1 @@\n-gone\n+kept",
|
||||
binary: true,
|
||||
truncated: true,
|
||||
before_mode: "0755",
|
||||
after_mode: "0755",
|
||||
}),
|
||||
],
|
||||
},
|
||||
}),
|
||||
]);
|
||||
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);
|
||||
});
|
||||
|
||||
test("changed-by lists the stage names in run order, deduped", () => {
|
||||
const changes = runChanges([
|
||||
step({ stage: "implementer", file_changes: { status: "complete", files: [file({ path: "x" })] } }),
|
||||
step({ stage: "reviewer", file_changes: { status: "complete", files: [file({ path: "x" })] } }),
|
||||
step({ stage: "implementer", file_changes: { status: "complete", files: [file({ path: "x" })] } }),
|
||||
]);
|
||||
assert.deepEqual(changes.files[0].steps, ["implementer", "reviewer"]);
|
||||
assert.equal(changeRowMeta(changes.files[0]), "changed by implementer → reviewer");
|
||||
});
|
||||
|
||||
test("a blank stage name falls back to `stage` and blank paths are skipped", () => {
|
||||
const changes = runChanges([
|
||||
step({ stage: " ", file_changes: { status: "complete", files: [file({ path: "x" }), file({ path: " " })] } }),
|
||||
]);
|
||||
assert.equal(changes.files.length, 1);
|
||||
assert.deepEqual(changes.files[0].steps, ["stage"]);
|
||||
});
|
||||
|
||||
test("partial is OR'd from the capture status, a truncated file or any omitted count", () => {
|
||||
assert.equal(
|
||||
runChanges([step({ file_changes: { status: "partial", files: [] } })]).partial,
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
runChanges([step({ file_changes: { status: "complete", files: [file({ truncated: true })] } })]).partial,
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
runChanges([step({ file_changes: { status: "complete", files: [], omitted: 2 } })]).partial,
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("diagnostics from several captures are joined with a space, deduped", () => {
|
||||
const changes = runChanges([
|
||||
step({ file_changes: { status: "partial", files: [], diagnostic: "why one" } }),
|
||||
step({ file_changes: { status: "partial", files: [], diagnostic: "why one" } }),
|
||||
step({ file_changes: { status: "partial", files: [], diagnostic: "why two" } }),
|
||||
]);
|
||||
assert.equal(changes.diagnostic, "why one why two");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Header, note and detail wording
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("runChangesHeader covers every empty-capture variant", () => {
|
||||
assert.equal(
|
||||
runChangesHeader({ unavailable: true, files: [], partial: false, pending: false, stepsWithChanges: 0, missingCaptures: 0 }),
|
||||
"Changes · capture unavailable",
|
||||
);
|
||||
assert.equal(
|
||||
runChangesHeader({ unavailable: false, files: [], partial: false, pending: true, stepsWithChanges: 0, missingCaptures: 0 }),
|
||||
"Changes · capture pending",
|
||||
);
|
||||
assert.equal(
|
||||
runChangesHeader({ unavailable: false, files: [], partial: true, pending: false, stepsWithChanges: 1, missingCaptures: 0 }),
|
||||
"Changes · partial capture",
|
||||
);
|
||||
assert.equal(
|
||||
runChangesHeader({ unavailable: false, files: [], partial: false, pending: false, stepsWithChanges: 0, missingCaptures: 0 }),
|
||||
"Changes · not recorded for this run",
|
||||
);
|
||||
assert.equal(
|
||||
runChangesHeader({ unavailable: false, files: [], partial: false, pending: false, stepsWithChanges: 1, missingCaptures: 1 }),
|
||||
"Changes · capture incomplete",
|
||||
);
|
||||
assert.equal(
|
||||
runChangesHeader({ unavailable: false, files: [], partial: false, pending: false, stepsWithChanges: 2, missingCaptures: 0 }),
|
||||
"Changes · no changes observed",
|
||||
);
|
||||
});
|
||||
|
||||
test("runChangesHeader counts files, omits a zero stat side and appends the caveats", () => {
|
||||
const one = { unavailable: false, partial: false, pending: false, stepsWithChanges: 1, missingCaptures: 0, added: 4, removed: 0, files: [{}] };
|
||||
assert.equal(runChangesHeader(one), "1 file changed · +4");
|
||||
|
||||
const many = { ...one, added: 0, removed: 0, files: [{}, {}] };
|
||||
assert.equal(runChangesHeader(many), "2 files changed");
|
||||
|
||||
const partial = { ...one, partial: true, added: 4, removed: 2, files: [{}, {}] };
|
||||
assert.equal(runChangesHeader(partial), "2 files changed · +4 -2 · partial capture");
|
||||
|
||||
const incomplete = { ...one, added: 4, removed: 2, files: [{}, {}], missingCaptures: 1 };
|
||||
assert.equal(runChangesHeader(incomplete), "2 files changed · +4 -2 · capture incomplete");
|
||||
});
|
||||
|
||||
test("runChangesNote spells the partial, missing and unavailable notes", () => {
|
||||
assert.equal(
|
||||
runChangesNote({ unavailable: true, diagnostic: "" }),
|
||||
"The workspace snapshot could not be compared; the changes below may be incomplete.",
|
||||
);
|
||||
assert.equal(
|
||||
runChangesNote({ unavailable: true, diagnostic: "server says so" }),
|
||||
"server says so",
|
||||
);
|
||||
assert.equal(
|
||||
runChangesNote({
|
||||
unavailable: false,
|
||||
partial: true,
|
||||
skipped: 8,
|
||||
omitted: 0,
|
||||
diagnostic: "Excluded protected files.",
|
||||
files: [],
|
||||
missingCaptures: 1,
|
||||
}),
|
||||
"Partial capture: some changes may be missing. (8 files skipped) Excluded protected files. " +
|
||||
"Missing capture: 1 stage did not record changes.",
|
||||
);
|
||||
assert.equal(
|
||||
runChangesNote({
|
||||
unavailable: false,
|
||||
partial: true,
|
||||
skipped: 0,
|
||||
omitted: 3,
|
||||
diagnostic: "",
|
||||
files: [{ truncated: true }, { truncated: true }],
|
||||
missingCaptures: 2,
|
||||
}),
|
||||
"Partial capture: some changes may be missing. (3 omitted, 2 truncated) " +
|
||||
"Missing capture: 2 stages did not record changes.",
|
||||
);
|
||||
assert.equal(runChangesNote({ unavailable: false, partial: false, missingCaptures: 0 }), "");
|
||||
assert.equal(
|
||||
runChangesNote({ unavailable: false, partial: false, missingCaptures: 1 }),
|
||||
"Missing capture: 1 stage did not record changes.",
|
||||
);
|
||||
});
|
||||
|
||||
test("noChangeDetail distinguishes pending, unavailable, not-recorded and unchanged", () => {
|
||||
assert.equal(
|
||||
noChangeDetail({ pending: true }),
|
||||
"The capture runs after the stage finishes; nothing is recorded yet.",
|
||||
);
|
||||
assert.equal(
|
||||
noChangeDetail({ pending: false, unavailable: true }),
|
||||
"The workspace snapshot could not be compared, so no changes can be shown.",
|
||||
);
|
||||
assert.equal(
|
||||
noChangeDetail({ pending: false, unavailable: false, stepsWithChanges: 0 }),
|
||||
"This run recorded no change capture (a historical step, or a stage that does not capture).",
|
||||
);
|
||||
assert.equal(
|
||||
noChangeDetail({ pending: false, unavailable: false, stepsWithChanges: 2 }),
|
||||
"The captured snapshots were identical: the workspace was unchanged.",
|
||||
);
|
||||
});
|
||||
|
||||
test("changeEntryTags and changeRowMeta spell the tags and mode exactly", () => {
|
||||
const binary = { binary: true, truncated: false, otherModeChange: true, beforeMode: "0644", afterMode: "0755", steps: ["a"] };
|
||||
assert.deepEqual(changeEntryTags(binary), ["binary"]);
|
||||
assert.equal(changeRowMeta(binary), "changed by a · binary");
|
||||
|
||||
const truncated = { binary: false, truncated: true, otherModeChange: false, steps: ["a", "b"] };
|
||||
assert.deepEqual(changeEntryTags(truncated), ["truncated"]);
|
||||
assert.equal(changeRowMeta(truncated), "changed by a → b · truncated");
|
||||
|
||||
const modeOnly = { binary: false, truncated: false, otherModeChange: true, beforeMode: "0644", afterMode: "0755", steps: ["a"] };
|
||||
assert.deepEqual(changeEntryTags(modeOnly), ["mode change"]);
|
||||
assert.equal(changeRowMeta(modeOnly), "changed by a · mode change · mode 0644→0755");
|
||||
});
|
||||
|
||||
test("patchUnavailableReason names the truncation, the mode-only change, else the bare record", () => {
|
||||
assert.equal(
|
||||
patchUnavailableReason({ truncated: true }),
|
||||
"The server truncated this file's patch at its capture limit; no diff text was recorded.",
|
||||
);
|
||||
assert.equal(
|
||||
patchUnavailableReason({ truncated: false, otherModeChange: true, beforeMode: "0644", afterMode: "0755" }),
|
||||
"Only the file's mode changed (0644→0755); the server recorded no text diff.",
|
||||
);
|
||||
assert.equal(
|
||||
patchUnavailableReason({ truncated: false, otherModeChange: false }),
|
||||
"The server recorded this change without a patch.",
|
||||
);
|
||||
});
|
||||
|
||||
test("the viewer's honest messages are the app's exact wording", () => {
|
||||
assert.equal(
|
||||
BINARY_DIFF_MESSAGE,
|
||||
"This is a binary file: the server recorded the change but has no textual diff to show.",
|
||||
);
|
||||
assert.equal(
|
||||
TRUNCATED_PATCH_NOTE,
|
||||
"The server truncated this patch at its capture limit; the raw text is the whole record.",
|
||||
);
|
||||
assert.equal(NO_LINE_CHANGES_MESSAGE, "no line changes recorded");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Viewer helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("changePositionLabel and gutterWidth line up", () => {
|
||||
assert.equal(changePositionLabel(0, 3), "1 of 3");
|
||||
assert.equal(changePositionLabel(2, 3), "3 of 3");
|
||||
assert.equal(gutterWidth({ lines: [] }), 1);
|
||||
assert.equal(gutterWidth({ lines: [{ oldLine: 9, newLine: 0 }, { oldLine: 0, newLine: 12 }] }), 2);
|
||||
assert.equal(gutterText(0, 2), " ");
|
||||
assert.equal(gutterText(7, 2), " 7");
|
||||
});
|
||||
|
||||
test("diffLineSymbol and diffLineClass are the app's one diff language", () => {
|
||||
assert.equal(diffLineSymbol(ChangeLineKind.Add), "+");
|
||||
assert.equal(diffLineSymbol(ChangeLineKind.Remove), "-");
|
||||
assert.equal(diffLineSymbol(ChangeLineKind.Context), " ");
|
||||
assert.equal(diffLineClass(ChangeLineKind.Add), "diff-add");
|
||||
assert.equal(diffLineClass(ChangeLineKind.Remove), "diff-remove");
|
||||
assert.equal(diffLineClass(ChangeLineKind.Context), "diff-context");
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// A full aggregate matches the section it renders
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test("runChanges derives run 438's shape: 22 files, partial, one missing capture", () => {
|
||||
// Six steps, 23 recorded file rows for 22 unique paths, one step without a
|
||||
// capture, every capture partial with a diagnostic.
|
||||
const diag = "Excluded protected, symlinked, oversized or unreadable files; this is not a complete workspace diff.";
|
||||
const patch = "@@ -1 +1 @@\n-old\n+new";
|
||||
const steps = [
|
||||
step({
|
||||
stage: "implementer",
|
||||
file_changes: {
|
||||
status: "partial",
|
||||
skipped: 2,
|
||||
diagnostic: diag,
|
||||
files: [
|
||||
file({ path: "docs/notes.md", kind: "added", patch }),
|
||||
file({ path: "internal/server/retry_test.go", kind: "modified", patch }),
|
||||
file({ path: "internal/server/runner.go", kind: "modified", patch }),
|
||||
],
|
||||
},
|
||||
}),
|
||||
step({ stage: "reviewer", file_changes: { status: "partial", skipped: 2, diagnostic: diag, files: [] } }),
|
||||
step({
|
||||
stage: "implementer",
|
||||
file_changes: {
|
||||
status: "partial",
|
||||
skipped: 2,
|
||||
diagnostic: diag,
|
||||
files: [file({ path: "internal/server/retry_test.go", kind: "modified", patch })],
|
||||
},
|
||||
}),
|
||||
step({ stage: "reviewer", file_changes: { status: "partial", skipped: 2, diagnostic: diag, files: [] } }),
|
||||
step({ stage: "ui_reviewer" }),
|
||||
step({
|
||||
stage: "committer",
|
||||
file_changes: {
|
||||
status: "partial",
|
||||
skipped: 2,
|
||||
diagnostic: diag,
|
||||
files: Array.from({ length: 19 }, (_, i) => file({ path: `android/file${i}.kt`, kind: "modified", patch })),
|
||||
},
|
||||
}),
|
||||
];
|
||||
const changes = runChanges(steps);
|
||||
assert.equal(changes.files.length, 22);
|
||||
assert.equal(changes.stepsWithChanges, 5);
|
||||
assert.equal(changes.missingCaptures, 1);
|
||||
assert.equal(changes.partial, true);
|
||||
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);
|
||||
assert.equal(
|
||||
runChangesHeader(changes),
|
||||
`22 files changed · +23 -23 · 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."));
|
||||
});
|
||||
@@ -808,6 +808,277 @@ try {
|
||||
shots.push(await page.screenshot(`${out}/27-run-output-empty.png`));
|
||||
}
|
||||
|
||||
// R4: the run Summary's collapsible Changes section and its rendered/raw diff
|
||||
// viewer. Run 438 changed 22 unique files across 6 steps with every capture
|
||||
// partial, so the header/row count are asserted against each other rather than
|
||||
// against a hardcoded total.
|
||||
const changesToggle = () =>
|
||||
page.evaluate(`(() => {
|
||||
const t = [...document.querySelectorAll(".run-detail .collapsible .section-toggle")]
|
||||
.find((n) => /\\d+ files? changed/.test(n.querySelector(".section-title")?.textContent ?? ""));
|
||||
if (!t) return null;
|
||||
return {
|
||||
title: t.querySelector(".section-title")?.textContent ?? "",
|
||||
expanded: t.getAttribute("aria-expanded"),
|
||||
rows: t.parentElement?.querySelectorAll(".change-row").length ?? 0,
|
||||
};
|
||||
})()`);
|
||||
const expandChanges = async () => {
|
||||
const marked = await page.evaluate(`(() => {
|
||||
const t = [...document.querySelectorAll(".run-detail .collapsible .section-toggle")]
|
||||
.find((n) => /\\d+ files? changed/.test(n.querySelector(".section-title")?.textContent ?? ""));
|
||||
if (!t) return false;
|
||||
t.scrollIntoView({ block: "center" });
|
||||
t.setAttribute("data-test-changes-toggle", "1");
|
||||
return true;
|
||||
})()`);
|
||||
if (!marked) throw new Error("no Changes section toggle rendered");
|
||||
await page.click("[data-test-changes-toggle='1']");
|
||||
await page.evaluate(
|
||||
`document.querySelector("[data-test-changes-toggle='1']")?.removeAttribute("data-test-changes-toggle")`,
|
||||
);
|
||||
await page.waitForSelector(".run-detail .changes-list .change-row", { timeout: 15000 });
|
||||
};
|
||||
const closeChangeViewer = async (how) => {
|
||||
if (how === "escape") {
|
||||
await page.evaluate(
|
||||
`document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }))`,
|
||||
);
|
||||
} else if (how === "backdrop") {
|
||||
await page.evaluate(`document.querySelector(".change-viewer").click()`);
|
||||
} else {
|
||||
await page.click(".change-viewer-close");
|
||||
}
|
||||
await eventually(() => page.evaluate(`!document.querySelector(".change-viewer")`), {
|
||||
timeout: 5000,
|
||||
what: `the diff viewer to close (${how})`,
|
||||
});
|
||||
};
|
||||
|
||||
step("opening run 438: the collapsed Changes section (R4)");
|
||||
await page.click('.list.runs .run-row-meta[data-run-id="438"]');
|
||||
await page.waitForText("run 438 ·", { timeout: 25000 });
|
||||
await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 });
|
||||
const collapsed = await changesToggle();
|
||||
if (!collapsed) throw new Error("run 438's Summary rendered no Changes section");
|
||||
if (collapsed.expanded !== "false") {
|
||||
throw new Error(`the Changes section is not collapsed on first render: ${collapsed.expanded}`);
|
||||
}
|
||||
if (collapsed.rows !== 0) throw new Error(`a collapsed Changes section drew ${collapsed.rows} row(s)`);
|
||||
const changesCount = Number((/^(\d+) files? changed/.exec(collapsed.title) ?? [])[1] ?? 0);
|
||||
if (!changesCount) throw new Error(`the Changes header has no file count: ${collapsed.title}`);
|
||||
if (!collapsed.title.includes("partial capture")) {
|
||||
throw new Error(`run 438's Changes header should note the partial capture: ${collapsed.title}`);
|
||||
}
|
||||
console.log(` collapsed changes header: ${collapsed.title}`);
|
||||
shots.push(await page.screenshot(`${out}/28-run-438-changes-collapsed.png`));
|
||||
|
||||
step("expanding the Changes section: the observed-file rows");
|
||||
await expandChanges();
|
||||
const expanded = await page.evaluate(`(() => ({
|
||||
summary: document.querySelector(".run-detail .changes-summary")?.textContent ?? "",
|
||||
note: document.querySelector(".run-detail .changes-note")?.textContent ?? "",
|
||||
rows: document.querySelectorAll(".run-detail .changes-list .change-row").length,
|
||||
kinds: [...document.querySelectorAll(".run-detail .changes-list .change-kind")].map((n) => n.textContent),
|
||||
expanded: [...document.querySelectorAll(".run-detail .collapsible .section-toggle")]
|
||||
.find((n) => /\\d+ files? changed/.test(n.querySelector(".section-title")?.textContent ?? ""))
|
||||
?.getAttribute("aria-expanded"),
|
||||
}))()`);
|
||||
if (expanded.expanded !== "true") throw new Error("the Changes section did not expand");
|
||||
if (expanded.rows !== changesCount) {
|
||||
throw new Error(`the Changes section drew ${expanded.rows} rows for a header count of ${changesCount}`);
|
||||
}
|
||||
if (!expanded.note.startsWith("Partial capture: some changes may be missing.")) {
|
||||
throw new Error(`the partial-capture note is missing: ${expanded.note}`);
|
||||
}
|
||||
console.log(` expanded: ${expanded.summary} — ${expanded.rows} row(s)`);
|
||||
console.log(` note: ${expanded.note}`);
|
||||
console.log(` kinds: ${[...new Set(expanded.kinds)].join(", ")}`);
|
||||
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`));
|
||||
|
||||
step("opening the rendered diff viewer on the first changed file");
|
||||
await page.click(".run-detail .changes-list .change-row");
|
||||
await page.waitForSelector(".change-viewer", { timeout: 15000 });
|
||||
const rendered = await page.evaluate(`(() => ({
|
||||
kind: document.querySelector(".change-viewer .change-kind")?.textContent ?? "",
|
||||
path: document.querySelector(".change-viewer-path")?.textContent ?? "",
|
||||
position: document.querySelector(".change-viewer-position")?.textContent ?? "",
|
||||
renderedActive: document.querySelector('.change-form[data-form="rendered"]')?.classList.contains("active") ?? false,
|
||||
renderedDisabled: document.querySelector('.change-form[data-form="rendered"]')?.disabled ?? null,
|
||||
rawDisabled: document.querySelector('.change-form[data-form="raw"]')?.disabled ?? null,
|
||||
hunks: document.querySelectorAll(".change-viewer .change-hunk").length,
|
||||
lines: document.querySelectorAll(".change-viewer .change-line").length,
|
||||
gutter: document.querySelector(".change-viewer .change-gutter")?.textContent ?? "",
|
||||
adds: document.querySelectorAll(".change-viewer .change-text.diff-add").length,
|
||||
removes: document.querySelectorAll(".change-viewer .change-text.diff-remove").length,
|
||||
prevDisabled: document.querySelector('.change-page[data-page="prev"]')?.disabled ?? null,
|
||||
}))()`);
|
||||
if (!rendered.renderedActive || rendered.renderedDisabled !== true) {
|
||||
throw new Error(`Rendered is not the default selected form: ${JSON.stringify(rendered)}`);
|
||||
}
|
||||
if (!rendered.path || !rendered.position.includes("of ")) {
|
||||
throw new Error(`the viewer did not identify its file: ${JSON.stringify(rendered)}`);
|
||||
}
|
||||
if (!rendered.hunks || !rendered.lines) {
|
||||
throw new Error(`the rendered viewer drew no hunks/lines: ${JSON.stringify(rendered)}`);
|
||||
}
|
||||
if (rendered.gutter.trim() === "") throw new Error("the rendered viewer drew no gutter numbers");
|
||||
if (rendered.prevDisabled !== true) throw new Error("Previous should be disabled on the first file");
|
||||
console.log(
|
||||
` rendered: ${rendered.kind} ${rendered.path} — ${rendered.position}; ` +
|
||||
`${rendered.hunks} hunk(s), ${rendered.lines} line(s), ${rendered.adds}+/${rendered.removes}-`,
|
||||
);
|
||||
shots.push(await page.screenshot(`${out}/30-run-438-changes-diff-rendered.png`));
|
||||
|
||||
step("switching the diff viewer to the Raw patch");
|
||||
await page.evaluate(`document.querySelector('.change-form[data-form="raw"]').click()`);
|
||||
await page.waitForSelector(".change-viewer .change-raw", { timeout: 15000 });
|
||||
const raw = await page.evaluate(`(() => ({
|
||||
rawActive: document.querySelector('.change-form[data-form="raw"]')?.classList.contains("active") ?? false,
|
||||
renderedDisabled: document.querySelector('.change-form[data-form="rendered"]')?.disabled ?? null,
|
||||
text: document.querySelector(".change-viewer .change-raw")?.textContent ?? "",
|
||||
}))()`);
|
||||
if (!raw.rawActive) throw new Error("Raw patch did not become the selected form");
|
||||
if (!raw.text.includes("@@")) {
|
||||
throw new Error(`the raw patch does not look like a unified diff: ${raw.text.slice(0, 80)}`);
|
||||
}
|
||||
console.log(` raw patch: ${raw.text.split("\n")[0]} (${raw.text.length} chars)`);
|
||||
shots.push(await page.screenshot(`${out}/31-run-438-changes-diff-raw.png`));
|
||||
|
||||
step("paging between files: Next to the last, then Previous");
|
||||
await page.evaluate(`document.querySelector('.change-page[data-page="next"]').click()`);
|
||||
await eventually(
|
||||
async () => (await page.evaluate(`document.querySelector(".change-viewer-position")?.textContent ?? ""`)).startsWith("2 of "),
|
||||
{ what: "the viewer to page to file 2" },
|
||||
);
|
||||
await page.evaluate(`(() => {
|
||||
for (let i = 0; i < 500; i += 1) {
|
||||
const next = document.querySelector('.change-page[data-page="next"]');
|
||||
if (!next || next.disabled) break;
|
||||
next.click();
|
||||
}
|
||||
})()`);
|
||||
const last = await page.evaluate(`(() => ({
|
||||
position: document.querySelector(".change-viewer-position")?.textContent ?? "",
|
||||
nextDisabled: document.querySelector('.change-page[data-page="next"]')?.disabled ?? null,
|
||||
prevDisabled: document.querySelector('.change-page[data-page="prev"]')?.disabled ?? null,
|
||||
}))()`);
|
||||
if (last.nextDisabled !== true) throw new Error("Next is not disabled on the last file");
|
||||
if (!last.position.startsWith(`${changesCount} of `)) {
|
||||
throw new Error(`the viewer did not reach the last file: ${last.position}`);
|
||||
}
|
||||
console.log(` paged to the last file: ${last.position}`);
|
||||
await page.evaluate(`document.querySelector('.change-page[data-page="prev"]').click()`);
|
||||
await eventually(
|
||||
async () => (await page.evaluate(`document.querySelector(".change-viewer-position")?.textContent ?? ""`)).startsWith(`${changesCount - 1} of `),
|
||||
{ what: "the viewer to page back" },
|
||||
);
|
||||
|
||||
step("closing the diff viewer with Escape returns focus to the row");
|
||||
await closeChangeViewer("escape");
|
||||
const restoredFocus = await page.evaluate(
|
||||
`document.activeElement?.getAttribute?.("data-change-index") ?? ""`,
|
||||
);
|
||||
// The viewer was paged back one file just before closing, so focus returns to
|
||||
// that row (index changesCount - 2).
|
||||
if (restoredFocus !== String(changesCount - 2)) {
|
||||
throw new Error(`focus did not return to the opened row: ${restoredFocus}`);
|
||||
}
|
||||
console.log(` focus returned to change row ${restoredFocus}`);
|
||||
|
||||
step("reopening and closing the diff viewer by a backdrop click");
|
||||
await page.click(".run-detail .changes-list .change-row");
|
||||
await page.waitForSelector(".change-viewer", { timeout: 15000 });
|
||||
await closeChangeViewer("backdrop");
|
||||
|
||||
// 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 });
|
||||
await expandChanges();
|
||||
await page.click(".run-detail .changes-list .change-row");
|
||||
await page.waitForSelector(".change-viewer .change-honest", { timeout: 15000 });
|
||||
const binary = await page.evaluate(`(() => ({
|
||||
message: document.querySelector(".change-viewer .change-honest")?.textContent ?? "",
|
||||
rawDisabled: document.querySelector('.change-form[data-form="raw"]')?.disabled ?? null,
|
||||
hunks: document.querySelectorAll(".change-viewer .change-hunk").length,
|
||||
}))()`);
|
||||
if (
|
||||
binary.message !==
|
||||
"This is a binary file: the server recorded the change but has no textual diff to show."
|
||||
) {
|
||||
throw new Error(`the binary message is wrong: ${binary.message}`);
|
||||
}
|
||||
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`));
|
||||
await closeChangeViewer("close");
|
||||
|
||||
// A truncated capture: the truncation reason, still no fabricated diff.
|
||||
step("opening a truncated capture (run 450): the truncation reason");
|
||||
await page.click('.list.runs .run-row-meta[data-run-id="450"]');
|
||||
await page.waitForText("run 450 ·", { timeout: 25000 });
|
||||
await page.waitForSelector(".detail .detail-tabs", { timeout: 25000 });
|
||||
await expandChanges();
|
||||
const openedTruncated = await page.evaluate(`(() => {
|
||||
const row = [...document.querySelectorAll(".run-detail .changes-list .change-row")]
|
||||
.find((n) => (n.querySelector(".change-meta")?.textContent ?? "").includes("truncated"));
|
||||
if (!row) return false;
|
||||
row.click();
|
||||
return true;
|
||||
})()`);
|
||||
if (!openedTruncated) throw new Error("run 450's Changes list showed no truncated row");
|
||||
await page.waitForSelector(".change-viewer .change-honest", { timeout: 15000 });
|
||||
const truncated = await page.evaluate(
|
||||
`document.querySelector(".change-viewer .change-honest")?.textContent ?? ""`,
|
||||
);
|
||||
if (
|
||||
truncated !==
|
||||
"The server truncated this file's patch at its capture limit; no diff text was recorded."
|
||||
) {
|
||||
throw new Error(`the truncation reason is wrong: ${truncated}`);
|
||||
}
|
||||
console.log(` truncated: ${truncated}`);
|
||||
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(`(() => {
|
||||
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");
|
||||
} 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}`);
|
||||
}
|
||||
console.log(` running run ${pendingRunId} changes header: ${pendingToggle}`);
|
||||
shots.push(await page.screenshot(`${out}/34-run-${pendingRunId}-changes-pending.png`));
|
||||
}
|
||||
|
||||
console.log("\nUI SMOKE PASS");
|
||||
for (const shot of shots) console.log(` ${shot}`);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user