fix(npm): preserve explicit setup versions (#465)

* fix(npm): refresh stale setup bootstraps

* fix(npm): preserve explicit setup versions

* docs: distinguish first-run and refresh setup
This commit is contained in:
morluto
2026-08-10 02:59:52 +08:00
committed by GitHub
parent ed4a62871f
commit 1783bf6dfd
13 changed files with 34 additions and 296 deletions
-8
View File
@@ -13,10 +13,6 @@ describe("executable dispatcher", () => {
await workspace.mkdir("dist");
await Promise.all([
copyFile("scripts/rea.mjs", join(scripts, "rea.mjs")),
copyFile(
"scripts/package-runner-bootstrap.mjs",
join(scripts, "package-runner-bootstrap.mjs"),
),
workspace.write(
"package.json",
JSON.stringify({ type: "module", version: "1.0.0" }),
@@ -72,10 +68,6 @@ describe("executable dispatcher", () => {
const scripts = await workspace.mkdir("scripts");
await Promise.all([
copyFile("scripts/rea.mjs", join(scripts, "rea.mjs")),
copyFile(
"scripts/package-runner-bootstrap.mjs",
join(scripts, "package-runner-bootstrap.mjs"),
),
workspace.write(
"package.json",
JSON.stringify({ type: "module", version: "1.0.0" }),
@@ -1,153 +0,0 @@
import { chmod, readFile, writeFile } from "node:fs/promises";
import { delimiter, join } from "node:path";
import { describe, expect, it } from "vitest";
import {
packageRunnerSetupPlan,
runPackageRunnerSetupBootstrap,
} from "../../../scripts/package-runner-bootstrap.mjs";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
describe("package-runner setup bootstrap", () => {
it("reruns bare setup through the current release when npm selected a local package", () => {
expect(
packageRunnerSetupPlan({
args: ["setup", "--client", "codex"],
environment: {
npm_lifecycle_event: "npx",
npm_config_local_prefix: "/work/project",
},
packageRoot: "/work/project/node_modules/rea-agents",
packageName: "rea-agents",
}),
).toEqual({
command: "npm",
args: [
"exec",
"--yes",
"--package=rea-agents@latest",
"--",
"rea",
"setup",
"--client",
"codex",
],
});
});
it("leaves explicit rollback and non-local invocations untouched", () => {
const base = {
args: ["setup"],
packageRoot: "/work/project/node_modules/rea-agents",
packageName: "rea-agents",
} as const;
expect(
packageRunnerSetupPlan({
...base,
environment: {
npm_lifecycle_event: "npx",
npm_config_local_prefix: "/work/project",
npm_config_package: "rea-agents@2.4.0",
},
}),
).toBeUndefined();
expect(
packageRunnerSetupPlan({
...base,
environment: {
npm_lifecycle_event: "npx",
npm_config_local_prefix: "/work/project",
npm_config_package: "rea-agents@^2.4.0",
},
}),
).toEqual(
expect.objectContaining({
args: expect.arrayContaining(["--package=rea-agents@latest"]),
}),
);
expect(
packageRunnerSetupPlan({
...base,
packageRoot: "/root/.npm/_npx/cache/node_modules/rea-agents",
environment: {
npm_lifecycle_event: "npx",
npm_config_local_prefix: "/work/project",
},
}),
).toBeUndefined();
});
it("does not redirect recursively or affect commands other than setup", () => {
const environment = {
npm_lifecycle_event: "npx",
npm_config_local_prefix: "/work/project",
REA_PACKAGE_RUNNER_BOOTSTRAPPED: "1",
};
expect(
packageRunnerSetupPlan({
args: ["setup"],
environment,
packageRoot: "/work/project/node_modules/rea-agents",
packageName: "rea-agents",
}),
).toBeUndefined();
expect(
packageRunnerSetupPlan({
args: ["doctor"],
environment: {
npm_lifecycle_event: "npx",
npm_config_local_prefix: "/work/project",
},
packageRoot: "/work/project/node_modules/rea-agents",
packageName: "rea-agents",
}),
).toBeUndefined();
});
it("forwards setup arguments to npm with a recursion marker", async () => {
const directory = await createTestTempDirectory("rea-bootstrap-");
const npm = join(directory, "npm");
const log = join(directory, "invocation.json");
await writeFile(
npm,
`#!/usr/bin/env node
import { writeFileSync } from "node:fs";
writeFileSync(process.env.REA_BOOTSTRAP_TEST_LOG, JSON.stringify({
args: process.argv.slice(2),
marker: process.env.REA_PACKAGE_RUNNER_BOOTSTRAPPED,
}));
`,
);
await chmod(npm, 0o755);
await expect(
runPackageRunnerSetupBootstrap({
args: ["setup", "--dry-run"],
environment: {
...process.env,
PATH: `${directory}${delimiter}${process.env.PATH ?? ""}`,
REA_BOOTSTRAP_TEST_LOG: log,
npm_lifecycle_event: "npx",
npm_config_local_prefix: "/work/project",
},
packageRoot: "/work/project/node_modules/rea-agents",
packageName: "rea-agents",
}),
).resolves.toBe(0);
await expect(readFile(log, "utf8").then(JSON.parse)).resolves.toEqual({
args: [
"exec",
"--yes",
"--package=rea-agents@latest",
"--",
"rea",
"setup",
"--dry-run",
],
marker: "1",
});
});
});
+9 -4
View File
@@ -67,6 +67,9 @@ describe("localized README product facts", () => {
"curl -fsSL https://raw.githubusercontent.com/morluto/rea/main/install.sh | bash",
);
expect(content).toContain("npx rea-agents setup");
expect(content).toContain(
"npx --yes --prefer-online rea-agents@latest setup",
);
expect(content).toContain("npx -y rea-agents@latest doctor");
expect(content).toContain("rea uninstall");
expect(content).toContain(
@@ -95,15 +98,17 @@ describe("localized README product facts", () => {
expect(content).toContain("--install-hopper");
expect(content).toContain("docs/installation.md");
expect(content).toContain("You do not need both");
expect(normalizedProse(content)).toContain(
"npx -y rea-agents@latest setup` once to repair registrations",
expect(content).toContain(
"npx --yes --prefer-online rea-agents@latest setup",
);
});
it("documents stale bootstrap recovery and explicit rollback", async () => {
it("documents explicit setup freshness and rollback", async () => {
const content = await readFile(resolve("docs/installation.md"), "utf8");
const prose = normalizedProse(content);
expect(prose).toContain("before REA plans or writes configuration");
expect(prose).toContain(
"explicit `@latest` request and `--prefer-online` metadata policy",
);
expect(prose).toContain(
"npm exec --yes --package=rea-agents@2.4.0 -- rea setup",
);