|
2 | 2 | import type { Model } from "openclaw/plugin-sdk/llm"; |
3 | 3 | import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; |
4 | 4 | import type { ModelProviderConfig } from "../config/config.js"; |
| 5 | +import { captureEnv, deleteTestEnvValue, setTestEnvValue } from "../test-utils/env.js"; |
5 | 6 | import type { AuthProfileStore } from "./auth-profiles.js"; |
6 | 7 | import { |
7 | 8 | CUSTOM_LOCAL_AUTH_MARKER, |
@@ -211,30 +212,22 @@ describe("createRuntimeProviderAuthLookup", () => { |
211 | 212 | }); |
212 | 213 |
|
213 | 214 | async function withoutEnv<T>(key: string, fn: () => Promise<T>): Promise<T> { |
214 | | - const previous = process.env[key]; |
215 | | - delete process.env[key]; |
| 215 | + const snapshot = captureEnv([key]); |
| 216 | + deleteTestEnvValue(key); |
216 | 217 | try { |
217 | 218 | return await fn(); |
218 | 219 | } finally { |
219 | | - if (previous === undefined) { |
220 | | - delete process.env[key]; |
221 | | - } else { |
222 | | - process.env[key] = previous; |
223 | | - } |
| 220 | + snapshot.restore(); |
224 | 221 | } |
225 | 222 | } |
226 | 223 |
|
227 | 224 | async function withEnv<T>(key: string, value: string, fn: () => Promise<T>): Promise<T> { |
228 | | - const previous = process.env[key]; |
229 | | - process.env[key] = value; |
| 225 | + const snapshot = captureEnv([key]); |
| 226 | + setTestEnvValue(key, value); |
230 | 227 | try { |
231 | 228 | return await fn(); |
232 | 229 | } finally { |
233 | | - if (previous === undefined) { |
234 | | - delete process.env[key]; |
235 | | - } else { |
236 | | - process.env[key] = previous; |
237 | | - } |
| 230 | + snapshot.restore(); |
238 | 231 | } |
239 | 232 | } |
240 | 233 |
|
|
0 commit comments