mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +03:00
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host. Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean. Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
71 lines
3.3 KiB
TypeScript
71 lines
3.3 KiB
TypeScript
/**
|
|
* Issue #9486 — Anthropic OAuth returns HTTP 400 with "out of extra usage" in
|
|
* the error body when a tool-carrying request exceeds the account's usage quota.
|
|
* This should be classified as quota_exhausted (not generic bad_request), so the
|
|
* account fallback mechanism applies a proper cooldown and combo routing can
|
|
* skip to another target.
|
|
*/
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { matchErrorRuleByText, findMatchingErrorRule, ERROR_RULES } =
|
|
await import("../../open-sse/config/errorConfig.ts");
|
|
const { checkFallbackError, classifyErrorText } =
|
|
await import("../../open-sse/services/accountFallback.ts");
|
|
const { RateLimitReason } = await import("../../open-sse/config/constants.ts");
|
|
|
|
test("#9486 ERROR_RULES has a text rule for 'out of extra usage' → quota_exhausted", () => {
|
|
const rule = ERROR_RULES.find((r) => r.text === "out of extra usage");
|
|
assert.ok(rule, "expected a rule for 'out of extra usage'");
|
|
assert.equal(rule!.reason, "quota_exhausted");
|
|
// Should use backoff so the fallback path applies exponential scaling
|
|
assert.equal(rule!.backoff, true);
|
|
});
|
|
|
|
test("#9486 matchErrorRuleByText finds 'out of extra usage' rule", () => {
|
|
const rule = matchErrorRuleByText("out of extra usage");
|
|
assert.ok(rule, "expected a matching rule");
|
|
assert.equal(rule!.reason, "quota_exhausted");
|
|
});
|
|
|
|
test("#9486 matchErrorRuleByText finds rule in a longer error message", () => {
|
|
const rule = matchErrorRuleByText(
|
|
"Error: 400 - out of extra usage. You have exceeded your usage quota for this billing period."
|
|
);
|
|
assert.ok(rule, "expected a matching rule from longer message");
|
|
assert.equal(rule!.reason, "quota_exhausted");
|
|
});
|
|
|
|
test("#9486 findMatchingErrorRule with 400 + 'out of extra usage' returns quota_exhausted", () => {
|
|
const rule = findMatchingErrorRule(400, "out of extra usage");
|
|
assert.ok(rule, "expected a matching rule");
|
|
assert.equal(rule!.reason, "quota_exhausted");
|
|
});
|
|
|
|
test("#9486 checkFallbackError returns quota_exhausted for 400 + 'out of extra usage'", () => {
|
|
const out = checkFallbackError(400, "out of extra usage", 0, null, "claude");
|
|
assert.equal(out.shouldFallback, true);
|
|
assert.equal(out.reason, RateLimitReason.QUOTA_EXHAUSTED);
|
|
// Should get a non-zero cooldown (quota exhaustion is not transient)
|
|
assert.ok(out.cooldownMs > 0, `expected positive cooldown, got ${out.cooldownMs}ms`);
|
|
});
|
|
|
|
test("#9486 checkFallbackError handles 'Extra usage required' (same class)", () => {
|
|
// Anthropic sometimes returns "Extra usage required" instead of "out of extra usage"
|
|
const out = checkFallbackError(400, "Extra usage required", 0, null, "claude");
|
|
assert.equal(out.shouldFallback, true);
|
|
assert.equal(out.reason, RateLimitReason.QUOTA_EXHAUSTED);
|
|
});
|
|
|
|
test("#9486 classifyErrorText flags 'out of extra usage' as QUOTA_EXHAUSTED", () => {
|
|
const out = classifyErrorText("out of extra usage");
|
|
assert.equal(out, RateLimitReason.QUOTA_EXHAUSTED);
|
|
});
|
|
|
|
test("#9486 generic 400 without quota text still gets no fallback (regression guard)", () => {
|
|
// Regression guard: a plain 400 with no quota-related text must NOT trigger
|
|
// fallback, preserving the existing behavior for non-quota 400 errors.
|
|
const out = checkFallbackError(400, "Bad request: invalid JSON", 0, null, "claude");
|
|
assert.equal(out.shouldFallback, false);
|
|
assert.equal(out.reason, RateLimitReason.UNKNOWN);
|
|
}); |