@@ -4,6 +4,7 @@ import os from "node:os";
|
4 | 4 | import path from "node:path"; |
5 | 5 | import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; |
6 | 6 | import type { RuntimeEnv } from "../runtime.js"; |
| 7 | +import { captureEnv, setTestEnvValue } from "../test-utils/env.js"; |
7 | 8 | import { createTempHomeEnv, type TempHomeEnv } from "../test-utils/temp-home.js"; |
8 | 9 | import * as backupShared from "./backup-shared.js"; |
9 | 10 | import { |
@@ -103,15 +104,16 @@ describe("backup commands", () => {
|
103 | 104 | async function withInvalidWorkspaceBackupConfig<T>(fn: (runtime: RuntimeEnv) => Promise<T>) { |
104 | 105 | const stateDir = path.join(tempHome.home, ".openclaw"); |
105 | 106 | const configPath = path.join(tempHome.home, "custom-config.json"); |
106 | | -process.env.OPENCLAW_CONFIG_PATH = configPath; |
107 | 107 | await fs.writeFile(path.join(stateDir, "openclaw.json"), JSON.stringify({}), "utf8"); |
108 | 108 | await fs.writeFile(configPath, '{"agents": { defaults: { workspace: ', "utf8"); |
109 | | -const runtime = createBackupTestRuntime(); |
110 | 109 | |
| 110 | +const envSnapshot = captureEnv(["OPENCLAW_CONFIG_PATH"]); |
| 111 | +setTestEnvValue("OPENCLAW_CONFIG_PATH", configPath); |
| 112 | +const runtime = createBackupTestRuntime(); |
111 | 113 | try { |
112 | 114 | return await fn(runtime); |
113 | 115 | } finally { |
114 | | -delete process.env.OPENCLAW_CONFIG_PATH; |
| 116 | +envSnapshot.restore(); |
115 | 117 | } |
116 | 118 | } |
117 | 119 | |
@@ -233,8 +235,9 @@ describe("backup commands", () => {
|
233 | 235 | let capturedManifest: CapturedBackupManifest | null = null; |
234 | 236 | let capturedEntryPaths: string[] = []; |
235 | 237 | let capturedOnWriteEntry: ((entry: { path: string }) => void) | null = null; |
| 238 | +const envSnapshot = captureEnv(["OPENCLAW_CONFIG_PATH"]); |
236 | 239 | try { |
237 | | -process.env.OPENCLAW_CONFIG_PATH = configPath; |
| 240 | +setTestEnvValue("OPENCLAW_CONFIG_PATH", configPath); |
238 | 241 | await fs.writeFile( |
239 | 242 | configPath, |
240 | 243 | JSON.stringify({ |
@@ -351,7 +354,7 @@ describe("backup commands", () => {
|
351 | 354 | ), |
352 | 355 | ); |
353 | 356 | } finally { |
354 | | -delete process.env.OPENCLAW_CONFIG_PATH; |
| 357 | +envSnapshot.restore(); |
355 | 358 | await fs.rm(externalWorkspace, { recursive: true, force: true }); |
356 | 359 | await fs.rm(backupDir, { recursive: true, force: true }); |
357 | 360 | } |
|