Fix bug 1: Only fetch Anthropic models when API key exists

getAnthropicModels() was called unconditionally on mount, causing a
console error when no API key was set. Now chains the call after
getAnthropicApiKeyExists() confirms a key is present.

Includes regression test added before the fix per bug workflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dave
2026-02-20 12:01:47 +00:00
parent e12985f40c
commit 3e99929d03
3 changed files with 48 additions and 16 deletions

View File

@@ -592,4 +592,17 @@ describe("Chat review panel", () => {
expect(await screen.findByText("Cannot read stories")).toBeInTheDocument();
});
it("does not fetch Anthropic models when no API key exists", async () => {
mockedApi.getAnthropicApiKeyExists.mockResolvedValue(false);
mockedApi.getAnthropicModels.mockClear();
render(<Chat projectPath="/tmp/project" onCloseProject={vi.fn()} />);
await waitFor(() => {
expect(mockedApi.getAnthropicApiKeyExists).toHaveBeenCalled();
});
expect(mockedApi.getAnthropicModels).not.toHaveBeenCalled();
});
});