Skip to content

Commit ffd8c6e

Browse files
committed
fix: scope model auth env helpers
1 parent 9fced92 commit ffd8c6e

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

src/agents/model-auth.test.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { Model } from "openclaw/plugin-sdk/llm";
33
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
44
import type { ModelProviderConfig } from "../config/config.js";
5+
import { captureEnv, deleteTestEnvValue, setTestEnvValue } from "../test-utils/env.js";
56
import type { AuthProfileStore } from "./auth-profiles.js";
67
import {
78
CUSTOM_LOCAL_AUTH_MARKER,
@@ -211,30 +212,22 @@ describe("createRuntimeProviderAuthLookup", () => {
211212
});
212213

213214
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);
216217
try {
217218
return await fn();
218219
} finally {
219-
if (previous === undefined) {
220-
delete process.env[key];
221-
} else {
222-
process.env[key] = previous;
223-
}
220+
snapshot.restore();
224221
}
225222
}
226223

227224
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);
230227
try {
231228
return await fn();
232229
} finally {
233-
if (previous === undefined) {
234-
delete process.env[key];
235-
} else {
236-
process.env[key] = previous;
237-
}
230+
snapshot.restore();
238231
}
239232
}
240233

0 commit comments

Comments
 (0)