Files
oh-my-opencode/src/hooks/runtime-fallback/quota-error-classifier.regression.test.ts
T
wenghuayang863 1c7881ec09 fix(runtime-fallback): match Volcano Engine 'exceeded the usage quota' errors
Volcano Engine sends quota exceeded errors with the words in reverse
order: 'You have exceeded the 5-hour usage quota'. The existing
patterns required 'quota' to precede 'exceeded', so they never matched.

- Add /exceeded.*quota/i and /usage.?quota/i to RETRYABLE_ERROR_PATTERNS
- Add exceeded.*quota and usage\s*quota to AUTO_RETRY_PATTERNS
- Add regression tests for both detection paths

Fixes: runtime-fallback not triggering on Volcano Engine quota errors
2026-05-11 00:43:58 +08:00

75 lines
2.3 KiB
TypeScript

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)
})
test("classifies Volcano Engine 'exceeded the usage quota' as retryable", () => {
//#given
const error = {
name: "SessionRetry",
message: "You have exceeded the 5-hour usage quota. It will reset at 2026-05-11 01:20:12 +0800 CST. We recommend using a different model.",
}
//#when
const retryable = isRetryableError(error, [429, 500, 502, 503, 504])
//#then
// Volcano Engine quota errors trigger fallback to the next model
expect(retryable).toBe(true)
})
})