v3-orchestrator

This commit is contained in:
jparkerweb committed 2026-10-23 10:04:13 -07:00
1 parent 7a4b7c6db8
commit 681c4a4b85
27 files changed
+1138 -36

No files matched your search

+314
View File
@@ -7,7 +7,9 @@
import test from "node:test";
import assert from "node:assert/strict";
import crypto from "node:crypto";
import fs from "node:fs";
import http from "node:http";
import os from "node:os";
import path from "node:path";
import { spawnSync } from "node:child_process";
@@ -186,3 +188,315 @@ test("install.js: --update is in the usage line, and an unknown option still exi
assert.equal(result.status, 1);
assert.ok(result.stderr.includes("Usage: node install.js [--build-skills | --verify-skills | --update]"), result.stderr);
});
// ---------------------------------------------------------------------------------------------
// The desktop app: downloaded from a release, checked against its checksum list, placed in
// ~/.plan2code/app/. A stand-in release server stands in for GitHub; PLAN2CODE_RELEASE_BASE
// points the installer at it, and nothing here reaches the network.
// ---------------------------------------------------------------------------------------------
const ASSET = installer.appAssetName(VERSION);
const SUMS = `plan2code-app-${VERSION}-SHA256SUMS.txt`;
const APP_DIR = path.dirname(installer.APP_DEST);
const sha = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex");
/** A release server for `files` (`{ path: Buffer | string }`); `hits` lists every path asked for. */
async function releaseServer(files) {
const hits = [];
const server = http.createServer((req, res) => {
const name = decodeURIComponent(req.url.slice(1));
hits.push(name);
if (name in files) {
res.writeHead(200);
res.end(files[name]);
} else {
res.writeHead(404);
res.end("not found");
}
});
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
process.env.PLAN2CODE_RELEASE_BASE = `http://127.0.0.1:${server.address().port}/release`;
return {
hits,
close: () => {
delete process.env.PLAN2CODE_RELEASE_BASE;
server.close();
},
};
}
/** A release serving `bytes` as this system's app, listed under `listedHash` (default: its real hash). */
function goodRelease(bytes, listedHash = sha(bytes)) {
return {
[`release/${ASSET}`]: bytes,
[`release/${SUMS}`]: `${listedHash} ${ASSET}\n${"0".repeat(64)} plan2code-app-other\n`,
};
}
/** Run `fn` with console output captured; resolves `{ result, out }`. */
async function captured(fn) {
const lines = [];
const log = console.log;
console.log = (...args) => lines.push(args.join(" "));
try {
const result = await fn();
return { result, out: lines.join("\n").replace(/\x1b\[[0-9;]*m/g, "") };
} finally {
console.log = log;
}
}
function freshApp() {
fs.rmSync(APP_DIR, { recursive: true, force: true });
clearRecord();
}
test("app: the release file is named by system and cpu, and an unbuilt system has none", () => {
assert.equal(installer.appAssetName("3.0.0", "win32", "x64"), "plan2code-app-3.0.0-windows-x64.exe");
assert.equal(installer.appAssetName("3.0.0", "darwin", "arm64"), "plan2code-app-3.0.0-macos-arm64");
assert.equal(installer.appAssetName("3.0.0", "darwin", "x64"), "plan2code-app-3.0.0-macos-x64");
assert.equal(installer.appAssetName("3.0.0", "linux", "x64"), "plan2code-app-3.0.0-linux-x64");
assert.equal(installer.appAssetName("3.0.0", "freebsd", "x64"), null);
assert.equal(installer.appAssetName("3.0.0", "linux", "ia32"), null);
});
test("app: checksumFor reads text and binary mode lines and wants the exact name", () => {
const hex = "ab".repeat(32);
const list = `${hex} plan2code-app-1-linux-x64\n${"cd".repeat(32)} *plan2code-app-1-macos-arm64\r\nnot a checksum line\n`;
assert.equal(installer.checksumFor(list, "plan2code-app-1-linux-x64"), hex);
assert.equal(installer.checksumFor(list, "plan2code-app-1-macos-arm64"), "cd".repeat(32));
assert.equal(installer.checksumFor(list, "plan2code-app-1-linux"), null);
assert.equal(installer.checksumFor("", "x"), null);
});
test("app installed: the file is downloaded, verified, placed and recorded", { skip: !ASSET }, async () => {
freshApp();
writeRecord(["skills", "launcher"]);
const bytes = Buffer.from("pretend this is an executable");
const server = await releaseServer(goodRelease(bytes));
try {
const outcome = {};
const { result, out } = await captured(() => installer.installDesktopApp({ quiet: true, outcome }));
assert.equal(result, 0, out);
assert.equal(outcome.app, true);
assert.deepEqual(fs.readFileSync(installer.APP_DEST), bytes);
assert.deepEqual(installer.readInstallRecord().pieces, ["app", "launcher", "skills"]);
assert.deepEqual(fs.readdirSync(APP_DIR), [path.basename(installer.APP_DEST)], "no temp or .old file is left");
assert.match(out, /unsigned/);
assert.deepEqual(server.hits, [`release/${SUMS}`, `release/${ASSET}`]);
} finally {
server.close();
}
});
test("app checksum mismatch: the file is rejected, nothing is placed and the old app stays", { skip: !ASSET }, async () => {
freshApp();
fs.mkdirSync(APP_DIR, { recursive: true });
fs.writeFileSync(installer.APP_DEST, "the app that was already here");
writeRecord(["skills", "launcher", "app"]);
const server = await releaseServer(goodRelease(Buffer.from("tampered bytes"), "1".repeat(64)));
try {
const outcome = {};
const { result, out } = await captured(() => installer.installDesktopApp({ quiet: true, outcome }));
assert.equal(result, 1);
assert.equal(outcome.app, false);
assert.match(out, /does not match its checksum/);
// Said plainly: the rest is installed and --classic is today's flow.
assert.match(out, /skills and the plan2code command are installed/);
assert.equal(fs.readFileSync(installer.APP_DEST, "utf8"), "the app that was already here");
assert.deepEqual(fs.readdirSync(APP_DIR), [path.basename(installer.APP_DEST)]);
} finally {
server.close();
}
});
test("app: a release without the file, or without a checksum entry, fails plainly and places nothing", { skip: !ASSET }, async () => {
for (const files of [{}, { [`release/${SUMS}`]: `${"2".repeat(64)} some-other-file\n` }]) {
freshApp();
writeRecord(["skills", "launcher"]);
const server = await releaseServer(files);
try {
const outcome = {};
const { result, out } = await captured(() => installer.installDesktopApp({ quiet: true, outcome }));
assert.equal(result, 1, out);
assert.equal(outcome.app, false);
assert.match(out, /The desktop app was not installed: /);
assert.equal(fs.existsSync(installer.APP_DEST), false);
assert.deepEqual(installer.readInstallRecord().pieces, ["skills", "launcher"], "a failed install leaves the record as it was");
} finally {
server.close();
}
}
});
test("app: a server that is not there fails plainly", { skip: !ASSET }, async () => {
freshApp();
writeRecord(["skills", "launcher"]);
process.env.PLAN2CODE_RELEASE_BASE = "http://127.0.0.1:1/release";
try {
const { result, out } = await captured(() => installer.installDesktopApp({ quiet: true }));
assert.equal(result, 1);
assert.match(out, /could not download it/);
} finally {
delete process.env.PLAN2CODE_RELEASE_BASE;
}
});
test("app update: plan2code update replaces an older app and reports it", { skip: !ASSET }, async () => {
freshApp();
fs.mkdirSync(APP_DIR, { recursive: true });
fs.writeFileSync(installer.APP_DEST, "an older app");
writeRecord(["app"]);
const bytes = Buffer.from("the newer app");
const server = await releaseServer(goodRelease(bytes));
try {
// The real app step, in the real update loop; the record lists only the app.
const { result, out } = await captured(() => installer.update({ steps: installer.UPDATE_STEPS }));
assert.equal(result, 0, out);
assert.match(out, /app: updated/);
assert.deepEqual(fs.readFileSync(installer.APP_DEST), bytes);
assert.deepEqual(fs.readdirSync(APP_DIR), [path.basename(installer.APP_DEST)]);
} finally {
server.close();
}
});
test("app update: a checksum mismatch fails the update naming the app, nothing else", { skip: !ASSET }, async () => {
freshApp();
writeRecord(["app"]);
const server = await releaseServer(goodRelease(Buffer.from("tampered bytes"), "1".repeat(64)));
try {
const { result, out } = await captured(() => installer.update({ steps: installer.UPDATE_STEPS }));
assert.equal(result, 1);
assert.match(out, /Update failed for: app/);
} finally {
server.close();
}
});
test("app update: a release with no app file yet keeps the installed app and does not fail the update", { skip: !ASSET }, async () => {
freshApp();
fs.mkdirSync(APP_DIR, { recursive: true });
fs.writeFileSync(installer.APP_DEST, "the installed app");
writeRecord(["app"]);
// main moves to a new version before the release's files are attached: every file is a 404.
const server = await releaseServer({});
try {
const { result, out } = await captured(() => installer.update({ steps: installer.UPDATE_STEPS }));
assert.equal(result, 0, out);
assert.match(out, /app: kept/);
assert.doesNotMatch(out, /Update failed/);
assert.equal(fs.readFileSync(installer.APP_DEST, "utf8"), "the installed app");
} finally {
server.close();
}
});
test("app: interactively, a release with no app file is a plain failure, and a placement error is not called a download error", { skip: !ASSET }, async () => {
freshApp();
writeRecord(["skills", "launcher"]);
let server = await releaseServer({});
try {
const { result, out } = await captured(() => installer.installDesktopApp({ quiet: true }));
assert.equal(result, 1);
assert.match(out, /has no desktop app file for/);
} finally {
server.close();
}
// The download is fine but the folder cannot be made: a file sits where the app folder goes.
fs.mkdirSync(path.dirname(APP_DIR), { recursive: true });
fs.writeFileSync(APP_DIR, "in the way");
server = await releaseServer(goodRelease(Buffer.from("a good file")));
try {
const { result, out } = await captured(() => installer.installDesktopApp({ quiet: true }));
assert.equal(result, 1);
assert.match(out, /the file was verified but could not be put in/);
assert.doesNotMatch(out, /could not download/);
} finally {
server.close();
fs.rmSync(APP_DIR, { force: true });
}
});
test("app offered: a system with no build is never asked about, never downloaded for and says nothing red", { skip: !ASSET }, async () => {
freshApp();
writeRecord(["skills", "launcher"]);
const server = await releaseServer(goodRelease(Buffer.from("never fetched")));
const arch = Object.getOwnPropertyDescriptor(process, "arch");
Object.defineProperty(process, "arch", { value: "ia32", configurable: true });
try {
for (const unattended of [true, false]) {
const { out } = await captured(() => installer.offerDesktopApp({ unattended, outcome: {} }));
assert.doesNotMatch(out, /was not installed/);
}
assert.deepEqual(server.hits, []);
assert.equal(fs.existsSync(installer.APP_DEST), false);
} finally {
Object.defineProperty(process, "arch", arch);
server.close();
}
});
test("app offered: unattended with no app file in the release yet is a dim note, not a failure", { skip: !ASSET }, async () => {
freshApp();
writeRecord(["skills", "launcher"]);
const server = await releaseServer({});
try {
const outcome = {};
const { out } = await captured(() => installer.offerDesktopApp({ unattended: true, outcome }));
assert.match(out, /No desktop app update/);
assert.doesNotMatch(out, /was not installed/);
assert.equal(outcome.app, false);
assert.equal(fs.existsSync(installer.APP_DEST), false);
} finally {
server.close();
}
});
test("app skipped: an unattended offer downloads nothing when the app is recorded or was declined", { skip: !ASSET }, async () => {
const server = await releaseServer(goodRelease(Buffer.from("never fetched")));
try {
// Recorded: the update loop owns it. Declined: the person said no once.
for (const record of [{ pieces: ["skills", "app"] }, { pieces: ["skills"], skipped: ["app"] }]) {
freshApp();
fs.mkdirSync(path.dirname(RECORD), { recursive: true });
fs.writeFileSync(RECORD, JSON.stringify({ version: "1.0.0", scope: "global", ...record }));
await captured(() => installer.offerDesktopApp({ unattended: true, outcome: {} }));
assert.equal(fs.existsSync(installer.APP_DEST), false, JSON.stringify(record));
}
assert.deepEqual(server.hits, []);
} finally {
server.close();
}
});
test("app offered: unattended with nothing recorded about it means yes, and installing clears an old no", { skip: !ASSET }, async () => {
freshApp();
writeRecord(["skills", "launcher"]);
const bytes = Buffer.from("first time app");
const server = await releaseServer(goodRelease(bytes));
try {
const outcome = {};
await captured(() => installer.offerDesktopApp({ unattended: true, outcome }));
assert.equal(outcome.app, true);
assert.deepEqual(fs.readFileSync(installer.APP_DEST), bytes);
} finally {
server.close();
}
// A recorded decline is dropped once the piece is installed, and the key leaves the file when empty.
fs.writeFileSync(RECORD, JSON.stringify({ version: "1.0.0", scope: "global", pieces: ["skills"], skipped: ["app"] }));
installer.recordInstalled("app");
assert.deepEqual(installer.readInstallRecord(), { version: VERSION, scope: "global", pieces: ["app", "skills"] });
});
test("app declined: the no is remembered next to the pieces, and needs a record to be kept", () => {
clearRecord();
installer.recordSkipped("app");
assert.equal(installer.readInstallRecord(), null, "no record is invented for a decline");
writeRecord(["skills"]);
installer.recordSkipped("app");
assert.deepEqual(installer.readInstallRecord(), { version: VERSION, scope: "global", pieces: ["skills"], skipped: ["app"] });
installer.recordInstalled("launcher");
assert.deepEqual(installer.readInstallRecord().skipped, ["app"], "other writes keep the decline");
});
+230 -2
View File
@@ -25,8 +25,11 @@ const NOTICE = "will use the model you last used in it";
* `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 } = {}) {
function sandbox(clis, { installed, project = true } = {}) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-launcher-"));
// `dir` is the launcher's cwd below; mark it as a project so the project-confirmation gate
// does not fire in every other test here. The gate's own tests pass `project: false`.
if (project) fs.writeFileSync(path.join(dir, "AGENTS.md"), "");
const home = path.join(dir, "home");
const bin = path.join(dir, "bin");
fs.mkdirSync(home);
@@ -57,8 +60,31 @@ function sandbox(clis, { installed } = {}) {
fs.chmodSync(file, 0o755);
}
}
// A stand-in for the desktop app that records its arguments like the CLIs do. It is not
// on PATH: the launcher finds it through PLAN2CODE_APP, set only for the run that wants it.
const appDir = path.join(dir, "app");
fs.mkdirSync(appDir);
const appFile = path.join(appDir, IS_WINDOWS ? "stand-in-app.cmd" : "stand-in-app");
if (IS_WINDOWS) {
// The first line leaves the sandbox folder (the app's working directory) so nothing holds it open.
fs.writeFileSync(appFile, `@cd /d "${os.tmpdir()}"\r\n@"${process.execPath}" "${recorder}" app %*\r\n`);
} else {
fs.writeFileSync(appFile, `#!/bin/sh\ncd "${os.tmpdir()}" && exec "${process.execPath}" "${recorder}" app "$@"\n`);
fs.chmodSync(appFile, 0o755);
}
// One that starts and dies at once, as a program with a missing system library does.
const crashFile = path.join(appDir, IS_WINDOWS ? "crashing-app.cmd" : "crashing-app");
if (IS_WINDOWS) {
fs.writeFileSync(crashFile, "@exit /b 3\r\n");
} else {
fs.writeFileSync(crashFile, "#!/bin/sh\nexit 3\n");
fs.chmodSync(crashFile, 0o755);
}
return {
dir,
home,
appFile,
crashFile,
stateFile: path.join(home, ".plan2code", "launcher.json"),
cacheFile: path.join(consoleHome, "update-check.json"),
run: (args, env = {}) =>
@@ -72,8 +98,28 @@ function sandbox(clis, { installed } = {}) {
const file = path.join(bin, `${cli}.json`);
return fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, "utf8")) : null;
},
// The app starts detached and the launcher exits at once, so its record can land a moment later.
appArgs: () => {
const file = path.join(bin, "app.json");
for (let waited = 0; waited < 10000 && !fs.existsSync(file); waited += 50) {
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);
}
return fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, "utf8")) : null;
},
appExists: () => fs.existsSync(path.join(bin, "app.json")),
// 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 }),
// The stand-in app runs detached with the sandbox as its folder, so on Windows it can hold
// the directory for a moment after its record lands, and rmSync's own retries give up on
// that EPERM at once. Try again for a few seconds; a temp folder left behind is harmless.
cleanup: () => {
for (let attempt = 0; attempt < 25; attempt++) {
try {
return fs.rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
} catch {
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);
}
}
},
};
}
@@ -379,3 +425,185 @@ test("launcher: a piped run prints no escape codes, with or without NO_COLOR", (
}
});
// The desktop app hand-off. The stand-in app is found through PLAN2CODE_APP; "no display" is
// only something a Linux run can ask for, since Windows and macOS always count as having one.
const NO_DISPLAY = { DISPLAY: "", WAYLAND_DISPLAY: "" };
const CLASSIC_ARGS = ["/plan2code", "--permission-mode", "bypassPermissions"];
test("launcher app: with no app installed the agent starts exactly as before", (t) => {
const box = sandbox(["claude"]);
t.after(box.cleanup);
const result = box.run([]);
assert.equal(result.status, 0, result.stderr);
assert.deepEqual(box.argsOf("claude"), CLASSIC_ARGS);
assert.equal(box.appExists(), false);
});
test("launcher app: --classic runs today's flow even with the app installed, and is never forwarded", (t) => {
const box = sandbox(["claude"]);
t.after(box.cleanup);
const result = box.run(["--classic", "--verbose"], { PLAN2CODE_APP: box.appFile });
assert.equal(result.status, 0, result.stderr);
assert.deepEqual(box.argsOf("claude"), [...CLASSIC_ARGS, "--verbose"]);
assert.equal(box.appExists(), false);
});
test("launcher app: no display on Linux runs today's flow even with the app installed", { skip: process.platform !== "linux" }, (t) => {
const box = sandbox(["claude"]);
t.after(box.cleanup);
const result = box.run([], { PLAN2CODE_APP: box.appFile, ...NO_DISPLAY });
assert.equal(result.status, 0, result.stderr);
assert.deepEqual(box.argsOf("claude"), CLASSIC_ARGS);
assert.equal(box.appExists(), false);
});
test("launcher app: with the app and a display it starts the app on the folder, agent and model, and no agent", (t) => {
const box = sandbox(["claude", "codex"]);
t.after(box.cleanup);
const display = process.platform === "linux" ? { DISPLAY: ":0" } : {};
const result = box.run(["--cli", "codex", "--model", "gpt-5"], { PLAN2CODE_APP: box.appFile, ...display });
assert.equal(result.status, 0, result.stderr);
const appArgs = box.appArgs();
assert.ok(appArgs, "the stand-in app was never started");
// The launcher runs in the sandbox folder, so that folder is the project.
assert.equal(appArgs[0], "--project");
assert.equal(fs.realpathSync(appArgs[1]), fs.realpathSync(box.dir));
assert.deepEqual(appArgs.slice(2), ["--agent", "codex", "--model", "gpt-5"]);
assert.equal(box.argsOf("claude"), null);
assert.equal(box.argsOf("codex"), null);
assert.match(result.stdout, /Opened the Plan2Code app/);
});
test("launcher app: a model is left out of the app's arguments when none was chosen", (t) => {
const box = sandbox(["claude"]);
t.after(box.cleanup);
const display = process.platform === "linux" ? { DISPLAY: ":0" } : {};
const result = box.run([], { PLAN2CODE_APP: box.appFile, ...display });
assert.equal(result.status, 0, result.stderr);
assert.deepEqual(box.appArgs().slice(2), ["--agent", "claude"]);
});
test("launcher app: an app that cannot start falls back to the terminal flow", (t) => {
const box = sandbox(["claude"]);
t.after(box.cleanup);
const display = process.platform === "linux" ? { DISPLAY: ":0" } : {};
// Present but not runnable (no execute bit on POSIX, not a program on Windows).
const broken = path.join(path.dirname(box.appFile), IS_WINDOWS ? "broken.exe" : "broken");
fs.writeFileSync(broken, "not a program");
const result = box.run([], { PLAN2CODE_APP: broken, ...display });
assert.equal(result.status, 0, result.stderr);
assert.match(result.stderr, /could not start the app/);
assert.deepEqual(box.argsOf("claude"), CLASSIC_ARGS);
});
test("launcher app: modelFrom reads --model, --model= and Codex's -m", () => {
const { modelFrom } = require(LAUNCHER);
assert.equal(modelFrom(["--model", "x"], "claude"), "x");
assert.equal(modelFrom(["--model=x"], "claude"), "x");
assert.equal(modelFrom(["-m", "x"], "codex"), "x");
assert.equal(modelFrom(["-m=x"], "codex"), "x");
assert.equal(modelFrom(["-m", "x"], "claude"), null);
assert.equal(modelFrom(["--verbose"], "claude"), null);
});
test("launcher app: an app that starts and then exits with a failure falls back to the terminal flow", (t) => {
const box = sandbox(["claude"]);
t.after(box.cleanup);
const display = process.platform === "linux" ? { DISPLAY: ":0" } : {};
const result = box.run([], { PLAN2CODE_APP: box.crashFile, ...display });
assert.equal(result.status, 0, result.stderr);
assert.match(result.stderr, /the app exited at once \(code 3\)/);
assert.deepEqual(box.argsOf("claude"), CLASSIC_ARGS);
assert.doesNotMatch(result.stdout, /Opened the Plan2Code app/);
});
test("launcher app: hasDisplay refuses an SSH session on Windows and macOS, but Linux only cares about DISPLAY", () => {
const launcherPath = require.resolve(LAUNCHER);
const realPlatform = process.platform;
const saved = {
DISPLAY: process.env.DISPLAY,
WAYLAND_DISPLAY: process.env.WAYLAND_DISPLAY,
SSH_CONNECTION: process.env.SSH_CONNECTION,
SSH_TTY: process.env.SSH_TTY,
};
for (const key of Object.keys(saved)) delete process.env[key];
// IS_WINDOWS/IS_MAC are consts captured from process.platform at require time, so testing a
// platform other than this machine's needs a fresh module instance loaded under a faked one.
function hasDisplayOn(platform) {
Object.defineProperty(process, "platform", { value: platform, configurable: true });
delete require.cache[launcherPath];
try {
return require(LAUNCHER).hasDisplay();
} finally {
Object.defineProperty(process, "platform", { value: realPlatform, configurable: true });
delete require.cache[launcherPath];
}
}
try {
for (const platform of ["win32", "darwin"]) {
assert.equal(hasDisplayOn(platform), true, platform);
process.env.SSH_CONNECTION = "10.0.0.1 51000 10.0.0.2 22";
assert.equal(hasDisplayOn(platform), false, `${platform} SSH_CONNECTION`);
delete process.env.SSH_CONNECTION;
process.env.SSH_TTY = "/dev/ttys000";
assert.equal(hasDisplayOn(platform), false, `${platform} SSH_TTY`);
delete process.env.SSH_TTY;
}
// Linux never looks at the SSH env vars; DISPLAY/WAYLAND_DISPLAY alone still decides.
process.env.SSH_CONNECTION = "10.0.0.1 51000 10.0.0.2 22";
assert.equal(hasDisplayOn("linux"), false);
process.env.DISPLAY = ":0";
assert.equal(hasDisplayOn("linux"), true);
delete process.env.DISPLAY;
delete process.env.SSH_CONNECTION;
} finally {
for (const [key, value] of Object.entries(saved)) {
if (value === undefined) delete process.env[key];
else process.env[key] = value;
}
// Re-require with the real platform so later tests in this file see the host's own module.
delete require.cache[launcherPath];
require(LAUNCHER);
}
});
test("launcher app: looksLikeProject checks for a .git entry, AGENTS.md or a specs folder", () => {
const { looksLikeProject } = require(LAUNCHER);
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-project-"));
try {
assert.equal(looksLikeProject(dir), false);
fs.writeFileSync(path.join(dir, "AGENTS.md"), "");
assert.equal(looksLikeProject(dir), true);
fs.rmSync(path.join(dir, "AGENTS.md"));
// A worktree's .git is a file, not a directory, and still counts.
fs.writeFileSync(path.join(dir, ".git"), "gitdir: ../elsewhere/.git/worktrees/x\n");
assert.equal(looksLikeProject(dir), true);
fs.rmSync(path.join(dir, ".git"));
assert.equal(looksLikeProject(dir), false);
fs.mkdirSync(path.join(dir, "specs"));
assert.equal(looksLikeProject(dir), true);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test("launcher app: a folder that doesn't look like a project is refused without a terminal to confirm it", (t) => {
const box = sandbox(["claude"], { project: false });
t.after(box.cleanup);
const result = box.run([]);
assert.equal(result.status, 0, result.stderr);
assert.match(result.stderr, /doesn't look like a project/);
assert.equal(box.argsOf("claude"), null);
});
test("launcher app: an AGENTS.md marks the folder as a project, so the agent starts as usual", (t) => {
const box = sandbox(["claude"]);
t.after(box.cleanup);
const result = box.run([]);
assert.equal(result.status, 0, result.stderr);
assert.doesNotMatch(result.stderr, /doesn't look like a project/);
assert.notEqual(box.argsOf("claude"), null);
});
+2 -1
View File
@@ -1144,7 +1144,8 @@ test("the dashboard matrix lights only the cards a spec state allows", () => {
assert.equal(on(skill, scan, s), true, `${skill} on for ${s.state}`);
}
}
assert.equal(on("plan2code-1b-revise-plan", scan, sel("built")), false);
// Revise stays lit on a built spec: a change found in the last manual checks is still a plan change.
assert.equal(on("plan2code-1b-revise-plan", scan, sel("built")), true);
assert.equal(on("plan2code-4-finalize", scan, sel("built")), true);
// A diagnosed bug: Quick Task (its next step) and Plan, never the build steps.
+50
View File
@@ -106,6 +106,56 @@ test("the dashboard refuses question cards: nothing there would draw them", () =
assert.ok(validate(state).some((p) => p.includes("dashboard draws no question cards")));
});
test("an unanswered note blocks a settle that ignores it", () => {
const withNote = {
...choice("q1"),
thread: [{ who: "user", text: "Why this option?" }],
submitted: { k: "A", at: "2026-01-01T00:00:00.000Z" },
};
const state = { ...blankState({ sid: "x", project: "p", workflow: "plan" }), items: [withNote] };
const next = applyPatch(state, { settle: ["q1"] });
assert.ok(validate(next).some((p) => p.includes('item "q1" has an unanswered note')));
});
test("adding a thread reply in the same patch clears the note and allows the settle", () => {
const withNote = {
...choice("q1"),
thread: [{ who: "user", text: "Why this option?" }],
submitted: { k: "A", at: "2026-01-01T00:00:00.000Z" },
};
const state = { ...blankState({ sid: "x", project: "p", workflow: "plan" }), items: [withNote] };
const next = applyPatch(state, {
items: [{ id: "q1", thread: [{ who: "agent", text: "Because it matches the brief." }] }],
settle: ["q1"],
});
assert.deepEqual(validate(next), []);
});
test("an item with no user note left unanswered is unaffected", () => {
const state = { ...blankState({ sid: "x", project: "p", workflow: "plan" }), items: [choice("q1"), choice("q2")] };
assert.deepEqual(validate(state), []);
const answered = {
...choice("q3"),
thread: [{ who: "user", text: "Note" }, { who: "agent", text: "Reply." }],
};
assert.deepEqual(validate({ ...state, items: [answered] }), []);
});
test("deleting the item in the same patch is exempt from the unanswered-note check", () => {
const withNote = { ...choice("q1"), thread: [{ who: "user", text: "Why this option?" }] };
const state = { ...blankState({ sid: "x", project: "p", workflow: "plan" }), items: [withNote] };
const next = applyPatch(state, { items: [{ id: "q1", _delete: true }] });
assert.deepEqual(next.items, []);
assert.deepEqual(validate(next), []);
});
test("a finish patch is exempt from the unanswered-note check", () => {
const withNote = { ...choice("q1"), thread: [{ who: "user", text: "Why this option?" }] };
const state = { ...blankState({ sid: "x", project: "p", workflow: "plan" }), items: [withNote] };
const next = applyPatch(state, { finish: { headline: "Done" } });
assert.deepEqual(validate(next), []);
});
/* ------------------------------------------------------------- the CLI */
test("post --file reads a patch PowerShell wrote: a UTF-8 BOM, or UTF-16", () => {
+5
View File
@@ -439,6 +439,10 @@ test("cleanup finds old sessions and strays in both folders, and keeps every pro
// Handoffs are Plan2Code's own, however old: swept by age on open, never offered here.
backdate(put(path.join(plan2code, "handoffs", "2025-01-01-0900-handoff.md")));
backdate(path.join(plan2code, "handoffs"));
// The desktop app and its settings are Plan2Code's own too, however old.
backdate(put(path.join(plan2code, "app", "plan2code-app"), "x"));
backdate(path.join(plan2code, "app"));
backdate(put(path.join(plan2code, "app.json")));
// In use right now: a held lock and a temp between its write and rename.
const live = [put(path.join(consoleDir, "workspaces.json.lock"), ""), put(path.join(plan2code, "models.json.123.tmp"))];
kept.push(...live);
@@ -454,6 +458,7 @@ test("cleanup finds old sessions and strays in both folders, and keeps every pro
"session:20250801-101010-aaaaaa",
]);
assert.equal(items.some((i) => i.id === "root:handoffs"), false, "the handoffs folder is never a stray");
for (const id of ["root:app", "root:app.json"]) assert.equal(items.some((i) => i.id === id), false, `${id} is never a stray`);
assert.equal(STRAY_GRACE_MS, 60 * 60 * 1000);
assert.equal(items.find((i) => i.id === "console:p1.json").bytes, 5);
assert.equal(items.find((i) => i.id === "root:console-dev").kind, "folder");
+1 -1
View File
@@ -176,7 +176,7 @@ const CARDS = {
planned: { on: false, reason: "Needs a spec that is already written up" },
documented: { on: true },
building: { on: true },
built: { on: false, reason: "The spec is fully built" },
built: { on: true },
unrecognized: { on: false, reason: "Needs a spec that is already written up" },
},
"plan2code-2-document": {