mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-29 05:11:19 -08:00
Add the Review Loop: unattended review-and-fix rounds in the desktop app and in loop phases
AI Assisted
This commit is contained in:
1 parent
d6a28b5dc8
commit
57567d7a0b
71 files changed
+11331
-443
No files matched your search
@@ -17,7 +17,7 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { applyPatch, blankState, validate, switchWorkflow } from "../src/web-console/patches.mjs";
|
||||
import { applyPatch, blankState, validate, switchWorkflow, ROUND_ROLES } from "../src/web-console/patches.mjs";
|
||||
import { ROOT, CONSOLE_CLI, ENV, HOME, MODELS_DIR, cli, readState, sessionUrl, payload } from "./web-console-test-helpers.mjs";
|
||||
|
||||
const APP_VARS = ["PLAN2CODE_IN_APP", "PLAN2CODE_EMBED_ORIGIN", "PLAN2CODE_APP_ANNOUNCE", "PLAN2CODE_APP_TOKEN", "PLAN2CODE_CONSOLE_SID"];
|
||||
@@ -82,13 +82,13 @@ test("open --loop under the app locks the session: loop { driving: true } in sta
|
||||
}
|
||||
});
|
||||
|
||||
test("open --loop goes only with Implement or Implement + Review: any other workflow, or none, exits 2", () => {
|
||||
test("open --loop goes only with Implement, Implement + Review or Review: any other workflow, or none, exits 2", () => {
|
||||
const cwd = tempProject("gate-wf");
|
||||
const before = sessionCount();
|
||||
for (const args of [["--workflow", "plan"], ["--workflow", "dashboard"], []]) {
|
||||
const res = run(["open", ...args, "--loop", "--no-open"], { cwd, extra: IN_APP });
|
||||
assert.equal(res.status, 2, `exit 2 for ${args.join(" ") || "no workflow"}`);
|
||||
assert.match(res.stderr, /--loop goes only with --workflow implement or --workflow implement-review/);
|
||||
assert.match(res.stderr, /--loop goes only with --workflow implement or --workflow implement-review or --workflow review/);
|
||||
}
|
||||
assert.equal(sessionCount(), before, "no session folder was made");
|
||||
});
|
||||
@@ -546,6 +546,75 @@ test("loopEnd: an unknown evidence id, a push in can, and the other bad fields a
|
||||
}
|
||||
});
|
||||
|
||||
const REPORT_DOC = { id: "report", title: "Review Loop report", blocks: [{ id: "b1", md: "# Clean\n\nNo findings." }] };
|
||||
const PARTIAL_DOC = { id: "partial-diff", title: "partial.diff", blocks: [{ id: "d1", diff: "partial.diff", text: "diff --git a/x b/x\n" }] };
|
||||
const reviewEnd = (extra = {}) => ({
|
||||
kind: "review",
|
||||
line: "Clean after 2 rounds",
|
||||
reason: "clean",
|
||||
report: "report",
|
||||
canContinue: false,
|
||||
canSquash: false,
|
||||
can: [],
|
||||
...extra,
|
||||
});
|
||||
|
||||
test("loopEnd: a review end with each reason is stored, with no phases or uncommitted", () => {
|
||||
for (const reason of ["clean", "cap", "person", "failed"]) {
|
||||
const { problems, next } = tryPatch(loopState(), { docs: [REPORT_DOC], loopEnd: reviewEnd({ reason }) });
|
||||
assert.deepEqual(problems, [], reason);
|
||||
assert.equal(next.loopEnd.reason, reason);
|
||||
assert.equal(next.loopEnd.kind, "review");
|
||||
}
|
||||
const full = reviewEnd({
|
||||
reason: "person",
|
||||
canContinue: true,
|
||||
canSquash: true,
|
||||
partial: { files: 1, added: 2, removed: 0, diff: "partial-diff" },
|
||||
suggestions: [{ id: "s1", title: "Rename it", file: "src/a.js", line: 4 }, { id: "s2", title: "Tidy", file: "" }],
|
||||
open: [{ title: "Unchecked input", file: "src/b.js", line: 9 }, { level: "warning", title: "Slow loop", file: "src/c.js" }],
|
||||
signedOff: true,
|
||||
note: "Squashed 3 round commits into one.",
|
||||
can: ["dashboard"],
|
||||
});
|
||||
const stored = tryPatch(loopState(), { docs: [REPORT_DOC, PARTIAL_DOC], loopEnd: full });
|
||||
assert.deepEqual(stored.problems, []);
|
||||
assert.equal(stored.next.loopEnd.signedOff, true);
|
||||
});
|
||||
|
||||
test("loopEnd: bad review fields are refused, each named", () => {
|
||||
const cases = [
|
||||
["a bad reason", reviewEnd({ reason: "done" }), /loopEnd\.reason must be one of clean, cap, person, failed/],
|
||||
["a missing report", reviewEnd({ report: undefined }), /loopEnd\.report must be the id of a doc on the page/],
|
||||
["an unknown report", reviewEnd({ report: "nope" }), /loopEnd\.report must be the id of a doc on the page/],
|
||||
["a non-boolean canContinue", reviewEnd({ canContinue: "yes" }), /loopEnd\.canContinue must be true or false/],
|
||||
["a non-boolean canSquash", reviewEnd({ canSquash: 1 }), /loopEnd\.canSquash must be true or false/],
|
||||
["a non-boolean signedOff", reviewEnd({ signedOff: "yes" }), /loopEnd\.signedOff must be true or false/],
|
||||
["can that is not an array", reviewEnd({ can: undefined }), /loopEnd\.can must be an array/],
|
||||
["a two-line note", reviewEnd({ note: "a\nb" }), /loopEnd\.note must be one line/],
|
||||
["a two-line line", reviewEnd({ line: "a\nb" }), /loopEnd\.line must be one line/],
|
||||
["a partial with an unknown diff", reviewEnd({ partial: { files: 1, added: 1, removed: 1, diff: "nope" } }), /loopEnd\.partial\.diff must be the id of a doc on the page/],
|
||||
["a negative partial count", reviewEnd({ partial: { files: -1, added: 1, removed: 1, diff: "report" } }), /loopEnd\.partial\.files must be a non-negative integer/],
|
||||
["a suggestion with a bad id", reviewEnd({ suggestions: [{ id: "x", title: "T", file: "" }] }), /loopEnd\.suggestions\[0\]\.id must look like s1/],
|
||||
["duplicate suggestion ids", reviewEnd({ suggestions: [{ id: "s1", title: "A", file: "" }, { id: "s1", title: "B", file: "" }] }), /loopEnd\.suggestions\[1\]\.id must be unique/],
|
||||
["a suggestion file that climbs out", reviewEnd({ suggestions: [{ id: "s1", title: "A", file: "../x" }] }), /loopEnd\.suggestions\[0\]\.file must be a relative path/],
|
||||
["a suggestion line of zero", reviewEnd({ suggestions: [{ id: "s1", title: "A", file: "a.js", line: 0 }] }), /loopEnd\.suggestions\[0\]\.line must be a positive integer/],
|
||||
["an open item with no file", reviewEnd({ open: [{ title: "A" }] }), /loopEnd\.open\[0\]\.file must be a relative path/],
|
||||
["an open item with a bad level", reviewEnd({ open: [{ level: "info", title: "A", file: "a.js" }] }), /loopEnd\.open\[0\]\.level must be/],
|
||||
["a forbidden marker in line", reviewEnd({ line: "TASK_COMPLETE" }), /loopEnd\.line: contains a loop completion marker/],
|
||||
];
|
||||
for (const [what, end, expected] of cases) {
|
||||
const { problems } = tryPatch(loopState(), { docs: [REPORT_DOC], loopEnd: end });
|
||||
assert.ok(problems.some((p) => expected.test(p)), `${what}: expected ${expected}, got ${JSON.stringify(problems)}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("loopEnd: an Implementation Loop end still needs its phases and uncommitted, and review ones never need evidence", () => {
|
||||
assert.deepEqual(tryPatch(loopState(), { loopEnd: goodEnd() }).problems, []);
|
||||
const { phases, ...noPhases } = goodEnd();
|
||||
assert.ok(tryPatch(loopState(), { loopEnd: noPhases }).problems.some((p) => /loopEnd\.phases must be an array/.test(p)));
|
||||
});
|
||||
|
||||
test("handledBy: \"loop\" is accepted in a loop session and refused outside one or with any other value", () => {
|
||||
const card = (extra = {}) => ({
|
||||
id: "fixes",
|
||||
@@ -604,6 +673,7 @@ test("loop-setup: a new project reads as the defaults with remembered false, and
|
||||
assert.equal(got.setup.onQuestion, "guess");
|
||||
assert.deepEqual(got.setup.fix, ["critical", "warning", "suggestion"]);
|
||||
assert.equal(got.setup.silenceMinutes, 20);
|
||||
assert.equal(got.setup.reviewRounds, 2, "a phase gets two extra review rounds by default");
|
||||
assert.equal(got.setup.notifyUrl, "", "no web address is called by default");
|
||||
assert.equal(got.setup.notifyKind, "query");
|
||||
assert.equal(got.setup.notifyParam, "message");
|
||||
@@ -658,6 +728,38 @@ test("loop-setup: a save reads back per project, keeps another project's entry,
|
||||
|
||||
const WORKSPACE_URL = pathToFileURL(path.join(ROOT, "src", "web-console", "workspace.mjs")).href;
|
||||
|
||||
test("loop-setup: an entry saved before reviewRounds existed reads the default 2", () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const got = inStore(
|
||||
async (m, { project, workspace }) => {
|
||||
const fs = await import("node:fs");
|
||||
const { foldKey } = await import(workspace);
|
||||
const { reviewRounds, ...legacy } = { ...m.LOOP_DEFAULTS, fix: ["warning"], saved: "2026-01-01T00:00:00.000Z" };
|
||||
fs.writeFileSync(m.LOOP_SETUP_FILE, JSON.stringify({ schema: 1, projects: { [foldKey(project)]: legacy } }));
|
||||
const stored = JSON.parse(fs.readFileSync(m.LOOP_SETUP_FILE, "utf8")).projects[foldKey(project)];
|
||||
const kept = m.saveLoopSetup(project, { ...m.LOOP_DEFAULTS, fix: ["warning"], reviewRounds: 0 });
|
||||
return { read: m.readLoopSetup(project), onDisk: "reviewRounds" in stored, kept: kept.reviewRounds };
|
||||
},
|
||||
{ project: projectA, workspace: WORKSPACE_URL }
|
||||
);
|
||||
assert.equal(got.onDisk, false, "the stored entry has no reviewRounds");
|
||||
assert.equal(got.kept, 0, "0 turns the rounds off and is remembered");
|
||||
assert.equal(got.read.reviewRounds, 0);
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const old = inStore(
|
||||
async (m, { project, workspace }) => {
|
||||
const fs = await import("node:fs");
|
||||
const { foldKey } = await import(workspace);
|
||||
const { reviewRounds, ...legacy } = { ...m.LOOP_DEFAULTS, fix: ["warning"], saved: "2026-01-01T00:00:00.000Z" };
|
||||
fs.writeFileSync(m.LOOP_SETUP_FILE, JSON.stringify({ schema: 1, projects: { [foldKey(project)]: legacy } }));
|
||||
return m.readLoopSetup(project);
|
||||
},
|
||||
{ project: projectA, workspace: WORKSPACE_URL }
|
||||
);
|
||||
assert.equal(old.reviewRounds, 2, "an older entry reads the default");
|
||||
assert.equal(old.remembered, true);
|
||||
});
|
||||
|
||||
test("loop-setup: an entry saved before fixMode existed reads as levels", () => {
|
||||
fs.rmSync(LOOP_SETUP_PATH, { force: true });
|
||||
const got = inStore(
|
||||
@@ -724,6 +826,7 @@ test("loop-setup: a bad field throws with the problem named and leaves the file
|
||||
const cases = [
|
||||
["silenceMinutes: 0", { silenceMinutes: 0 }, /"silenceMinutes" must be a whole number from 1 to 60/],
|
||||
["silenceMinutes: 61", { silenceMinutes: 61 }, /"silenceMinutes"/],
|
||||
...[-1, 7, 1.5, "2", null].map((reviewRounds) => [`reviewRounds: ${reviewRounds}`, { reviewRounds }, /"reviewRounds" must be a whole number from 0 to 6/]),
|
||||
...["example.com", "ftp://example.com", "javascript:alert(1)", "https:/example.com", "https://", "https://me:secret@example.com/", "https://exa mple.com", "https://example.com/é", "https://example.com/\nx", `https://e.com/${"x".repeat(2000)}`].map((notifyUrl) => [`notifyUrl: ${notifyUrl.slice(0, 30)}`, { notifyUrl }, /"notifyUrl" must be an http or https web address/]),
|
||||
["notifyUrl as a number", { notifyUrl: 5 }, /"notifyUrl"/],
|
||||
["notifyKind: carrier-pigeon", { notifyKind: "carrier-pigeon" }, /"notifyKind" must be one of query, discord, slack, teams, google-chat, json/],
|
||||
@@ -854,7 +957,7 @@ test("loop-setup: GET /loop-setup lists the phases left for a spec and refuses a
|
||||
}
|
||||
|
||||
// Saving through the route, then reading it back in a new request.
|
||||
const save = await send({ review: true, fixMode: "smart", fix: ["critical"], commit: true, onQuestion: "stop", afterLast: "offer-finalize", quickCheck: "", notifyKind: "query", notifyUrl: "https://example.com/hook", notifyParam: "msg", notifyPhases: true, retryOnce: true, silenceMinutes: 30, phaseStrength: false, strengths: {} });
|
||||
const save = await send({ review: true, reviewRounds: 3, fixMode: "smart", fix: ["critical"], commit: true, onQuestion: "stop", afterLast: "offer-finalize", quickCheck: "", notifyKind: "query", notifyUrl: "https://example.com/hook", notifyParam: "msg", notifyPhases: true, retryOnce: true, silenceMinutes: 30, phaseStrength: false, strengths: {} });
|
||||
assert.equal(save.status, 200, await save.clone().text());
|
||||
const after = await get("?spec=specs/demo");
|
||||
assert.equal(after.body.remembered, true);
|
||||
@@ -1024,7 +1127,7 @@ test("GET /loop-setup?agent= answers the loop agent's resolved strengths and thi
|
||||
// A save with picks reads back for its own spec; a pick for a phase that is not there is pruned.
|
||||
const entry = {
|
||||
review: true, fixMode: "smart", fix: ["critical"], commit: true, onQuestion: "guess", afterLast: "offer-finalize", quickCheck: "",
|
||||
notifyKind: "query", notifyUrl: "", notifyParam: "message", notifyPhases: false, retryOnce: true, silenceMinutes: 20, phaseStrength: true,
|
||||
notifyKind: "query", notifyUrl: "", notifyParam: "message", notifyPhases: false, retryOnce: true, silenceMinutes: 20, reviewRounds: 2, phaseStrength: true,
|
||||
strengths: { "specs/demo": [{ n: 2, name: "Two", strength: "best" }, { n: 9, name: "Gone", strength: "best" }] },
|
||||
};
|
||||
const save = await fetch(`${base}/loop-setup`, { method: "POST", headers: { "content-type": "application/json", cookie, origin: base, connection: "close" }, body: JSON.stringify(entry) });
|
||||
@@ -1078,3 +1181,226 @@ test("loopSuggest: each bad field is refused with a message naming it", () => {
|
||||
assert.ok(got.problems.some((p) => pattern.test(p)), `${label}: ${got.problems.join(" | ") || "accepted"}`);
|
||||
}
|
||||
});
|
||||
|
||||
/* -------------------------------------- Review Loop rounds: open and report */
|
||||
|
||||
const ROUND_FLAGS = (scope) => ["--round", "2", "--role", "both", "--scope-file", scope];
|
||||
|
||||
function openRound(name = "round", flags = {}) {
|
||||
const cwd = tempProject(name);
|
||||
const scope = path.join(cwd, "scope.md");
|
||||
fs.writeFileSync(scope, "Scope: the branch diff\n");
|
||||
const args = ["open", "--workflow", "review", "--loop", "--no-open", "--round", String(flags.round ?? 2), "--role", flags.role ?? "both", "--scope-file", scope];
|
||||
const res = run(args, { cwd, extra: IN_APP });
|
||||
assert.equal(res.status, 0, res.stderr);
|
||||
const stop = () => cli(["stop", "--session", res.json.sid, "--force"], { cwd, expectFail: true });
|
||||
return { cwd, sid: res.json.sid, session: res.json.session, scope, json: res.json, stop };
|
||||
}
|
||||
|
||||
test("a Review Loop round opens only with --round, --role and --scope-file, each checked, exit 2 naming the flag", () => {
|
||||
const cwd = tempProject("round-gate");
|
||||
const scope = path.join(cwd, "scope.md");
|
||||
fs.writeFileSync(scope, "x");
|
||||
const before = sessionCount();
|
||||
const base = ["open", "--workflow", "review", "--loop", "--no-open"];
|
||||
const cases = [
|
||||
[["--role", "both", "--scope-file", scope], /--round/],
|
||||
[["--round", "2", "--scope-file", scope], /--role/],
|
||||
[["--round", "2", "--role", "both"], /--scope-file/],
|
||||
[["--round", "0", "--role", "both", "--scope-file", scope], /--round/],
|
||||
[["--round", "x", "--role", "both", "--scope-file", scope], /--round/],
|
||||
[["--round", "2", "--role", "boss", "--scope-file", scope], /--role/],
|
||||
[["--round", "2", "--role", "both", "--scope-file", path.join(cwd, "nope.md")], /--scope-file/],
|
||||
];
|
||||
for (const [flags, pattern] of cases) {
|
||||
const res = run([...base, ...flags], { cwd, extra: IN_APP });
|
||||
assert.equal(res.status, 2, flags.join(" "));
|
||||
assert.match(res.stderr, pattern);
|
||||
}
|
||||
assert.equal(sessionCount(), before, "no session folder was made");
|
||||
});
|
||||
|
||||
test("the round flags are refused on an Implement loop open and without --loop, and outside the app a round open exits 3", () => {
|
||||
const cwd = tempProject("round-other");
|
||||
const scope = path.join(cwd, "scope.md");
|
||||
fs.writeFileSync(scope, "x");
|
||||
const withRound = ROUND_FLAGS(scope);
|
||||
assert.equal(run(["open", "--workflow", "implement", "--loop", "--no-open", ...withRound], { cwd, extra: IN_APP }).status, 2);
|
||||
assert.equal(run(["open", "--workflow", "review", "--no-open", ...withRound], { cwd, extra: IN_APP }).status, 2);
|
||||
const outside = run(["open", "--workflow", "review", "--loop", "--no-open", ...withRound], { cwd });
|
||||
assert.equal(outside.status, 3);
|
||||
assert.match(outside.stderr, /desktop app/);
|
||||
});
|
||||
|
||||
test("a round session is stamped with its round, role and scope file, and its open names the round notes", () => {
|
||||
const s = openRound("round-stamp", { round: 3, role: "reviewer" });
|
||||
try {
|
||||
assert.deepEqual(readState(s.session).loop, { driving: true, round: 3, role: "reviewer", scopeFile: s.scope });
|
||||
assert.deepEqual(s.json.read, [path.join(path.dirname(CONSOLE_CLI), "notes", "review-loop.md")]);
|
||||
const again = run(["open", "--resume", s.sid, "--workflow", "review", "--loop", "--no-open", "--round", "3", "--role", "reviewer", "--scope-file", s.scope], { cwd: s.cwd, extra: IN_APP });
|
||||
assert.equal(again.status, 0, again.stderr);
|
||||
assert.equal(readState(s.session).loop.round, 3);
|
||||
} finally {
|
||||
s.stop();
|
||||
}
|
||||
// An Implement loop keeps its stamp exactly as it was.
|
||||
const impl = openLoop("implement", "round-impl");
|
||||
try {
|
||||
assert.deepEqual(readState(impl.session).loop, { driving: true });
|
||||
} finally {
|
||||
impl.stop();
|
||||
}
|
||||
});
|
||||
|
||||
// A round session's state as post would see it: the stamp, and the report doc.
|
||||
const roundState = (role = "both", extra = {}) => ({
|
||||
...blankState({ sid: "s", workflow: "review", project: "p" }),
|
||||
loop: { driving: true, round: 2, role, scopeFile: "scope.md" },
|
||||
docs: [{ id: "report", title: "Report", version: 1, stale: false, blocks: [{ id: "b", md: "Findings" }] }],
|
||||
...extra,
|
||||
});
|
||||
const goodRound = (role = "both") => ({
|
||||
round: 2,
|
||||
role,
|
||||
result: "passed",
|
||||
reason: null,
|
||||
summary: "Fixed 2 warnings; 1 suggestion left",
|
||||
report: "report",
|
||||
review: {
|
||||
critical: 0,
|
||||
warning: 2,
|
||||
suggestion: 1,
|
||||
fixed: [{ title: "Close the file handle", file: "src/z.js", line: 12 }],
|
||||
unfixed: [],
|
||||
suggestions: [{ title: "Name the timer", file: "src/x.js" }],
|
||||
},
|
||||
tests: { ran: true, passed: true, summary: "14 pass" },
|
||||
subject: "Close the file handle in z.js",
|
||||
});
|
||||
|
||||
test("a roundOutcome is stored with its report doc in the session, once, for each role", () => {
|
||||
assert.deepEqual(ROUND_ROLES, ["both", "reviewer", "fixer"]);
|
||||
for (const role of ROUND_ROLES) {
|
||||
const o = goodRound(role);
|
||||
if (role === "reviewer") delete o.tests;
|
||||
if (role === "fixer") delete o.report;
|
||||
const got = tryPatch(roundState(role, role === "fixer" ? { docs: [] } : {}), { roundOutcome: o });
|
||||
assert.deepEqual(got.problems, [], role);
|
||||
assert.deepEqual(got.next.roundOutcome, o);
|
||||
}
|
||||
const first = tryPatch(roundState(), { roundOutcome: goodRound() });
|
||||
const second = tryPatch(first.next, { roundOutcome: goodRound() });
|
||||
assert.match(second.problems.join(" "), /roundOutcome: was already posted/);
|
||||
});
|
||||
|
||||
test("a roundOutcome with no report doc is refused naming roundOutcome.report", () => {
|
||||
for (const role of ["both", "reviewer"]) {
|
||||
const missing = tryPatch(roundState(role, { docs: [] }), { roundOutcome: goodRound(role) });
|
||||
assert.match(missing.problems.join(" "), /roundOutcome\.report must name a report doc already posted in this session/, role);
|
||||
}
|
||||
const wrong = tryPatch(roundState(), { roundOutcome: { ...goodRound(), report: "other" } });
|
||||
assert.match(wrong.problems.join(" "), /roundOutcome\.report/);
|
||||
});
|
||||
|
||||
test("each bad roundOutcome field is refused with a message naming it", () => {
|
||||
const mut = (fn, role = "both") => {
|
||||
const o = goodRound(role);
|
||||
fn(o);
|
||||
return tryPatch(roundState(role), { roundOutcome: o }).problems.join(" | ");
|
||||
};
|
||||
const cases = [
|
||||
["round", (o) => (o.round = 3), /roundOutcome\.round/],
|
||||
["round type", (o) => (o.round = "2"), /roundOutcome\.round/],
|
||||
["role", (o) => (o.role = "fixer"), /roundOutcome\.role/],
|
||||
["result", (o) => (o.result = "maybe"), /roundOutcome\.result/],
|
||||
["reason when passed", (o) => (o.reason = "tests"), /roundOutcome\.reason/],
|
||||
["reason when failed", (o) => ((o.result = "failed"), (o.reason = "nope")), /roundOutcome\.reason/],
|
||||
["summary empty", (o) => (o.summary = ""), /roundOutcome\.summary/],
|
||||
["summary long", (o) => (o.summary = "x".repeat(201)), /roundOutcome\.summary/],
|
||||
["summary lines", (o) => (o.summary = "a\nb"), /roundOutcome\.summary/],
|
||||
["subject long", (o) => (o.subject = "x".repeat(101)), /roundOutcome\.subject/],
|
||||
["review missing", (o) => delete o.review, /roundOutcome\.review /],
|
||||
["review count", (o) => (o.review.warning = -1), /roundOutcome\.review\.warning/],
|
||||
["review list", (o) => (o.review.fixed = "none"), /roundOutcome\.review\.fixed/],
|
||||
["review list size", (o) => (o.review.unfixed = Array.from({ length: 51 }, () => ({ title: "t", file: "a.js" }))), /roundOutcome\.review\.unfixed/],
|
||||
["finding file", (o) => (o.review.fixed[0].file = "../x"), /roundOutcome\.review\.fixed\[0\]\.file/],
|
||||
["finding line", (o) => (o.review.fixed[0].line = 0), /roundOutcome\.review\.fixed\[0\]\.line/],
|
||||
["tests missing", (o) => delete o.tests, /roundOutcome\.tests /],
|
||||
["tests passed", (o) => (o.tests.passed = "yes"), /roundOutcome\.tests\.passed/],
|
||||
["completion marker", (o) => (o.summary = "TASK_COMPLETE"), /roundOutcome\.summary/],
|
||||
];
|
||||
for (const [label, fn, pattern] of cases) assert.match(mut(fn), pattern, label);
|
||||
});
|
||||
|
||||
test("a roundOutcome outside a round session is refused, and a loopOutcome in a round session is refused", () => {
|
||||
const plain = tryPatch({ ...blankState({ sid: "s", workflow: "review", project: "p" }) }, { roundOutcome: goodRound() });
|
||||
assert.match(plain.problems.join(" "), /roundOutcome: is only accepted in a Review Loop round session/);
|
||||
const impl = tryPatch(loopState(), { roundOutcome: goodRound() });
|
||||
assert.match(impl.problems.join(" "), /roundOutcome: is only accepted in a Review Loop round session/);
|
||||
const viaLoop = tryPatch(roundState(), { loopOutcome: goodOutcome() });
|
||||
assert.match(viaLoop.problems.join(" "), /a round reports roundOutcome, not loopOutcome/);
|
||||
});
|
||||
|
||||
test("blankState holds no roundOutcome and a hop drops it", () => {
|
||||
assert.equal("roundOutcome" in blankState({ sid: "s", workflow: "review", project: "p" }), false);
|
||||
const hopped = switchWorkflow(roundState("both", { roundOutcome: goodRound() }), { workflow: "plan", title: "t", specDir: "" });
|
||||
assert.equal("roundOutcome" in hopped, false);
|
||||
assert.equal("loop" in hopped, false);
|
||||
});
|
||||
|
||||
test("a resume drops a stored roundOutcome and report doc when the round or role changes or the lock goes, and keeps them otherwise", () => {
|
||||
const s = openRound("round-resume", { round: 2, role: "reviewer" });
|
||||
const resume = (flags) => run(["open", "--resume", s.sid, "--no-open", ...flags], { cwd: s.cwd, extra: IN_APP });
|
||||
const loopFlags = (round, role) => ["--workflow", "review", "--loop", "--round", String(round), "--role", role, "--scope-file", s.scope];
|
||||
const seed = () => {
|
||||
const o = goodRound("reviewer");
|
||||
delete o.tests;
|
||||
const res = post(s, { docs: [{ id: "report", title: "Report", blocks: [{ id: "b1", md: "Findings" }] }], roundOutcome: o });
|
||||
assert.equal(res.status, 0, res.stderr);
|
||||
assert.ok(readState(s.session).roundOutcome, "seeded");
|
||||
};
|
||||
try {
|
||||
seed();
|
||||
assert.equal(resume(loopFlags(2, "reviewer")).status, 0);
|
||||
assert.ok(readState(s.session).roundOutcome, "the same round and role keeps its report");
|
||||
assert.ok(readState(s.session).docs.some((d) => d.id === "report"));
|
||||
assert.equal(resume(loopFlags(2, "fixer")).status, 0);
|
||||
let state = readState(s.session);
|
||||
assert.equal("roundOutcome" in state, false, "a new role starts without the old report");
|
||||
assert.equal(state.docs.some((d) => d.id === "report"), false, "and without the old report doc");
|
||||
assert.equal(state.loop.role, "fixer");
|
||||
// The fixer's own report is now accepted.
|
||||
const o = goodRound("fixer");
|
||||
delete o.report;
|
||||
assert.equal(post(s, { roundOutcome: o }).status, 0);
|
||||
assert.equal(resume(loopFlags(3, "fixer")).status, 0);
|
||||
assert.equal("roundOutcome" in readState(s.session), false, "a new round starts without the old report");
|
||||
seedFixer(s);
|
||||
assert.equal(resume(["--workflow", "review"]).status, 0);
|
||||
state = readState(s.session);
|
||||
assert.equal("roundOutcome" in state, false, "a resume without --loop drops the report");
|
||||
assert.equal("loop" in state, false);
|
||||
} finally {
|
||||
s.stop();
|
||||
}
|
||||
function seedFixer(sess) {
|
||||
const o = goodRound("fixer");
|
||||
o.round = 3;
|
||||
delete o.report;
|
||||
const res = run(["open", "--resume", sess.sid, "--no-open", ...loopFlags(3, "fixer")], { cwd: sess.cwd, extra: IN_APP });
|
||||
assert.equal(res.status, 0);
|
||||
assert.equal(post(sess, { roundOutcome: o }).status, 0);
|
||||
}
|
||||
});
|
||||
|
||||
test("a round session's scope file is stored as an absolute path", () => {
|
||||
const cwd = tempProject("round-scope");
|
||||
fs.writeFileSync(path.join(cwd, "scope.md"), "x");
|
||||
const res = run(["open", "--workflow", "review", "--loop", "--no-open", "--round", "1", "--role", "both", "--scope-file", "scope.md"], { cwd, extra: IN_APP });
|
||||
try {
|
||||
assert.equal(res.status, 0, res.stderr);
|
||||
assert.equal(readState(res.json.session).loop.scopeFile, path.join(cwd, "scope.md"));
|
||||
} finally {
|
||||
cli(["stop", "--session", res.json.sid, "--force"], { cwd, expectFail: true });
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user