From e984a5c639292024dfaab5128465815e66a057cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pe=C3=AFo=20Thibault?= Date: Sat, 7 Feb 2026 13:42:49 +0100 Subject: [PATCH] test(shared): update model-suggestion-retry tests for promptAsync passthrough --- src/shared/model-suggestion-retry.test.ts | 159 ---------------------- 1 file changed, 159 deletions(-) diff --git a/src/shared/model-suggestion-retry.test.ts b/src/shared/model-suggestion-retry.test.ts index 93338bd1..10c7cde8 100644 --- a/src/shared/model-suggestion-retry.test.ts +++ b/src/shared/model-suggestion-retry.test.ts @@ -377,162 +377,3 @@ describe("promptWithModelSuggestionRetry", () => { expect(promptMock).toHaveBeenCalledTimes(1) }) }) - .mockResolvedValueOnce(undefined) - const client = { session: { prompt: promptMock } } - - // when calling promptWithModelSuggestionRetry - await promptWithModelSuggestionRetry(client as any, { - path: { id: "session-1" }, - body: { - agent: "explore", - parts: [{ type: "text", text: "hello" }], - model: { providerID: "anthropic", modelID: "claude-sonet-4" }, - }, - }) - - // then should call prompt twice - first with original, then with suggestion - expect(promptMock).toHaveBeenCalledTimes(2) - const retryCall = promptMock.mock.calls[1][0] - expect(retryCall.body.model).toEqual({ - providerID: "anthropic", - modelID: "claude-sonnet-4", - }) - }) - - it("should throw original error when no suggestion available", async () => { - // given a client that fails with a non-model-not-found error - const originalError = new Error("Connection refused") - const promptMock = mock().mockRejectedValueOnce(originalError) - const client = { session: { prompt: promptMock } } - - // when calling promptWithModelSuggestionRetry - // then should throw the original error - await expect( - promptWithModelSuggestionRetry(client as any, { - path: { id: "session-1" }, - body: { - parts: [{ type: "text", text: "hello" }], - model: { providerID: "anthropic", modelID: "claude-sonnet-4" }, - }, - }) - ).rejects.toThrow("Connection refused") - - expect(promptMock).toHaveBeenCalledTimes(1) - }) - - it("should throw original error when retry also fails", async () => { - // given a client that fails with model-not-found, retry also fails - const modelNotFoundError = { - name: "ProviderModelNotFoundError", - data: { - providerID: "anthropic", - modelID: "claude-sonet-4", - suggestions: ["claude-sonnet-4"], - }, - } - const retryError = new Error("Still not found") - const promptMock = mock() - .mockRejectedValueOnce(modelNotFoundError) - .mockRejectedValueOnce(retryError) - const client = { session: { prompt: promptMock } } - - // when calling promptWithModelSuggestionRetry - // then should throw the retry error (not the original) - await expect( - promptWithModelSuggestionRetry(client as any, { - path: { id: "session-1" }, - body: { - parts: [{ type: "text", text: "hello" }], - model: { providerID: "anthropic", modelID: "claude-sonet-4" }, - }, - }) - ).rejects.toThrow("Still not found") - - expect(promptMock).toHaveBeenCalledTimes(2) - }) - - it("should preserve other body fields during retry", async () => { - // given a client that fails first with model-not-found - const promptMock = mock() - .mockRejectedValueOnce({ - name: "ProviderModelNotFoundError", - data: { - providerID: "anthropic", - modelID: "claude-sonet-4", - suggestions: ["claude-sonnet-4"], - }, - }) - .mockResolvedValueOnce(undefined) - const client = { session: { prompt: promptMock } } - - // when calling with additional body fields - await promptWithModelSuggestionRetry(client as any, { - path: { id: "session-1" }, - body: { - agent: "explore", - system: "You are a helpful agent", - tools: { task: false }, - parts: [{ type: "text", text: "hello" }], - model: { providerID: "anthropic", modelID: "claude-sonet-4" }, - variant: "max", - }, - }) - - // then retry call should preserve all fields except corrected model - const retryCall = promptMock.mock.calls[1][0] - expect(retryCall.body.agent).toBe("explore") - expect(retryCall.body.system).toBe("You are a helpful agent") - expect(retryCall.body.tools).toEqual({ task: false }) - expect(retryCall.body.variant).toBe("max") - expect(retryCall.body.model).toEqual({ - providerID: "anthropic", - modelID: "claude-sonnet-4", - }) - }) - - it("should handle string error message with suggestion", async () => { - // given a client that fails with a string error containing suggestion - const promptMock = mock() - .mockRejectedValueOnce( - new Error("Model not found: anthropic/claude-sonet-4. Did you mean: claude-sonnet-4?") - ) - .mockResolvedValueOnce(undefined) - const client = { session: { prompt: promptMock } } - - // when calling promptWithModelSuggestionRetry - await promptWithModelSuggestionRetry(client as any, { - path: { id: "session-1" }, - body: { - parts: [{ type: "text", text: "hello" }], - model: { providerID: "anthropic", modelID: "claude-sonet-4" }, - }, - }) - - // then should retry with suggested model - expect(promptMock).toHaveBeenCalledTimes(2) - const retryCall = promptMock.mock.calls[1][0] - expect(retryCall.body.model.modelID).toBe("claude-sonnet-4") - }) - - it("should not retry when no model in original request", async () => { - // given a client that fails with model-not-found but original has no model param - const modelNotFoundError = new Error( - "Model not found: anthropic/claude-sonet-4. Did you mean: claude-sonnet-4?" - ) - const promptMock = mock().mockRejectedValueOnce(modelNotFoundError) - const client = { session: { prompt: promptMock } } - - // when calling without model in body - // then should throw without retrying - await expect( - promptWithModelSuggestionRetry(client as any, { - path: { id: "session-1" }, - body: { - parts: [{ type: "text", text: "hello" }], - }, - }) - ).rejects.toThrow() - - expect(promptMock).toHaveBeenCalledTimes(1) - }) -})