diff --git a/src/commands/agent.test.ts b/src/commands/agent.test.ts index e3e4fa8a248..764fb291fe7 100644 --- a/src/commands/agent.test.ts +++ b/src/commands/agent.test.ts @@ -234,7 +234,11 @@ vi.mock("../config/sessions/transcript-resolve.runtime.js", () => { const runtime = createThrowingTestRuntime(); async function withTempHome(fn: (home: string) => Promise): Promise { - return withTempHomeBase(fn, { prefix: "openclaw-agent-", skipSessionCleanup: true }); + return withTempHomeBase(fn, { + prefix: "openclaw-agent-", + skipHomeCleanup: true, + skipSessionCleanup: true, + }); } function mockConfig( diff --git a/src/plugin-sdk/test-helpers/temp-home.ts b/src/plugin-sdk/test-helpers/temp-home.ts index 2877b3dd1ab..acfcb37000d 100644 --- a/src/plugin-sdk/test-helpers/temp-home.ts +++ b/src/plugin-sdk/test-helpers/temp-home.ts @@ -104,6 +104,7 @@ export async function withTempHome( opts: { env?: Record; prefix?: string; + skipHomeCleanup?: boolean; skipSessionCleanup?: boolean; } = {}, ): Promise { @@ -139,22 +140,24 @@ export async function withTempHome( } restoreExtraEnv(envSnapshot); restoreEnv(snapshot); - try { - if (process.platform === "win32") { - await fs.rm(base, { - recursive: true, - force: true, - maxRetries: 10, - retryDelay: 50, - }); - } else { - await fs.rm(base, { - recursive: true, - force: true, - }); + if (!opts.skipHomeCleanup) { + try { + if (process.platform === "win32") { + await fs.rm(base, { + recursive: true, + force: true, + maxRetries: 10, + retryDelay: 50, + }); + } else { + await fs.rm(base, { + recursive: true, + force: true, + }); + } + } catch { + // ignore cleanup failures in tests } - } catch { - // ignore cleanup failures in tests } } }