Skip to content

Commit 126ebfc

Browse files
committed
test: share probe target env cleanup
1 parent 4b15159 commit 126ebfc

1 file changed

Lines changed: 5 additions & 38 deletions

File tree

src/commands/models/list.probe.targets.test.ts

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
33
import type { AuthProfileStore } from "../../agents/auth-profiles.js";
44
import type { ModelCatalogEntry } from "../../agents/model-catalog.js";
55
import type { OpenClawConfig } from "../../config/config.js";
6+
import { withEnvAsync } from "../../test-utils/env.js";
67

78
let mockStore: AuthProfileStore;
89
let mockAgentStore: AuthProfileStore | undefined;
@@ -114,46 +115,12 @@ async function buildAnthropicProbePlan(order: string[]) {
114115
});
115116
}
116117

117-
async function withClearedAnthropicEnv<T>(fn: () => Promise<T>): Promise<T> {
118-
const previousAnthropic = process.env.ANTHROPIC_API_KEY;
119-
const previousAnthropicOauth = process.env.ANTHROPIC_OAUTH_TOKEN;
120-
delete process.env.ANTHROPIC_API_KEY;
121-
delete process.env.ANTHROPIC_OAUTH_TOKEN;
122-
try {
123-
return await fn();
124-
} finally {
125-
if (previousAnthropic === undefined) {
126-
delete process.env.ANTHROPIC_API_KEY;
127-
} else {
128-
process.env.ANTHROPIC_API_KEY = previousAnthropic;
129-
}
130-
if (previousAnthropicOauth === undefined) {
131-
delete process.env.ANTHROPIC_OAUTH_TOKEN;
132-
} else {
133-
process.env.ANTHROPIC_OAUTH_TOKEN = previousAnthropicOauth;
134-
}
135-
}
118+
function withClearedAnthropicEnv<T>(fn: () => Promise<T>): Promise<T> {
119+
return withEnvAsync({ ANTHROPIC_API_KEY: undefined, ANTHROPIC_OAUTH_TOKEN: undefined }, fn);
136120
}
137121

138-
async function withClearedZaiEnv<T>(fn: () => Promise<T>): Promise<T> {
139-
const previousZai = process.env.ZAI_API_KEY;
140-
const previousLegacyZai = process.env.Z_AI_API_KEY;
141-
delete process.env.ZAI_API_KEY;
142-
delete process.env.Z_AI_API_KEY;
143-
try {
144-
return await fn();
145-
} finally {
146-
if (previousZai === undefined) {
147-
delete process.env.ZAI_API_KEY;
148-
} else {
149-
process.env.ZAI_API_KEY = previousZai;
150-
}
151-
if (previousLegacyZai === undefined) {
152-
delete process.env.Z_AI_API_KEY;
153-
} else {
154-
process.env.Z_AI_API_KEY = previousLegacyZai;
155-
}
156-
}
122+
function withClearedZaiEnv<T>(fn: () => Promise<T>): Promise<T> {
123+
return withEnvAsync({ ZAI_API_KEY: undefined, Z_AI_API_KEY: undefined }, fn);
157124
}
158125

159126
async function buildAnthropicPlanFromModelsJsonApiKey(apiKey: string) {

0 commit comments

Comments
 (0)