fix(fixtures): keep pnpm in a linked fixture from installing (F-4)
pnpm verifies the install before a script, and a fixture running it with CI=true against an install made without CI saw other settings and installed through the linked .pnpm and .bin, rewriting the shared lock.yaml and shims. Every fixture pnpm run now turns that check off; a test pins it for all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
66aca38179
commit
a8520f6dfb
@@ -41,7 +41,10 @@ import {
|
||||
releaseCandidateManifestSchema,
|
||||
} from "./lib/release-candidate.ts";
|
||||
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
||||
import { linkFixtureNodeModules } from "./lib/fixture-node-modules.ts";
|
||||
import {
|
||||
FIXTURE_PNPM_ENVIRONMENT,
|
||||
linkFixtureNodeModules,
|
||||
} from "./lib/fixture-node-modules.ts";
|
||||
|
||||
const repositoryRoot = process.cwd();
|
||||
const fixtureRoot = await mkdtemp(path.join(tmpdir(), "provider-exact-five-fixture-"));
|
||||
@@ -74,6 +77,7 @@ try {
|
||||
maxBuffer: 32 * 1024 * 1024,
|
||||
env: {
|
||||
...process.env,
|
||||
...FIXTURE_PNPM_ENVIRONMENT,
|
||||
CI: "true",
|
||||
VITE_BUILD_ID: "provider-exact-five-fixture",
|
||||
VITE_COMMIT_SHA: revision,
|
||||
|
||||
@@ -27,6 +27,20 @@ import path from "node:path";
|
||||
* the linked directories. It is rewritten to name the fixture root instead:
|
||||
* the packages are the repository's own, already validated.
|
||||
*/
|
||||
/**
|
||||
* F-4. The environment for every `pnpm` a linked fixture runs. pnpm verifies
|
||||
* the install before a script and, when the fixture's copied state disagrees
|
||||
* with its own settings (for example `CI=true` against an install made
|
||||
* without it), installs. `.pnpm` and `.bin` are links into the repository's
|
||||
* node_modules, so that install rewrote the shared `.pnpm/lock.yaml` and bin
|
||||
* shims. A fixture started through `pnpm <script>` inherits this setting from
|
||||
* pnpm; one started directly (`node scripts/run-vitest.ts run <file>`) did not.
|
||||
* The fixture uses the repository's packages as they are; it never installs.
|
||||
*/
|
||||
export const FIXTURE_PNPM_ENVIRONMENT = Object.freeze({
|
||||
pnpm_config_verify_deps_before_run: "false",
|
||||
});
|
||||
|
||||
export async function linkFixtureNodeModules(
|
||||
fixtureRoot: string,
|
||||
sourceRoot: string = process.cwd(),
|
||||
|
||||
@@ -15,7 +15,10 @@ import {
|
||||
loadCiGateContract,
|
||||
parseCiGateContract,
|
||||
} from "../contracts/ci-gates.ts";
|
||||
import { linkFixtureNodeModules } from "./fixture-node-modules.ts";
|
||||
import {
|
||||
FIXTURE_PNPM_ENVIRONMENT,
|
||||
linkFixtureNodeModules,
|
||||
} from "./fixture-node-modules.ts";
|
||||
import { generateCiWorkflow } from "../generate-ci-workflow.ts";
|
||||
import { updateCiContractBaseline } from "../update-ci-contract-baseline.ts";
|
||||
|
||||
@@ -189,7 +192,7 @@ export function runRemovalFixtureCheck(
|
||||
const status = spawnSync(process.execPath, [pnpmCli, script, ...extra], {
|
||||
cwd: root,
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT },
|
||||
}).status;
|
||||
return status === 0
|
||||
? { name, passed: true }
|
||||
@@ -243,7 +246,7 @@ export function runRemovalFixturePnpm(
|
||||
return spawnSync(process.execPath, [pnpmCli, script, ...extra], {
|
||||
cwd: root,
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, ...env },
|
||||
env: { ...process.env, ...FIXTURE_PNPM_ENVIRONMENT, ...env },
|
||||
}).status === 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ import {
|
||||
RELEASE_CANDIDATE_MANIFEST_PATH,
|
||||
releaseCandidateManifestSchema,
|
||||
} from "../../scripts/lib/release-candidate.ts";
|
||||
import { linkFixtureNodeModules } from "../../scripts/lib/fixture-node-modules.ts";
|
||||
import {
|
||||
FIXTURE_PNPM_ENVIRONMENT,
|
||||
linkFixtureNodeModules,
|
||||
} from "../../scripts/lib/fixture-node-modules.ts";
|
||||
|
||||
it(
|
||||
"builds a real candidate assessment and passes the default archived verifier from the captured archive",
|
||||
@@ -61,6 +64,7 @@ it(
|
||||
maxBuffer: 32 * 1024 * 1024,
|
||||
env: {
|
||||
...process.env,
|
||||
...FIXTURE_PNPM_ENVIRONMENT,
|
||||
CI: "true",
|
||||
VITE_BUILD_ID: "security-followup-integration",
|
||||
VITE_COMMIT_SHA: revision,
|
||||
|
||||
@@ -19,7 +19,10 @@ import {
|
||||
validateCiArtifact,
|
||||
} from "../../../scripts/lib/ci-artifact-validator.ts";
|
||||
import { writeCiGateLogAtomic } from "../../../scripts/lib/ci-gate-log.ts";
|
||||
import { linkFixtureNodeModules } from "../../../scripts/lib/fixture-node-modules.ts";
|
||||
import {
|
||||
FIXTURE_PNPM_ENVIRONMENT,
|
||||
linkFixtureNodeModules,
|
||||
} from "../../../scripts/lib/fixture-node-modules.ts";
|
||||
import { copyReleaseEvidenceTree } from "../../../scripts/lib/removal-fixture.ts";
|
||||
import { captureCiCandidateArchive, verifyCiCandidateArchive } from "../../../scripts/lib/ci-candidate-archive.ts";
|
||||
import {
|
||||
@@ -2289,6 +2292,7 @@ async function ensureProviderBaseFixture(): Promise<string> {
|
||||
maxBuffer: 32 * 1024 * 1024,
|
||||
env: {
|
||||
...process.env,
|
||||
...FIXTURE_PNPM_ENVIRONMENT,
|
||||
CI: "true",
|
||||
VITE_BUILD_ID: "provider-v2-fixture",
|
||||
VITE_COMMIT_SHA: revision,
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
import { lstat, mkdtemp, mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import {
|
||||
copyFile,
|
||||
lstat,
|
||||
mkdtemp,
|
||||
mkdir,
|
||||
readdir,
|
||||
readFile,
|
||||
rm,
|
||||
stat,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { linkFixtureNodeModules } from "../../scripts/lib/fixture-node-modules.ts";
|
||||
import {
|
||||
FIXTURE_PNPM_ENVIRONMENT,
|
||||
linkFixtureNodeModules,
|
||||
} from "../../scripts/lib/fixture-node-modules.ts";
|
||||
|
||||
/**
|
||||
* A removal or provider fixture runs `pnpm` inside a throwaway copy of the
|
||||
@@ -146,3 +160,128 @@ describe("fixture node_modules linking", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* F-4. pnpm 11 verifies the install before it runs a script and, finding the
|
||||
* fixture's copied state unfamiliar, installs. `.pnpm` and `.bin` are
|
||||
* directory links into the repository's own node_modules, so that install
|
||||
* rewrote the shared `.pnpm/lock.yaml` and bin shims. A fixture launched
|
||||
* through `pnpm <script>` inherited `pnpm_config_verify_deps_before_run=false`
|
||||
* from pnpm and was safe; the same fixture started directly
|
||||
* (`node scripts/run-vitest.ts run <file>`) was not.
|
||||
*/
|
||||
describe("pnpm inside a linked fixture (F-4)", () => {
|
||||
const scratch: string[] = [];
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
scratch.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
/** A tiny installed workspace standing in for the repository, offline. */
|
||||
async function installedSource() {
|
||||
const root = await mkdtemp(path.join(tmpdir(), "fixture-pnpm-"));
|
||||
scratch.push(root);
|
||||
const tool = path.join(root, "tool");
|
||||
const source = path.join(root, "source");
|
||||
await mkdir(tool, { recursive: true });
|
||||
await mkdir(source, { recursive: true });
|
||||
await writeFile(
|
||||
path.join(tool, "package.json"),
|
||||
JSON.stringify({ name: "tool", version: "1.0.0", bin: { tool: "cli.js" } }),
|
||||
);
|
||||
await writeFile(path.join(tool, "cli.js"), "#!/usr/bin/env node\n");
|
||||
await writeFile(
|
||||
path.join(source, "package.json"),
|
||||
JSON.stringify({
|
||||
name: "fixture-source",
|
||||
version: "1.0.0",
|
||||
private: true,
|
||||
packageManager: "pnpm@11.17.0",
|
||||
scripts: { hello: "echo hello-from-fixture" },
|
||||
dependencies: { tool: "file:../tool" },
|
||||
}),
|
||||
);
|
||||
await writeFile(path.join(source, "pnpm-workspace.yaml"), "allowBuilds: {}\n");
|
||||
const environment: NodeJS.ProcessEnv = {
|
||||
...pnpmFreeEnvironment(),
|
||||
pnpm_config_store_dir: path.join(root, "store"),
|
||||
};
|
||||
// Installed on a developer machine (no CI); the fixtures then run pnpm
|
||||
// with CI=true, which pnpm reads as different settings and reinstalls.
|
||||
const { CI: _ci, ...developer } = environment;
|
||||
const install = spawnSync("corepack", ["pnpm", "install", "--offline"], {
|
||||
cwd: source,
|
||||
encoding: "utf8",
|
||||
env: developer,
|
||||
});
|
||||
expect(install.status, install.stdout + install.stderr).toBe(0);
|
||||
return { root, source, environment };
|
||||
}
|
||||
|
||||
// The test runner itself may run under pnpm, which exports the setting.
|
||||
function pnpmFreeEnvironment(): NodeJS.ProcessEnv {
|
||||
const environment: NodeJS.ProcessEnv = { ...process.env, CI: "true" };
|
||||
delete environment.pnpm_config_verify_deps_before_run;
|
||||
return environment;
|
||||
}
|
||||
|
||||
async function sharedState(source: string) {
|
||||
const lock = await stat(path.join(source, "node_modules/.pnpm/lock.yaml"));
|
||||
const bin = await stat(path.join(source, "node_modules/.bin/tool"));
|
||||
return [lock.mtimeMs, lock.ino, bin.mtimeMs, bin.ino];
|
||||
}
|
||||
|
||||
async function runInFixture(
|
||||
root: string,
|
||||
source: string,
|
||||
environment: NodeJS.ProcessEnv,
|
||||
) {
|
||||
const fixture = path.join(root, `fixture-${scratch.length}-${Date.now()}`);
|
||||
await mkdir(fixture);
|
||||
for (const file of ["package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml"]) {
|
||||
await copyFile(path.join(source, file), path.join(fixture, file));
|
||||
}
|
||||
await linkFixtureNodeModules(fixture, source);
|
||||
const before = await sharedState(source);
|
||||
const result = spawnSync("corepack", ["pnpm", "hello"], {
|
||||
cwd: fixture,
|
||||
encoding: "utf8",
|
||||
env: environment,
|
||||
});
|
||||
return { result, changed: (await sharedState(source)).join() !== before.join() };
|
||||
}
|
||||
|
||||
it("installs through the linked directories unless told not to", async () => {
|
||||
const { root, source, environment } = await installedSource();
|
||||
|
||||
// The hazard: the default re-verification installs into the shared tree.
|
||||
expect((await runInFixture(root, source, environment)).changed).toBe(true);
|
||||
|
||||
const guarded = await runInFixture(root, source, {
|
||||
...environment,
|
||||
...FIXTURE_PNPM_ENVIRONMENT,
|
||||
});
|
||||
expect(guarded.result.status, guarded.result.stderr).toBe(0);
|
||||
expect(guarded.result.stdout).toContain("hello-from-fixture");
|
||||
expect(guarded.changed).toBe(false);
|
||||
}, 60_000);
|
||||
|
||||
it("is used by every fixture that links node_modules and runs pnpm", async () => {
|
||||
const listed = spawnSync(
|
||||
"git",
|
||||
["grep", "-l", "linkFixtureNodeModules(", "--", "scripts", "tests"],
|
||||
{ encoding: "utf8" },
|
||||
);
|
||||
expect(listed.status, listed.stderr).toBe(0);
|
||||
const offenders: string[] = [];
|
||||
for (const file of listed.stdout.trim().split("\n")) {
|
||||
if (file === "scripts/lib/fixture-node-modules.ts") continue;
|
||||
if (file === "tests/unit/fixture-node-modules.test.ts") continue;
|
||||
const source = await readFile(file, "utf8");
|
||||
const runsPnpm = /\["pnpm"|\[pnpmCli\b/u.test(source);
|
||||
if (runsPnpm && !source.includes("FIXTURE_PNPM_ENVIRONMENT")) offenders.push(file);
|
||||
}
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user