|
1 | 1 | import { describe, test, expect, beforeEach, afterEach, vi } from "vitest"; |
2 | 2 | import { setupOpenCodeConfig } from "@/setup/opencode.js"; |
3 | 3 | import { __resetCatalogForTests } from "@/translate/catalog.js"; |
| 4 | +import { mockCcModelsFetch } from "./helpers.js"; |
4 | 5 | import fs from "node:fs"; |
5 | 6 |
|
6 | 7 | // Never hit the real CC API or read the developer's saved auth during tests. |
@@ -64,21 +65,10 @@ describe("setupOpenCodeConfig", () => { |
64 | 65 | test("builds config from the live API catalog when a key is available", async () => { |
65 | 66 | process.env.CC_API_KEY = "test-key"; |
66 | 67 | process.env.CC_API_BASE = "https://api.test-cc.example"; |
67 | | - const realFetch = globalThis.fetch.bind(globalThis); |
68 | | - vi.spyOn(globalThis, "fetch").mockImplementation(async (input, init) => { |
69 | | - const url = typeof input === "string" ? input : (input as Request).url ?? String(input); |
70 | | - if (!url.includes("/provider/v1/models")) return realFetch(input, init); |
71 | | - return new Response( |
72 | | - JSON.stringify({ |
73 | | - object: "list", |
74 | | - data: [ |
75 | | - { id: "claude-opus-5", name: "Claude Opus 5", context_length: 1000000 }, |
76 | | - { id: "zai-org/GLM-5.3", name: "GLM-5.3", context_length: 1000000 }, |
77 | | - ], |
78 | | - }), |
79 | | - { status: 200 }, |
80 | | - ) as unknown as Response; |
81 | | - }); |
| 68 | + mockCcModelsFetch([ |
| 69 | + { id: "claude-opus-5", name: "Claude Opus 5", context_length: 1000000 }, |
| 70 | + { id: "zai-org/GLM-5.3", name: "GLM-5.3", context_length: 1000000 }, |
| 71 | + ]); |
82 | 72 |
|
83 | 73 | await setupOpenCodeConfig("local"); |
84 | 74 | const config = JSON.parse(written as string); |
|
0 commit comments