fix: treat credential validation errors as auth errors (#822) (thanks @sebslight)

This commit is contained in:
Peter Steinberger
2026-01-13 04:02:47 +00:00
parent c4014c0092
commit 2c2ca7f03b
4 changed files with 25 additions and 5 deletions

View File

@@ -124,6 +124,26 @@ describe("runWithModelFallback", () => {
expect(run.mock.calls[1]?.[1]).toBe("claude-haiku-3-5");
});
it("falls back on missing API key errors", async () => {
const cfg = makeCfg();
const run = vi
.fn()
.mockRejectedValueOnce(new Error("No API key found for profile openai."))
.mockResolvedValueOnce("ok");
const result = await runWithModelFallback({
cfg,
provider: "openai",
model: "gpt-4.1-mini",
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: {