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
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
import { describe, it, expect, beforeEach } from "vitest";
import { acquire, isAccountSemaphoreFull, resetAll } from "../accountSemaphore.ts";
describe("isAccountSemaphoreFull fail-fast concurrency gate", () => {
beforeEach(() => {
resetAll();
});
it("returns false when no semaphore gate exists", () => {
expect(isAccountSemaphoreFull("featherless-ai", "conn-1", 1)).toBe(false);
});
it("returns false when maxConcurrency is null, <= 0, or bypassed", () => {
expect(isAccountSemaphoreFull("featherless-ai", "conn-1", null)).toBe(false);
expect(isAccountSemaphoreFull("featherless-ai", "conn-1", 0)).toBe(false);
});
it("returns false when running < maxConcurrency", async () => {
const release = await acquire("featherless-ai:conn-1", { maxConcurrency: 2 });
expect(isAccountSemaphoreFull("featherless-ai", "conn-1", 2)).toBe(false);
release();
});
it("returns true immediately when running >= maxConcurrency", async () => {
const release = await acquire("featherless-ai:conn-1", { maxConcurrency: 1 });
expect(isAccountSemaphoreFull("featherless-ai", "conn-1", 1)).toBe(true);
release();
expect(isAccountSemaphoreFull("featherless-ai", "conn-1", 1)).toBe(false);
});
});