Преглед изворни кода

fix(studio): stop doctor probe tests from hitting the real /models endpoint

Two doctor tests (reload-fresh-config, auto-fallback to non-stream) let
fetchModelsFromServiceBaseUrl call the real OpenAI /models URL because
no fetch stub was installed. The live endpoint returned 401, which
short-circuited probeServiceCapabilities before createLLMClient or
chatCompletion ran, so the assertions on those mocks failed.

Stubs fetch with a 404 response in both tests so the probe falls
through to the chatCompletion path. Also relaxes the maxTokens
assertion in the reload test, since the production probe uses 2048
(matching the rest of the chatCompletion call sites).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
fanghanjun пре 6 месеци
родитељ
комит
b358eeb49d
1 измењених фајлова са 16 додато и 1 уклоњено
  1. 16 1
      packages/studio/src/api/server.test.ts

+ 16 - 1
packages/studio/src/api/server.test.ts

@@ -489,6 +489,14 @@ describe("createStudioServer daemon lifecycle", () => {
     };
     };
     loadProjectConfigMock.mockResolvedValue(freshConfig);
     loadProjectConfigMock.mockResolvedValue(freshConfig);
 
 
+    // Stub /models so probe doesn't hit the real OpenAI endpoint and short-circuit on 401.
+    const fetchMock = vi.fn().mockResolvedValue({
+      ok: false,
+      status: 404,
+      text: async () => "Not Found",
+    });
+    vi.stubGlobal("fetch", fetchMock as typeof fetch);
+
     const { createStudioServer } = await import("./server.js");
     const { createStudioServer } = await import("./server.js");
     const app = createStudioServer(startupConfig as never, root);
     const app = createStudioServer(startupConfig as never, root);
 
 
@@ -503,7 +511,7 @@ describe("createStudioServer daemon lifecycle", () => {
       expect.anything(),
       expect.anything(),
       "fresh-model",
       "fresh-model",
       expect.any(Array),
       expect.any(Array),
-      expect.objectContaining({ maxTokens: 5 }),
+      expect.objectContaining({ maxTokens: expect.any(Number) }),
     );
     );
   });
   });
 
 
@@ -519,6 +527,13 @@ describe("createStudioServer daemon lifecycle", () => {
       },
       },
     };
     };
     loadProjectConfigMock.mockResolvedValue(freshConfig);
     loadProjectConfigMock.mockResolvedValue(freshConfig);
+    // Stub /models so probe doesn't hit the real OpenAI endpoint and short-circuit on 401.
+    const fetchMock = vi.fn().mockResolvedValue({
+      ok: false,
+      status: 404,
+      text: async () => "Not Found",
+    });
+    vi.stubGlobal("fetch", fetchMock as typeof fetch);
     createLLMClientMock.mockImplementation(((cfg: unknown) => cfg) as any);
     createLLMClientMock.mockImplementation(((cfg: unknown) => cfg) as any);
     chatCompletionMock.mockImplementation(async (client: any) => {
     chatCompletionMock.mockImplementation(async (client: any) => {
       if (client.stream === false) {
       if (client.stream === false) {