mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-12-04 00:15:41 -08:00
Sync upstream v3.2.4: slim install refs, a crash-safe installer, Change project restarts the agent (v3.2.4)
AI Assisted
This commit is contained in:
1 parent
50319aa332
commit
f997a82c4d
45 files changed
+7851
-306
No files matched your search
+130
-2
@@ -14,6 +14,11 @@ import { spawn, spawnSync } from "node:child_process";
|
||||
import { createRequire } from "node:module";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
// Imported before anything builds a git fixture: it scrubs the whole test process's git config
|
||||
// (the AGENTS.md failure-log rule), so the ref fixtures below and git agree.
|
||||
import "./skill-script-helpers.mjs";
|
||||
import { createInstallRefFixture } from "./install-ref-fixtures.mjs";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const LAUNCHER = path.join(ROOT, "src", "launcher", "plan2code.js");
|
||||
@@ -60,6 +65,8 @@ function sandbox(clis, { installed, project = true, lookup = true, agents } = {}
|
||||
'require("fs").writeFileSync(require("path").join(__dirname, process.argv[2] + ".json"), JSON.stringify(process.argv.slice(3)));\n' +
|
||||
// The ref the launcher marks its installer runs with, so install.js never redirects them.
|
||||
'if (process.env.PLAN2CODE_INSTALL_REF) require("fs").writeFileSync(require("path").join(__dirname, process.argv[2] + ".ref"), process.env.PLAN2CODE_INSTALL_REF);\n' +
|
||||
// The logical release a fetch ref stands for (an install-vX.Y.Z fetch is still vX.Y.Z).
|
||||
'if (process.env.PLAN2CODE_RELEASE_REF) require("fs").writeFileSync(require("path").join(__dirname, process.argv[2] + ".release"), process.env.PLAN2CODE_RELEASE_REF);\n' +
|
||||
"process.exitCode = Number(process.env.P2C_TEST_EXIT || 0);\n"
|
||||
);
|
||||
for (const cli of clis) {
|
||||
@@ -536,16 +543,137 @@ test("launcher: update --tag reinstalls for a branch, and not for a release tag"
|
||||
assert.ok(args.includes(`${REPO}#v3.0.2`) && !args.includes("--force"), args.join(" "));
|
||||
});
|
||||
|
||||
test("launcher: update --tag installs that ref without asking for the release list", (t) => {
|
||||
test("launcher: update --tag installs the plain release tag when the ref list cannot be read", (t) => {
|
||||
const box = sandbox(["npx"]);
|
||||
t.after(box.cleanup);
|
||||
// No tag list is available at all: --tag must not need one.
|
||||
// No tag list is available at all: --tag must not need one, and falls back to the plain tag.
|
||||
const result = box.run(["update", "--tag", "v3.0.2"], { PLAN2CODE_LS_REMOTE_FILE: path.join(box.dir, "missing.txt") });
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.match(result.stdout, /Updating Plan2Code to v3\.0\.2\.\.\./);
|
||||
assert.ok(box.argsOf("npx").includes(`${REPO}#v3.0.2`), box.argsOf("npx").join(" "));
|
||||
});
|
||||
|
||||
/** A fixture's `git ls-remote --tags --heads` answer, written where the launcher reads it in git's place. */
|
||||
function fixtureStub(box, text) {
|
||||
const file = path.join(box.dir, "ls-remote-fixture.txt");
|
||||
fs.writeFileSync(file, text);
|
||||
return { PLAN2CODE_LS_REMOTE_FILE: file };
|
||||
}
|
||||
|
||||
/** What the last npx run got (its arguments, the fetch ref and the release ref it was marked with), cleared for the next run. */
|
||||
function lastInstall(box) {
|
||||
const bin = path.join(box.dir, "bin");
|
||||
const read = (name) => {
|
||||
const file = path.join(bin, name);
|
||||
if (!fs.existsSync(file)) return null;
|
||||
const text = fs.readFileSync(file, "utf8");
|
||||
fs.rmSync(file);
|
||||
return text;
|
||||
};
|
||||
const args = read("npx.json");
|
||||
return { args: args && JSON.parse(args), ref: read("npx.ref"), releaseRef: read("npx.release") };
|
||||
}
|
||||
|
||||
test("launcher: update fetches the newest release's install tag and names the logical release", (t) => {
|
||||
const fx = createInstallRefFixture();
|
||||
t.after(fx.cleanup);
|
||||
const box = sandbox(["npx"]);
|
||||
t.after(box.cleanup);
|
||||
const result = box.run(["update"], fixtureStub(box, fx.snapshotText()));
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.match(result.stdout, /Updating Plan2Code to v3\.1\.2\.\.\./);
|
||||
assert.doesNotMatch(result.stdout, /install-v/, "the person reads the release, never the fetch ref");
|
||||
const { args, ref, releaseRef } = lastInstall(box);
|
||||
assert.deepEqual(args, ["--yes", "--allow-git=all", `${REPO}#install-v3.1.2`, "--update"]);
|
||||
assert.equal(ref, "install-v3.1.2");
|
||||
assert.equal(releaseRef, "v3.1.2");
|
||||
});
|
||||
|
||||
test("launcher: update ignores a stale moving release branch and falls back to plain tags when no install tag is advertised", (t) => {
|
||||
const stale = createInstallRefFixture({ releaseVersion: "2.0.0" });
|
||||
t.after(stale.cleanup);
|
||||
const legacy = createInstallRefFixture({ releases: [{ version: "1.0.0" }, { version: "2.0.0", annotated: true }] });
|
||||
t.after(legacy.cleanup);
|
||||
const box = sandbox(["npx"]);
|
||||
t.after(box.cleanup);
|
||||
assert.equal(box.run(["update"], fixtureStub(box, stale.snapshotText())).status, 0);
|
||||
assert.deepEqual(lastInstall(box), { args: ["--yes", "--allow-git=all", `${REPO}#install-v3.1.2`, "--update"], ref: "install-v3.1.2", releaseRef: "v3.1.2" });
|
||||
const result = box.run(["update"], fixtureStub(box, legacy.snapshotText()));
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.match(result.stdout, /Updating Plan2Code to v2\.0\.0\.\.\./);
|
||||
assert.deepEqual(lastInstall(box), { args: ["--yes", "--allow-git=all", `${REPO}#v2.0.0`, "--update"], ref: "v2.0.0", releaseRef: "v2.0.0" });
|
||||
});
|
||||
|
||||
test("launcher: update --tag vX.Y.Z rolls back through the install tag when advertised, the plain tag otherwise", (t) => {
|
||||
const fx = createInstallRefFixture();
|
||||
t.after(fx.cleanup);
|
||||
const box = sandbox(["npx"]);
|
||||
t.after(box.cleanup);
|
||||
const env = fixtureStub(box, fx.snapshotText());
|
||||
for (const [tag, fetchRef] of [
|
||||
["v2.0.0", "install-v2.0.0"],
|
||||
["v3.1.2", "install-v3.1.2"],
|
||||
["v1.0.0", "v1.0.0"],
|
||||
["v0.9.0", "v0.9.0"],
|
||||
]) {
|
||||
const result = box.run(["update", "--tag", tag], env);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.match(result.stdout, new RegExp(`Updating Plan2Code to ${tag.replace(/\./g, "\\.")}\\.\\.\\.`));
|
||||
// A release rollback never forces: the installer's own version check decides.
|
||||
assert.deepEqual(lastInstall(box), { args: ["--yes", "--allow-git=all", `${REPO}#${fetchRef}`, "--update"], ref: fetchRef, releaseRef: tag }, tag);
|
||||
}
|
||||
});
|
||||
|
||||
test("launcher: update --tag install-vX.Y.Z is read as its release, with a notice; a malformed install-v is refused", (t) => {
|
||||
const fx = createInstallRefFixture();
|
||||
t.after(fx.cleanup);
|
||||
const box = sandbox(["npx"]);
|
||||
t.after(box.cleanup);
|
||||
const env = fixtureStub(box, fx.snapshotText());
|
||||
const result = box.run(["update", "--tag", "install-v2.0.0"], env);
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.match(result.stdout, /install-v2\.0\.0 is how release v2\.0\.0 is fetched; updating by its release name, v2\.0\.0\./);
|
||||
assert.match(result.stdout, /Updating Plan2Code to v2\.0\.0\.\.\./);
|
||||
assert.deepEqual(lastInstall(box), { args: ["--yes", "--allow-git=all", `${REPO}#install-v2.0.0`, "--update"], ref: "install-v2.0.0", releaseRef: "v2.0.0" });
|
||||
for (const bad of ["install-v2", "install-v2.0.0-rc1", "install-vlatest", "install-v"]) {
|
||||
const refused = box.run(["update", "--tag", bad], env);
|
||||
assert.equal(refused.status, 2, bad);
|
||||
assert.match(refused.stderr, /is not a release install tag: use --tag with the release, for example --tag v3\.0\.2/, bad);
|
||||
assert.equal(lastInstall(box).args, null, bad);
|
||||
}
|
||||
});
|
||||
|
||||
test("launcher: --main and branch tags force a reinstall and carry no release ref", (t) => {
|
||||
const fx = createInstallRefFixture();
|
||||
t.after(fx.cleanup);
|
||||
const box = sandbox(["npx"]);
|
||||
t.after(box.cleanup);
|
||||
// An inherited release ref must not leak into a run that is not a release.
|
||||
const env = { ...fixtureStub(box, fx.snapshotText()), PLAN2CODE_RELEASE_REF: "v9.9.9" };
|
||||
assert.equal(box.run(["update", "--main"], env).status, 0);
|
||||
assert.deepEqual(lastInstall(box), { args: ["--yes", "--allow-git=all", REPO, "--update", "--force"], ref: "main", releaseRef: null });
|
||||
for (const branch of ["feature/demo", "release", "install-feature"]) {
|
||||
assert.equal(box.run(["update", "--tag", branch], env).status, 0, branch);
|
||||
assert.deepEqual(lastInstall(box), { args: ["--yes", "--allow-git=all", `${REPO}#${branch}`, "--update", "--force"], ref: branch, releaseRef: null }, branch);
|
||||
}
|
||||
});
|
||||
|
||||
test("launcher: uninstall runs the newest release's installer through its install tag", (t) => {
|
||||
const fx = createInstallRefFixture();
|
||||
t.after(fx.cleanup);
|
||||
const box = sandbox(["npx"]);
|
||||
t.after(box.cleanup);
|
||||
assert.equal(box.run(["uninstall", "--yes"], fixtureStub(box, fx.snapshotText())).status, 0);
|
||||
assert.deepEqual(lastInstall(box), { args: ["--yes", "--allow-git=all", `${REPO}#install-v3.1.2`, "--uninstall", "--yes"], ref: "install-v3.1.2", releaseRef: "v3.1.2" });
|
||||
});
|
||||
|
||||
test("launcher: normalizeUpdateTagInput maps only an exact install tag, refuses a malformed one, leaves the rest", () => {
|
||||
const { normalizeUpdateTagInput } = require(LAUNCHER);
|
||||
assert.deepEqual(normalizeUpdateTagInput("install-v3.10.0"), { ref: "v3.10.0", notice: "install-v3.10.0 is how release v3.10.0 is fetched; updating by its release name, v3.10.0." });
|
||||
assert.match(normalizeUpdateTagInput("install-v3.1").error, /install-v3\.1 is not a release install tag/);
|
||||
for (const ref of ["v3.0.2", "main", "release", "feature/install-v1.0.0", "install-feature"]) assert.deepEqual(normalizeUpdateTagInput(ref), { ref }, ref);
|
||||
});
|
||||
|
||||
test("launcher: update --force reaches the installer", (t) => {
|
||||
const box = sandbox(["npx"]);
|
||||
t.after(box.cleanup);
|
||||
|
||||
Reference in new issue
Block a user