|
1 | 1 | /** Tests provider request error classification for retry/fallback decisions. */ |
2 | 2 | import { describe, expect, it } from "vitest"; |
| 3 | +import { FailoverError } from "../../agents/failover-error.js"; |
3 | 4 | import { |
4 | 5 | classifyProviderRequestError, |
| 6 | + PROVIDER_AUTHENTICATION_ERROR_USER_MESSAGE, |
5 | 7 | PROVIDER_CONVERSATION_STATE_ERROR_USER_MESSAGE, |
6 | 8 | PROVIDER_INTERNAL_ERROR_USER_MESSAGE, |
7 | 9 | PROVIDER_RATE_LIMIT_OR_QUOTA_ERROR_USER_MESSAGE, |
8 | 10 | } from "./provider-request-error-classifier.js"; |
9 | 11 |
|
10 | 12 | describe("provider request error classifier", () => { |
| 13 | + it("classifies provider HTTP 401 authentication failures", () => { |
| 14 | + const message = |
| 15 | + "unexpected status 401 Unauthorized: Missing bearer or basic authentication in header, url: https://api.openai.com/v1/responses"; |
| 16 | + |
| 17 | + expect(classifyProviderRequestError(new Error(message))).toEqual({ |
| 18 | + code: "provider_authentication_error", |
| 19 | + userMessage: PROVIDER_AUTHENTICATION_ERROR_USER_MESSAGE, |
| 20 | + technicalMessage: message, |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + it("classifies typed authentication failures without relying on raw provider text", () => { |
| 25 | + const error = new FailoverError("LLM request unauthorized.", { |
| 26 | + reason: "auth", |
| 27 | + provider: "openai", |
| 28 | + model: "gpt-5.5", |
| 29 | + status: 401, |
| 30 | + }); |
| 31 | + |
| 32 | + expect(classifyProviderRequestError(error)).toEqual({ |
| 33 | + code: "provider_authentication_error", |
| 34 | + userMessage: PROVIDER_AUTHENTICATION_ERROR_USER_MESSAGE, |
| 35 | + technicalMessage: "LLM request unauthorized.", |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + it("does not label typed HTTP 403 authorization failures as HTTP 401", () => { |
| 40 | + const error = new FailoverError("Provider access denied.", { |
| 41 | + reason: "auth_permanent", |
| 42 | + provider: "openai", |
| 43 | + model: "gpt-5.5", |
| 44 | + status: 403, |
| 45 | + }); |
| 46 | + |
| 47 | + expect(classifyProviderRequestError(error)).toBeUndefined(); |
| 48 | + }); |
| 49 | + |
| 50 | + it("leaves unrelated HTTP 401 failures unclassified", () => { |
| 51 | + expect( |
| 52 | + classifyProviderRequestError( |
| 53 | + new Error("401 input item id does not belong to this conversation"), |
| 54 | + ), |
| 55 | + ).toBeUndefined(); |
| 56 | + }); |
| 57 | + |
11 | 58 | it.each([ |
12 | 59 | [ |
13 | 60 | "OpenAI missing custom tool output", |
|
0 commit comments