mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
fix: scope model auth env helpers
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import type { Model } from "openclaw/plugin-sdk/llm";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ModelProviderConfig } from "../config/config.js";
|
||||
import { captureEnv, deleteTestEnvValue, setTestEnvValue } from "../test-utils/env.js";
|
||||
import type { AuthProfileStore } from "./auth-profiles.js";
|
||||
import {
|
||||
CUSTOM_LOCAL_AUTH_MARKER,
|
||||
@@ -211,30 +212,22 @@ describe("createRuntimeProviderAuthLookup", () => {
|
||||
});
|
||||
|
||||
async function withoutEnv<T>(key: string, fn: () => Promise<T>): Promise<T> {
|
||||
const previous = process.env[key];
|
||||
delete process.env[key];
|
||||
const snapshot = captureEnv([key]);
|
||||
deleteTestEnvValue(key);
|
||||
try {
|
||||
return await fn();
|
||||
} finally {
|
||||
if (previous === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = previous;
|
||||
}
|
||||
snapshot.restore();
|
||||
}
|
||||
}
|
||||
|
||||
async function withEnv<T>(key: string, value: string, fn: () => Promise<T>): Promise<T> {
|
||||
const previous = process.env[key];
|
||||
process.env[key] = value;
|
||||
const snapshot = captureEnv([key]);
|
||||
setTestEnvValue(key, value);
|
||||
try {
|
||||
return await fn();
|
||||
} finally {
|
||||
if (previous === undefined) {
|
||||
delete process.env[key];
|
||||
} else {
|
||||
process.env[key] = previous;
|
||||
}
|
||||
snapshot.restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user