Add plan2code uninstall to remove everything the installer put in place

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-08 17:25:40 -08:00
1 parent bd2bbc2764
commit e5155778bf
9 files changed
+260 -25

No files matched your search

+99 -2
View File
@@ -183,10 +183,10 @@ test("update: every step is an install function, never an uninstall", () => {
}
});
test("install.js: --update is in the usage line, and an unknown option still exits 1", () => {
test("install.js: --update and --uninstall are 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);
assert.ok(result.stderr.includes("Usage: node install.js [--build-skills | --verify-skills | --update | --uninstall [--yes] [--purge]]"), result.stderr);
});
// ---------------------------------------------------------------------------------------------
@@ -605,3 +605,100 @@ test("the skills CLI is pinned to one exact version, and every doc line that run
}
}
});
/** Run uninstall() with console output captured and the answers to its y/N questions scripted. */
async function runUninstall(options, answers = []) {
const lines = [];
const asked = [];
const calls = [];
const log = console.log;
console.log = (...args) => lines.push(args.join(" "));
try {
const code = await installer.uninstall({
ask: async (prompt) => {
asked.push(prompt.replace(/\x1b\[[0-9;]*m/g, ""));
return answers.shift() ?? false;
},
remove: () => (calls.push("remove"), 0),
purgeIt: () => (calls.push("purge"), 0),
...options,
});
return { code, asked, calls, out: lines.join("\n").replace(/\x1b\[[0-9;]*m/g, "") };
} finally {
console.log = log;
}
}
test("uninstall: a no at the confirmation removes nothing", async () => {
const r = await runUninstall({}, [false]);
assert.equal(r.code, 0);
assert.deepEqual(r.calls, []);
assert.equal(r.asked.length, 1);
assert.match(r.out, /CANCELED/);
});
test("uninstall: a yes removes everything, then asks about the data and keeps it on a no", async () => {
const r = await runUninstall({}, [true, false]);
assert.equal(r.code, 0);
assert.deepEqual(r.calls, ["remove"]);
assert.equal(r.asked.length, 2);
assert.match(r.asked[1], /Also delete your Plan2Code data/);
assert.match(r.out, /data in .* was kept/);
});
test("uninstall: a yes to the data question purges it", async () => {
const r = await runUninstall({}, [true, true]);
assert.deepEqual(r.calls, ["remove", "purge"]);
});
test("uninstall: --yes skips both questions and keeps the data", async () => {
const r = await runUninstall({ yes: true });
assert.deepEqual(r.asked, []);
assert.deepEqual(r.calls, ["remove"]);
});
test("uninstall: --yes --purge deletes the data without a question", async () => {
const r = await runUninstall({ yes: true, purge: true });
assert.deepEqual(r.asked, []);
assert.deepEqual(r.calls, ["remove", "purge"]);
});
test("uninstall: --purge alone still confirms the uninstall but never asks about the data", async () => {
const r = await runUninstall({ purge: true }, [true]);
assert.equal(r.asked.length, 1);
assert.deepEqual(r.calls, ["remove", "purge"]);
});
test("uninstall: a failing removal or purge makes the exit code non-zero", async () => {
assert.equal((await runUninstall({ yes: true, remove: () => 1 })).code, 1);
assert.equal((await runUninstall({ yes: true, purge: true, purgeIt: () => 1 })).code, 1);
});
test("purgeData: deletes the folder and everything in it, and copes with it missing", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-purge-"));
fs.mkdirSync(path.join(dir, "notepads"));
fs.writeFileSync(path.join(dir, "notepads", "a.json"), "{}");
const log = console.log;
console.log = () => {};
try {
assert.equal(installer.purgeData(dir), 0);
assert.equal(fs.existsSync(dir), false);
assert.equal(installer.purgeData(dir), 0);
} finally {
console.log = log;
}
});
test("install.js --uninstall: an unknown extra option is refused", () => {
const r = spawnSync(process.execPath, [INSTALL, "--uninstall", "--nuke"], { encoding: "utf8", env: { ...process.env, HOME, USERPROFILE: HOME } });
assert.equal(r.status, 1);
assert.match(r.stderr, /Unknown option\(s\): --uninstall --nuke/);
});
test("install.js --uninstall: with no terminal and no --yes it explains, exits 1 and removes nothing", () => {
fs.mkdirSync(path.join(HOME, ".plan2code"), { recursive: true });
const r = spawnSync(process.execPath, [INSTALL, "--uninstall"], { encoding: "utf8", input: "", env: { ...process.env, HOME, USERPROFILE: HOME } });
assert.equal(r.status, 1, r.stderr);
assert.match(r.stdout, /Run plan2code uninstall --yes/);
assert.ok(fs.existsSync(path.join(HOME, ".plan2code")));
});
+28
View File
@@ -475,6 +475,34 @@ test("launcher: update passes npx's exit code through", (t) => {
assert.equal(box.run(["update"], { P2C_TEST_EXIT: "3" }).status, 3);
});
test("launcher: uninstall runs the npx install with --uninstall and starts no agent", (t) => {
const box = sandbox(["npx", "claude"]);
t.after(box.cleanup);
const result = box.run(["uninstall", "--yes", "--purge"]);
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Uninstalling Plan2Code\.\.\./);
const args = box.argsOf("npx");
assert.ok(args, "npx was not run");
assert.ok(args.includes("--uninstall") && args.includes("--yes") && args.includes("--purge"), args.join(" "));
assert.ok(!args.includes("--update"), args.join(" "));
assert.equal(box.argsOf("claude"), null);
});
test("launcher: uninstall passes npx's exit code through", (t) => {
const box = sandbox(["npx"]);
t.after(box.cleanup);
assert.equal(box.run(["uninstall"], { P2C_TEST_EXIT: "4" }).status, 4);
});
test("launcher: uninstall refuses an unknown option without running npx", (t) => {
const box = sandbox(["npx"]);
t.after(box.cleanup);
const result = box.run(["uninstall", "--nuke"]);
assert.equal(result.status, 2);
assert.match(result.stderr, /unknown option\(s\) for uninstall: --nuke/);
assert.equal(box.argsOf("npx"), null);
});
test("launcher: release notice prints from a fresh cache", (t) => {
const box = sandbox(["claude"], { installed: "1.0.0" });
t.after(box.cleanup);