Add the Review Loop: unattended review-and-fix rounds in the desktop app and in loop phases

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-28 21:09:02 -08:00
1 parent d6a28b5dc8
commit 57567d7a0b
71 files changed
+11331 -443

No files matched your search

+7
View File
@@ -118,6 +118,13 @@ test("loadAgentList: the shipped agents.json loads with 3 built-ins and 5 templa
assert.deepEqual(templates.map((a) => a.id), ["copilot", "opencode", "gemini", "pi", "cursor"]);
});
test("loadAgentList: helpers is true for claude, false for every other shipped entry and for one without the key", (t) => {
const { builtins, templates } = loadAgentList({ dir: path.join(ROOT, "src", "launcher") });
for (const a of [...builtins, ...templates]) assert.equal(a.helpers, a.id === "claude", a.id);
const dir = listDir(t, JSON.stringify({ schema: 1, agents: [{ kind: "template", id: "x", name: "X", command: "x" }, { kind: "template", id: "y", name: "Y", command: "y", helpers: "yes" }] }));
assert.deepEqual(loadAgentList({ dir }).templates.map((a) => a.helpers), [false, false]);
});
test("every shipped template passes normalizeAgents() with no warnings", () => {
const { templates } = loadAgentList({ dir: path.join(ROOT, "src", "launcher") });
const { agents, warnings } = normalizeAgents(JSON.stringify({ schema: 1, agents: templates }));
+90 -2
View File
@@ -471,8 +471,9 @@ test("the stop buttons: Stop after is a toggle, off on the last phase, and both
test("app.js sends the toggle's wish and shows a failed press with a Retry", () => {
const app = fs.readFileSync(path.join(HERE, "..", "plan2code-app", "ui", "app.js"), "utf8");
assert.match(app, /invoke\(command, args\)\.then\(hideLoopError/, "a good press clears the error");
assert.match(app, /pressLoop\('loop_stop_after_phase', \{ on: !loopStopAfterOn \}\)/);
assert.match(app, /pressLoop\('loop_stop_now'\)/);
// The press goes to the phase commands for an Implementation Loop and to the Review Loop's own for rounds.
assert.match(app, /'loop_stop_after_phase', \{ on: !loopStopAfterOn \}\)/);
assert.match(app, /: 'loop_stop_now'\)/);
assert.match(app, /loopRetryBtn\.hidden = false/, "a failed press offers Retry");
const html = fs.readFileSync(path.join(HERE, "..", "plan2code-app", "ui", "index.html"), "utf8");
assert.match(html, /id="loop-error"[^>]*hidden/);
@@ -570,6 +571,93 @@ test("the banner and stop buttons agree for a state carrying stopping, stopAfter
assert.equal(loopStopLabels(last).afterDisabled, true);
});
// The Review Loop's banner: the same states in round words, one pip per round, and the detail the app builds.
const ROUNDS = { running: true, kind: "rounds", round: 2, rounds: 3, phase: 2, phases: 3, phaseName: "Round 2 of 3: Reviewing", step: "Reviewing", stopAfterRound: false, stopAfterPhase: false, stopping: false, canStopAfter: true, phaseRetried: false, roundCounts: [{ critical: 2, warning: 1 }] };
test("a rounds state says Review Loop, with one pip per round and the app's detail line", () => {
const banner = loopBanner(ROUNDS);
assert.equal(banner.title, "Review Loop running");
assert.equal(banner.detail, "Round 2 of 3: Reviewing");
assert.equal(banner.tone, "running");
assert.deepEqual(banner.pips, ["done", "current", "todo"]);
assert.deepEqual(loopBanner({ ...ROUNDS, round: 1 }).pips, ["current", "todo", "todo"]);
assert.deepEqual(loopBanner({ ...ROUNDS, round: 3 }).pips, ["done", "done", "current"]);
assert.deepEqual(loopBanner({ ...ROUNDS, rounds: 6, round: 4 }).pips, ["done", "done", "done", "current", "todo", "todo"]);
});
test("a rounds state in each step: fixing with counts, starting, retrying, waiting, stopping, stop after this round", () => {
const fixing = loopBanner({ ...ROUNDS, step: "Fixing", phaseName: "Round 2 of 3: Fixing 3 findings (1 Critical, 2 Warning)" });
assert.equal(fixing.title, "Review Loop running");
assert.equal(fixing.detail, "Round 2 of 3: Fixing 3 findings (1 Critical, 2 Warning)");
// Without the app's detail line the banner builds the plain one from the round and step.
assert.equal(loopBanner({ ...ROUNDS, step: "Testing", phaseName: "" }).detail, "Round 2 of 3: Testing");
assert.equal(loopBanner({ ...ROUNDS, step: "Testing", phaseName: "Round 2 of 3: Testing", model: "sonnet", effort: "low", strength: "thrifty" }).detail, "Round 2 of 3: Testing \u00b7 Thrifty (sonnet, low)");
const first = loopBanner({ ...ROUNDS, round: 1, step: "Starting" });
assert.equal(first.title, "Starting the Review Loop");
assert.equal(first.detail, "Opening a fresh agent for Round 1 of 3.");
const next = loopBanner({ ...ROUNDS, step: "Starting" });
assert.equal(next.title, "Round 1 done");
assert.equal(next.detail, "Opening a fresh agent for Round 2 of 3.");
const retry = loopBanner({ ...ROUNDS, step: "Starting", phaseRetried: true });
assert.equal(retry.title, "Retrying round 2");
assert.match(retry.detail, /crashed or went quiet, so a fresh one is picking up Round 2 of 3/);
const waiting = loopBanner({ ...ROUNDS, step: "Waiting on you" });
assert.equal(waiting.title, "The Review Loop needs your answer");
assert.equal(waiting.tone, "waiting");
assert.equal(waiting.detail, "Round 2 of 3 is waiting on the question below.");
const stopping = loopBanner({ ...ROUNDS, stopping: true });
assert.equal(stopping.title, "Stopping");
assert.deepEqual(stopping.pips, ["done", "current", "todo"]);
const after = loopBanner({ ...ROUNDS, stopAfterRound: true, stopAfterPhase: true });
assert.equal(after.title, "Stopping after this round");
assert.match(after.detail, /Round 2 of 3 finishes, is judged and committed, then the Review Loop stops/);
});
test("a rounds state's stop buttons and window title use round words", () => {
assert.deepEqual(loopStopLabels(ROUNDS), { afterText: "Stop after this round", afterDisabled: false, nowDisabled: false });
assert.deepEqual(loopStopLabels({ ...ROUNDS, stopAfterRound: true }), { afterText: "Cancel stop after this round", afterDisabled: false, nowDisabled: false });
assert.equal(loopStopLabels({ ...ROUNDS, canStopAfter: false }).afterDisabled, true, "the cap round has nothing to stop after");
assert.deepEqual(loopStopLabels({ ...ROUNDS, stopping: true }), { afterText: "Stop after this round", afterDisabled: true, nowDisabled: true });
assert.equal(loopWindowTitle("C:/git/lunch", ROUNDS), "Review Loop: Round 2 of 3 - lunch");
assert.equal(loopWindowTitle("C:/git/lunch", { ...ROUNDS, step: "Waiting on you" }), "Review Loop needs you: Round 2 - lunch");
});
test("the Suggestions batch and final check are named for what they are, never as a round past the cap", () => {
const batch = { ...ROUNDS, round: 3, phase: 3, afterRounds: "Suggestions batch", phaseName: "Suggestions batch: Fixing", step: "Fixing" };
const shown = loopBanner(batch);
assert.equal(shown.detail, "Suggestions batch: Fixing");
assert.deepEqual(shown.pips, ["done", "done", "done"]);
assert.equal(loopBanner({ ...batch, step: "Starting" }).detail, "Opening a fresh agent for the suggestions batch.");
assert.equal(loopWindowTitle("C:/git/lunch", { ...batch, afterRounds: "Final check" }), "Review Loop: Final check - lunch");
assert.doesNotMatch(JSON.stringify(shown), /Round 4|of 3: Fixing/);
});
test("a phases state renders exactly as before, whatever kind it names", () => {
const phases = { running: true, phase: 2, phases: 4, phaseName: "API", step: "Build", stopAfterPhase: false, stopping: false, canStopAfter: true };
const plain = loopBanner(phases);
assert.equal(plain.title, "Implementation loop running");
assert.equal(plain.detail, "Phase 2 of 4: API \u00b7 Build");
assert.deepEqual(plain.pips, ["done", "current", "todo", "todo"]);
assert.deepEqual(loopBanner({ ...phases, kind: "phases", round: 0, rounds: 0, roundCounts: [], stopAfterRound: false }), plain);
assert.deepEqual(loopStopLabels({ ...phases, kind: "phases" }), loopStopLabels(phases));
assert.equal(loopWindowTitle("C:/git/lunch", { ...phases, kind: "phases" }), "Loop: Phase 2 of 4 - lunch");
});
test("app.js hangs round counts on the pips and sends the Review Loop's stop buttons to its own commands", () => {
assert.match(APP_JS, /function roundPipTitle\(state, i\)/);
assert.match(APP_JS, /pip\.title = roundPipTitle\(state, i\)/);
const title = APP_JS.slice(APP_JS.indexOf("function roundPipTitle"), APP_JS.indexOf("function applyLoopState"));
assert.match(title, /if \(state\.kind !== 'rounds'\) return `Phase \$\{i \+ 1\}`/, "a phases pip keeps its title");
assert.match(title, /Round \$\{i \+ 1\}: \$\{found\.length \? found\.join\(', '\) : 'nothing found'\}/);
assert.match(APP_JS, /pressLoop\(loopKind === 'rounds' \? 'review_loop_stop_after' : 'loop_stop_after_phase'/);
assert.match(APP_JS, /pressLoop\(rounds \? 'review_loop_stop_now' : 'loop_stop_now'\)/);
assert.match(APP_JS, /loopStopAfterOn = !!\(state\.kind === 'rounds' \? state\.stopAfterRound : state\.stopAfterPhase\)/);
});
test("app.js asks loop_state after attach and again once it listens, without calling a reload a loop's end", () => {
assert.match(APP_JS, /async function syncLoopState\(\)[\s\S]*?invoke\('loop_state'\)/);
assert.match(APP_JS, /\.listen\('loop-state'[\s\S]*?\.then\(syncLoopState/, "asked again once the listener is up");
+2 -1
View File
@@ -43,7 +43,8 @@ export const BUDGETS = {
"plan.md": 1023, // raised by the UI prototype line's bytes only
"pr-prep.md": 4500,
"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
"review-loop.md": 4000, // its written size (3,564 bytes) plus 10 percent, rounded up to the next 100
"review.md": 1190, // raised by the lessons card line's bytes, then the Review Loop pointer 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
"ui-prototype.md": 4600,
+2
View File
@@ -120,6 +120,7 @@
"test-web-console-page-help.mjs",
"test-web-console-page-learning.mjs",
"test-web-console-page-loop.mjs",
"test-web-console-page-review-loop.mjs",
"test-web-console-page-notepad.mjs",
"test-web-console-page-prefs.mjs",
"test-web-console-page-send.mjs",
@@ -128,6 +129,7 @@
"test-web-console-page-workspace.mjs",
"test-web-console-pointers.mjs",
"test-web-console-qa.mjs",
"test-web-console-review-loop.mjs",
"test-web-console-server.mjs",
"test-web-console-session.mjs",
"test-web-console-source.mjs",
+331 -5
View File
@@ -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 });
}
});
+34
View File
@@ -956,3 +956,37 @@ test("a pick for an unmapped word, or a phase left out, keeps that row as it was
assert.deepEqual((await strengthRows(s)).map((r) => r.pick), ["", "thrifty"]);
assert.equal(await s.page.locator(".loop-strength-why").count(), 0, "no reason shows for a pick that was not applied");
});
test("Review rounds per phase shows under Review, is off with Review off, and goes out with the setup", async (t) => {
const s = await openSetup(t);
const rounds = s.page.locator("#loop-review-rounds");
const field = s.page.locator(".loop-field", { hasText: "Review each phase with a fresh agent" });
assert.equal(await field.locator("#loop-review-rounds").count(), 1, "the number sits in the Review field");
assert.equal(await rounds.inputValue(), "2", "two rounds by default");
assert.deepEqual(await rounds.evaluate((el) => [el.min, el.max, el.disabled]), ["0", "6", false]);
assert.equal(await field.getByText("Applies only with Review on").count(), 0, "no hint while Review is on");
await rounds.fill("4");
await s.page.locator("#loop-review").uncheck();
assert.equal(await rounds.isDisabled(), true, "Review off disables the field");
assert.equal(await field.getByText("Applies only with Review on").count(), 1);
assert.equal(await rounds.inputValue(), "4", "the number is kept while it is off");
await s.page.locator("#loop-review").check();
assert.equal(await rounds.isDisabled(), false);
const body = await s.page.evaluate(async () => {
const { page } = await import(new URL("state.js", document.baseURI).href);
const { setupBody } = await import(new URL("screens/loop-setup.js", document.baseURI).href);
return setupBody(page.loopSetup.form, page.loopSetup);
});
assert.equal(body.reviewRounds, 4, "the number is in the posted body");
const saved = await s.page.evaluate(async () => {
const { page } = await import(new URL("state.js", document.baseURI).href);
const { setupBody } = await import(new URL("screens/loop-setup.js", document.baseURI).href);
const res = await fetch("/loop-setup", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(setupBody(page.loopSetup.form, page.loopSetup)) });
return { status: res.status, body: await res.json() };
});
assert.equal(saved.status, 200, JSON.stringify(saved.body));
const reread = await s.page.evaluate(async () => (await fetch("/loop-setup")).json());
assert.equal(reread.reviewRounds, 4, "remembered with the rest of the setup");
});
@@ -0,0 +1,421 @@
// 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);
});
+199
View File
@@ -0,0 +1,199 @@
// Web console tests: the Review Loop's setup store and its route. Run with:
// node --test scripts/test-web-console-review-loop.mjs
//
// The store (review-loop-setup.mjs) keeps one entry per project in
// review-loop-setup.json; GET and POST /review-loop-setup serve it. The
// store fixes its file at import time from PLAN2CODE_CONSOLE_HOME, so it runs
// in a child process here, as test-web-console-loop.mjs does for loop-setup.mjs.
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { pathToFileURL } from "node:url";
import { ROOT, ENV, HOME, cli, sessionUrl } from "./web-console-test-helpers.mjs";
const APP_VARS = ["PLAN2CODE_IN_APP", "PLAN2CODE_EMBED_ORIGIN", "PLAN2CODE_APP_ANNOUNCE", "PLAN2CODE_APP_TOKEN", "PLAN2CODE_CONSOLE_SID", "PLAN2CODE_LOOP_STRENGTH"];
const SETUP_PATH = path.join(HOME, "review-loop-setup.json");
const LOOP_SETUP_PATH = path.join(HOME, "loop-setup.json");
const STORE_URL = pathToFileURL(path.join(ROOT, "src", "web-console", "review-loop-setup.mjs")).href;
function cleanEnv() {
const env = { ...ENV };
for (const key of APP_VARS) delete env[key];
return env;
}
// Runs `fn(m, args)` in a child process where m is review-loop-setup.mjs. `fn`
// must be self-contained: it is sent as source text. Returns its JSON result.
function inStore(fn, args = {}) {
const code =
`const m = await import(${JSON.stringify(STORE_URL)});` +
`const out = await (${fn.toString()})(m, ${JSON.stringify(args)});` +
"console.log(JSON.stringify(out));";
const res = spawnSync(process.execPath, ["--input-type=module", "-e", code], { env: cleanEnv(), encoding: "utf8", cwd: ROOT });
assert.equal(res.status, 0, res.stderr);
return JSON.parse(String(res.stdout).trim().split("\n").pop());
}
const projectA = path.join(HOME, "review-store-a");
const projectB = path.join(HOME, "review-store-b");
test("review-loop-setup: a new project reads as the defaults with remembered false, and nothing is written", () => {
fs.rmSync(SETUP_PATH, { force: true });
const got = inStore((m, { project }) => ({ setup: m.readReviewLoopSetup(project), defaults: m.REVIEW_LOOP_DEFAULTS }), { project: projectA });
assert.deepEqual(got.setup, { ...got.defaults, remembered: false });
assert.deepEqual(got.defaults, { scope: "branch", spec: "", cap: 3, commit: true, suggestions: false, strength: "", silenceMinutes: 20, notifyRounds: false });
assert.equal(fs.existsSync(SETUP_PATH), false, "reading never creates the file");
});
test("review-loop-setup: a save reads back per project and keeps another project's entry", () => {
fs.rmSync(SETUP_PATH, { force: true });
inStore(
(m, { a, b }) => {
m.saveReviewLoopSetup(a, { ...m.REVIEW_LOOP_DEFAULTS, cap: 5, suggestions: true, scope: "spec", spec: "specs/demo", strength: "best" });
m.saveReviewLoopSetup(b, { ...m.REVIEW_LOOP_DEFAULTS, cap: 2, notifyRounds: true });
return null;
},
{ a: projectA, b: projectB }
);
const got = inStore((m, { a, b }) => ({ a: m.readReviewLoopSetup(a), b: m.readReviewLoopSetup(b) }), { a: projectA, b: projectB });
assert.equal(got.a.cap, 5);
assert.equal(got.a.suggestions, true);
assert.equal(got.a.scope, "spec");
assert.equal(got.a.spec, "specs/demo");
assert.equal(got.a.strength, "best");
assert.equal(got.a.remembered, true);
assert.equal(got.b.cap, 2);
assert.equal(got.b.notifyRounds, true);
const file = JSON.parse(fs.readFileSync(SETUP_PATH, "utf8"));
assert.equal(file.schema, 1);
assert.equal(Object.keys(file.projects).length, 2);
for (const entry of Object.values(file.projects)) assert.match(entry.saved, /^\d{4}-\d\d-\d\dT/);
});
test("review-loop-setup: unknown keys and out-of-range values are refused with the problem named", () => {
fs.rmSync(SETUP_PATH, { force: true });
const problems = (patch) => inStore((m, { patch }) => m.reviewLoopSetupProblems({ ...m.REVIEW_LOOP_DEFAULTS, ...patch }), { patch });
assert.deepEqual(problems({}), []);
assert.match(problems({ notifyUrl: "https://x.example/" }).join(), /"notifyUrl" is not a setup field/, "the notify address is the loop setup's, never kept here");
assert.match(problems({ cap: 0 }).join(), /"cap" must be a whole number from 1 to 6/);
assert.match(problems({ cap: 7 }).join(), /"cap"/);
assert.match(problems({ cap: 2.5 }).join(), /"cap"/);
assert.deepEqual(problems({ cap: 1 }), []);
assert.deepEqual(problems({ cap: 6 }), []);
assert.match(problems({ silenceMinutes: 0 }).join(), /"silenceMinutes" must be a whole number from 1 to 60/);
assert.match(problems({ silenceMinutes: 61 }).join(), /"silenceMinutes"/);
assert.match(problems({ scope: "everything" }).join(), /"scope" must be one of branch, uncommitted, spec/);
for (const spec of ["demo", "specs/", "specs/a/b", "specs/.hidden", "../x", 3]) {
assert.match(problems({ spec }).join(), /"spec" must be empty or a folder directly under specs\//, `spec ${spec}`);
}
assert.deepEqual(problems({ spec: "specs/demo" }), []);
assert.match(problems({ commit: "yes" }).join(), /"commit" must be true or false/);
assert.match(problems({ strength: "mighty" }).join(), /"strength"/);
assert.match(inStore((m) => m.reviewLoopSetupProblems(null), {}).join(), /must be an object/);
const before = inStore((m, { a }) => (m.saveReviewLoopSetup(a, { ...m.REVIEW_LOOP_DEFAULTS }), null), { a: projectA });
assert.equal(before, null);
const text = fs.readFileSync(SETUP_PATH, "utf8");
const threw = inStore(
(m, { a }) => {
try {
m.saveReviewLoopSetup(a, { ...m.REVIEW_LOOP_DEFAULTS, cap: 99 });
return "saved";
} catch (e) {
return { message: e.message, problems: e.problems };
}
},
{ a: projectA }
);
assert.match(threw.message, /the review loop setup is not valid/);
assert.equal(threw.problems.length, 1);
assert.equal(fs.readFileSync(SETUP_PATH, "utf8"), text, "a refused save leaves the file as it was");
});
test("review-loop-setup: the picks live only in review-loop-setup.json, never in the project or the loop's setup", () => {
fs.rmSync(SETUP_PATH, { force: true });
fs.rmSync(LOOP_SETUP_PATH, { force: true });
const project = fs.mkdtempSync(path.join(HOME, "review-nowrite-"));
inStore((m, { project }) => (m.saveReviewLoopSetup(project, { ...m.REVIEW_LOOP_DEFAULTS, cap: 4 }), null), { project });
assert.ok(fs.existsSync(SETUP_PATH));
assert.equal(fs.existsSync(LOOP_SETUP_PATH), false, "the Implementation Loop's file is untouched");
assert.deepEqual(fs.readdirSync(project), [], "nothing appears in the project");
});
test("review-loop-setup: Cleanup never offers the file", () => {
const code = `const m = await import(${JSON.stringify(pathToFileURL(path.join(ROOT, "src", "web-console", "sessions.mjs")).href)}); console.log(JSON.stringify([...m.PROTECTED_CONSOLE_FILES]));`;
const res = spawnSync(process.execPath, ["--input-type=module", "-e", code], { env: cleanEnv(), encoding: "utf8", cwd: ROOT });
assert.equal(res.status, 0, res.stderr);
assert.ok(JSON.parse(String(res.stdout).trim().split("\n").pop()).includes("review-loop-setup.json"));
});
test("review-loop-setup: GET and POST /review-loop-setup, with ?spec= filling the answer without saving", async () => {
fs.rmSync(SETUP_PATH, { force: true });
const cwd = fs.mkdtempSync(path.join(HOME, "review-route-"));
const opened = cli(["open", "--workflow", "review", "--no-open"], { cwd });
const parsed = JSON.parse(String(opened.stdout).trim().split("\n").filter((l) => l.startsWith("{")).pop());
const { base, cookie } = sessionUrl(parsed.url);
const get = async (query = "") => {
const res = await fetch(`${base}/review-loop-setup${query}`, { headers: { cookie, connection: "close" } });
return { status: res.status, body: await res.json() };
};
const send = (body, { origin = base } = {}) =>
fetch(`${base}/review-loop-setup`, {
method: "POST",
headers: { "content-type": "application/json", cookie, ...(origin ? { origin } : {}), connection: "close" },
body: typeof body === "string" ? body : JSON.stringify(body),
});
try {
const bare = await get();
assert.equal(bare.status, 200);
assert.equal(bare.body.remembered, false);
assert.equal(bare.body.scope, "branch");
assert.equal(bare.body.cap, 3);
const filled = await get("?spec=specs/demo");
assert.equal(filled.body.spec, "specs/demo");
assert.equal(filled.body.scope, "spec");
assert.equal(filled.body.remembered, false);
assert.equal(fs.existsSync(SETUP_PATH), false, "a pre-fill is never saved");
assert.equal((await get()).body.scope, "branch", "and the next plain read is the defaults again");
for (const spec of ["../x", "specs/../x", "specs/a/b", "specs/.hidden", "specs", "specs/"]) {
const refused = await get(`?spec=${spec}`);
assert.equal(refused.status, 400, `spec=${spec} is refused`);
assert.match(refused.body.error, /spec must be a folder directly under specs\//);
}
const facts = await get("?facts=1");
assert.equal(typeof facts.body.branch, "string");
assert.ok("pending" in facts.body);
const good = { scope: "uncommitted", spec: "", cap: 4, commit: false, suggestions: true, strength: "balanced", silenceMinutes: 15, notifyRounds: true };
const saved = await send(good);
assert.equal(saved.status, 200, await saved.clone().text());
const back = await get();
assert.equal(back.body.remembered, true);
for (const [key, value] of Object.entries(good)) assert.equal(back.body[key], value, key);
const bad = await send({ ...good, cap: 9, extra: 1 });
assert.equal(bad.status, 400);
const badBody = await bad.json();
assert.equal(badBody.ok, false);
assert.ok(badBody.problems.some((p) => /"cap"/.test(p)));
assert.ok(badBody.problems.some((p) => /"extra" is not a setup field/.test(p)));
assert.equal((await get()).body.cap, 4, "a refused save changes nothing");
assert.equal((await send("[1]")).status, 400);
// The POST is origin-checked: another page's origin is refused, and nothing is saved by it.
const before = JSON.stringify((await get()).body);
const foreign = await send({ ...good, cap: 2 }, { origin: "http://evil.example" });
assert.equal(foreign.status, 403, "a foreign origin is refused");
assert.equal(JSON.stringify((await get()).body), before);
} finally {
cli(["stop", "--session", parsed.sid, "--force"], { cwd, expectFail: true });
}
assert.deepEqual(fs.readdirSync(cwd), [], "the route never wrote into the project");
assert.equal(fs.existsSync(LOOP_SETUP_PATH), false, "and never touched the Implementation Loop's file");
});
+3 -1
View File
@@ -365,6 +365,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
file("looks.json"),
file("workspaces.json"),
file("loop-setup.json"),
file("review-loop-setup.json"),
file("spec-carry.json"),
file("loop-reports.json"),
file("subagents.json"),
@@ -382,7 +383,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
const stale = staleScratch(dir, Date.now(), SESSION_MAX_AGE_MS).sort();
assert.deepEqual(stale, ["helper.mjs", "p2.json"]);
assert.deepEqual(
(await removeScratch(dir, [...stale, "looks.json", "workspaces.json", "loop-setup.json", "loop-reports.json", "subagents.json", "spec-carry.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
(await removeScratch(dir, [...stale, "looks.json", "workspaces.json", "loop-setup.json", "review-loop-setup.json", "loop-reports.json", "subagents.json", "spec-carry.json", "pr-hosts.json", "../p.json", "console-dir", "update-check.json"])).sort(),
["helper.mjs", "p2.json"]
);
for (const p of removable) assert.equal(fs.existsSync(p), false, p);
@@ -393,6 +394,7 @@ test("the scratch sweep removes old patches and helpers, never looks, the pointe
"loop-reports.json",
"loop-setup.json",
"pr-hosts.json",
"review-loop-setup.json",
"spec-carry.json",
"subagents.json",
"update-check.json",
+1 -1
View File
@@ -193,7 +193,7 @@ const ROUTE_ORDER = [
"/notepad", "/notepad/text", "/notepad/image", "/notepad/thumb", "/notepad/image/delete", "/notepad/tab",
"/notepad/tab/rename", "/notepad/tab/delete", "/notepad/tab/order", "/notepad/tab/last", "/notepad/tab/sent", "/notepad/images/",
"/attachments/", "/shots/", "/uploads/", "/submit", "/open-link", "/open-prototype", "/chat", "/chat/decision", "/workspace",
"WORKSPACE_EDITS", "/workspace/scope", "/workspace/browse", "/loop-setup", "/loop-setup", "/spec-carry", "/cancel", "/ping", "/bye",
"WORKSPACE_EDITS", "/workspace/scope", "/workspace/browse", "/loop-setup", "/loop-setup", "/review-loop-setup", "/review-loop-setup", "/spec-carry", "/cancel", "/ping", "/bye",
];
test("shape: routes.mjs lists every URL the server answers, in order", () => {
+30 -15
View File
@@ -19,7 +19,7 @@ import {
isWorkflow,
isAgentless,
} from "../src/web-console/public/skills.js";
import { CONSOLE_WORKFLOWS, SKILL_CATALOG, catalogEntry, launchVariant, START_POSES, WORKFLOW_LABEL, dashNoteKind, onInitialPick, startPose, startingHint } from "../src/web-console/public/answers.js";
import { APP_ONLY_ENTRIES, REVIEW_LOOP_ENTRY, cardAvailability, CONSOLE_WORKFLOWS, SKILL_CATALOG, catalogEntry, launchVariant, START_POSES, WORKFLOW_LABEL, dashNoteKind, onInitialPick, startPose, startingHint } from "../src/web-console/public/answers.js";
import { LAUNCH_COUNTED, PROGRESS_WORKFLOWS } from "../src/web-console/public/meter.js";
import { BUILD_WORKFLOWS } from "../src/web-console/public/labels.js";
import { helpTabFor } from "../src/web-console/public/help.js";
@@ -428,19 +428,34 @@ test("helper-strength.md ships in the eighteen skills that start helpers (the da
]);
});
// The Implementation Loop is a card the desktop app offers, not a skill: it
// has no workflow, so no list built from the workflows may hold it.
test("the app-only Implementation Loop entry stays out of every workflow list", () => {
const loop = EVERY_ENTRY.find((s) => s.appOnly);
assert.ok(loop, "skills.js has an appOnly entry");
assert.equal(loop.skill, "plan2code-loop");
assert.equal(loop.workflow, null);
assert.deepEqual(EVERY_ENTRY.filter((s) => s.appOnly).length, 1);
assert.ok(!SKILLS.includes(loop), "FLOW_SKILLS leaves it out");
assert.ok(!WORKFLOWS.includes(null) && !isWorkflow("plan2code-loop") && !isWorkflow(null));
assert.equal(skillByName("plan2code-loop"), null);
assert.ok(!CONSOLE_WORKFLOWS.includes(loop.command), "no console page is offered for it");
assert.ok(!SKILL_CATALOG.some((e) => e.skill === loop.skill), "the dashboard does not draw it yet");
// The Implementation Loop and the Review Loop are cards the desktop app offers,
// not skills: neither has a workflow, so no list built from the workflows may hold them.
test("the app-only Implementation Loop and Review Loop entries stay out of every workflow list", () => {
const apps = EVERY_ENTRY.filter((s) => s.appOnly);
assert.deepEqual(apps.map((s) => s.skill), ["plan2code-loop", "plan2code-review-loop"], "both, the Implementation Loop first");
for (const entry of apps) {
assert.equal(entry.workflow, null);
assert.ok(!SKILLS.includes(entry), "FLOW_SKILLS leaves it out");
assert.ok(!isWorkflow(entry.skill));
assert.equal(skillByName(entry.skill), null);
assert.ok(!CONSOLE_WORKFLOWS.includes(entry.command), "no console page is offered for it");
assert.ok(!SKILL_CATALOG.some((e) => e.skill === entry.skill), "the dashboard draws it apart from the catalog");
assert.equal(entry.subagents, null);
assert.equal(entry.card.group, "pipeline", "beside the Implementation Loop");
}
assert.ok(!WORKFLOWS.includes(null) && !isWorkflow(null));
assert.ok(!("null" in WORKFLOW_LABEL));
assert.deepEqual([...loop.states], ["documented", "building"]);
assert.deepEqual([...apps[0].states], ["documented", "building"]);
assert.equal(apps[1].states, "any", "a Review Loop needs no spec");
assert.equal(apps[1].card.title, "Review Loop");
assert.equal(apps[1].card.blurb, "Review and fix in rounds on its own, each round checked by a fresh reviewer.");
});
test("the Review card carries the app-only pointer line, and the app-only cards are the dashboard's extras", () => {
const review = SKILL_CATALOG.find((e) => e.skill === "plan2code-review");
assert.equal(review.appNote, "In the app, the Review Loop runs review and fix rounds on its own.");
assert.deepEqual(SKILL_CATALOG.filter((e) => e.appNote).map((e) => e.skill), ["plan2code-review"], "no other card has one");
assert.deepEqual(APP_ONLY_ENTRIES.map((e) => e.skill), ["plan2code-loop", "plan2code-review-loop"]);
assert.equal(REVIEW_LOOP_ENTRY.command, "Desktop app only");
assert.equal(cardAvailability(REVIEW_LOOP_ENTRY, { hasAgents: true }, null).on, true, "lit for any project state");
});
+4
View File
@@ -52,6 +52,10 @@ test("state: the rest of the shared state starts as app.js always started it", (
terminalCollapsed: false,
loop: null,
loopSetup: null,
reviewLoopSetup: null,
reviewFacts: null,
reviewStart: null,
reviewAction: null,
loopFacts: null,
loopNotifyTest: null,
loopStart: null,