Files
oh-my-pi/packages/ai/test/anthropic-retry.test.ts
T
2026-04-01 04:52:47 +02:00

32 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { isProviderRetryableError } from "@oh-my-pi/pi-ai/providers/anthropic";
describe("isProviderRetryableError", () => {
it("retries known transient rate-limit errors", () => {
expect(isProviderRetryableError(new Error("Rate limit exceeded"))).toBe(true);
expect(isProviderRetryableError(new Error("error 1302 from upstream"))).toBe(true);
});
it("retries transient stream envelope parse errors", () => {
expect(isProviderRetryableError(new Error("JSON Parse error: Unterminated string"))).toBe(true);
expect(isProviderRetryableError(new Error("Unexpected end of JSON input"))).toBe(true);
});
it("retries HTTP/2 stream errors (INTERNAL_ERROR)", () => {
expect(
isProviderRetryableError(new Error("stream error: stream ID 391; INTERNAL_ERROR; received from peer")),
).toBe(true);
});
it("retries first-event timeout errors", () => {
expect(isProviderRetryableError(new Error("Anthropic stream timed out while waiting for the first event"))).toBe(
true,
);
});
it("does not retry non-transient validation errors", () => {
expect(isProviderRetryableError(new Error("Invalid tool schema"))).toBe(false);
expect(isProviderRetryableError(new Error("Bad request"))).toBe(false);
});
});