Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.7 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

import {
  API_KEY_BYPASS_PROVIDER_QUOTA_SCOPE,
  hasProviderQuotaBypassScope,
} from "../../src/shared/constants/apiKeyPolicyScopes.ts";

const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");

test("provider quota bypass scope helper is explicit and strict", () => {
  assert.equal(API_KEY_BYPASS_PROVIDER_QUOTA_SCOPE, "policy:bypass-provider-quota");
  assert.equal(hasProviderQuotaBypassScope([API_KEY_BYPASS_PROVIDER_QUOTA_SCOPE]), true);
  assert.equal(hasProviderQuotaBypassScope(["policy:other"]), false);
  assert.equal(hasProviderQuotaBypassScope(null), false);
});

test("chat handler maps API key provider quota bypass scope to auth bypass option", () => {
  const source = fs.readFileSync(path.join(repoRoot, "src/sse/handlers/chat.ts"), "utf8");

  assert.match(source, /hasProviderQuotaBypassScope\(apiKeyInfo\?\.scopes\)/);
  assert.match(source, /bypassProviderQuotaPolicy[\s\S]*bypassQuotaPolicy: true/);
  assert.match(source, /relayOptions[\s\S]*bypassProviderQuotaPolicy: true/);
});

test("auto combo disables hard provider quota cutoffs when relay requests bypass", () => {
  // The auto-strategy bypass logic was extracted verbatim from combo.ts into the
  // resolveAutoStrategy leaf (Block J Task 2); the source scan follows the code.
  const source = fs.readFileSync(
    path.join(repoRoot, "open-sse/services/combo/resolveAutoStrategy.ts"),
    "utf8"
  );

  assert.match(source, /relayOptions\?\.bypassProviderQuotaPolicy === true/);
  assert.match(source, /quotaPreflight:[\s\S]*enabled: false/);
});