diff --git a/test/helpers/temp-home.ts b/test/helpers/temp-home.ts index 391a00db4b..8451e13bbf 100644 --- a/test/helpers/temp-home.ts +++ b/test/helpers/temp-home.ts @@ -9,6 +9,7 @@ type EnvSnapshot = { userProfile: string | undefined; homeDrive: string | undefined; homePath: string | undefined; + openclawHome: string | undefined; stateDir: string | undefined; }; @@ -18,6 +19,7 @@ function snapshotEnv(): EnvSnapshot { userProfile: process.env.USERPROFILE, homeDrive: process.env.HOMEDRIVE, homePath: process.env.HOMEPATH, + openclawHome: process.env.OPENCLAW_HOME, stateDir: process.env.OPENCLAW_STATE_DIR, }; } @@ -34,6 +36,7 @@ function restoreEnv(snapshot: EnvSnapshot) { restoreKey("USERPROFILE", snapshot.userProfile); restoreKey("HOMEDRIVE", snapshot.homeDrive); restoreKey("HOMEPATH", snapshot.homePath); + restoreKey("OPENCLAW_HOME", snapshot.openclawHome); restoreKey("OPENCLAW_STATE_DIR", snapshot.stateDir); } @@ -58,6 +61,8 @@ function restoreExtraEnv(snapshot: Record) { function setTempHome(base: string) { process.env.HOME = base; process.env.USERPROFILE = base; + // Ensure tests using HOME isolation aren't affected by leaked OPENCLAW_HOME. + delete process.env.OPENCLAW_HOME; process.env.OPENCLAW_STATE_DIR = path.join(base, ".openclaw"); if (process.platform !== "win32") {