Skip to content

Commit b2e9dc0

Browse files
test(models): isolate ambient CLI availability
Co-authored-by: Tak Hoffman <[email protected]>
1 parent 9ee215e commit b2e9dc0

1 file changed

Lines changed: 19 additions & 20 deletions

File tree

‎src/gateway/server-methods/models-list-result.cli-runtime-availability.test.ts‎

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
13
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4+
import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js";
25
import type { OpenClawConfig } from "../../config/types.openclaw.js";
36
import {
47
listModels,
58
providerCatalogEntry,
69
} from "./models-list-result.openai-routes.test-support.js";
710

8-
const mocks = vi.hoisted(() => ({
9-
readClaudeCliCredentialsCached: vi.fn<() => unknown>(() => null),
10-
readCodexCliCredentialsCached: vi.fn<() => unknown>(() => null),
11-
readMiniMaxCliCredentialsCached: vi.fn<() => unknown>(() => null),
12-
}));
13-
14-
vi.mock("../../agents/cli-credentials.js", () => mocks);
11+
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
1512

1613
const config = {
1714
agents: {
@@ -40,26 +37,28 @@ async function listClaudeCliModel() {
4037
describe("models.list CLI runtime availability", () => {
4138
beforeEach(() => {
4239
vi.stubEnv("ANTHROPIC_API_KEY", "");
43-
mocks.readClaudeCliCredentialsCached.mockReset();
44-
mocks.readClaudeCliCredentialsCached.mockReturnValue(null);
45-
mocks.readCodexCliCredentialsCached.mockReset();
46-
mocks.readCodexCliCredentialsCached.mockReturnValue(null);
47-
mocks.readMiniMaxCliCredentialsCached.mockReset();
48-
mocks.readMiniMaxCliCredentialsCached.mockReturnValue(null);
4940
});
5041

5142
afterEach(() => {
5243
vi.unstubAllEnvs();
5344
});
5445

5546
it("marks a Claude CLI runtime model available with ambient CLI OAuth", async () => {
56-
mocks.readClaudeCliCredentialsCached.mockReturnValue({
57-
type: "oauth",
58-
provider: "anthropic",
59-
access: "test-access",
60-
refresh: "test-refresh",
61-
expires: Date.now() + 3_600_000,
62-
});
47+
const homeDir = tempDirs.make("models-list-claude-cli-");
48+
const credentialDir = path.join(homeDir, ".claude");
49+
fs.mkdirSync(credentialDir, { recursive: true, mode: 0o700 });
50+
fs.writeFileSync(
51+
path.join(credentialDir, ".credentials.json"),
52+
JSON.stringify({
53+
claudeAiOauth: {
54+
accessToken: "test-access",
55+
refreshToken: "test-refresh",
56+
expiresAt: Date.now() + 3_600_000,
57+
},
58+
}),
59+
{ mode: 0o600 },
60+
);
61+
vi.stubEnv("HOME", homeDir);
6362

6463
await expect(listClaudeCliModel()).resolves.toEqual({
6564
models: [expect.objectContaining({ id: "claude-opus-5", available: true })],

0 commit comments

Comments
 (0)