diff --git a/scripts/test-web-console-session.mjs b/scripts/test-web-console-session.mjs index 115b104..5ebf151 100644 --- a/scripts/test-web-console-session.mjs +++ b/scripts/test-web-console-session.mjs @@ -56,6 +56,8 @@ import { ask, until, clientFor, + consoleSession, + postPatch, } from "./web-console-test-helpers.mjs"; let sid; @@ -1559,6 +1561,27 @@ test("finish.changelog is accepted on quick-task and finalize, and refused on im assert.deepEqual(problems("implement", true, "Paused at Phase 2"), []); }); +// A quick task once re-posted its finish with Review it now after every +// review, so each press started the same review again. +test("a quick-task finish offering the review again after one ran in that launch is refused", () => { + const s = consoleSession(["--workflow", "quick-task"]); + try { + const finish = (review) => ({ finish: { headline: "Built", command: "git add -A", ...(review ? { review: true } : {}), dashboard: true } }); + assert.equal(postPatch(s, finish(true)).status, 0, "before any review, the finish offers it"); + assert.equal(postPatch(s, { finish: null, run: { event: "review", id: "review" } }).status, 0); + const again = postPatch(s, finish(true), { expectFail: true }); + assert.equal(again.status, 3); + assert.match(again.stderr, /finish\.review: a review already ran in this quick task/); + assert.equal(postPatch(s, finish(false)).status, 0, "the finish without review goes through"); + // A new launch starts clean. + cli(["open", "--resume", s.sid, "--no-open", "--workflow", "dashboard"]); + cli(["open", "--resume", s.sid, "--no-open", "--workflow", "quick-task"]); + assert.equal(postPatch(s, finish(true)).status, 0, "a new quick task may offer its own review"); + } finally { + cli(["stop", "--session", s.sid, "--force"]); + } +}); + // Update CHANGELOG first is a hop like Commit it now, into Changelog. test("a changelog request from a finished screen carries the resume into the changelog workflow and its skill file", async () => { await post("/submit", { diff --git a/src/web-console/cmd-post-wait.mjs b/src/web-console/cmd-post-wait.mjs index 6289e72..4239396 100644 --- a/src/web-console/cmd-post-wait.mjs +++ b/src/web-console/cmd-post-wait.mjs @@ -220,6 +220,7 @@ function postOnce() { delete patch.folderIssue; const reread = liftReread(patch, before.workflow); const ledgerLines = ledgerFromPost(dir, run, folderIssue, before.workflow); + refuseReviewAgain(dir, patch.finish, ledgerLines, before.workflow); // Taken before the lock: git processes must not run while it is held. const snap = reread === undefined ? null : snapshot(before.worktree || repoRoots().worktree, { prHosts: readPrHosts() }); @@ -323,6 +324,29 @@ export function gitBlock(snap, reread, previous) { return { ...snap, refreshFailed }; } +/** + * A quick task whose review already ran in this launch ends on a finish + * without `review` (building-review.md, "The way back out"). Offering + * Review it now again sends the person round the same review for as long as + * they press it, which happened once: exit 3 instead. + */ +export function refuseReviewAgain(dir, finish, ledgerLines, workflow) { + if (workflow !== "quick-task" || !finish || typeof finish !== "object" || !finish.review) return; + const ledger = readLedger(dir); + const launch = lastLaunchId(ledger); + const reviewed = [...ledger, ...ledgerLines].some((e) => e.kind === "run" && e.event === "review" && String(e.id).startsWith(`${launch}:`)); + if (!reviewed) return; + die( + rule( + "", + "finish.review", + 'a review already ran in this quick task, so offering it again only loops. Post "Check the fixes" if anything was fixed, then the finish without "review" (building-review.md, "The way back out")', + { finish: { headline: "The review is done", doc: "review", commit: true, changelog: true, dashboard: true } }, + ), + 3, + ); +} + /** * The ledger lines a post's `run` and `folderIssue` stand for, or exit 3 on * the first bad one. Ids are scoped by the skill run in progress, so the same