Skip to content

Commit 2261169

Browse files
author
Peter Steinberger
committed
fix: bind offline pnpm registries across supported versions
1 parent 52561c9 commit 2261169

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

‎src/repair/target-validation.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,12 @@ function openClawValidationNeedsPinnedHelper(
554554
const changedPaths = options.pinnedBaseRef
555555
? gitChangedFilesFromRef(cwd, options.pinnedBaseRef)
556556
: gitChangedFiles(cwd, DEFAULT_BASE_BRANCH);
557-
return changedPaths.some((file) =>
557+
const untrackedPaths = run("git", ["ls-files", "--others", "--exclude-standard", "-z"], {
558+
cwd,
559+
})
560+
.split("\0")
561+
.filter(Boolean);
562+
return [...changedPaths, ...untrackedPaths].some((file) =>
558563
/^(?:src|extensions|ui|packages)\/.+\.[cm]?[jt]sx?$/.test(file),
559564
);
560565
}
@@ -1290,7 +1295,11 @@ export function runAllowedValidationCommandsWithBinding(
12901295
// violates checkout identity despite having no bearing on validation proof.
12911296
validationEnv.OPENCLAW_TEST_PROJECTS_TIMINGS = "0";
12921297
// The changed gate invokes `pnpm dlx`; require its resolver to use the
1293-
// frozen helper metadata instead of attempting a network-only refresh.
1298+
// frozen helper metadata and the same approved registry used for setup.
1299+
// pnpm 11 ignores legacy npm_config_* environment configuration, while
1300+
// pnpm 10 ignores the newer PNPM_CONFIG_OFFLINE environment variable.
1301+
validationEnv.PNPM_CONFIG_REGISTRY = approvedTargetInstallRegistry(validationEnv);
1302+
validationEnv.PNPM_CONFIG_OFFLINE = "true";
12941303
validationEnv.npm_config_offline = "true";
12951304
}
12961305
const validationTimeoutMs = targetValidationTimeoutMs(

‎test/repair/target-validation.test.ts‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,7 +3656,7 @@ test(
36563656
const fs = require("node:fs");
36573657
const path = require("node:path");
36583658
const args = process.argv.slice(2);
3659-
fs.appendFileSync(${JSON.stringify(logPath)}, JSON.stringify({ args, cwd: process.cwd(), cache: process.env.XDG_CACHE_HOME, jitiFsCache: process.env.JITI_FS_CACHE, offline: process.env.npm_config_offline }) + "\\n");
3659+
fs.appendFileSync(${JSON.stringify(logPath)}, JSON.stringify({ args, cwd: process.cwd(), cache: process.env.XDG_CACHE_HOME, jitiFsCache: process.env.JITI_FS_CACHE, offline: process.env.PNPM_CONFIG_OFFLINE, legacyOffline: process.env.npm_config_offline, registry: process.env.PNPM_CONFIG_REGISTRY }) + "\\n");
36603660
if (args[0] === "install") {
36613661
fs.mkdirSync("node_modules", { recursive: true });
36623662
if (process.cwd().includes(".__clawsweeper_pnpm_helper_cache__")) {
@@ -3678,7 +3678,13 @@ if (args[0] === "install") {
36783678
}
36793679
}
36803680
if (args.at(-1) === "first" || args.at(-1) === "second") {
3681-
const marker = path.join(process.env.XDG_CACHE_HOME, "pnpm", "dlx", "a6769c4cf56f1a323ac28af3b6359f2b", "marker");
3681+
const registry = process.env.PNPM_CONFIG_REGISTRY;
3682+
const cacheKey = require("node:crypto")
3683+
.createHash("sha256")
3684+
.update(JSON.stringify([["[email protected]"], [["@jsr", "https://npm.jsr.io/"], ["default", registry]]]))
3685+
.digest("hex")
3686+
.slice(0, 32);
3687+
const marker = path.join(process.env.XDG_CACHE_HOME, "pnpm", "dlx", cacheKey, "marker");
36823688
if (fs.readFileSync(marker, "utf8") !== "frozen helper") process.exit(42);
36833689
const knip = path.join(path.dirname(marker), "pinned", "node_modules", ".bin", "knip");
36843690
if (!fs.readFileSync(knip, "utf8").includes("JITI_FS_CACHE=0")) process.exit(43);
@@ -3751,6 +3757,8 @@ if (args[0] === "enable") {
37513757
assert.equal(validations[0].cache, validations[1].cache);
37523758
assert.ok(validations.every(({ jitiFsCache }) => jitiFsCache === undefined));
37533759
assert.ok(validations.every(({ offline }) => offline === "true"));
3760+
assert.ok(validations.every(({ legacyOffline }) => legacyOffline === "true"));
3761+
assert.ok(validations.every(({ registry }) => registry === "https://registry.npmjs.org/"));
37543762

37553763
withCommandOverridesUnset(["corepack", "pnpm"], () =>
37563764
withPathOnlyPrefix(hostBin, () => {
@@ -3765,6 +3773,18 @@ if (args[0] === "enable") {
37653773
process.env.npm_config_registry = "https://registry.example.invalid:8443/";
37663774
try {
37673775
prepareTargetToolchain(cwd, options, ["pnpm check:changed"]);
3776+
assert.deepEqual(runAllowedValidationCommands(["pnpm first"], cwd, options), [
3777+
"pnpm first",
3778+
]);
3779+
const customValidation = fs
3780+
.readFileSync(logPath, "utf8")
3781+
.trim()
3782+
.split(/\r?\n/)
3783+
.map((line) => JSON.parse(line))
3784+
.findLast(({ args }) => args.at(-1) === "first");
3785+
assert.equal(customValidation.registry, "https://registry.example.invalid:8443/");
3786+
assert.equal(customValidation.offline, "true");
3787+
assert.equal(customValidation.legacyOffline, "true");
37683788
} finally {
37693789
restoreEnv("npm_config_registry", previousRegistry);
37703790
}
@@ -3789,6 +3809,11 @@ if (args[0] === "enable") {
37893809
fs.writeFileSync(path.join(cwd, "README.md"), "# Docs-only repair\n");
37903810
git(cwd, "add", "README.md");
37913811
prepareTargetToolchain(cwd, options, ["pnpm check:changed"]);
3812+
const untrackedSource = path.join(cwd, "src", "new-feature", "new.ts");
3813+
fs.mkdirSync(path.dirname(untrackedSource), { recursive: true });
3814+
fs.writeFileSync(untrackedSource, "export const untracked = true;\n");
3815+
prepareTargetToolchain(cwd, options, ["pnpm check:changed"]);
3816+
fs.rmSync(untrackedSource);
37923817
const subsequentPrefetches = fs
37933818
.readFileSync(logPath, "utf8")
37943819
.split(/\r?\n/)
@@ -3800,7 +3825,7 @@ if (args[0] === "enable") {
38003825
invocation.cwd.includes(".__clawsweeper_pnpm_helper_cache__")
38013826
);
38023827
}).length;
3803-
assert.equal(subsequentPrefetches, previousPrefetches);
3828+
assert.equal(subsequentPrefetches, previousPrefetches + 1);
38043829
}),
38053830
);
38063831
},

0 commit comments

Comments
 (0)