diff --git a/src/plugins/bundle-mcp.test-support.ts b/src/plugins/bundle-mcp.test-support.ts index ce41d11bdc29..8ee43ff4949c 100644 --- a/src/plugins/bundle-mcp.test-support.ts +++ b/src/plugins/bundle-mcp.test-support.ts @@ -2,7 +2,7 @@ import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; -import { captureEnv } from "../test-utils/env.js"; +import { withEnvAsync } from "../test-utils/env.js"; export function createBundleMcpTempHarness() { const tempDirs: string[] = []; @@ -91,16 +91,16 @@ export async function withBundleHomeEnv( prefix: string, run: (params: { homeDir: string; workspaceDir: string }) => Promise, ): Promise { - const env = captureEnv(["HOME", "USERPROFILE", "OPENCLAW_HOME", "OPENCLAW_STATE_DIR"]); - try { - const homeDir = await tempHarness.createTempDir(`${prefix}-home-`); - const workspaceDir = await tempHarness.createTempDir(`${prefix}-workspace-`); - process.env.HOME = homeDir; - process.env.USERPROFILE = homeDir; - delete process.env.OPENCLAW_HOME; - delete process.env.OPENCLAW_STATE_DIR; - return await run({ homeDir, workspaceDir }); - } finally { - env.restore(); - } + const homeDir = await tempHarness.createTempDir(`${prefix}-home-`); + const workspaceDir = await tempHarness.createTempDir(`${prefix}-workspace-`); + + return withEnvAsync( + { + HOME: homeDir, + USERPROFILE: homeDir, + OPENCLAW_HOME: undefined, + OPENCLAW_STATE_DIR: undefined, + }, + () => run({ homeDir, workspaceDir }), + ); }