Files
oh-my-opencode/src/hooks/runtime-fallback/quota-error-classifier.regression.test.ts
T

60 lines
1.8 KiB
TypeScript
Raw Normal View History

import { describe, expect, test } from "bun:test"
import { classifyErrorType, isRetryableError } from "./error-classifier"
describe("runtime-fallback quota error regressions", () => {
test("classifies subscription quota errors as quota_exceeded and triggers fallback", () => {
//#given
const error = {
name: "AI_APICallError",
message: "Subscription quota exceeded. You can continue using free models.",
}
//#when
const errorType = classifyErrorType(error)
const retryable = isRetryableError(error, [429, 500, 502, 503, 504])
//#then
expect(errorType).toBe("quota_exceeded")
// quota exhaustion should trigger fallback to the next model
expect(retryable).toBe(true)
})
test("treats HTTP 402 payment required as fallback-eligible", () => {
//#given
const error = { statusCode: 402, message: "Payment Required" }
//#when
const retryable = isRetryableError(error, [429, 500, 502, 503, 504])
//#then
// payment failure triggers fallback to a different provider/model
expect(retryable).toBe(true)
})
test("keeps HTTP 429 rate limit retryable", () => {
//#given
const error = { statusCode: 429, message: "Too Many Requests: rate limit reached" }
//#when
const retryable = isRetryableError(error, [429, 500, 502, 503, 504])
//#then
expect(retryable).toBe(true)
})
test("classifies quota error names as quota_exceeded and triggers fallback", () => {
//#given
const error = { name: "QuotaExceededError", message: "Request failed." }
//#when
const errorType = classifyErrorType(error)
const retryable = isRetryableError(error, [429, 500, 502, 503, 504])
//#then
expect(errorType).toBe("quota_exceeded")
// quota errors trigger fallback to next configured model
expect(retryable).toBe(true)
})
})