Files
OmniRoute/tests/unit/geminiProjectBlock.test.ts
Bl0ck 6f9a10b8cc fix(gemini): cool the connection on project-wide billing refusals (#18848)
Gemini can reject an entire Google project with messages such as "free tier is not available for this project", "prepayment credits are depleted", or "project has exceeded its monthly spending cap".

Those errors are unrelated to the requested model. Today a passthrough connection can get a brief per-model lockout and be selected again immediately for other models from the same project.

Recognize those three specific responses and temporarily park the affected connection for six hours while keeping the credentials and active setting intact. Other 403s, ordinary quota 429s and transient 5xx errors follow the existing logic.

The patch is limited to one classifier, the account-unavailable path, and tests covering matching and non-matching cases.

Thanks @Bl0ck154.
2026-11-08 20:04:28 -03:00

73 lines
2.0 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { classifyGeminiProjectBlock } from "../../src/sse/services/geminiProjectBlock.ts";
test("Gemini: project free tier is unavailable (not a generic model cooldown)", () => {
assert.equal(
classifyGeminiProjectBlock(
"gemini",
403,
"The Gemini API free tier is not available for this project. To use the Gemini API, please set up billing."
),
"gemini_free_tier_ineligible"
);
assert.equal(
classifyGeminiProjectBlock(
"gemini",
403,
"Your project has been denied access. Please contact support."
),
"gemini_free_tier_ineligible"
);
});
test("Gemini: prepaid funds and monthly spend cap are project-scoped", () => {
assert.equal(
classifyGeminiProjectBlock("gemini", 402, "Your prepayment credits are depleted."),
"gemini_prepay_depleted"
);
assert.equal(
classifyGeminiProjectBlock(
"gemini",
429,
"Your project has exceeded its monthly spending cap."
),
"gemini_monthly_spend_cap"
);
});
test("Gemini: ordinary rate limiting and transient failures stay transient", () => {
assert.equal(
classifyGeminiProjectBlock(
"gemini",
429,
"You exceeded your current quota, please check your plan and billing details."
),
null
);
assert.equal(
classifyGeminiProjectBlock("gemini", 503, "The model is experiencing high demand"),
null
);
assert.equal(classifyGeminiProjectBlock("gemini", 403, "Content not permitted"), null);
assert.equal(
classifyGeminiProjectBlock(
"antigravity",
403,
"The Gemini API free tier is not available for this project"
),
null
);
});
test("Gemini: terminal account deactivation is not downgraded to a project cooldown", () => {
assert.equal(
classifyGeminiProjectBlock(
"gemini",
403,
"Your project has been denied access because your account has been deactivated."
),
null
);
});