Add Diagnose and X-ray, shared building habits, fresh-helper reviews, and a Bug fixed spec state

AI Assisted
This commit is contained in:
jparkerweb committed 2026-10-16 19:28:11 -07:00
1 parent 80ae3decdd
commit 33a0dbd34a
58 files changed
+3270 -236

No files matched your search

+188
View File
@@ -0,0 +1,188 @@
// Tests for `node install.js --update` and the install record (~/.plan2code/install.json).
// Run with: node --test scripts/test-install-update.mjs
//
// install.js reads the home directory once, at load, so HOME and USERPROFILE point at a temp
// folder before it is required. update() takes its install steps as an argument: the tests
// pass stand-ins that record their calls, so nothing reaches the skills CLI, npm or the network.
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
const require = createRequire(import.meta.url);
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const INSTALL = path.join(ROOT, "install.js");
const VERSION = JSON.parse(fs.readFileSync(path.join(ROOT, "version.json"), "utf8")).version;
const HOME = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-install-update-"));
process.env.HOME = HOME;
process.env.USERPROFILE = HOME;
const installer = require(INSTALL);
test.after(() => fs.rmSync(HOME, { recursive: true, force: true }));
const RECORD = path.join(HOME, ".plan2code", "install.json");
function writeRecord(pieces) {
fs.mkdirSync(path.dirname(RECORD), { recursive: true });
fs.writeFileSync(RECORD, JSON.stringify({ version: "1.0.0", scope: "global", pieces }));
}
function clearRecord() {
fs.rmSync(RECORD, { force: true });
}
/** Stand-in install steps: each logs its piece and options, then returns `codes[piece]` (default 0) or throws `throws[piece]`. */
function fakeSteps({ codes = {}, throws = {}, launcherWithSkills = true } = {}) {
const calls = [];
const steps = {};
for (const piece of installer.INSTALL_PIECES) {
steps[piece] = async (options) => {
calls.push({ piece, options });
if (throws[piece]) throw new Error(throws[piece]);
let code = codes[piece] ?? 0;
if (piece === "skills") {
// As the real install(): the skills first, then the command, and 1 if either failed.
options.outcome.skills = code === 0;
options.outcome.launcher = code === 0 && launcherWithSkills;
if (code === 0 && !launcherWithSkills) code = 1;
}
return code;
};
}
return { steps, calls, ran: () => calls.map((c) => c.piece) };
}
/** Run update() with console output captured: `{ code, out }`. */
async function runUpdate(steps) {
const lines = [];
const log = console.log;
console.log = (...args) => lines.push(args.join(" "));
try {
const code = await installer.update({ steps });
return { code, out: lines.join("\n").replace(/\x1b\[[0-9;]*m/g, "") };
} finally {
console.log = log;
}
}
test("install record: recordInstalled and forgetInstalled round trip a sorted set", () => {
clearRecord();
assert.equal(installer.INSTALL_RECORD, RECORD);
assert.equal(installer.readInstallRecord(), null);
installer.recordInstalled("loop");
installer.recordInstalled("skills");
installer.recordInstalled("skills");
installer.recordInstalled("not-a-piece");
assert.deepEqual(installer.readInstallRecord(), { version: VERSION, scope: "global", pieces: ["loop", "skills"] });
installer.forgetInstalled("loop");
assert.deepEqual(installer.readInstallRecord().pieces, ["skills"]);
installer.forgetInstalled("skills");
assert.deepEqual(installer.readInstallRecord().pieces, []);
// No temp file is left beside the record.
assert.deepEqual(fs.readdirSync(path.dirname(RECORD)), ["install.json"]);
});
test("install record: a missing or unparsable record reads as null, and forgetting needs none", () => {
clearRecord();
installer.forgetInstalled("skills");
assert.equal(fs.existsSync(RECORD), false);
fs.writeFileSync(RECORD, "{ not json");
assert.equal(installer.readInstallRecord(), null);
fs.writeFileSync(RECORD, JSON.stringify({ pieces: "skills" }));
assert.equal(installer.readInstallRecord(), null);
});
test("update: with no record it says so and updates the skills and the plan2code command", async () => {
clearRecord();
const fake = fakeSteps();
const { code, out } = await runUpdate(fake.steps);
assert.equal(code, 0, out);
assert.match(out, new RegExp(`No install record found \\(installed before v${VERSION.replace(/\./g, "\\.")}\\); updating the skills and the plan2code command\\.`));
// install() covers the command with the skills, so the launcher step does not run again.
assert.deepEqual(fake.ran(), ["skills"]);
assert.match(out, /skills: updated/);
assert.match(out, /launcher: updated/);
});
test("update: a partial record runs only the listed pieces, in order, unattended", async () => {
writeRecord(["loop", "statusline"]);
const fake = fakeSteps();
const { code, out } = await runUpdate(fake.steps);
assert.equal(code, 0, out);
assert.deepEqual(fake.ran(), ["statusline", "loop"]);
for (const call of fake.calls) assert.equal(call.options.unattended, true, call.piece);
assert.doesNotMatch(out, /No install record/);
assert.doesNotMatch(out, /skills:/);
});
test("update: a failing piece exits 1 naming it, and the others still run", async () => {
writeRecord(["skills", "launcher", "loop", "metrics", "bot"]);
const fake = fakeSteps({ codes: { loop: 1 }, throws: { metrics: "npm exploded" } });
const { code, out } = await runUpdate(fake.steps);
assert.equal(code, 1, out);
assert.deepEqual(fake.ran(), ["skills", "loop", "metrics", "bot"]);
assert.match(out, /loop: failed: /);
assert.match(out, /metrics: failed: npm exploded/);
assert.match(out, /bot: updated/);
assert.match(out, /Update failed for: loop, metrics/);
});
test("update: when the skills install leaves the command out, the launcher step runs on its own", async () => {
writeRecord(["skills", "launcher"]);
const fake = fakeSteps({ launcherWithSkills: false });
const { code, out } = await runUpdate(fake.steps);
assert.equal(code, 0, out);
assert.deepEqual(fake.ran(), ["skills", "launcher"]);
// install() returned 1 for the command alone: the skills still read as updated.
assert.match(out, /skills: updated/);
assert.match(out, /launcher: updated/);
});
test("update: a command that fails on the retry is the only piece named", async () => {
writeRecord(["skills", "launcher"]);
const fake = fakeSteps({ launcherWithSkills: false, codes: { launcher: 1 } });
const { code, out } = await runUpdate(fake.steps);
assert.equal(code, 1, out);
assert.match(out, /skills: updated/);
assert.match(out, /Update failed for: launcher\b/);
});
test("update: the real status line step keeps a custom statusLine without asking", async () => {
const claudeDir = path.join(HOME, ".claude");
const settingsFile = path.join(claudeDir, "settings.json");
fs.mkdirSync(claudeDir, { recursive: true });
const settings = JSON.stringify({ statusLine: { type: "command", command: "my-own-status-line" } }, null, 2);
fs.writeFileSync(settingsFile, settings);
clearRecord();
// stdin is not a TTY here: a prompt would hang the test until it times out.
const log = console.log;
console.log = () => {};
let code;
try {
code = await installer.UPDATE_STEPS.statusline({ quiet: true, unattended: true });
} finally {
console.log = log;
}
assert.equal(code, 0);
assert.equal(fs.readFileSync(settingsFile, "utf8"), settings);
assert.ok(fs.existsSync(path.join(claudeDir, "plan2code-statusline.js")));
assert.deepEqual(installer.readInstallRecord().pieces, ["statusline"]);
});
test("update: every step is an install function, never an uninstall", () => {
assert.deepEqual(Object.keys(installer.UPDATE_STEPS), installer.INSTALL_PIECES);
for (const [piece, fn] of Object.entries(installer.UPDATE_STEPS)) {
assert.match(fn.name, /^install/, piece);
}
});
test("install.js: --update is in the usage line, and an unknown option still exits 1", () => {
const result = spawnSync(process.execPath, [INSTALL, "--bogus"], { encoding: "utf8" });
assert.equal(result.status, 1);
assert.ok(result.stderr.includes("Usage: node install.js [--build-skills | --verify-skills | --update]"), result.stderr);
});
+89 -5
View File
@@ -20,13 +20,28 @@ const LAUNCHER = path.join(ROOT, "src", "launcher", "plan2code.js");
const IS_WINDOWS = process.platform === "win32";
const NOTICE = "will use the model you last used in it";
/** A temp home and a bin dir holding stand-ins for `clis`; each writes its args to <bin>/<cli>.json. */
function sandbox(clis) {
/**
* A temp home and a bin dir holding stand-ins for `clis`; each writes its args to <bin>/<cli>.json.
* `installed: "X.Y.Z"` runs an installed copy instead, as install.js lays it out: the launcher,
* models.json and update-check.mjs in <home>/.plan2code/bin/ beside a version.json saying X.Y.Z.
*/
function sandbox(clis, { installed } = {}) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-launcher-"));
const home = path.join(dir, "home");
const bin = path.join(dir, "bin");
fs.mkdirSync(home);
fs.mkdirSync(bin);
const consoleHome = path.join(home, ".plan2code", "console");
let launcher = LAUNCHER;
if (installed) {
const binCopy = path.join(home, ".plan2code", "bin");
fs.mkdirSync(binCopy, { recursive: true });
launcher = path.join(binCopy, "plan2code.js");
fs.copyFileSync(LAUNCHER, launcher);
fs.copyFileSync(path.join(path.dirname(LAUNCHER), "models.json"), path.join(binCopy, "models.json"));
fs.copyFileSync(path.join(ROOT, "src", "web-console", "update-check.mjs"), path.join(binCopy, "update-check.mjs"));
fs.writeFileSync(path.join(binCopy, "version.json"), JSON.stringify({ name: "Plan2Code", version: installed }));
}
const recorder = path.join(bin, "record.js");
fs.writeFileSync(
recorder,
@@ -45,21 +60,31 @@ function sandbox(clis) {
return {
home,
stateFile: path.join(home, ".plan2code", "launcher.json"),
cacheFile: path.join(consoleHome, "update-check.json"),
run: (args, env = {}) =>
spawnSync(process.execPath, [LAUNCHER, ...args], {
spawnSync(process.execPath, [launcher, ...args], {
cwd: dir,
input: "",
encoding: "utf8",
env: { ...process.env, PATH: bin, HOME: home, USERPROFILE: home, ...env },
env: { ...process.env, PATH: bin, HOME: home, USERPROFILE: home, PLAN2CODE_CONSOLE_HOME: consoleHome, ...env },
}),
argsOf: (cli) => {
const file = path.join(bin, `${cli}.json`);
return fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, "utf8")) : null;
},
cleanup: () => fs.rmSync(dir, { recursive: true, force: true }),
// A detached release-check refresh may still be writing its cache; retry rather than fail.
cleanup: () => fs.rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 }),
};
}
const NOTICE_LINE = /is out \(you have v/;
/** Write the console's cached release check, `ageMs` old. */
function writeCache(box, latest, ageMs = 0) {
fs.mkdirSync(path.dirname(box.cacheFile), { recursive: true });
fs.writeFileSync(box.cacheFile, JSON.stringify({ checkedAt: Date.now() - ageMs, latest }));
}
test("launcher: Claude Code gets the prompt first, then bypassPermissions and the forwarded args", (t) => {
const box = sandbox(["claude"]);
t.after(box.cleanup);
@@ -263,6 +288,65 @@ test("launcher: the CLI's non-zero exit code is passed through", (t) => {
assert.equal(result.status, 7, result.stderr);
assert.notEqual(box.argsOf("claude"), null);
});
test("launcher: update runs the npx install and starts no agent", (t) => {
const box = sandbox(["npx", "claude"]);
t.after(box.cleanup);
const result = box.run(["update"]);
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Updating Plan2Code\.\.\./);
const args = box.argsOf("npx");
assert.ok(args, "npx was not run");
assert.ok(args.includes("--update"), args.join(" "));
assert.ok(args.includes("git+https://github.com/jparkerweb/plan2code.git"), args.join(" "));
assert.equal(box.argsOf("claude"), null);
});
test("launcher: update passes npx's exit code through", (t) => {
const box = sandbox(["npx"]);
t.after(box.cleanup);
assert.equal(box.run(["update"], { P2C_TEST_EXIT: "3" }).status, 3);
});
test("launcher: release notice prints from a fresh cache", (t) => {
const box = sandbox(["claude"], { installed: "1.0.0" });
t.after(box.cleanup);
writeCache(box, "9.9.9");
const result = box.run([]);
assert.equal(result.status, 0, result.stderr);
assert.ok(result.stdout.includes("Plan2Code v9.9.9 is out (you have v1.0.0). Run: plan2code update"), result.stdout);
assert.notEqual(box.argsOf("claude"), null);
});
test("launcher: no notice when current, stale or missing, and the start does not wait", (t) => {
// PATH holds only the stand-ins, so the detached refresh finds no git: nothing may wait on it.
const cases = [
["current", (box) => writeCache(box, "1.0.0")],
["stale", (box) => writeCache(box, "9.9.9", 2 * 60 * 60 * 1000)],
["missing", () => {}],
];
for (const [name, setup] of cases) {
const box = sandbox(["claude"], { installed: "1.0.0" });
t.after(box.cleanup);
setup(box);
const started = Date.now();
const result = box.run([]);
const took = Date.now() - started;
assert.equal(result.status, 0, `${name}: ${result.stderr}`);
assert.doesNotMatch(result.stdout, NOTICE_LINE, name);
assert.notEqual(box.argsOf("claude"), null, name);
assert.ok(took < 5000, `${name}: the start took ${took} ms`);
}
});
test("launcher: compareVersions orders X.Y.Z numerically and refuses anything else", () => {
const { compareVersions } = require(LAUNCHER);
assert.equal(compareVersions("1.9.0", "1.10.0"), -1);
assert.equal(compareVersions("2.0.0", "2.0.0"), 0);
assert.equal(compareVersions("3.0.0", "2.9.9"), 1);
assert.equal(compareVersions("1.0.0", null), null);
assert.equal(compareVersions("v1.0.0", "1.0.0"), null);
});
test("launcher: renderBanner draws Planny and the name, colored only through paint", () => {
const { renderBanner, paint } = require(LAUNCHER);
const plain = renderBanner(paint(false));
+113
View File
@@ -0,0 +1,113 @@
// Tests for plan2code-xray's scripts/xray.mjs.
//
// See skill-script-helpers.mjs for how these run.
import { test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { execFileSync } from "node:child_process";
import { runScript, tmp, write, gitInit } from "./skill-script-helpers.mjs";
const X = (cwd, args, env) => runScript("plan2code-xray", "xray.mjs", args, { cwd, env });
// One fixture for the file: a.js and b.js always change together, hot.js
// changes in most commits and has no test, the others are tested, and
// old1.js and old2.js changed together before they were deleted.
let fixture;
function repo() {
if (fixture) return fixture;
const dir = tmp("xray");
const g = gitInit(dir);
const commit = (msg, files) => {
for (const [rel, content] of Object.entries(files)) write(dir, rel, content);
g("add", "-A");
g("commit", "-q", "-m", msg);
};
commit("Start", { "a.js": "a1\n", "b.js": "b1\n", "hot.js": "h1\n", "c.js": "c1\n", "tests/a.test.js": "t\n", "tests/b.test.js": "t\n", "tests/c.test.js": "t\n" });
commit("Change a and b (#12)", { "a.js": "a2\n", "b.js": "b2\n", "hot.js": "h2\n", "package-lock.json": "{}\n" });
commit("Change a and b again", { "a.js": "a3\n", "b.js": "b3\n", "hot.js": "h3\n", "package-lock.json": "{ }\n" });
commit("Change hot and c", { "hot.js": "h4\nmore\n", "c.js": "c2\n" });
commit("Change hot alone", { "hot.js": "h5\nmore\n", "dist/out.js": "x\n" });
// Without hot.js, so a-b (support 1) outranks a-hot and b-hot on support, not on name.
commit("Change a and b only", { "a.js": "a4\n", "b.js": "b4\n" });
for (let i = 1; i <= 3; i++) commit(`Change the old pair ${i}`, { "old1.js": `o${i}\n`, "old2.js": `p${i}\n` });
g("rm", "-q", "old1.js", "old2.js");
g("commit", "-q", "-m", "Delete the old pair");
fixture = dir;
return dir;
}
// PATH with git (and node) but no gh: git's own exec dir holds a git binary
// on every platform, so the directory that also holds gh is never needed.
function pathWithoutGh() {
const gitDir = execFileSync("git", ["--exec-path"], { encoding: "utf8" }).trim();
const dirs = [path.resolve(gitDir)];
const nodeDir = path.dirname(process.execPath);
const hasGh = ["gh", "gh.exe"].some((n) => fs.existsSync(path.join(nodeDir, n)));
if (!hasGh) dirs.push(nodeDir);
const value = dirs.join(path.delimiter);
// Windows keys env case-insensitively but a child gets both spellings: set both.
return { PATH: value, Path: value };
}
test("xray hotspots: the always-together pair ranks first, the hot file without a test is listed", () => {
const r = X(repo(), ["hotspots"]);
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.ok, true);
assert.deepEqual(r.json.window, { commits: 10, capped: false });
assert.deepEqual(r.json.churn[0], { file: "hot.js", commits: 5 });
assert.ok(!r.json.churn.some((c) => c.file === "package-lock.json" || c.file.startsWith("dist/")), "lockfiles and dist/ are skipped");
assert.deepEqual(r.json.pairs[0], { a: "a.js", b: "b.js", together: 4, support: 1 });
assert.ok(r.json.pairs[1].support < 1, JSON.stringify(r.json.pairs));
assert.ok(r.json.pairs.every((p) => p.together >= 3));
const untested = r.json.untested.map((u) => u.file);
assert.ok(untested.includes("hot.js"), JSON.stringify(r.json.untested));
for (const tested of ["a.js", "b.js", "c.js"]) assert.ok(!untested.includes(tested), `${tested} has a test`);
});
test("xray hotspots: files deleted since drop out of churn and pairs", () => {
const r = X(repo(), ["hotspots"]);
assert.equal(r.code, 0, r.stderr);
const named = [...r.json.churn.map((c) => c.file), ...r.json.pairs.flatMap((p) => [p.a, p.b])];
assert.ok(!named.some((f) => f.startsWith("old")), JSON.stringify(named));
});
test("xray hotspots: --max-commits below the history sets capped", () => {
const r = X(repo(), ["hotspots", "--max-commits", "2"]);
assert.equal(r.code, 0, r.stderr);
assert.deepEqual(r.json.window, { commits: 2, capped: true });
assert.equal(X(repo(), ["hotspots", "--top", "1"]).json.churn.length, 1);
});
test("xray history: commits, blame and gh missing when gh is not on PATH", () => {
const r = X(repo(), ["history", "hot.js"], pathWithoutGh());
assert.equal(r.code, 0, r.stderr);
assert.equal(r.json.path, "hot.js");
assert.equal(r.json.commits.length, 5);
assert.equal(r.json.commits[0].subject, "Change hot alone");
assert.equal(r.json.commits[0].author, "Test");
assert.match(r.json.commits[0].hash, /^[0-9a-f]{40}$/);
assert.equal(r.json.blame.lines, 2);
assert.deepEqual(r.json.blame.authors, [{ author: "Test", lines: 2, share: 1 }]);
assert.match(r.json.blame.oldest, /^\d{4}-\d{2}-\d{2}$/);
assert.deepEqual(r.json.prs, [{ number: 12, subject: "Change a and b (#12)", title: null, summary: null }]);
assert.deepEqual(r.json.sources, { git: true, blame: true, gh: "missing" });
});
test("xray: a folder outside any repository is exit 3 not-a-repo", () => {
const plain = tmp("xray-plain");
for (const args of [["hotspots"], ["history", "x.js"]]) {
const r = X(plain, args);
assert.equal(r.code, 3);
assert.equal(r.json.ok, false);
assert.equal(r.json.error, "not-a-repo");
assert.match(r.json.next, /explain mode/);
}
});
test("xray: --help documents the exit codes", () => {
const r = X(repo(), ["--help"]);
assert.equal(r.code, 0);
assert.match(r.stdout, /Exit:/);
});
+207
View File
@@ -115,6 +115,27 @@ test("specs list: active specs with state, drafts and archives, never specs--com
assert.equal(r.json.hasAgents, true);
});
test("specs list: a folder holding only Diagnose's write-up is diagnosed", () => {
const root = specFixture();
write(root, "specs/csv-drops-rows/DIAGNOSIS-20261016.md", "# Diagnosis: CSV drops rows\n\n**Status:** Diagnosed\n");
const r = runScript("plan2code-diagnose", "specs.mjs", ["list", "--root", root]);
assert.equal(r.code, 0, r.stderr);
const bug = r.json.specs.find((s) => s.name === "csv-drops-rows");
assert.equal(bug.state, "diagnosed");
assert.equal(bug.detail, "bug diagnosed, not fixed");
assert.equal(bug.phaseFiles, 0);
});
test("specs list: a diagnosis Quick Task marked Fixed is a fixed bug", () => {
const root = specFixture();
write(root, "specs/csv-drops-rows/DIAGNOSIS-20261016.md", "# Diagnosis: CSV drops rows\n\n**Status:** Fixed\n");
const r = runScript("plan2code-quick-task", "specs.mjs", ["list", "--root", root]);
assert.equal(r.code, 0, r.stderr);
const bug = r.json.specs.find((s) => s.name === "csv-drops-rows");
assert.equal(bug.state, "fixed");
assert.equal(bug.detail, "bug fixed");
});
test("specs status: checklist formats, groups, task markers, numbering, totals, checks", () => {
const root = specFixture();
const r = runScript("plan2code-3-implement", "specs.mjs", ["status", "specs/lunch-vote/overview.md", "--root", root]);
@@ -140,6 +161,25 @@ test("specs status: checklist formats, groups, task markers, numbering, totals,
assert.deepEqual(j.pending.map((p) => p.number), [2, 3, 4]);
});
test("specs status: a plain ` - Test:` sub-bullet under a task is not counted or flagged", () => {
const plain = specFixture();
const withTests = specFixture();
// The shape Document writes: a task line followed directly by a non-checkbox sub-bullet.
for (const [n, ids] of [[2, ["2.1", "2.2"]], [3, ["3.1", "3.4"]]]) {
const rel = `specs/lunch-vote/phase-${n}.md`;
let text = read(withTests, rel);
for (const id of ids) text = text.replace(`**Task ${id}:** Do ${id}\n`, `**Task ${id}:** Do ${id}\n - Test: through \`POST /votes\`\n`);
assert.match(text, /\n - Test: through/);
write(withTests, rel, text);
}
const status = (root) => runScript("plan2code-3-implement", "specs.mjs", ["status", "lunch-vote", "--root", root]).json;
const a = status(plain);
const b = status(withTests);
assert.deepEqual(b.phases.map((p) => p.tasks), a.phases.map((p) => p.tasks));
assert.deepEqual(b.totals, a.totals);
assert.deepEqual(b.checks, a.checks);
});
test("specs status: the implement selection table", () => {
const root = specFixture();
const ov = (m1, m2, m3, m4) => OVERVIEW.replace("- [x] **[Phase 1", `- [${m1}] **[Phase 1`).replace("- [/] [Phase 2", `- [${m2}] [Phase 2`).replace("- [ ] **Phase 3", `- [${m3}] **Phase 3`).replace("- [ ] [Phase 4", `- [${m4}] [Phase 4`);
@@ -473,6 +513,173 @@ test("specs: --set cannot override computed fields; empty overview exists; uncou
assert.ok(!e.checks.some((c) => c.code === "no-overview"));
});
// A spec with nothing for check to find: a checklist row per phase file,
// sequential task numbers, a Test-first sub-bullet and plain-bullet criteria.
function cleanSpec(root) {
write(root, "specs/clean/overview.md", "# Clean\n\n## Phase Checklist\n\n- [ ] [Phase 1: Data model](./phase-1.md)\n- [ ] [Phase 2: API](./phase-2.md)\n");
write(root, "specs/clean/phase-1.md", phase(1, "Not Started", [[" ", "1.1"], [" ", "1.2"]]).replace("**Task 1.1:** Do 1.1\n", "**Task 1.1:** Do 1.1\n - Test: through `POST /votes`\n"));
write(root, "specs/clean/phase-2.md", phase(2, "Not Started", [[" ", "2.1"]]));
return root;
}
test("specs check: a well-formed spec passes", () => {
const root = cleanSpec(specFixture());
assert.match(read(root, "specs/clean/phase-1.md"), /\n - Test: through/);
const r = runScript("plan2code-2-document", "specs.mjs", ["check", "clean", "--root", root]);
assert.equal(r.code, 0, r.stdout);
assert.equal(r.json.ok, true);
assert.equal(r.json.errors, 0);
assert.deepEqual(r.json.checked, ["specs/clean/overview.md", "specs/clean/phase-1.md", "specs/clean/phase-2.md"]);
assert.deepEqual(r.json.problems, []);
});
test("specs check: a bad task line, a checklist row with no phase file, a loop token and a bare metric word each fail", () => {
const root = cleanSpec(specFixture());
write(root, "specs/clean/overview.md", read(root, "specs/clean/overview.md") + "- [ ] [Phase 3: Docs](./phase-3.md)\n");
write(root, "specs/clean/phase-1.md", read(root, "specs/clean/phase-1.md").replace("- [ ] **Task 1.2:** Do 1.2", "- [ ] Task 1.2 without the bold"));
write(root, "specs/clean/phase-2.md", read(root, "specs/clean/phase-2.md") + "\n## Notes\n\nPrint TASK_COMPLETE when done. Risk: 3 of 5.\n");
const r = runScript("plan2code-2-document", "specs.mjs", ["check", "clean", "--root", root]);
assert.equal(r.code, 4, r.stdout);
assert.equal(r.json.ok, false);
assert.equal(r.json.error, "check-failed");
assert.match(r.json.next, /rerun check/);
assert.match(r.stderr, /^error: check found \d+ errors?\.\nnext: /);
const errs = r.json.problems.filter((p) => p.level === "error");
assert.equal(r.json.errors, errs.length);
const by = (code) => errs.filter((p) => p.code === code);
assert.deepEqual(by("bad-task-line").map((p) => p.file), ["specs/clean/phase-1.md"]);
assert.deepEqual(by("missing-phase-file").map((p) => p.file), ["specs/clean/overview.md"]);
assert.deepEqual(by("loop-token").map((p) => p.file), ["specs/clean/phase-2.md"]);
assert.deepEqual(by("metric-word").map((p) => p.file), ["specs/clean/phase-2.md"]);
for (const p of r.json.problems) assert.deepEqual(Object.keys(p), ["level", "file", "code", "message"]);
assert.equal(runScript("plan2code-2-document", "specs.mjs", ["check", "nope", "--root", root]).code, 3);
// A status problem names the phase file by its real name, not phase-N.md.
fs.renameSync(path.join(root, "specs/clean/phase-2.md"), path.join(root, "specs/clean/phase-2-api.md"));
write(root, "specs/clean/phase-2-api.md", phase(2, "Not Started", [[" ", "2.2"]]));
const named = runScript("plan2code-2-document", "specs.mjs", ["check", "clean", "--root", root]).json;
assert.deepEqual(named.problems.filter((p) => p.code === "task-numbering").map((p) => p.file), ["specs/clean/phase-2-api.md"]);
});
// A draft in the shape Plan's Phase 7 writes, with every heading Document reads.
const COMPLETE_DRAFT = `# Lunch vote - Implementation Plan
**Created:** 2026-08-01
**Status:** Complete
**Confidence:** 92% (Requirements-clarity 24/25 · Feasibility-technical 23/25 · Integration-points 23/25 · Risk-assessment 22/25)
## 1. Executive Summary
A lunch vote.
## 2. Requirements
### 2.1 Functional Requirements
- [ ] FR-1: People vote
### 2.4 Testing Strategy
| Type | Phase Testing | Coverage |
|------|---------------|----------|
## 3. Tech Stack
Node.
## 4. Architecture
One server.
## 5. Implementation Phases
### Phase 1: Votes
Build the vote (FR-1).
## 6. Risks and Mitigations
| Risk | Likelihood | Impact | Mitigation |
## 7. Success Criteria
- [ ] Votes count
## 9. Assumptions
- People eat lunch
## Planning Metrics
<!-- METRICS_JSON {"confidence": 92, "confidence_breakdown": {"requirements": 24, "risk": 22}} -->
`;
test("specs check-draft: a complete draft passes", () => {
const root = specFixture();
write(root, "specs/lunch-vote/PLAN-DRAFT-20260801.md", COMPLETE_DRAFT);
for (const arg of ["lunch-vote", "specs/lunch-vote/PLAN-DRAFT-20260801.md"]) {
const r = runScript("plan2code-1-plan", "specs.mjs", ["check-draft", arg, "--root", root]);
assert.equal(r.code, 0, r.stdout);
assert.equal(r.json.errors, 0);
assert.equal(r.json.warnings, 0);
assert.equal(r.json.status, "Complete");
assert.deepEqual(r.json.checked, ["specs/lunch-vote/PLAN-DRAFT-20260801.md"]);
}
// A newer -prev copy is archived, never the one checked.
write(root, "specs/lunch-vote/PLAN-DRAFT-20260802-prev.md", "# old\n");
assert.equal(runScript("plan2code-1-plan", "specs.mjs", ["check-draft", "lunch-vote", "--root", root]).code, 0);
// Untraced requirements only warn.
write(root, "specs/lunch-vote/PLAN-DRAFT-20260801.md", COMPLETE_DRAFT.replace("Build the vote (FR-1).", "Build the vote."));
const w = runScript("plan2code-1-plan", "specs.mjs", ["check-draft", "lunch-vote", "--root", root]);
assert.equal(w.code, 0, w.stdout);
assert.deepEqual(w.json.problems.map((p) => [p.level, p.code]), [["warn", "untraced-requirements"]]);
});
test("specs check-draft: a missing section, a bad status, no metrics, a loop token each fail", () => {
const root = specFixture();
const check = (text) => {
write(root, "specs/lunch-vote/PLAN-DRAFT-20260801.md", text);
const r = runScript("plan2code-1-plan", "specs.mjs", ["check-draft", "lunch-vote", "--root", root]);
assert.equal(r.code, 4, r.stdout);
assert.equal(r.json.error, "check-draft-failed");
return r.json.problems.filter((p) => p.level === "error").map((p) => p.code);
};
const noTech = check(COMPLETE_DRAFT.replace("## 3. Tech Stack", "## 3. Tools"));
assert.deepEqual(noTech, ["missing-section"]);
assert.deepEqual(check(COMPLETE_DRAFT.replace("**Status:** Complete", "**Status:** Finished")), ["bad-status"]);
assert.deepEqual(check(COMPLETE_DRAFT.replace("**Status:** Complete\n", "")), ["bad-status"]);
assert.deepEqual(check(COMPLETE_DRAFT.replace(/## Planning Metrics\n<!--.*-->\n/, "")), ["no-metrics"]);
assert.deepEqual(check(COMPLETE_DRAFT.replace('{"confidence": 92,', '{"confidence": 92')), ["no-metrics"]);
assert.deepEqual(check(COMPLETE_DRAFT.replace("METRICS_JSON {", "METRICS_JSON{")), ["no-metrics"], "the collector needs whitespace after METRICS_JSON");
assert.deepEqual(check(COMPLETE_DRAFT.replace("### Phase 1: Votes", "Phase 1, votes")), ["no-phases"]);
assert.deepEqual(check(COMPLETE_DRAFT.replace("Node.", "Node. Then say PHASE_COMPLETE.")), ["loop-token"]);
assert.deepEqual(check(COMPLETE_DRAFT.replace("One server.", "One server. Integration: 4 services.")), ["metric-word"]);
const missing = runScript("plan2code-1-plan", "specs.mjs", ["check-draft", "specs/lunch-vote/PLAN-DRAFT-nope.md", "--root", root]);
assert.equal(missing.code, 3);
assert.equal(runScript("plan2code-1-plan", "specs.mjs", ["check-draft", "idea-only", "--root", root]).json.error, "no-draft");
});
test("specs check-draft: a pathfinder draft at Resume at Phase 4 is checked lightly", () => {
const root = specFixture();
const draft = "# Idea - Implementation Plan\n\n*Written by /plan2code-0-pathfinder.*\n\n**Status:** Phase 3 Complete - Resume at Phase 4\n\n## 1. Executive Summary\n\nTBD\n";
write(root, "specs/idea-only/PLAN-DRAFT-20260801.md", draft);
const r = runScript("plan2code-1-plan", "specs.mjs", ["check-draft", "idea-only", "--root", root]);
assert.equal(r.code, 0, r.stdout);
assert.deepEqual(r.json.problems, [], "no section, phase or metrics checks before Plan's Phase 4");
// Status, loop tokens and every metric pattern still apply, confidence included.
write(root, "specs/idea-only/PLAN-DRAFT-20260801.md", draft + "\n**Confidence:** 80%\n\nSay WORK_COMPLETE.\n");
const bad = runScript("plan2code-1-plan", "specs.mjs", ["check-draft", "idea-only", "--root", root]);
assert.equal(bad.code, 4);
assert.deepEqual(bad.json.problems.map((p) => p.code).sort(), ["loop-token", "metric-word"]);
});
test("common.mjs exports the shared loop-token and scrape patterns", async () => {
const common = await import(new URL(`file:///${path.join(SKILLS, "plan2code-2-document", "scripts", "common.mjs").replace(/\\/g, "/")}`).href);
assert.ok(common.LOOP_TOKENS instanceof RegExp);
assert.ok(common.LOOP_TOKENS.test("then TASK_COMPLETE"));
assert.equal(common.SCRAPE.length, 6);
assert.deepEqual(common.scrapeHits("Risk: 3"), ['bare Risk + number: "Risk: 3"']);
assert.deepEqual(common.scrapeHits("Risk-assessment 22/25"), []);
});
test("commit-msg: a repo with no commits, stray arguments, and paths quoted for every shell", () => {
const repo = tmp("commit2");
gitInit(repo, "feature/ABC-12-x");
+2 -1
View File
@@ -303,7 +303,8 @@ test("git: the Git card's copy, place and availability are pinned (FR-58, FR-59)
);
assert.equal(entry.group, "extra");
assert.equal(entry.chip, "Utility");
assert.equal(SKILL_CATALOG.at(-1), entry, "the Git card is last");
assert.equal(SKILL_CATALOG.at(-2), entry, "the Git card comes right before Handoff");
assert.equal(SKILL_CATALOG.at(-1).skill, "plan2code-handoff", "the Handoff card is last");
for (const isGit of [true, false, undefined]) {
for (const pending of [0, 3, null]) {
const scan = { hasAgents: true, pending, ...(isGit === undefined ? {} : { isGit }) };
+44
View File
@@ -182,3 +182,47 @@ test("a fresh open whose --file is refused leaves no session folder behind", ()
const after = fs.readdirSync(sessionsDir).filter((n) => !before.has(n));
assert.deepEqual(after, [], "no orphan session folders");
});
// Show me it working: an image block may only point at a picture the agent
// saved directly inside the session's shots/ folder, and only a real one.
test("an image block outside the session's shots folder, or not an image, is refused", () => {
const s = consoleSession(["--file", payload("shots-safety.json", BASE)]);
try {
const shots = path.join(s.session, "shots");
fs.mkdirSync(shots, { recursive: true });
const png = Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), Buffer.alloc(32)]);
const outside = path.join(HOME, "outside-shot.png");
fs.writeFileSync(outside, png);
fs.writeFileSync(path.join(s.session, "beside.png"), png);
fs.writeFileSync(path.join(shots, "renamed.png"), "just some text, not a picture\n");
fs.writeFileSync(path.join(shots, "huge.png"), Buffer.concat([png, Buffer.alloc(6 * 1024 * 1024)]));
const cases = [
["../../outside-shot.png", /outside the session's shots\/ folder/],
[outside, /outside the session's shots\/ folder/],
["beside.png", /outside the session's shots\/ folder/],
["shots/missing.png", /does not exist/],
["shots/renamed.png", /not a PNG image/],
["shots/huge.png", /larger than 5 MB/],
];
let linked = false;
try {
fs.symlinkSync(outside, path.join(shots, "link.png"), "file");
linked = true;
} catch {
// Windows without the symlink privilege: the realpath check is still covered by the cases above.
}
if (linked) cases.push(["shots/link.png", /outside the session's shots\/ folder/]);
for (const [image, why] of cases) {
const patch = { docs: [{ id: "shown", title: "Shown", blocks: [{ id: "b1", image, alt: "The page" }] }] };
const res = cli(["post", "--session", s.sid, "--file", payload("shots-bad.json", patch)], { expectFail: true });
assert.equal(res.status, 3, image);
assert.match(res.stderr, why, image);
}
const both = { docs: [{ id: "shown", title: "Shown", blocks: [{ id: "b1", image: "shots/renamed.png", md: "x" }] }] };
const res = cli(["post", "--session", s.sid, "--file", payload("shots-both.json", both)], { expectFail: true });
assert.equal(res.status, 3);
assert.match(res.stderr, /cannot also carry "md" or "file"/);
} finally {
cli(["stop", "--session", s.sid]);
}
});
+222
View File
@@ -32,6 +32,7 @@ import {
sortAttachments,
cardAvailability,
cardPresentation,
defaultSpec,
CATALOG_GROUPS,
CONTINUE_IN_CONSOLE,
CONSOLE_WORKFLOWS,
@@ -46,6 +47,11 @@ import {
handoffShape,
handoffText,
launchReply,
launchTarget,
deleteAction,
deleteReply,
deleteSummary,
isDeletableSpecDir,
MAX_NOTE_IMAGES,
noteAction,
noteReplyLines,
@@ -148,6 +154,7 @@ import {
writeSubagentSetting,
repoRoots,
scanProject,
removeSpec,
SPEC_STATES,
validate,
WORKSPACE_FILE,
@@ -634,6 +641,15 @@ test("the project scan reads each spec's pipeline stage off its files", () => {
"PLAN-DRAFT-20260923.md": "# draft\n\n**Status:** Phase 3 Complete - Resume at Phase 4\n",
"pathfinder/map.md": "**Status:** Cleared\n",
});
// The other Status forms specs.mjs accepts read the same, CRLF included.
fakeSpec(root, "planned-bold-colon", { "PLAN-DRAFT-20260923.md": "# draft\n\n**Status**: Complete\n" });
fakeSpec(root, "draft-mid-plan-bold-colon", {
"PLAN-DRAFT-20260923.md": "# draft\r\n\r\n**Status**: Phase 3 Complete - Resume at Phase 4\r\n",
});
fakeSpec(root, "mapped-bold-colon", {
"pathfinder/map.md": "**Status**: Cleared\n",
"pathfinder/questions/00-a.md": "State: resolved\n",
});
fakeSpec(root, "documented", {
"overview.md": "# spec\n",
"phase-1.md": "- [ ] Task one\n- [ ] Task two\n",
@@ -648,6 +664,19 @@ test("the project scan reads each spec's pipeline stage off its files", () => {
"phase-1.md": "- [x] Task one\n- [x] Task two\n",
});
fakeSpec(root, "weird", { "DESIGN.md": "# notes\n" });
fakeSpec(root, "diagnosed", { "DIAGNOSIS-20261016.md": "# Diagnosis: rows go missing\n\n**Status:** Diagnosed\n" });
// Once planning starts on a diagnosed bug, the usual states win.
fakeSpec(root, "diagnosed-then-planned", {
"DIAGNOSIS-20261016.md": "# Diagnosis\n\n**Status:** Diagnosed\n",
"PLAN-DRAFT-20261017.md": "# draft\n\n**Status:** Complete\n",
});
// Quick Task marks the write-up Fixed: a finished bug, not loose files.
fakeSpec(root, "diagnosed-then-fixed", { "DIAGNOSIS-20261016.md": "# Diagnosis\n\n**Status:** Fixed\n" });
// A fixed bug someone then started planning around is mid-plan again.
fakeSpec(root, "fixed-then-conversation", {
"DIAGNOSIS-20261016.md": "# Diagnosis\n\n**Status:** Fixed\n",
"PLAN-CONVERSATION-20261017.md": "# conversation\n",
});
fs.writeFileSync(path.join(root, "AGENTS.md"), "# agents\n");
const scan = scanProject(root);
@@ -658,10 +687,17 @@ test("the project scan reads each spec's pipeline stage off its files", () => {
["mapped", "mapped"],
["planned", "planned"],
["draft-mid-plan", "mapped"],
["planned-bold-colon", "planned"],
["draft-mid-plan-bold-colon", "mapped"],
["mapped-bold-colon", "mapped"],
["documented", "documented"],
["building", "building"],
["built", "built"],
["weird", "unrecognized"],
["diagnosed", "diagnosed"],
["diagnosed-then-planned", "planned"],
["diagnosed-then-fixed", "fixed"],
["fixed-then-conversation", "mapped"],
]) {
assert.ok(byName[name], `spec ${name} was scanned`);
assert.equal(byName[name].state, state, `spec ${name}`);
@@ -671,6 +707,12 @@ test("the project scan reads each spec's pipeline stage off its files", () => {
assert.equal(byName.exploring.detail, "1 of 2 decisions made");
assert.equal(byName.building.detail, "1 of 2 tasks done");
assert.equal(byName["draft-mid-plan"].detail, "plan draft, resume at Phase 4");
assert.equal(byName["draft-mid-plan-bold-colon"].detail, "plan draft, resume at Phase 4");
assert.equal(byName.diagnosed.detail, "bug diagnosed, not fixed");
assert.equal(byName["diagnosed-then-fixed"].detail, "bug fixed");
for (const state of SPEC_STATES) assert.ok(SPEC_STATE_LABELS[state], `state ${state} has a picker label`);
assert.equal(SPEC_STATE_LABELS.diagnosed, "Bug diagnosed");
assert.equal(SPEC_STATE_LABELS.fixed, "Bug fixed");
// A pathfinder folder with no map yet is still mid-exploration; a map
// whose status line is missing or unreadable is too.
@@ -689,6 +731,118 @@ test("the project scan reads each spec's pipeline stage off its files", () => {
}
});
// Deleting a spec from the dashboard: the page offers only folders it can
// name exactly, and the agent's `delete-spec` refuses anything else on disk.
test("isDeletableSpecDir takes exactly specs/<one name>", () => {
for (const ok of ["specs/lunch-vote", "specs/codebase-health", "specs/a b"]) {
assert.equal(isDeletableSpecDir(ok), true, ok);
}
for (const bad of [
"specs/../x",
"specs/..",
"specs/.",
"specs/.hidden",
"specs/a/b",
"specs/",
"specs",
"specs--completed/x",
"/specs/x",
"C:/specs/x",
"specs\\x",
"other/x",
"",
undefined,
null,
]) {
assert.equal(isDeletableSpecDir(bad), false, String(bad));
}
});
test("a delete is a session action naming the folder, and its reply says it is for good", () => {
const spec = { dir: "specs/lunch-vote", name: "lunch-vote", state: "building", detail: "1 of 2 tasks done", files: 3, touched: 1 };
assert.deepEqual(deleteAction(spec), { i: "__delete", type: "delete", spec: "specs/lunch-vote" });
const reply = deleteReply(spec);
assert.match(reply, /specs\/lunch-vote\//);
assert.match(reply, /for good/);
assert.doesNotMatch(reply, /\b(brief|recap|minutes)\b/i);
const sum = deleteSummary(spec);
assert.equal(sum.folder, "specs/lunch-vote/");
assert.equal(sum.stage, `${SPEC_STATE_LABELS.building}: 1 of 2 tasks done`);
assert.equal(sum.files, "3 files");
assert.equal(sum.touched, 1);
assert.equal(deleteSummary({ ...spec, files: 1 }).files, "1 file");
assert.equal(deleteSummary({ ...spec, files: undefined }).files, "");
assert.equal(deleteSummary({ ...spec, detail: "" }).stage, SPEC_STATE_LABELS.building);
});
test("scanProject counts each spec's files", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-scan-files-"));
try {
fakeSpec(root, "three", { "overview.md": "# o\n", "phase-1.md": "- [ ] **Task 1.1:** a\n", "pathfinder/map.md": "# m\n" });
fakeSpec(root, "one", { "DESIGN.md": "# d\n" });
const byName = Object.fromEntries(scanProject(root).specs.map((s) => [s.name, s]));
assert.equal(byName.three.files, 3);
assert.equal(byName.one.files, 1);
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
});
test("removeSpec deletes one spec folder and refuses everything else", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-remove-spec-"));
const outside = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-remove-outside-"));
try {
fakeSpec(root, "keep", { "overview.md": "# keep\n" });
fakeSpec(root, "gone", { "overview.md": "# gone\n", "pathfinder/map.md": "# m\n" });
fs.mkdirSync(path.join(root, "specs--completed", "old"), { recursive: true });
fs.writeFileSync(path.join(outside, "precious.md"), "do not touch\n");
assert.deepEqual(removeSpec(root, "specs/gone"), { ok: true, removed: "specs/gone" });
assert.equal(fs.existsSync(path.join(root, "specs", "gone")), false);
assert.equal(fs.existsSync(path.join(root, "specs", "keep", "overview.md")), true);
for (const bad of ["specs/../specs--completed/old", "specs--completed/old", "specs/keep/pathfinder", "specs/missing", "specs"]) {
assert.throws(() => removeSpec(root, bad), Error, bad);
}
assert.equal(fs.existsSync(path.join(root, "specs--completed", "old")), true);
// A spec folder that is a link to somewhere else is refused, and what it
// points at survives.
fs.symlinkSync(outside, path.join(root, "specs", "linked"), "junction");
assert.throws(() => removeSpec(root, "specs/linked"), /outside|link/i);
assert.equal(fs.existsSync(path.join(outside, "precious.md")), true);
// A file named like a spec is not a spec folder.
fs.writeFileSync(path.join(root, "specs", "note.md"), "x\n");
assert.throws(() => removeSpec(root, "specs/note.md"), /folder/i);
} finally {
fs.rmSync(root, { recursive: true, force: true });
fs.rmSync(outside, { recursive: true, force: true });
}
});
test("delete-spec removes a spec from the worktree it runs in, and exits 3 with the reason when it refuses", () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-delete-cli-"));
try {
fakeSpec(root, "scratch", { "overview.md": "# s\n" });
const done = cli(["delete-spec", "--spec", "specs/scratch"], { cwd: root });
assert.equal(done.status, 0, done.stderr);
assert.equal(done.json.ok, true);
assert.equal(done.json.removed, "specs/scratch");
assert.equal(fs.existsSync(path.join(root, "specs", "scratch")), false);
const refused = cli(["delete-spec", "--spec", "specs/../AGENTS.md"], { cwd: root, expectFail: true });
assert.equal(refused.status, 3);
assert.equal(refused.json.ok, false);
assert.ok(refused.json.message);
const usage = cli(["delete-spec"], { cwd: root, expectFail: true });
assert.equal(usage.status, 2);
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
});
// The dashboard's Git card offers to start a repository when the folder
// is not one. The scan answers that from the filesystem, never from a git
// process, and a linked worktree (a .git file, not a folder) must count.
@@ -864,6 +1018,49 @@ test("the dashboard matrix lights only the cards a spec state allows", () => {
assert.equal(on("plan2code-1b-revise-plan", scan, sel("built")), false);
assert.equal(on("plan2code-4-finalize", scan, sel("built")), true);
// A diagnosed bug: Quick Task (its next step) and Plan, never the build steps.
for (const skill of ["plan2code-quick-task", "plan2code-1-plan", "plan2code-review", "plan2code-diagnose"]) {
assert.equal(on(skill, scan, sel("diagnosed")), true, `${skill} on for a diagnosed bug`);
}
for (const skill of [
"plan2code-0-pathfinder",
"plan2code-1b-revise-plan",
"plan2code-2-document",
"plan2code-3-implement",
"plan2code-3-implement-review",
"plan2code-4-finalize",
]) {
assert.equal(on(skill, scan, sel("diagnosed")), false, `${skill} off for a diagnosed bug`);
}
assert.equal(cardAvailability(entry("plan2code-quick-task"), scan, sel("diagnosed")).next, true);
assert.ok(!cardAvailability(entry("plan2code-1-plan"), scan, sel("diagnosed")).next);
assert.ok(!cardAvailability(entry("plan2code-quick-task"), scan, sel("building")).next);
// Quick Task carries the folder only for a diagnosed bug; spec cards always do.
assert.equal(launchTarget(entry("plan2code-quick-task"), sel("diagnosed")).dir, "specs/x");
assert.equal(launchTarget(entry("plan2code-quick-task"), sel("building")), null);
assert.equal(launchTarget(entry("plan2code-1-plan"), sel("diagnosed")).dir, "specs/x");
assert.equal(launchTarget(entry("plan2code-review"), sel("diagnosed")), null);
assert.equal(launchTarget(entry("plan2code-1-plan"), null), null);
// A fixed bug is finished: no pipeline card, and Quick Task starts fresh.
for (const skill of [
"plan2code-0-pathfinder",
"plan2code-1-plan",
"plan2code-1b-revise-plan",
"plan2code-2-document",
"plan2code-3-implement",
"plan2code-3-implement-review",
"plan2code-4-finalize",
]) {
const av = cardAvailability(entry(skill), scan, sel("fixed"));
assert.equal(av.on, false, `${skill} off for a fixed bug`);
assert.ok(av.reason, `${skill} says why it is off for a fixed bug`);
}
assert.equal(on("plan2code-quick-task", scan, sel("fixed")), true);
assert.ok(!cardAvailability(entry("plan2code-quick-task"), scan, sel("fixed")).next);
assert.equal(launchTarget(entry("plan2code-quick-task"), sel("fixed")), null);
// A greyed card always says why, and a selected spec's next step is marked.
assert.ok(cardAvailability(entry("plan2code-3-implement"), scan, sel("exploring")).reason);
assert.equal(cardAvailability(entry("plan2code-3-implement"), scan, sel("documented")).next, true);
@@ -903,6 +1100,29 @@ test("dashboard card presentation follows the current picker selection", () => {
assert.equal(planned.detail, "plan drafted");
});
test("the picker never opens on a fixed bug", () => {
const fixed = { dir: "specs/old-bug", name: "old-bug", state: "fixed", detail: "bug fixed" };
const live = { dir: "specs/lunch-vote", name: "lunch-vote", state: "documented", detail: "2 phases, 8 tasks ready" };
assert.equal(defaultSpec([fixed, live]), live);
assert.equal(defaultSpec([live, fixed]), live);
assert.equal(defaultSpec([fixed]), null);
assert.equal(defaultSpec([]), null);
assert.equal(defaultSpec(undefined), null);
// The agent's recommendation describes the default pick, not the fixed bug
// the server listed first.
const entry = (skill) => SKILL_CATALOG.find((e) => e.skill === skill);
const scan = { hasAgents: true, specs: [fixed, live] };
const menu = { recommend: "plan2code-3-implement", details: { "plan2code-3-implement": "Phase 1 of 2 is next" } };
const shown = cardPresentation(entry("plan2code-3-implement"), scan, live, menu);
assert.equal(shown.recommended, true);
assert.equal(shown.detail, "Phase 1 of 2 is next");
// Only fixed bugs on disk: the default is "start from scratch".
const onlyFixed = { hasAgents: true, specs: [fixed] };
const fresh = cardPresentation(entry("plan2code-0-pathfinder"), onlyFixed, null, { recommend: "plan2code-0-pathfinder" });
assert.equal(fresh.recommended, true);
});
test("the launch reply names the picked spec", () => {
const e = SKILL_CATALOG.find((x) => x.skill === "plan2code-3-implement");
assert.equal(
@@ -1071,6 +1291,8 @@ const CONSOLE_WORKFLOW_LIST = [
"review",
"finalize",
"handoff",
"xray",
"diagnose",
];
test("STARTER_SETS: 3 to 4 starters a set, one without context at least, known lead roles, unique ids", () => {
+56
View File
@@ -716,3 +716,59 @@ test("notes/quick-task.md has the finished quick task offer Back to the dashboar
assert.ok(bullet.includes('"dashboard": true'));
assert.ok(bullet.includes("Review it now"));
});
// Show me it working: a screenshot saved under <session>/shots/ posts as an
// image block and is served back; nothing else is reachable through /shots/.
test("an image block under the session's shots folder round-trips, and /shots/ serves nothing else", async () => {
const res = cli(["open", "--workflow", "implement", "--no-open"]);
const m = res.json.url.match(/^(http:\/\/127\.0\.0\.1:\d+)\/s\/([^/]+)\//);
const cookie = cookieFor(m[1], m[2]);
try {
const shots = path.join(res.json.session, "shots");
fs.mkdirSync(shots, { recursive: true });
const png = Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), Buffer.alloc(32, 7)]);
fs.writeFileSync(path.join(shots, "home-page.png"), png);
const patch = { docs: [{ id: "shown", title: "Shown working", blocks: [{ id: "s1", image: "shots/home-page.png", alt: "The home page with the new button" }] }] };
cli(["post", "--session", res.json.sid, "--file", payload("shots-ok.json", patch)]);
const block = readState(res.json.session).docs.find((d) => d.id === "shown").blocks[0];
assert.equal(block.image, "shots/home-page.png", "stored session-relative");
assert.equal(block.md, undefined);
// Its alt text is a caption, held to the same vocabulary rule as a title.
const jargon = { docs: [{ id: "shown", blocks: [{ id: "s1", image: "shots/home-page.png", alt: "Grilling the home page" }] }] };
const refused = cli(["post", "--session", res.json.sid, "--file", payload("shots-jargon.json", jargon)], { expectFail: true });
assert.equal(refused.status, 3);
assert.match(refused.stderr, /alt text contains internal vocabulary/);
// A changed picture or caption is a new version of the doc.
const before = readState(res.json.session).docs.find((d) => d.id === "shown").version;
const recaption = { docs: [{ id: "shown", blocks: [{ id: "s1", image: "shots/home-page.png", alt: "The home page, after the fix" }] }] };
cli(["post", "--session", res.json.sid, "--file", payload("shots-recaption.json", recaption)]);
assert.equal(readState(res.json.session).docs.find((d) => d.id === "shown").version, before + 1);
const got = await fetch(m[1] + "/shots/home-page.png", { headers: { cookie } });
assert.equal(got.status, 200);
assert.equal(got.headers.get("content-type"), "image/png");
assert.equal(got.headers.get("cache-control"), "no-store");
assert.deepEqual(Buffer.from(await got.arrayBuffer()), png);
const anon = await fetch(m[1] + "/shots/home-page.png");
assert.equal(anon.status, 403, "the cookie is still required");
await anon.arrayBuffer();
// Raw request lines: fetch would fold the `..` away before sending.
const raw = (p) =>
new Promise((resolve, reject) => {
const req = http.request({ host: "127.0.0.1", port: Number(new URL(m[1]).port), path: p, headers: { cookie } }, (r) => {
r.resume();
r.on("end", () => resolve(r.statusCode));
});
req.on("error", reject);
req.end();
});
for (const p of ["/shots/../state.json", "/shots/..%2fstate.json", "/shots/missing.png", "/shots/home-page.png?x=1"]) {
assert.equal(await raw(p), 404, p);
}
} finally {
cli(["stop", "--session", res.json.sid]);
}
});
+17
View File
@@ -225,6 +225,23 @@ test("a launch request round-trips with the skill the dashboard resumes as", asy
assert.ok(state.items.every((i) => i.id !== "__launch"), "a launch must not become a question");
});
// A delete from the dashboard's picker is a send like a launch, but no hop:
// the agent stays the dashboard, so it carries no resume and no skill file.
test("a delete request round-trips with the spec folder and no resume", async () => {
await post("/submit", {
actions: [{ i: "__delete", type: "delete", spec: "specs/lunch-vote" }],
reply: "Delete the spec folder specs/lunch-vote/ for good, right here in this session.",
});
const res = cli(["wait", "--session", sid, "--seconds", "10"]);
assert.equal(res.status, 0);
assert.equal(res.json.actions[0].i, "__delete");
assert.equal(res.json.actions[0].spec, "specs/lunch-vote");
assert.equal(res.json.resume, undefined);
assert.equal(res.json.skillFile, undefined);
const state = JSON.parse(fs.readFileSync(path.join(session, "state.json"), "utf8"));
assert.ok(state.items.every((i) => i.id !== "__delete"), "a delete must not become a question");
});
// Back to the dashboard is a send like the review button: it names no
// question, it is refused while an earlier send is uncollected, and the agent
// answers it by resuming the same session as the dashboard.
+2 -1
View File
@@ -406,7 +406,8 @@ test("every console workflow has its notes, and its skill's Interface reads them
const notesFor = {
init: "init", "init-update": "init", pathfinder: "pathfinder", plan: "plan", "revise-plan": "revise-plan",
document: "document", implement: "implement", "implement-review": "implement", "quick-task": "quick-task",
review: "review", finalize: "finalize", handoff: "handoff", changelog: "changelog", git: "git",
review: "review", finalize: "finalize", handoff: "handoff", changelog: "changelog", git: "git", xray: "xray",
diagnose: "diagnose",
};
const skills = fs.readdirSync(path.join(ROOT, "src")).filter((f) => /^plan2code(-.*)?\.md$/.test(f));
for (const f of skills) {