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.4 KB
Raw Blame
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";

// Split-guard for the default executor URL-normalizer extraction.
// The pure per-provider chat-URL normalizers live in default/urlNormalizers.ts
// (string transforms only). Host imports them back into buildUrl/transformRequest.
const HERE = dirname(fileURLToPath(import.meta.url));
const EXE = join(HERE, "../../open-sse/executors");
const HOST = join(EXE, "default.ts");
const LEAF = join(EXE, "default/urlNormalizers.ts");

test("leaf hosts the normalizers and does not import the host", () => {
  const src = readFileSync(LEAF, "utf8");
  for (const sym of [
    "normalizeOpenAIChatUrl",
    "normalizeSapChatUrl",
    "getOpenRouterConnectionPreset",
  ]) {
    assert.match(src, new RegExp(`export function ${sym}\\b`));
  }
  assert.doesNotMatch(src, /from "\.\.\/default\.ts"/);
});

test("host imports the normalizers back from the leaf", () => {
  const host = readFileSync(HOST, "utf8");
  assert.match(host, /from "\.\/default\/urlNormalizers\.ts"/);
});

test("normalizeOpenAIChatUrl appends chat/completions for a bare base URL", async () => {
  const { normalizeOpenAIChatUrl } =
    await import("../../open-sse/executors/default/urlNormalizers.ts");
  assert.match(normalizeOpenAIChatUrl("https://api.example.com"), /\/v1\/chat\/completions$/);
});