fix: treat credential validation failures as auth errors for fallback (#761)

This commit is contained in:
Sebastian
2026-01-12 22:48:37 -05:00
parent c08441c42c
commit c4014c0092
3 changed files with 27 additions and 1 deletions

View File

@@ -102,6 +102,28 @@ describe("runWithModelFallback", () => {
expect(run.mock.calls[1]?.[1]).toBe("claude-haiku-3-5");
});
it("falls back on credential validation errors", async () => {
const cfg = makeCfg();
const run = vi
.fn()
.mockRejectedValueOnce(
new Error('No credentials found for profile "anthropic:claude-cli".'),
)
.mockResolvedValueOnce("ok");
const result = await runWithModelFallback({
cfg,
provider: "anthropic",
model: "claude-opus-4",
run,
});
expect(result.result).toBe("ok");
expect(run).toHaveBeenCalledTimes(2);
expect(run.mock.calls[1]?.[0]).toBe("anthropic");
expect(run.mock.calls[1]?.[1]).toBe("claude-haiku-3-5");
});
it("appends the configured primary as a last fallback", async () => {
const cfg = makeCfg({
agents: {