@@ -2088,7 +2088,15 @@ test("pinned-base validation reproduction proves the same base failure", () => {
20882088 fs . mkdirSync ( path . join ( cwd , "src" ) ) ;
20892089 fs . writeFileSync (
20902090 path . join ( cwd , "check.js" ) ,
2091- "console.error('src/base.ts:1: lint failed'); process.exit(1);\n" ,
2091+ [
2092+ "const fs = require('node:fs');" ,
2093+ "const { execFileSync } = require('node:child_process');" ,
2094+ "const profile = Object.fromEntries(['HOME', 'XDG_CACHE_HOME', 'COREPACK_HOME'].map(key => [key, process.env[key]]));" ,
2095+ "for (const directory of Object.values(profile)) if (!fs.statSync(directory).isDirectory()) throw new Error('missing validation profile');" ,
2096+ "console.log('pinned-base-profile:' + JSON.stringify({ ...profile, cwd: process.cwd(), head: execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim(), pnpmOffline: process.env.PNPM_CONFIG_OFFLINE, npmOffline: process.env.npm_config_offline }));" ,
2097+ "console.error('src/base.ts:1: lint failed'); process.exit(1);" ,
2098+ "" ,
2099+ ] . join ( "\n" ) ,
20922100 ) ;
20932101 fs . writeFileSync ( path . join ( cwd , "src/base.ts" ) , "export const base = true;\n" ) ;
20942102 fs . writeFileSync ( path . join ( cwd , "src/repair.ts" ) , "export const value = 1;\n" ) ;
@@ -2099,13 +2107,32 @@ test("pinned-base validation reproduction proves the same base failure", () => {
20992107 git ( cwd , "add" , "src/repair.ts" ) ;
21002108 git ( cwd , "commit" , "-m" , "repair change" ) ;
21012109
2102- const baseError = reproduceValidationFailureAtPinnedBase ( {
2103- commands : [ "pnpm check:changed" ] ,
2104- targetDir : cwd ,
2105- options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2106- } ) ;
2110+ const profiles = withPinnedBasePnpm ( ( ) =>
2111+ Array . from ( { length : 2 } , ( ) => {
2112+ const baseError = reproduceValidationFailureAtPinnedBase ( {
2113+ commands : [ "pnpm check:changed" ] ,
2114+ targetDir : cwd ,
2115+ options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2116+ } ) ;
21072117
2108- assert . match ( String ( baseError ) , / s r c \/ b a s e \. t s : 1 : l i n t f a i l e d / ) ;
2118+ assert . match ( String ( baseError ) , / s r c \/ b a s e \. t s : 1 : l i n t f a i l e d / ) ;
2119+ const observation = / p i n n e d - b a s e - p r o f i l e : ( \{ [ ^ \r \n ] * ?\} ) / . exec ( String ( baseError ) ) ;
2120+ assert . ok ( observation , "check.js must report its validation environment" ) ;
2121+ return JSON . parse ( observation [ 1 ] ) ;
2122+ } ) ,
2123+ ) ;
2124+ for ( const profile of profiles ) {
2125+ assert . equal ( profile . head , pinnedBaseRef ) ;
2126+ assert . notEqual ( profile . cwd , fs . realpathSync ( cwd ) ) ;
2127+ assert . equal ( profile . pnpmOffline , "true" ) ;
2128+ assert . equal ( profile . npmOffline , "true" ) ;
2129+ assert . equal ( fs . existsSync ( profile . cwd ) , false , "pinned checkout must be removed" ) ;
2130+ for ( const key of [ "HOME" , "XDG_CACHE_HOME" , "COREPACK_HOME" ] ) {
2131+ assert . notEqual ( profile [ key ] , process . env [ key ] ) ;
2132+ assert . notEqual ( profiles [ 0 ] [ key ] , profiles [ 1 ] [ key ] , "reproductions need separate profiles" ) ;
2133+ assert . equal ( fs . existsSync ( profile [ key ] ) , false , "validation profile must be removed" ) ;
2134+ }
2135+ }
21092136} ) ;
21102137
21112138test ( "pinned-base reproduction avoids fetching unrelated missing partial-clone history" , ( ) => {
@@ -2154,11 +2181,13 @@ test("pinned-base reproduction avoids fetching unrelated missing partial-clone h
21542181 assert . match ( missingObjects , new RegExp ( `^\\?${ omittedHistoricalBlob } $` , "m" ) ) ;
21552182 git ( target , "remote" , "set-url" , "origin" , "https://invalid.invalid/offline.git" ) ;
21562183
2157- const baseError = reproduceValidationFailureAtPinnedBase ( {
2158- commands : [ "pnpm check:changed" ] ,
2159- targetDir : target ,
2160- options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2161- } ) ;
2184+ const baseError = withPinnedBasePnpm ( ( ) =>
2185+ reproduceValidationFailureAtPinnedBase ( {
2186+ commands : [ "pnpm check:changed" ] ,
2187+ targetDir : target ,
2188+ options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2189+ } ) ,
2190+ ) ;
21622191
21632192 assert . match ( String ( baseError ) , / s r c \/ b a s e \. t s : 1 : l i n t f a i l e d / ) ;
21642193 assert . match (
@@ -2197,11 +2226,13 @@ test("pinned-base reproduction preserves the source comparison branch for change
21972226 git ( cwd , "update-ref" , "refs/remotes/origin/main" , pinnedBaseRef ) ;
21982227 assert . notEqual ( sourceMainSha , pinnedBaseRef ) ;
21992228
2200- const baseError = reproduceValidationFailureAtPinnedBase ( {
2201- commands : [ "pnpm check:changed" ] ,
2202- targetDir : cwd ,
2203- options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2204- } ) ;
2229+ const baseError = withPinnedBasePnpm ( ( ) =>
2230+ reproduceValidationFailureAtPinnedBase ( {
2231+ commands : [ "pnpm check:changed" ] ,
2232+ targetDir : cwd ,
2233+ options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2234+ } ) ,
2235+ ) ;
22052236
22062237 assert . match ( String ( baseError ) , / s r c \/ b a s e \. t s : 1 : l i n t f a i l e d / ) ;
22072238} ) ;
@@ -2248,14 +2279,16 @@ test("pinned-base reproduction hydrates blobs required by the older pinned snaps
22482279 new RegExp ( `^\\?${ requiredBlob } $` , "m" ) ,
22492280 ) ;
22502281
2251- const baseError = reproduceValidationFailureAtPinnedBase ( {
2252- commands : [ "pnpm check:changed" ] ,
2253- targetDir : target ,
2254- options : validationOptions ( "openclaw/openclaw" , {
2255- pinnedBaseRef,
2256- pinnedBaseRemoteUrl : pathToFileURL ( remote ) . href ,
2282+ const baseError = withPinnedBasePnpm ( ( ) =>
2283+ reproduceValidationFailureAtPinnedBase ( {
2284+ commands : [ "pnpm check:changed" ] ,
2285+ targetDir : target ,
2286+ options : validationOptions ( "openclaw/openclaw" , {
2287+ pinnedBaseRef,
2288+ pinnedBaseRemoteUrl : pathToFileURL ( remote ) . href ,
2289+ } ) ,
22572290 } ) ,
2258- } ) ;
2291+ ) ;
22592292
22602293 assert . match ( String ( baseError ) , / s r c \/ b a s e \. t s : 1 : l i n t f a i l e d / ) ;
22612294} ) ;
@@ -2277,11 +2310,13 @@ test("pinned-base reproduction preserves the source SHA-256 object format", () =
22772310 const pinnedBaseRef = git ( cwd , "rev-parse" , "HEAD" ) ;
22782311 assert . equal ( pinnedBaseRef . length , 64 ) ;
22792312
2280- const baseError = reproduceValidationFailureAtPinnedBase ( {
2281- commands : [ "pnpm check:changed" ] ,
2282- targetDir : cwd ,
2283- options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2284- } ) ;
2313+ const baseError = withPinnedBasePnpm ( ( ) =>
2314+ reproduceValidationFailureAtPinnedBase ( {
2315+ commands : [ "pnpm check:changed" ] ,
2316+ targetDir : cwd ,
2317+ options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2318+ } ) ,
2319+ ) ;
22852320
22862321 assert . match ( String ( baseError ) , / s r c \/ b a s e \. t s : 1 : l i n t f a i l e d / ) ;
22872322} ) ;
@@ -2326,11 +2361,13 @@ test("pinned-base reproduction does not inherit target-controlled checkout hooks
23262361 } ) ;
23272362 git ( cwd , "config" , "core.hooksPath" , hooks ) ;
23282363
2329- const baseError = reproduceValidationFailureAtPinnedBase ( {
2330- commands : [ "pnpm check:changed" ] ,
2331- targetDir : cwd ,
2332- options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2333- } ) ;
2364+ const baseError = withPinnedBasePnpm ( ( ) =>
2365+ reproduceValidationFailureAtPinnedBase ( {
2366+ commands : [ "pnpm check:changed" ] ,
2367+ targetDir : cwd ,
2368+ options : validationOptions ( "openclaw/openclaw" , { pinnedBaseRef } ) ,
2369+ } ) ,
2370+ ) ;
23342371
23352372 assert . match ( String ( baseError ) , / s r c \/ b a s e \. t s : 1 : l i n t f a i l e d / ) ;
23362373 assert . equal ( fs . existsSync ( marker ) , false ) ;
@@ -8849,6 +8886,34 @@ function linuxValidationContainmentAvailable() {
88498886 return probe . status === 0 ;
88508887}
88518888
8889+ function withPinnedBasePnpm ( callback ) {
8890+ // Dependency-free pinned-base fixtures skip setup and must not resolve host pnpm.
8891+ const binDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "clawsweeper-pinned-base-pnpm-" ) ) ;
8892+ const pnpmPath = path . join ( binDir , "pnpm.cjs" ) ;
8893+ fs . writeFileSync (
8894+ pnpmPath ,
8895+ `const assert = require("node:assert/strict");
8896+ const fs = require("node:fs");
8897+ const { spawnSync } = require("node:child_process");
8898+ const args = process.argv.slice(2).filter(arg => ![
8899+ "--config.verify-deps-before-run=false",
8900+ "--config.enable-pre-post-scripts=false",
8901+ ].includes(arg));
8902+ assert.deepEqual(args, ["check:changed"]);
8903+ assert.equal(JSON.parse(fs.readFileSync("package.json", "utf8")).scripts["check:changed"], "node check.js");
8904+ const child = spawnSync(process.execPath, ["check.js"], { stdio: "inherit" });
8905+ if (child.error) throw child.error;
8906+ if (child.signal) process.kill(process.pid, child.signal);
8907+ else process.exit(child.status ?? 1);
8908+ ` ,
8909+ ) ;
8910+ try {
8911+ return withMockCommand ( "pnpm" , pnpmPath , callback ) ;
8912+ } finally {
8913+ fs . rmSync ( binDir , { recursive : true , force : true } ) ;
8914+ }
8915+ }
8916+
88528917function withMockCommand ( command , scriptPath , callback ) {
88538918 const overrides = mockCommandBinEnv ( command , scriptPath ) ;
88548919 const previous = Object . fromEntries ( Object . keys ( overrides ) . map ( ( key ) => [ key , process . env [ key ] ] ) ) ;
0 commit comments