mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-29 13:21:18 -08:00
421 lines
23 KiB
JavaScript
421 lines
23 KiB
JavaScript
// Page tests for the Review Loop's setup screen. The dashboard card that opens
|
|||
|
|
// it only shows inside the desktop app, so these open the screen through its
|
||
|
|
// own module, then drive the real page, the way test-web-console-page-loop.mjs
|
||
|
|
// does for the Implementation Loop's. Run with:
|
||
|
|
// node --test scripts/test-web-console-page-review-loop.mjs
|
||
|
|
|
||
|
|
import test from "node:test";
|
||
|
|
import assert from "node:assert/strict";
|
||
|
|
import fs from "node:fs";
|
||
|
|
import path from "node:path";
|
||
|
|
import { fileURLToPath } from "node:url";
|
||
|
|
import { pageSuite, openSession, tempProject, textOf } from "./page-test-helpers.mjs";
|
||
|
|
import { MODELS_DIR } from "./web-console-test-helpers.mjs";
|
||
|
|
|
||
|
|
const ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
||
|
|
|
||
|
|
const suite = pageSuite(test);
|
||
|
|
|
||
|
|
const PROJECT = {
|
||
|
|
"AGENTS.md": "# AGENTS.md\n\nA small demo project.\n",
|
||
|
|
"specs/ready/overview.md": "# Overview\n\n## Phase Checklist\n\n- [ ] Phase 1: One\n",
|
||
|
|
"specs/ready/phase-1.md": "# Phase 1\n\n- [ ] **Task 1.1:** One\n",
|
||
|
|
};
|
||
|
|
|
||
|
|
const MENU = { menu: { note: "Ready when you are." }, agent: { status: "waiting" } };
|
||
|
|
|
||
|
|
const FACTS = { agent: "claude", agentLabel: "Claude Code", helpers: true, strengthsMapped: true, running: false, promptSupport: true, notifyKind: "query", notifyUrl: "", notifyParam: "message" };
|
||
|
|
|
||
|
|
// Stands a real window in for the app that frames the page, listening to what
|
||
|
|
// the page tells it; the returned function replies the way the app does.
|
||
|
|
async function frameInFakeApp(s) {
|
||
|
|
await s.page.evaluate(() => {
|
||
|
|
const frame = document.createElement("iframe");
|
||
|
|
frame.hidden = true;
|
||
|
|
document.body.appendChild(frame);
|
||
|
|
const app = frame.contentWindow;
|
||
|
|
window.__told = [];
|
||
|
|
app.postMessage = (message) => window.__told.push(message);
|
||
|
|
Object.defineProperty(window, "parent", { value: app, configurable: true });
|
||
|
|
});
|
||
|
|
return (data) =>
|
||
|
|
s.page.evaluate((message) => {
|
||
|
|
window.dispatchEvent(new MessageEvent("message", { source: window.parent, data: message }));
|
||
|
|
}, data);
|
||
|
|
}
|
||
|
|
|
||
|
|
// The installed copy of the shipped model menu, with its strengths, as install.js drops it.
|
||
|
|
function installShippedModels() {
|
||
|
|
const shipped = path.join(MODELS_DIR, "bin", "models.json");
|
||
|
|
fs.mkdirSync(path.dirname(shipped), { recursive: true });
|
||
|
|
fs.copyFileSync(path.join(ROOT, "src", "launcher", "models.json"), shipped);
|
||
|
|
}
|
||
|
|
|
||
|
|
async function openReview(t, { spec = null } = {}) {
|
||
|
|
installShippedModels();
|
||
|
|
const browser = await suite.browser();
|
||
|
|
const s = await openSession(browser, { t, workflow: "dashboard", payload: MENU, project: tempProject(PROJECT) });
|
||
|
|
const skip = s.page.getByRole("button", { name: "Skip the intro" });
|
||
|
|
await skip.click();
|
||
|
|
await skip.waitFor({ state: "hidden" });
|
||
|
|
await s.page.locator("#main").getByRole("heading", { name: "What are we doing today?" }).waitFor();
|
||
|
|
const welcomeDone = s.page.getByRole("button", { name: "Start building" });
|
||
|
|
if (await welcomeDone.isVisible()) {
|
||
|
|
await welcomeDone.click();
|
||
|
|
await welcomeDone.waitFor({ state: "hidden" });
|
||
|
|
}
|
||
|
|
const answer = await frameInFakeApp(s);
|
||
|
|
await s.page.evaluate(async (pick) => {
|
||
|
|
const m = await import(new URL("screens/review-loop-setup.js", document.baseURI).href);
|
||
|
|
await m.openReviewLoopSetup(pick);
|
||
|
|
}, spec);
|
||
|
|
await s.page.locator("#review-loop-start").waitFor();
|
||
|
|
return { ...s, answer };
|
||
|
|
}
|
||
|
|
|
||
|
|
const radios = (s, name) => s.page.locator(`input[name="${name}"]`).evaluateAll((all) => all.map((r) => [r.id, r.checked]));
|
||
|
|
|
||
|
|
test("the screen asks the app for its facts and lists its fields in order, with their defaults", async (t) => {
|
||
|
|
const s = await openReview(t);
|
||
|
|
assert.ok(await s.page.evaluate(() => window.__told.some((m) => m.plan2code === "review-loop-facts")), "the facts were asked for");
|
||
|
|
|
||
|
|
const labels = await s.page.locator(".loop-label").allInnerTexts();
|
||
|
|
assert.deepEqual(labels, ["What to review", "Round cap", "Commit", "Suggestions", "Strength", "Reviewers", "If a round goes quiet", "Send a notification"]);
|
||
|
|
assert.deepEqual(await radios(s, "reviewscope"), [["loop-reviewscope-branch", true], ["loop-reviewscope-uncommitted", false], ["loop-reviewscope-spec", false]]);
|
||
|
|
assert.equal(await s.page.locator("#review-loop-spec").count(), 0, "no spec picker until the spec scope is chosen");
|
||
|
|
assert.equal(await s.page.locator("#review-loop-cap").inputValue(), "3");
|
||
|
|
assert.equal(await s.page.locator("#review-loop-commit").isChecked(), true, "commit each round is on");
|
||
|
|
assert.equal(await s.page.locator("#review-loop-suggestions").isChecked(), false, "Suggestions on their own are off");
|
||
|
|
assert.equal(await s.page.locator("#loop-silence").inputValue(), "20");
|
||
|
|
assert.equal(await s.page.locator("#loop-notify-url").inputValue(), "");
|
||
|
|
assert.equal(await s.page.locator("#review-loop-notify-rounds").isVisible(), false, "no address, no round messages to choose");
|
||
|
|
|
||
|
|
await s.page.locator("#loop-notify-url").fill("https://example.com/hook");
|
||
|
|
const rounds = s.page.locator("#review-loop-notify-rounds");
|
||
|
|
assert.equal(await rounds.isVisible(), true);
|
||
|
|
assert.equal(await rounds.isChecked(), false, "a message per round is opt-in");
|
||
|
|
assert.match(await textOf(s.page.locator("label", { has: rounds })), /Also tell me when each round finishes/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test("a spec picked on the dashboard fills the picker and the spec scope", async (t) => {
|
||
|
|
const s = await openReview(t, { spec: { dir: "specs/ready" } });
|
||
|
|
assert.deepEqual(await radios(s, "reviewscope"), [["loop-reviewscope-branch", false], ["loop-reviewscope-uncommitted", false], ["loop-reviewscope-spec", true]]);
|
||
|
|
assert.equal(await s.page.locator("#review-loop-spec").inputValue(), "specs/ready");
|
||
|
|
// The pre-fill is not a save.
|
||
|
|
const saved = await s.page.evaluate(async () => (await fetch("/review-loop-setup")).json());
|
||
|
|
assert.equal(saved.remembered, false);
|
||
|
|
assert.equal(saved.scope, "branch");
|
||
|
|
|
||
|
|
await s.page.locator("#review-loop-spec").selectOption("");
|
||
|
|
await s.answer({ plan2code: "review-loop-facts", facts: FACTS });
|
||
|
|
await s.page.getByText("Pick the spec whose work to review.").waitFor();
|
||
|
|
assert.equal(await s.page.locator("#review-loop-start").isDisabled(), true, "the spec scope needs a spec");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("uncommitted changes need a tick before Start, and the tick is what the app is told", async (t) => {
|
||
|
|
const s = await openReview(t);
|
||
|
|
await s.answer({ plan2code: "review-loop-facts", facts: FACTS });
|
||
|
|
const start = s.page.locator("#review-loop-start");
|
||
|
|
await s.page.waitForFunction(() => !document.getElementById("review-loop-start").disabled);
|
||
|
|
assert.equal(await s.page.locator("#review-loop-agree").count(), 0, "a clean tree has nothing to agree to");
|
||
|
|
|
||
|
|
// The tree is dirty: two files changed (what the console's scan counts).
|
||
|
|
await s.page.evaluate(async () => {
|
||
|
|
const { page, redraw } = await import(new URL("state.js", document.baseURI).href);
|
||
|
|
page.reviewLoopSetup.facts.pending = 2;
|
||
|
|
redraw();
|
||
|
|
});
|
||
|
|
const tick = s.page.locator("#review-loop-agree");
|
||
|
|
await tick.waitFor();
|
||
|
|
assert.match(await textOf(s.page.locator("label", { has: tick })), /Commit my current changes first as Work before Review Loop/);
|
||
|
|
assert.equal(await tick.isChecked(), false);
|
||
|
|
assert.equal(await start.isDisabled(), true, "Start waits on the tick");
|
||
|
|
assert.match(await textOf(s.page.locator(".loop-why")), /2 uncommitted changes need your say-so/);
|
||
|
|
|
||
|
|
await tick.check();
|
||
|
|
assert.equal(await start.isDisabled(), false);
|
||
|
|
await start.click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "review-loop-start"));
|
||
|
|
const sent = await s.page.evaluate(() => window.__told.find((m) => m.plan2code === "review-loop-start"));
|
||
|
|
assert.deepEqual(sent.setup, { scope: "branch", spec: "", cap: 3, commit: true, suggestions: false, strength: "", silenceMinutes: 20, notifyRounds: false, preRunCommitAgreed: true });
|
||
|
|
const saved = await s.page.evaluate(async () => (await fetch("/review-loop-setup")).json());
|
||
|
|
assert.equal(saved.remembered, true, "the picks were saved first");
|
||
|
|
assert.equal("preRunCommitAgreed" in saved, false, "the agreement is never remembered");
|
||
|
|
|
||
|
|
await s.page.getByText("Waiting for the app's confirm...").waitFor();
|
||
|
|
await s.answer({ plan2code: "review-loop-start-result", ok: false, started: false, error: "A loop is already running." });
|
||
|
|
await s.page.getByText("A loop is already running.").waitFor();
|
||
|
|
assert.equal(await start.isDisabled(), false, "a refusal shows inline and gives the button back");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("turning commits off drops the tick, and the app is told the work needs no agreement", async (t) => {
|
||
|
|
const s = await openReview(t);
|
||
|
|
await s.answer({ plan2code: "review-loop-facts", facts: FACTS });
|
||
|
|
await s.page.evaluate(async () => {
|
||
|
|
const { page, redraw } = await import(new URL("state.js", document.baseURI).href);
|
||
|
|
page.reviewLoopSetup.facts.pending = 1;
|
||
|
|
redraw();
|
||
|
|
});
|
||
|
|
await s.page.locator("#review-loop-agree").waitFor();
|
||
|
|
await s.page.locator("#review-loop-commit").uncheck();
|
||
|
|
assert.equal(await s.page.locator("#review-loop-agree").count(), 0);
|
||
|
|
await s.page.locator("#review-loop-start").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "review-loop-start"));
|
||
|
|
const sent = await s.page.evaluate(() => window.__told.find((m) => m.plan2code === "review-loop-start"));
|
||
|
|
assert.equal(sent.setup.commit, false);
|
||
|
|
assert.equal(sent.setup.preRunCommitAgreed, false);
|
||
|
|
});
|
||
|
|
|
||
|
|
test("the hands-off line and the reviewer note are on the screen", async (t) => {
|
||
|
|
const s = await openReview(t);
|
||
|
|
const main = await textOf(s.page.locator(".review-loop-setup"));
|
||
|
|
assert.ok(main.includes("Please do not edit this project's files while rounds run: anything changed goes into the round."));
|
||
|
|
assert.ok(main.includes("Each round's reviewer runs fresh, whatever the Subagents switch says; the switch still governs other helpers."));
|
||
|
|
});
|
||
|
|
|
||
|
|
test("an agent with no strengths mapped grays the strength choice and links to Agents & models", async (t) => {
|
||
|
|
const s = await openReview(t);
|
||
|
|
await s.answer({ plan2code: "review-loop-facts", facts: { ...FACTS, agent: "nonesuch", strengthsMapped: false } });
|
||
|
|
const note = s.page.locator(".loop-strength-none");
|
||
|
|
await note.waitFor();
|
||
|
|
assert.match(await textOf(note), /This agent has no strengths mapped yet\./);
|
||
|
|
assert.equal(await s.page.locator("#review-loop-strength").count(), 0, "no picker to choose from");
|
||
|
|
await note.getByRole("button", { name: "Map them in Agents & models" }).click();
|
||
|
|
await s.page.locator("#prefs-modal[open], dialog[open]").first().waitFor();
|
||
|
|
});
|
||
|
|
|
||
|
|
test("an agent with strengths shows the choice, and a running loop holds Start", async (t) => {
|
||
|
|
const s = await openReview(t);
|
||
|
|
await s.answer({ plan2code: "review-loop-facts", facts: FACTS });
|
||
|
|
await s.page.locator("#review-loop-strength").waitFor();
|
||
|
|
const options = await s.page.locator("#review-loop-strength option").allInnerTexts();
|
||
|
|
assert.equal(options[0], "Match my session");
|
||
|
|
assert.equal(await s.page.locator("#review-loop-strength").inputValue(), "");
|
||
|
|
|
||
|
|
await s.answer({ plan2code: "review-loop-facts", facts: { ...FACTS, running: true } });
|
||
|
|
await s.page.getByText(/A loop is already running in this window/).waitFor();
|
||
|
|
assert.equal(await s.page.locator("#review-loop-start").isDisabled(), true);
|
||
|
|
});
|
||
|
|
|
||
|
|
/* ---------------------------------------------------------------- the end */
|
||
|
|
|
||
|
|
const DIFF = [
|
||
|
|
"diff --git a/src/app.js b/src/app.js",
|
||
|
|
"index 1111111..2222222 100644",
|
||
|
|
"--- a/src/app.js",
|
||
|
|
"+++ b/src/app.js",
|
||
|
|
"@@ -1,2 +1,3 @@",
|
||
|
|
" one",
|
||
|
|
"-two",
|
||
|
|
"+TWO",
|
||
|
|
"+three",
|
||
|
|
"",
|
||
|
|
].join("\n");
|
||
|
|
|
||
|
|
const REPORT_DOC = { id: "report", title: "Review Loop report", blocks: [{ id: "r1", md: "# Report\n\nTwo rounds ran." }] };
|
||
|
|
const PARTIAL_DOC = { id: "partial", title: "Partial changes", blocks: [{ id: "p1", diff: "partial.diff" }] };
|
||
|
|
|
||
|
|
const END = {
|
||
|
|
kind: "review",
|
||
|
|
line: "No Critical or Warning findings are left.",
|
||
|
|
reason: "clean",
|
||
|
|
report: "report",
|
||
|
|
canContinue: false,
|
||
|
|
canSquash: false,
|
||
|
|
can: [],
|
||
|
|
};
|
||
|
|
|
||
|
|
const SUGGESTIONS = [
|
||
|
|
{ id: "s1", title: "Rename the helper", file: "src/a.js", line: 12 },
|
||
|
|
{ id: "s2", title: "Drop the unused import", file: "" },
|
||
|
|
];
|
||
|
|
|
||
|
|
// A review session as the app's window shows it, the app faked, with `end`
|
||
|
|
// posted along with the report and partial diff docs.
|
||
|
|
async function openEnd(t, end) {
|
||
|
|
const s = await openSession(await suite.browser(), {
|
||
|
|
t,
|
||
|
|
workflow: "implement",
|
||
|
|
open: ["--loop"],
|
||
|
|
env: { PLAN2CODE_IN_APP: "1" },
|
||
|
|
payload: { title: "demo", agent: { status: "working" } },
|
||
|
|
project: tempProject(PROJECT),
|
||
|
|
});
|
||
|
|
const answer = await frameInFakeApp(s);
|
||
|
|
fs.writeFileSync(path.join(s.session, "partial.diff"), DIFF);
|
||
|
|
s.post({ docs: [REPORT_DOC, PARTIAL_DOC], loopEnd: end, agent: { status: "waiting" } });
|
||
|
|
await s.page.locator(".review-end").waitFor();
|
||
|
|
return { ...s, answer };
|
||
|
|
}
|
||
|
|
|
||
|
|
const told = (s, kind) => s.page.evaluate((k) => window.__told.filter((m) => m.plan2code === k), kind);
|
||
|
|
const buttons = (s) => s.page.locator(".review-end button").evaluateAll((all) => all.map((b) => b.id).filter(Boolean));
|
||
|
|
|
||
|
|
test("the end screen heads each reason in words, with the line under it and the report behind a button", async (t) => {
|
||
|
|
const s = await openEnd(t, END);
|
||
|
|
const headings = { clean: "Clean", cap: "Stopped at the round cap", person: "Stopped by you", failed: "Failed" };
|
||
|
|
for (const [reason, words] of Object.entries(headings)) {
|
||
|
|
s.post({ loopEnd: { ...END, reason, line: `Line for ${reason}` } });
|
||
|
|
await s.page.getByText(`Line for ${reason}`).waitFor();
|
||
|
|
assert.equal(await textOf(s.page.locator(".review-end-heading")), words);
|
||
|
|
}
|
||
|
|
await s.page.getByRole("button", { name: "Read the full report" }).click();
|
||
|
|
await s.page.getByText("Two rounds ran.").waitFor();
|
||
|
|
});
|
||
|
|
|
||
|
|
test("Continue shows only when allowed, says Run one more round at the cap, and is held while the app answers", async (t) => {
|
||
|
|
const s = await openEnd(t, END);
|
||
|
|
assert.equal(await s.page.locator("#review-end-continue").count(), 0, "nothing to continue after a clean run");
|
||
|
|
|
||
|
|
s.post({ loopEnd: { ...END, reason: "person", line: "You stopped it", canContinue: true } });
|
||
|
|
const go = s.page.locator("#review-end-continue");
|
||
|
|
await go.waitFor();
|
||
|
|
assert.equal(await textOf(go), "Continue");
|
||
|
|
|
||
|
|
s.post({ loopEnd: { ...END, reason: "cap", line: "The cap was reached", canContinue: true } });
|
||
|
|
await s.page.getByRole("button", { name: "Run one more round" }).waitFor();
|
||
|
|
|
||
|
|
await s.page.locator("#review-end-continue").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "review-loop-continue"));
|
||
|
|
assert.equal(await s.page.locator("#review-end-continue").isDisabled(), true, "held while the app answers");
|
||
|
|
await s.answer({ plan2code: "review-loop-continue-result", ok: false, error: "A loop is already running." });
|
||
|
|
await s.page.getByText("A loop is already running.").waitFor();
|
||
|
|
assert.equal(await s.page.locator("#review-end-continue").isDisabled(), false, "an error gives the button back");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("after Stop now the partial diff, its stats, Keep and Discard show and Continue is hidden", async (t) => {
|
||
|
|
const s = await openEnd(t, {
|
||
|
|
...END,
|
||
|
|
reason: "person",
|
||
|
|
line: "You stopped it",
|
||
|
|
canContinue: true,
|
||
|
|
partial: { files: 1, added: 2, removed: 1, diff: "partial" },
|
||
|
|
});
|
||
|
|
await s.page.locator(".review-end-diff .diff-view").waitFor();
|
||
|
|
assert.match(await textOf(s.page.locator(".review-end-stats")), /1 file changed, \+2 -1/);
|
||
|
|
assert.match(await textOf(s.page.locator(".review-end-diff")), /app\.js/);
|
||
|
|
assert.equal(await s.page.locator("#review-end-continue").count(), 0, "Continue waits for Keep or Discard");
|
||
|
|
assert.equal(await s.page.locator("#review-end-signoff").isDisabled(), true, "Sign off waits for Keep or Discard too");
|
||
|
|
assert.match(await textOf(s.page.locator(".review-end")), /Keep or discard the partial changes first/);
|
||
|
|
|
||
|
|
await s.page.locator("#review-end-keep").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "review-loop-partial"));
|
||
|
|
assert.deepEqual(await told(s, "review-loop-partial"), [{ plan2code: "review-loop-partial", keep: true }]);
|
||
|
|
await s.answer({ plan2code: "review-loop-partial-result", ok: false, error: "Nothing to keep." });
|
||
|
|
await s.page.getByText("Nothing to keep.").waitFor();
|
||
|
|
await s.page.locator("#review-end-discard").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.filter((m) => m.plan2code === "review-loop-partial").length === 2);
|
||
|
|
assert.equal((await told(s, "review-loop-partial"))[1].keep, false);
|
||
|
|
|
||
|
|
// The app answers with a new end without the partial: Continue comes back.
|
||
|
|
s.post({ loopEnd: { ...END, reason: "person", line: "You stopped it", canContinue: true } });
|
||
|
|
await s.page.locator("#review-end-continue").waitFor();
|
||
|
|
assert.equal(await s.page.locator("#review-end-keep").count(), 0);
|
||
|
|
});
|
||
|
|
|
||
|
|
test("a second ending with the same words after Continue starts with live buttons", async (t) => {
|
||
|
|
const again = { ...END, reason: "cap", line: "Stopped at the cap", canContinue: true };
|
||
|
|
const s = await openEnd(t, again);
|
||
|
|
await s.page.locator("#review-end-continue").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "review-loop-continue"));
|
||
|
|
assert.equal(await s.page.locator("#review-end-continue").isDisabled(), true, "the press waits on the app");
|
||
|
|
// The app starts another round (a blank session, no end card), then it ends the same way again.
|
||
|
|
await s.page.evaluate(async () => {
|
||
|
|
const { page, redraw } = await import(new URL("state.js", document.baseURI).href);
|
||
|
|
window.__keptEnd = page.S.loopEnd;
|
||
|
|
delete page.S.loopEnd;
|
||
|
|
redraw();
|
||
|
|
});
|
||
|
|
await s.page.locator("#review-end-continue").waitFor({ state: "detached" });
|
||
|
|
await s.page.evaluate(async () => {
|
||
|
|
const { page, redraw } = await import(new URL("state.js", document.baseURI).href);
|
||
|
|
page.S.loopEnd = window.__keptEnd;
|
||
|
|
redraw();
|
||
|
|
});
|
||
|
|
await s.page.locator("#review-end-continue").waitFor();
|
||
|
|
assert.equal(await s.page.locator("#review-end-continue").isEnabled(), true, "Continue is live again");
|
||
|
|
assert.equal(await s.page.locator("#review-end-signoff").isEnabled(), true, "Sign off is live again");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("the Suggestions pick starts unticked, shows only with suggestions, and what is ticked is what Sign off sends", async (t) => {
|
||
|
|
const s = await openEnd(t, END);
|
||
|
|
assert.equal(await s.page.locator(".review-end-suggestions").count(), 0, "no pick without suggestions");
|
||
|
|
assert.equal(await s.page.locator("#review-end-signoff").isEnabled(), true, "Sign off is always there");
|
||
|
|
|
||
|
|
s.post({ loopEnd: { ...END, line: "With suggestions", suggestions: SUGGESTIONS } });
|
||
|
|
await s.page.locator(".review-end-suggestions").waitFor();
|
||
|
|
assert.deepEqual(
|
||
|
|
await s.page.locator(".review-end-pick input").evaluateAll((all) => all.map((i) => [i.id, i.checked])),
|
||
|
|
[["review-end-pick-s1", false], ["review-end-pick-s2", false]]
|
||
|
|
);
|
||
|
|
assert.match(await textOf(s.page.locator(".review-end-pick").first()), /Rename the helper\s*src\/a\.js:12/);
|
||
|
|
await s.page.locator("#review-end-pick-s2").check();
|
||
|
|
// A redraw keeps the tick.
|
||
|
|
await s.page.evaluate(async () => (await import(new URL("state.js", document.baseURI).href)).redraw());
|
||
|
|
assert.equal(await s.page.locator("#review-end-pick-s2").isChecked(), true);
|
||
|
|
|
||
|
|
await s.page.locator("#review-end-signoff").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "review-loop-sign-off"));
|
||
|
|
assert.deepEqual(await told(s, "review-loop-sign-off"), [{ plan2code: "review-loop-sign-off", picks: ["s2"], squash: false }]);
|
||
|
|
assert.equal(await s.page.locator("#review-end-signoff").isDisabled(), true);
|
||
|
|
await s.answer({ plan2code: "review-loop-sign-off-result", ok: false, error: "Something went wrong." });
|
||
|
|
await s.page.getByText("Something went wrong.").waitFor();
|
||
|
|
});
|
||
|
|
|
||
|
|
test("what was ticked survives Keep or Discard reposting the end without the partial changes", async (t) => {
|
||
|
|
const withPartial = { ...END, reason: "person", line: "You stopped it", canSquash: true, suggestions: SUGGESTIONS, partial: { files: 1, added: 2, removed: 1, diff: "partial" } };
|
||
|
|
const s = await openEnd(t, withPartial);
|
||
|
|
await s.page.locator("#review-end-pick-s2").check();
|
||
|
|
await s.page.locator("#review-end-squash").check();
|
||
|
|
const { partial, ...settled } = withPartial;
|
||
|
|
s.post({ loopEnd: { ...settled, canContinue: true } });
|
||
|
|
await s.page.locator("#review-end-continue").waitFor();
|
||
|
|
assert.equal(await s.page.locator("#review-end-pick-s2").isChecked(), true, "the pick is kept");
|
||
|
|
assert.equal(await s.page.locator("#review-end-squash").isChecked(), true, "the squash switch is kept");
|
||
|
|
assert.equal(await s.page.locator("#review-end-signoff").isEnabled(), true, "Sign off is back");
|
||
|
|
});
|
||
|
|
|
||
|
|
test("the squash switch shows only when canSquash, starts off, and is sent with Sign off", async (t) => {
|
||
|
|
const s = await openEnd(t, END);
|
||
|
|
assert.equal(await s.page.locator("#review-end-squash").count(), 0);
|
||
|
|
|
||
|
|
s.post({ loopEnd: { ...END, line: "Can squash", canSquash: true } });
|
||
|
|
const sw = s.page.locator("#review-end-squash");
|
||
|
|
await sw.waitFor();
|
||
|
|
assert.equal(await sw.isChecked(), false);
|
||
|
|
assert.match(await textOf(s.page.locator("label", { has: sw })), /Squash the round commits into one/);
|
||
|
|
await sw.check();
|
||
|
|
await s.page.locator("#review-end-signoff").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "review-loop-sign-off"));
|
||
|
|
assert.deepEqual(await told(s, "review-loop-sign-off"), [{ plan2code: "review-loop-sign-off", picks: [], squash: true }]);
|
||
|
|
});
|
||
|
|
|
||
|
|
test("the finished screen offers PR Prep, Fix what's left by hand when something is open, and the dashboard", async (t) => {
|
||
|
|
const done = { ...END, line: "Signed off", signedOff: true, note: "Squashed 3 round commits into one." };
|
||
|
|
const s = await openEnd(t, { ...done, open: [{ title: "Unchecked input", file: "src/b.js", line: 9 }] });
|
||
|
|
assert.deepEqual(await buttons(s), ["review-end-pr-prep", "review-end-quick-task", "review-end-dashboard"]);
|
||
|
|
assert.equal(await textOf(s.page.locator(".review-end-heading")), "Signed off");
|
||
|
|
assert.match(await textOf(s.page.locator(".review-end-note")), /Squashed 3 round commits into one\./);
|
||
|
|
assert.equal(await s.page.locator("#review-end-signoff").count(), 0, "no sign-off after sign-off");
|
||
|
|
|
||
|
|
await s.page.locator("#review-end-quick-task").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "review-loop-next"));
|
||
|
|
assert.deepEqual(await told(s, "review-loop-next"), [{ plan2code: "review-loop-next", next: "quick-task" }]);
|
||
|
|
assert.equal(await s.page.locator("#review-end-pr-prep").isDisabled(), true, "all held while the app answers");
|
||
|
|
await s.answer({ plan2code: "review-loop-next-result", ok: false, error: "Could not start it." });
|
||
|
|
await s.page.getByText("Could not start it.").waitFor();
|
||
|
|
await s.page.locator("#review-end-pr-prep").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.filter((m) => m.plan2code === "review-loop-next").length === 2);
|
||
|
|
assert.equal((await told(s, "review-loop-next"))[1].next, "pr-prep");
|
||
|
|
await s.answer({ plan2code: "review-loop-next-result", ok: false, error: "Nope." });
|
||
|
|
await s.page.locator("#review-end-dashboard").click();
|
||
|
|
await s.page.waitForFunction(() => window.__told.some((m) => m.plan2code === "loop-dashboard"));
|
||
|
|
});
|
||
|
|
|
||
|
|
test("Fix what's left by hand is hidden when nothing is open", async (t) => {
|
||
|
|
const s = await openEnd(t, { ...END, signedOff: true, line: "Signed off" });
|
||
|
|
assert.deepEqual(await buttons(s), ["review-end-pr-prep", "review-end-dashboard"]);
|
||
|
|
s.post({ loopEnd: { ...END, signedOff: true, line: "Signed off", open: [] } });
|
||
|
|
await s.page.locator("#review-end-pr-prep").waitFor();
|
||
|
|
assert.equal(await s.page.locator("#review-end-quick-task").count(), 0);
|
||
|
|
});
|