diff --git a/tests/config/owner-registry-isolation.test.ts b/tests/config/owner-registry-isolation.test.ts index 19cef25d2d..c13c16ade3 100644 --- a/tests/config/owner-registry-isolation.test.ts +++ b/tests/config/owner-registry-isolation.test.ts @@ -34,7 +34,9 @@ describe("owner registry home isolation", () => { import { ownerRegistryDir, readOwnerRegistry, registerOwnerRegistryHome, unregisterOwnerRegistryHome } from ${JSON.stringify(registryModule)}; const startupHome = homedir(); - process.env.HOME = process.env.USERPROFILE = ${JSON.stringify(home.path("worker"))}; + // Windows homedir() follows USERPROFILE changes. Keep production's default + // home stable; only guarded callers exercise a rewritten worker home. + if (${guarded}) process.env.HOME = process.env.USERPROFILE = ${JSON.stringify(home.path("worker"))}; // No preload and no registry override: child callers must still be isolated. delete process.env.OCX_OWNER_REGISTRY_DIR; const dir = ownerRegistryDir(); @@ -54,6 +56,8 @@ describe("owner registry home isolation", () => { unregisterOwnerRegistryHome(${JSON.stringify(foreignHome)}); } delete process.env.OCX_OWNER_REGISTRY_DIR; + // Unpin into the protected home on cached and dynamic homedir() runtimes. + process.env.HOME = process.env.USERPROFILE = startupHome; delete process.env.OPENCODEX_HOME; try { readOwnerRegistry(); } catch { unpinnedRefused = true; } } diff --git a/tests/service/service-state-isolation.test.ts b/tests/service/service-state-isolation.test.ts index 5464adc3f4..68c449584c 100644 --- a/tests/service/service-state-isolation.test.ts +++ b/tests/service/service-state-isolation.test.ts @@ -30,9 +30,10 @@ describe("service state home isolation", () => { import { homedir } from "node:os"; import { readServiceInstallState, serviceStatePathsForOpenCodexHome, writeServiceInstallState } from ${JSON.stringify(stateModule)}; - // Match the preload: changing HOME cannot move Bun's cached startup home. const startupHome = homedir(); - process.env.HOME = process.env.USERPROFILE = ${JSON.stringify(home.path("worker"))}; + // Windows homedir() follows USERPROFILE changes. Keep production's default + // home stable; only guarded callers exercise a rewritten worker home. + if (${guarded}) process.env.HOME = process.env.USERPROFILE = ${JSON.stringify(home.path("worker"))}; const before = readServiceInstallState(); const pinned = serviceStatePathsForOpenCodexHome(${JSON.stringify(nextConfigHome)}); writeServiceInstallState("scheduler", null);