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:
@@ -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