|
1 | 1 | // Covers provider hook structured failover signals. |
2 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
3 | 3 | import { resolveFailoverReasonFromError } from "../failover-error.js"; |
4 | | -import { classifyFailoverSignal } from "./errors.js"; |
| 4 | +import { makeAssistantMessageFixture } from "../test-helpers/assistant-message-fixtures.js"; |
| 5 | +import { |
| 6 | + classifyAssistantFailoverReason, |
| 7 | + classifyProviderRuntimeFailureKind, |
| 8 | + classifyFailoverSignal, |
| 9 | +} from "./errors.js"; |
5 | 10 |
|
6 | 11 | const providerRuntimeMocks = vi.hoisted(() => ({ |
7 | 12 | classifyProviderPluginError: vi.fn(), |
@@ -111,6 +116,40 @@ describe("provider failover hook structured signals", () => { |
111 | 116 | ).toBe("billing"); |
112 | 117 | }); |
113 | 118 |
|
| 119 | + it.each([ |
| 120 | + { errorType: "rate_limit_error", reason: "rate_limit", runtimeKind: "rate_limit" }, |
| 121 | + { errorType: "api_error", reason: "timeout", runtimeKind: "timeout" }, |
| 122 | + ] as const)( |
| 123 | + "classifies message-less Anthropic $errorType assistant failures", |
| 124 | + ({ errorType, reason, runtimeKind }) => { |
| 125 | + providerRuntimeMocks.classifyProviderPluginError.mockImplementation((context) => { |
| 126 | + if (context.provider !== "anthropic") { |
| 127 | + return undefined; |
| 128 | + } |
| 129 | + if (context.errorType === "rate_limit_error") { |
| 130 | + return "rate_limit"; |
| 131 | + } |
| 132 | + return context.errorType === "api_error" ? "timeout" : undefined; |
| 133 | + }); |
| 134 | + |
| 135 | + const message = makeAssistantMessageFixture({ |
| 136 | + provider: "anthropic", |
| 137 | + errorMessage: undefined, |
| 138 | + errorType, |
| 139 | + content: [], |
| 140 | + }); |
| 141 | + |
| 142 | + expect(classifyAssistantFailoverReason(message)).toBe(reason); |
| 143 | + expect( |
| 144 | + classifyProviderRuntimeFailureKind({ |
| 145 | + provider: "anthropic", |
| 146 | + message: "", |
| 147 | + errorType, |
| 148 | + }), |
| 149 | + ).toBe(runtimeKind); |
| 150 | + }, |
| 151 | + ); |
| 152 | + |
114 | 153 | it("does not promote generic SDK type strings as structured provider descriptors", () => { |
115 | 154 | providerRuntimeMocks.classifyProviderPluginError.mockReturnValue("billing"); |
116 | 155 |
|
|
0 commit comments