Add the Changes tab at sign-off: snapshot at start, diff at the end, drawn in the console

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-14 22:02:58 -08:00
1 parent 72ae44745f
commit f61ef6e0a7
25 files changed
+1324 -21

No files matched your search

+4 -4
View File
@@ -30,19 +30,19 @@ export const BUDGETS = {
notes: {
"changelog.md": 1400,
"dead-code.md": 4900,
"deps.md": 9000, // raised by the pin, newer-Node, baseline and full-suite lines, then the fix card and the install card (8765 bytes)
"deps.md": 9000, // raised by the pin, newer-Node, baseline and full-suite lines, then the fix card and the install card (8823 bytes)
"diagnose.md": 2840, // raised by the lessons card line's bytes only
"document.md": 400,
"finalize.md": 2000,
"git.md": 6500,
"handoff.md": 300,
"implement.md": 5700,
"implement.md": 6416, // raised by the Changes tab's lines only
"init.md": 300,
"loop.md": 11712, // raised by the failed report's nextStep line's bytes only
"loop.md": 11857, // raised by the failed report's nextStep line's and the Changes tab line's bytes only
"pathfinder.md": 2622, // raised by the UI prototype line's bytes only
"plan.md": 1023, // raised by the UI prototype line's bytes only
"pr-prep.md": 4500,
"quick-task.md": 4869, // raised by the UI prototype line's, the prototype recap line's, the prototype archive wording's and the lessons card line's bytes only
"quick-task.md": 5194, // raised by the UI prototype line's, the prototype recap line's, the prototype archive wording's, the lessons card line's and the Changes tab lines' bytes only
"review.md": 1140, // raised by the lessons card line's bytes only
"revise-plan.md": 1422, // raised by the UI prototype line's bytes only
"test.md": 5540, // raised by the lessons card line's bytes only
+2
View File
@@ -37,6 +37,7 @@
"test-us-english.mjs",
"test-web-console-agents-doc.mjs",
"test-web-console-card-rows.mjs",
"test-web-console-diff-parse.mjs",
"test-web-console-git-board.mjs",
"test-web-console-prototypes.mjs",
"test-web-console-send-state.mjs",
@@ -112,6 +113,7 @@
"test-web-console-page-activities.mjs",
"test-web-console-page-ask.mjs",
"test-web-console-page-cards.mjs",
"test-web-console-page-changes.mjs",
"test-web-console-page-dashboard.mjs",
"test-web-console-page-git.mjs",
"test-web-console-page-help.mjs",
+1
View File
@@ -148,6 +148,7 @@ test("changes: a sensitive file shows its name and counts but no lines", () => {
assert.match(diff, /^diff --git a\/\.env b\/\.env$/m);
assert.match(diff, /^Lines hidden: this file may hold a secret\.$/m);
assert.match(diff, /^# hidden: \.env$/m);
assert.match(diff, /^# counts: 2\t0\t\.env$/m, "a hidden file's counts travel in the trailer");
assert.match(diff, /^\+fine$/m, "other files keep their lines");
});
+301
View File
@@ -0,0 +1,301 @@
// Web console tests, the Changes tab's parser: public/diff-parse.js reads the
// unified diff changes.mjs writes into files, hunks and numbered lines, and
// never throws on text it cannot read. Run with:
// node --test scripts/test-web-console-diff-parse.mjs
import test from "node:test";
import assert from "node:assert/strict";
import { parseDiff, HIDDEN_LINE, TOO_LARGE_LINE } from "../src/web-console/public/diff-parse.js";
const one = (text) => {
const r = parseDiff(text);
assert.equal(r.bad, undefined, "read as a diff");
assert.equal(r.files.length, 1);
return r.files[0];
};
const shape = (lines) => lines.map((l) => [l.kind, l.oldNo, l.newNo, l.text]);
test("a modified file with two hunks numbers every line from its hunk header", () => {
const f = one(
[
"diff --git a/src/app.js b/src/app.js",
"index 1111111..2222222 100644",
"--- a/src/app.js",
"+++ b/src/app.js",
"@@ -3,3 +3,4 @@ function start() {",
" one",
"-two",
"+TWO",
"+two and a half",
" three",
"@@ -20,2 +21,1 @@",
"-gone",
" kept",
"",
].join("\n")
);
assert.equal(f.path, "src/app.js");
assert.equal(f.oldPath, null, "only a rename names an old path");
assert.equal(f.status, "modified");
assert.equal(f.added, 2);
assert.equal(f.removed, 2);
assert.equal(f.hunks.length, 2);
assert.equal(f.hunks[0].header, "@@ -3,3 +3,4 @@ function start() {");
assert.deepEqual(shape(f.hunks[0].lines), [
["ctx", 3, 3, "one"],
["del", 4, null, "two"],
["add", null, 4, "TWO"],
["add", null, 5, "two and a half"],
["ctx", 5, 6, "three"],
]);
assert.deepEqual(shape(f.hunks[1].lines), [
["del", 20, null, "gone"],
["ctx", 21, 21, "kept"],
]);
});
test("an added file and a deleted file", () => {
const r = parseDiff(
[
"diff --git a/new.txt b/new.txt",
"new file mode 100644",
"index 0000000..3333333",
"--- /dev/null",
"+++ b/new.txt",
"@@ -0,0 +1,2 @@",
"+hello",
"+world",
"diff --git a/old.txt b/old.txt",
"deleted file mode 100644",
"index 4444444..0000000",
"--- a/old.txt",
"+++ /dev/null",
"@@ -1 +0,0 @@",
"-bye",
"",
].join("\n")
);
assert.equal(r.files.length, 2);
const [added, deleted] = r.files;
assert.equal(added.status, "added");
assert.equal(added.path, "new.txt");
assert.deepEqual([added.added, added.removed], [2, 0]);
assert.deepEqual(shape(added.hunks[0].lines), [
["add", null, 1, "hello"],
["add", null, 2, "world"],
]);
assert.equal(deleted.status, "deleted");
assert.equal(deleted.path, "old.txt", "a deleted file keeps its own name");
assert.deepEqual([deleted.added, deleted.removed], [0, 1]);
assert.deepEqual(shape(deleted.hunks[0].lines), [["del", 1, null, "bye"]]);
});
test("a pure rename and a rename with edits", () => {
const r = parseDiff(
[
"diff --git a/a/old name.md b/b/new name.md",
"similarity index 100%",
"rename from a/old name.md",
"rename to b/new name.md",
"diff --git a/lib/x.js b/lib/y.js",
"similarity index 80%",
"rename from lib/x.js",
"rename to lib/y.js",
"index 5555555..6666666 100644",
"--- a/lib/x.js",
"+++ b/lib/y.js",
"@@ -1,2 +1,2 @@",
"-const x = 1;",
"+const y = 1;",
" export {};",
"",
].join("\n")
);
assert.equal(r.files.length, 2);
const [pure, edited] = r.files;
assert.equal(pure.status, "renamed");
assert.equal(pure.oldPath, "a/old name.md");
assert.equal(pure.path, "b/new name.md");
assert.equal(pure.hunks.length, 0);
assert.deepEqual([pure.added, pure.removed], [0, 0]);
assert.equal(edited.status, "renamed");
assert.equal(edited.oldPath, "lib/x.js");
assert.equal(edited.path, "lib/y.js");
assert.deepEqual([edited.added, edited.removed], [1, 1]);
});
test("a binary file and a hidden file show no lines", () => {
const r = parseDiff(
[
"diff --git a/logo.png b/logo.png",
"index 7777777..8888888 100644",
"Binary files a/logo.png and b/logo.png differ",
"diff --git a/.env b/.env",
"index 9999999..aaaaaaa 100644",
HIDDEN_LINE,
"# hidden: .env",
"",
].join("\n")
);
assert.equal(r.files.length, 2);
const [bin, secret] = r.files;
assert.equal(bin.binary, true);
assert.equal(bin.hunks.length, 0);
assert.equal(secret.path, ".env");
assert.equal(secret.hidden, true);
assert.equal(secret.hunks.length, 0);
assert.equal(secret.truncated, false);
});
test("a hidden file takes its counts from the trailer", () => {
const r = parseDiff(
["diff --git a/.env b/.env", "new file mode 100644", HIDDEN_LINE, "# hidden: .env", "# counts: 40\t3\t.env", ""].join("\n")
);
assert.equal(r.files.length, 1);
assert.equal(r.files[0].added, 40);
assert.equal(r.files[0].removed, 3);
});
test("a truncated set: the files after the too-large line hold only a header", () => {
const r = parseDiff(
[
"diff --git a/kept.txt b/kept.txt",
"--- a/kept.txt",
"+++ b/kept.txt",
"@@ -1 +1 @@",
"-a",
"+b",
TOO_LARGE_LINE,
"diff --git a/big.txt b/big.txt",
"diff --git a/moved.txt b/there.txt",
"rename from moved.txt",
"rename to there.txt",
"# truncated: true",
"",
].join("\n")
);
assert.equal(r.tooLarge, true);
assert.equal(r.files.length, 3);
assert.equal(r.files[0].truncated, false);
assert.deepEqual(shape(r.files[0].hunks[0].lines), [
["del", 1, null, "a"],
["add", null, 1, "b"],
]);
assert.equal(r.files[1].truncated, true);
assert.equal(r.files[1].path, "big.txt");
assert.equal(r.files[2].truncated, true);
assert.equal(r.files[2].status, "renamed");
assert.equal(r.files[2].path, "there.txt");
});
test("a change set too big to print: every name first, the too-large line last, each file listed only", () => {
const r = parseDiff(
[
"diff --git a/a.txt b/a.txt",
"diff --git a/old.txt b/new.txt",
"rename from old.txt",
"rename to new.txt",
"diff --git a/.env b/.env",
HIDDEN_LINE,
TOO_LARGE_LINE,
"# truncated: true",
"# hidden: .env",
"",
].join("\n")
);
assert.equal(r.tooLarge, true);
assert.deepEqual(
r.files.map((f) => [f.path, f.truncated, f.hidden]),
[
["a.txt", true, false],
["new.txt", true, false],
[".env", false, true],
]
);
assert.equal("afterCut" in r.files[0], false, "no working field leaks out");
});
test("a line starting +++ or --- inside a hunk stays a changed line", () => {
const f = one(
[
"diff --git a/notes.md b/notes.md",
"--- a/notes.md",
"+++ b/notes.md",
"@@ -1,2 +1,2 @@",
"--- a rule",
"+++ a plus rule",
" same",
"",
].join("\n")
);
assert.equal(f.path, "notes.md");
assert.deepEqual(shape(f.hunks[0].lines), [
["del", 1, null, "-- a rule"],
["add", null, 1, "++ a plus rule"],
["ctx", 2, 2, "same"],
]);
});
test("a file with no newline at its end keeps the marker as a meta line", () => {
const f = one(
[
"diff --git a/end.txt b/end.txt",
"--- a/end.txt",
"+++ b/end.txt",
"@@ -1 +1 @@",
"-old",
"\\ No newline at end of file",
"+new",
"\\ No newline at end of file",
"",
].join("\n")
);
assert.deepEqual(shape(f.hunks[0].lines), [
["del", 1, null, "old"],
["meta", null, null, "\\ No newline at end of file"],
["add", null, 1, "new"],
["meta", null, null, "\\ No newline at end of file"],
]);
assert.deepEqual([f.added, f.removed], [1, 1], "the marker is not counted");
});
test("paths with spaces and quoted paths", () => {
const r = parseDiff(
[
"diff --git a/with space.txt b/with space.txt",
"--- a/with space.txt\t",
"+++ b/with space.txt\t",
"@@ -1 +1,2 @@",
" a",
"+b",
'diff --git "a/say \\"hi\\".txt" "b/say \\"hi\\".txt"',
'--- "a/say \\"hi\\".txt"',
'+++ "b/say \\"hi\\".txt"',
"@@ -1 +1 @@",
"-x",
"+y",
'diff --git "a/caf\\303\\251 tab\\t.txt" "b/caf\\303\\251 tab\\t.txt"',
"new file mode 100644",
"",
].join("\n")
);
assert.deepEqual(
r.files.map((f) => f.path),
["with space.txt", 'say "hi".txt', "café tab\t.txt"]
);
assert.equal(r.files[0].added, 1);
});
test("an empty string is no files, and garbage never throws", () => {
assert.deepEqual(parseDiff(""), { files: [], tooLarge: false });
for (const junk of ["hello there\nthis is not a diff\n", "@@ -1 +1 @@\n+x\n", "diff --git nonsense", "\u0000\u0001", " \n"]) {
const r = parseDiff(junk);
assert.deepEqual(r.files, [], junk);
assert.equal(r.tooLarge, false);
}
assert.equal(parseDiff("hello there\nthis is not a diff\n").bad, true);
assert.equal(parseDiff("diff --git nonsense").bad, true);
assert.equal(parseDiff(" \n").bad, undefined, "blank text is an empty diff");
assert.equal(parseDiff(undefined).bad, true);
assert.equal(parseDiff(null).bad, true);
});
+265
View File
@@ -0,0 +1,265 @@
// Page tests for the Changes tab: a `diff` doc block (a .diff file saved in the
// session folder, changes.mjs diff) drawn as a file list and one unified diff,
// with its empty, error and loading states. Run with:
// node --test scripts/test-web-console-page-changes.mjs
//
// Each test drives the real console in a real Chrome or Edge through
// scripts/page-test-helpers.mjs: one browser for the file, a fresh console
// session per test.
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { pageSuite, openSession, itemCard, textOf, styleOf, scrollCard } from "./page-test-helpers.mjs";
const suite = pageSuite(test);
// Five files: a modified one with two hunks, an added one, a binary one, a
// hidden one, then a file cut by the size cap.
const DIFF = [
"diff --git a/src/app.js b/src/app.js",
"index 1111111..2222222 100644",
"--- a/src/app.js",
"+++ b/src/app.js",
"@@ -3,3 +3,4 @@ function start() {",
" one",
"-two",
"+TWO",
"+two and a half",
" three",
"@@ -20,2 +21,2 @@",
"-gone",
"+<b>not html</b>",
" kept",
"diff --git a/docs/new.md b/docs/new.md",
"new file mode 100644",
"--- /dev/null",
"+++ b/docs/new.md",
"@@ -0,0 +1,2 @@",
"+# New",
"+Hello.",
"diff --git a/logo.png b/logo.png",
"index 7777777..8888888 100644",
"Binary files a/logo.png and b/logo.png differ",
"diff --git a/.env b/.env",
"index 9999999..aaaaaaa 100644",
"Lines hidden: this file may hold a secret.",
"\\ No more lines shown: this change is too large to show in full.",
"diff --git a/big.txt b/big.txt",
"# truncated: true",
"# hidden: .env",
"",
].join("\n");
// A sign-off card about the report, as Implement posts it.
const SIGNOFF = {
id: "signoff",
kind: "review",
title: "Approve this phase",
doc: "report",
body: "Read the report, then approve it or say what to change.",
verdicts: [
{ id: "approve", label: "Approve this phase" },
{ id: "changes", label: "I want changes" },
],
};
const REPORT = { id: "report", title: "Completion report", blocks: [{ id: "summary", md: "## Summary\n\nPhase 3 draws the Changes tab." }] };
// Opens an implement session whose Changes doc reads `text` from changes.diff.
async function withChanges(t, text, extra = {}) {
const s = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "waiting" } } });
fs.writeFileSync(path.join(s.session, "changes.diff"), text);
s.post({
docs: [REPORT, { id: "changes", title: "Changes", blocks: [{ id: "c1", diff: "changes.diff" }] }],
agent: { status: "waiting" },
...extra,
});
return s;
}
const tab = (s, name) => s.page.locator("#views .view-tab", { hasText: new RegExp(`^${name}`) });
async function openChanges(s) {
await tab(s, "Changes").click();
await s.page.locator("#main .diff-view").waitFor();
}
// The rows of the diff pane as [old number, new number, mark, text].
async function paneRows(s) {
return s.page.locator("#main .diff-pane .diff-line").evaluateAll((rows) =>
rows.map((r) => [...r.children].map((c) => c.textContent))
);
}
// Whether the element is fully inside the window.
async function inViewport(s, locator) {
const box = await locator.boundingBox();
const size = s.page.viewportSize();
return Boolean(box) && box.y >= 0 && box.x >= 0 && box.y + box.height <= size.height && box.x + box.width <= size.width;
}
// What the person sees break: a tab that never shows, a list without its
// counts, or the wrong line numbers on the lines.
test("the Changes tab lists each file with its counts and draws the first file's lines numbered and marked", async (t) => {
const s = await withChanges(t, DIFF);
await tab(s, "Changes").waitFor();
const tabs = await s.page.locator("#views .view-tab").allTextContents();
const report = tabs.findIndex((x) => x.startsWith("Completion report"));
assert.ok(report >= 0, `the report tab: ${tabs}`);
assert.ok(tabs[report + 1].startsWith("Changes"), `the Changes tab sits beside the report tab: ${tabs}`);
await openChanges(s);
assert.equal(await textOf(s.page.locator("#main .diff-totals")), "5 files changed, +5 -2");
assert.match(await textOf(s.page.locator("#main .diff-notice")), /too large to show in full/);
const files = s.page.locator("#main .diff-file");
assert.equal(await files.count(), 5);
const first = files.nth(0);
assert.equal(await textOf(first.locator(".diff-file-name strong")), "app.js");
assert.equal(await textOf(first.locator(".diff-file-dir")), "src");
assert.equal(await textOf(first.locator(".diff-plus")), "+3");
assert.equal(await textOf(first.locator(".diff-minus")), "-2");
assert.equal(await files.nth(1).locator(".diff-status").textContent(), "Added");
assert.equal(await first.getAttribute("aria-selected"), "true", "the first file is picked");
assert.equal(await s.page.locator("#main .diff-list").getAttribute("role"), "listbox");
assert.deepEqual(await s.page.locator("#main .diff-hunk").allTextContents(), ["@@ -3,3 +3,4 @@ function start() {", "@@ -20,2 +21,2 @@"]);
assert.deepEqual(await paneRows(s), [
["3", "3", "", "one"],
["4", "", "-", "two"],
["", "4", "+", "TWO"],
["", "5", "+", "two and a half"],
["5", "6", "", "three"],
["20", "", "-", "gone"],
["", "21", "+", "<b>not html</b>"],
["21", "22", "", "kept"],
]);
// Diff text is never HTML: the tag stays text.
assert.equal(await s.page.locator("#main .diff-pane b").count(), 0);
});
test("clicking a file or pressing the arrows swaps the diff, and binary, hidden and cut files show one plain line", async (t) => {
const s = await withChanges(t, DIFF);
await openChanges(s);
const files = s.page.locator("#main .diff-file");
const pane = s.page.locator("#main .diff-pane");
await files.nth(1).click();
await pane.locator(".diff-pane-path", { hasText: "docs/new.md" }).waitFor();
assert.deepEqual(await paneRows(s), [
["", "1", "+", "# New"],
["", "2", "+", "Hello."],
]);
assert.equal(await files.nth(1).getAttribute("aria-selected"), "true");
assert.equal(await files.nth(0).getAttribute("aria-selected"), "false");
const plain = [
[2, "logo.png", "Binary file: no lines to show"],
[3, ".env", "Lines hidden: this file may hold a secret"],
[4, "big.txt", "Too large to show in full: this file is listed only"],
];
for (const [i, name, line] of plain) {
await files.nth(i).click();
await pane.locator(".diff-pane-path", { hasText: name }).waitFor();
assert.equal(await textOf(pane.locator(".diff-plain")), line, name);
assert.equal(await pane.locator(".diff-line").count(), 0, `${name} shows no lines`);
}
// Arrow keys on the list move the pick.
await s.page.locator("#main .diff-list").focus();
await s.page.keyboard.press("ArrowUp");
await pane.locator(".diff-pane-path", { hasText: ".env" }).waitFor();
await s.page.keyboard.press("Home");
await pane.locator(".diff-pane-path", { hasText: "src/app.js" }).waitFor();
assert.equal(await files.nth(0).getAttribute("aria-selected"), "true");
// The pick survives a redraw of the same block.
await files.nth(1).click();
s.post({ title: "Phase 3, again" });
await s.page.waitForFunction(() => document.getElementById("title").textContent.includes("Phase 3, again"));
await pane.locator(".diff-pane-path", { hasText: "docs/new.md" }).waitFor();
});
test("the empty state offers Check again, which sends the __changes action", async (t) => {
const s = await withChanges(t, "");
await openChanges(s);
const empty = s.page.locator("#main .diff-empty");
assert.equal(await textOf(empty.locator(".diff-state-msg")), "Nothing has changed since this run started.");
await empty.getByRole("button", { name: "Check again" }).click();
const got = s.wait(10);
assert.equal(got.code, 0, `nothing was sent (wait exit ${got.code})`);
assert.ok(got.actions.some((a) => a.i === "__changes" && a.type === "changes"), JSON.stringify(got.actions));
assert.match(got.reply, /Changes tab/);
});
// What the person sees break: a click on a finished session that leaves the
// page waiting for an agent who has gone.
test("on a finished session Check again sends nothing and says why", async (t) => {
const s = await withChanges(t, "");
s.post({ finish: { headline: "Phase 3 is done", body: "7 of 7 tasks." } });
await s.page.waitForFunction(() => document.body.textContent.includes("Phase 3 is done"));
await openChanges(s);
const empty = s.page.locator("#main .diff-empty");
await empty.getByRole("button", { name: "Check again" }).click();
await empty.locator(".diff-state-why", { hasText: "This session is finished." }).waitFor();
assert.equal(s.wait(2).code, 10, "nothing reached the agent");
});
test("a block with an error shows the reason and a Reload button that sends the __changes action", async (t) => {
const s = await openSession(await suite.browser(), { t, workflow: "implement", payload: { agent: { status: "waiting" } } });
s.post({ docs: [{ id: "changes", title: "Changes", blocks: [{ id: "c1", error: "No snapshot was taken at the start of this run." }] }] });
await tab(s, "Changes").click();
const box = s.page.locator("#main .diff-error");
await box.waitFor();
assert.equal(await textOf(box.locator(".diff-state-msg")), "The changes could not be read: No snapshot was taken at the start of this run.");
await box.getByRole("button", { name: "Reload the changes" }).click();
const got = s.wait(10);
assert.equal(got.code, 0, `nothing was sent (wait exit ${got.code})`);
assert.ok(got.actions.some((a) => a.i === "__changes" && a.type === "changes"), JSON.stringify(got.actions));
// A stale doc is still being read again: the loading rows show.
fs.writeFileSync(path.join(s.session, "changes.diff"), DIFF);
s.post({ docs: [{ id: "changes", stale: true, blocks: [{ id: "c1", diff: "changes.diff" }] }] });
await s.page.locator("#main .diff-view.is-loading .diff-skel-row").first().waitFor();
});
// What the person sees break: a long diff pushing the way to the sign-off off
// the screen, or a long line widening the page.
test("a long diff scrolls inside its own pane, the way back to the sign-off stays in view, and the added rows differ by theme", async (t) => {
const long = Array.from({ length: 640 }, (_, i) => `+line ${i + 1} ${i === 3 ? "x".repeat(600) : ""}`);
const text = ["diff --git a/long.txt b/long.txt", "new file mode 100644", "--- /dev/null", "+++ b/long.txt", "@@ -0,0 +1,640 @@", ...long, ""].join("\n");
const s = await withChanges(t, text, { items: [SIGNOFF] });
await itemCard(s.page, "signoff").waitFor();
await openChanges(s);
const pane = s.page.locator("#main .diff-pane");
assert.equal(await pane.locator(".diff-line").count(), 640);
// The pane scrolls itself; the column and the page do not grow past the window.
const sizes = await pane.evaluate((p) => ({ inner: p.scrollHeight > p.clientHeight, page: document.documentElement.scrollWidth <= window.innerWidth }));
assert.ok(sizes.inner, "the diff pane scrolls inside itself");
assert.ok(sizes.page, "a long line never gives the page a sideways scroll");
// The pane itself scrolls sideways, so its scrollbar sits at the window's
// edge of the pane, not under the file's last line.
assert.ok(await pane.evaluate((p) => p.scrollWidth > p.clientWidth), "the long line scrolls inside the diff pane");
await scrollCard(pane, "end");
const back = s.page.locator("#main .doc-head .back-home");
assert.ok(await inViewport(s, back), "Back to Questions stays in view with the diff scrolled to its end");
assert.ok(await inViewport(s, pane), "the whole diff pane fits in the window");
// One click from the Changes tab, the sign-off's verdicts are on screen.
await back.click();
const card = itemCard(s.page, "signoff");
await card.waitFor();
for (const name of ["Approve this phase", "I want changes"]) {
assert.ok(await inViewport(s, card.getByRole("button", { name })), `${name} is inside the window`);
}
await openChanges(s);
const added = s.page.locator("#main .diff-line.add").first();
await s.page.evaluate(() => document.documentElement.setAttribute("data-theme", "light"));
const light = await styleOf(added, "backgroundColor");
await s.page.evaluate(() => document.documentElement.setAttribute("data-theme", "dark"));
const dark = await styleOf(added, "backgroundColor");
assert.notEqual(light, dark, "the added rows take the theme's own soft color");
assert.notEqual(light, "rgba(0, 0, 0, 0)");
});
+43
View File
@@ -1048,6 +1048,49 @@ test("a diff block reads a .diff file in the session folder, refreshes and turns
}
});
// When the changes could not be read, the agent sends the plain reason as the
// block's `error` instead of a diff; a diff sent later replaces it.
test("a diff block may carry one line of error instead of a diff, never both", () => {
const res = cli(["open", "--workflow", "implement", "--no-open"]);
const sid = res.json.sid;
const dir = res.json.session;
const post = (name, patch, opts) => cli(["post", "--session", sid, "--file", payload(name, patch)], opts);
const block = () => readState(dir).docs.find((d) => d.id === "changes").blocks[0];
try {
post("err-ok.json", { docs: [{ id: "changes", title: "Changes", blocks: [{ id: "c1", error: " No snapshot was taken at the start of this run. " }] }] });
assert.equal(block().error, "No snapshot was taken at the start of this run.");
assert.equal(block().diff, undefined);
assert.equal(block().text, undefined);
assert.equal(block().state, "settled");
for (const [name, b, why] of [
["err-both.json", { id: "c1", diff: "changes.diff", error: "x" }, /carries "diff" or "error", never both/],
["err-md.json", { id: "c1", error: "x", md: "text" }, /an error block cannot also carry "md", "file" or "image"/],
["err-lines.json", { id: "c1", error: "one\ntwo" }, /must be one line of prose/],
["err-blank.json", { id: "c1", error: " " }, /must be one line of prose/],
["err-type.json", { id: "c1", error: 3 }, /must be one line of prose/],
]) {
fs.writeFileSync(path.join(dir, "changes.diff"), "diff --git a/a b/a\n");
const r = post(name, { docs: [{ id: "changes", blocks: [b] }] }, { expectFail: true });
assert.equal(r.status, 3, name);
assert.match(r.stderr, why, name);
}
// A diff over it clears the error, and an error over a diff clears the text.
const text = "diff --git a/a.txt b/a.txt\n--- a/a.txt\n+++ b/a.txt\n@@ -1 +1 @@\n-old\n+new\n";
fs.writeFileSync(path.join(dir, "changes.diff"), text);
post("err-to-diff.json", { docs: [{ id: "changes", blocks: [{ id: "c1", diff: "changes.diff" }] }] });
assert.equal(block().text, text);
assert.equal(block().error, undefined);
post("diff-to-err.json", { docs: [{ id: "changes", blocks: [{ id: "c1", error: "The snapshot is gone." }] }] });
assert.equal(block().error, "The snapshot is gone.");
assert.equal(block().diff, undefined);
assert.equal(block().text, undefined);
} finally {
cli(["stop", "--session", sid, "--force"]);
}
});
test("a diff block refuses a path, a wrong extension, a missing file and a link out of the session folder", () => {
const res = cli(["open", "--workflow", "implement", "--no-open"]);
const sid = res.json.sid;