@@ -117,6 +117,8 @@ describe("installTestEnv", () => {
117117 OPENCLAW_HOME : realHome ,
118118 OPENCLAW_STATE_DIR : path . join ( realHome , ".openclaw" ) ,
119119 OPENCLAW_CONFIG_PATH : configPath ,
120+ OPENCLAW_AGENT_DIR : path . join ( realHome , "caller-agent" ) ,
121+ PI_CODING_AGENT_DIR : path . join ( realHome , "caller-legacy-agent" ) ,
120122 OPENCLAW_LIVE_TEST : "1" ,
121123 OPENCLAW_LIVE_USE_REAL_HOME : undefined ,
122124 OPENCLAW_LIVE_TEST_QUIET : "1" ,
@@ -161,13 +163,17 @@ describe("installTestEnv", () => {
161163 const next = installTestEnv ( ) ;
162164 cleanupFns . push ( next . cleanup ) ;
163165 expect ( next . tempHome ) . not . toBe ( failedHome ) ;
166+ expect ( process . env . OPENCLAW_AGENT_DIR ) . toBeUndefined ( ) ;
167+ expect ( process . env . PI_CODING_AGENT_DIR ) . toBeUndefined ( ) ;
164168 expect ( process . env . ACQUISITION_PROFILE_ADDED ) . toBe ( "from-profile" ) ;
165169 expect ( process . env . ACQUISITION_PROFILE_EMPTY ) . toBe ( "from-profile" ) ;
166170 expect (
167171 fs . readFileSync ( path . join ( next . tempHome , ".claude" , "settings.json" ) , "utf8" ) ,
168172 ) . toBe ( "{}\n" ) ;
169173 next . cleanup ( ) ;
170174 expect ( process . env . HOME ) . toBe ( realHome ) ;
175+ expect ( process . env . OPENCLAW_AGENT_DIR ) . toBe ( callerEnv . OPENCLAW_AGENT_DIR ) ;
176+ expect ( process . env . PI_CODING_AGENT_DIR ) . toBe ( callerEnv . PI_CODING_AGENT_DIR ) ;
171177 expect ( process . env . OPENCLAW_TEST_FAST ) . toBe ( "from-profile" ) ;
172178 expect ( process . env . ACQUISITION_PROFILE_ADDED ) . toBe ( "from-profile" ) ;
173179 expect ( fs . readdirSync ( sandbox ) ) . toEqual ( [ ] ) ;
@@ -420,12 +426,21 @@ describe("installTestEnv", () => {
420426 setTestEnvValue ( "OPENCLAW_LIVE_TEST" , "1" ) ;
421427 setTestEnvValue ( "OPENCLAW_LIVE_USE_REAL_HOME" , "1" ) ;
422428 setTestEnvValue ( "OPENCLAW_LIVE_TEST_QUIET" , "1" ) ;
429+ const agentDir = path . join ( realHome , "caller-agent" ) ;
430+ const legacyAgentDir = path . join ( realHome , "caller-legacy-agent" ) ;
431+ setTestEnvValue ( "OPENCLAW_AGENT_DIR" , agentDir ) ;
432+ setTestEnvValue ( "PI_CODING_AGENT_DIR" , legacyAgentDir ) ;
423433
424434 const testEnv = installTestEnv ( ) ;
425435
426436 expect ( testEnv . tempHome ) . toBe ( realHome ) ;
427437 expect ( process . env . HOME ) . toBe ( realHome ) ;
428438 expect ( process . env . TEST_PROFILE_ONLY ) . toBe ( "from-profile" ) ;
439+ expect ( process . env . OPENCLAW_AGENT_DIR ) . toBe ( agentDir ) ;
440+ expect ( process . env . PI_CODING_AGENT_DIR ) . toBe ( legacyAgentDir ) ;
441+ testEnv . cleanup ( ) ;
442+ expect ( process . env . OPENCLAW_AGENT_DIR ) . toBe ( agentDir ) ;
443+ expect ( process . env . PI_CODING_AGENT_DIR ) . toBe ( legacyAgentDir ) ;
429444 } ) ;
430445
431446 it ( "keeps hermetic mode isolated when live flags request the real HOME" , ( ) => {
@@ -445,6 +460,8 @@ describe("installTestEnv", () => {
445460 setTestEnvValue ( "OPENCLAW_TEST_TRUST_BUNDLED_PLUGINS_DIR" , "1" ) ;
446461 setTestEnvValue ( "OPENCLAW_DISABLE_BUNDLED_PLUGINS" , "1" ) ;
447462 setTestEnvValue ( "OPENCLAW_HOME" , realHome ) ;
463+ setTestEnvValue ( "OPENCLAW_AGENT_DIR" , path . join ( realHome , "caller-agent" ) ) ;
464+ setTestEnvValue ( "PI_CODING_AGENT_DIR" , path . join ( realHome , "caller-legacy-agent" ) ) ;
448465
449466 const testEnv = installTestEnv ( { mode : "hermetic" } ) ;
450467 cleanupFns . push ( testEnv . cleanup ) ;
@@ -461,27 +478,34 @@ describe("installTestEnv", () => {
461478 expect ( process . env . OPENCLAW_TEST_TRUST_BUNDLED_PLUGINS_DIR ) . toBe ( "1" ) ;
462479 expect ( process . env . OPENCLAW_DISABLE_BUNDLED_PLUGINS ) . toBeUndefined ( ) ;
463480 expect ( process . env . OPENCLAW_HOME ) . toBeUndefined ( ) ;
481+ expect ( process . env . OPENCLAW_AGENT_DIR ) . toBeUndefined ( ) ;
482+ expect ( process . env . PI_CODING_AGENT_DIR ) . toBeUndefined ( ) ;
464483 expect ( fs . existsSync ( path . join ( testEnv . tempHome , ".openclaw" , "openclaw.json" ) ) ) . toBe ( false ) ;
465484 expect (
466485 fs . existsSync ( path . join ( testEnv . tempHome , ".openclaw" , "credentials" , "token.txt" ) ) ,
467486 ) . toBe ( false ) ;
468487 } ) ;
469488
470- it ( "clears and restores OPENCLAW_HOME for normal isolated test runs" , ( ) => {
471- const realHome = createTempHome ( ) ;
472- const configuredOpenClawHome = path . join ( realHome , "custom-openclaw-home" ) ;
473- setTestEnvValue ( "HOME" , realHome ) ;
474- setTestEnvValue ( "USERPROFILE" , realHome ) ;
475- setTestEnvValue ( "OPENCLAW_HOME" , configuredOpenClawHome ) ;
489+ it . each ( [ "OPENCLAW_HOME" , "OPENCLAW_AGENT_DIR" , "PI_CODING_AGENT_DIR" ] ) (
490+ "clears and restores %s for normal isolated test runs" ,
491+ ( key ) => {
492+ const realHome = createTempHome ( ) ;
493+ const callerPath = path . join ( realHome , "caller-override" ) ;
494+ setTestEnvValue ( "HOME" , realHome ) ;
495+ setTestEnvValue ( "USERPROFILE" , realHome ) ;
496+ setTestEnvValue ( key , callerPath ) ;
476497
477- const testEnv = installTestEnv ( ) ;
498+ const testEnv = installTestEnv ( ) ;
499+ cleanupFns . push ( testEnv . cleanup ) ;
478500
479- expect ( testEnv . tempHome ) . not . toBe ( realHome ) ;
480- expect ( process . env . OPENCLAW_HOME ) . toBeUndefined ( ) ;
501+ expect ( testEnv . tempHome ) . not . toBe ( realHome ) ;
502+ expect ( process . env [ key ] ) . toBeUndefined ( ) ;
503+ setTestEnvValue ( key , path . join ( testEnv . tempHome , "explicit-override" ) ) ;
481504
482- testEnv . cleanup ( ) ;
483- expect ( process . env . OPENCLAW_HOME ) . toBe ( configuredOpenClawHome ) ;
484- } ) ;
505+ testEnv . cleanup ( ) ;
506+ expect ( process . env [ key ] ) . toBe ( callerPath ) ;
507+ } ,
508+ ) ;
485509
486510 it . each ( [
487511 "TWILIO_ACCOUNT_SID" ,
0 commit comments