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 { test } from "node:test";
import assert from "node:assert/strict";
import { computeConnectionDefaultName } from "@/app/(dashboard)/dashboard/providers/[id]/components/modals/computeConnectionDefaultName";
// #6499 — the backend upserts API-key connections by (provider, name), so a second
// connection defaulting to "main" silently overwrites the first. The default name
// must stay "main" for the first connection (backward compatible) and get a unique
// numeric suffix afterwards.
test("first connection defaults to 'main'", () => {
assert.equal(computeConnectionDefaultName(0), "main");
});
test("undefined count is treated as zero → 'main'", () => {
assert.equal(computeConnectionDefaultName(undefined), "main");
});
test("subsequent connections get a unique numeric suffix", () => {
assert.equal(computeConnectionDefaultName(1), "main-2");
assert.equal(computeConnectionDefaultName(2), "main-3");
assert.equal(computeConnectionDefaultName(9), "main-10");
});
test("negative counts are clamped to 'main' (never a broken 'main-0')", () => {
assert.equal(computeConnectionDefaultName(-1), "main");
});