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

4.8 KB
Raw Blame
/**
 * Coverage for the OpenVecta (https://openvecta.com/) provider registration.
 *
 * Validates the seven wiring points established in the feat/openvecta-provider
 * branch:
 *   1. APIKEY_PROVIDERS.openvecta — catalog entry (id, alias, name, website, hasFree)
 *   2. providerRegistry.openvecta — format=openai / executor=default / apikey / bearer
 *   3. PROVIDER_ENDPOINTS — chat completions baseUrl
 *   4. providerModelsConfig — live /v1/models discovery URL
 *   5. NAMED_OPENAI_STYLE_PROVIDERS — openvecta classified for live-fetch
 *   6. Seeded registry catalog — non-empty, unique ids, includes a curated LLM subset
 *   7. Schema validation — Zod validateProviders(APIKEY_PROVIDERS) passes (the import
 *      would throw at module-load time if any entry were malformed)
 *
 * Rule #18 (TDD/VPS gate) — this test exists to keep the seven wiring points
 * in sync; if any one drifts, the relevant assertion fails immediately.
 */
import test from "node:test";
import assert from "node:assert/strict";

const { APIKEY_PROVIDERS } = await import(
  "../../src/shared/constants/providers.ts"
);
const { REGISTRY: providerRegistry } = await import(
  "../../open-sse/config/providerRegistry.ts"
);
const { NAMED_OPENAI_STYLE_PROVIDERS, isNamedOpenAIStyleProvider } = await import(
  "../../src/app/api/providers/[id]/models/discovery/providerSets.ts"
);
const { PROVIDER_MODELS_CONFIG } = await import(
  "../../src/app/api/providers/[id]/models/discovery/providerModelsConfig.ts"
);

const SPEC = {
  id: "openvecta",
  alias: "openvecta",
  name: "OpenVecta",
  website: "https://openvecta.com",
  chatUrl: "https://api.openvecta.com/v1/chat/completions",
  modelsUrl: "https://api.openvecta.com/v1/models",
  expectedSeedIds: [
    "glm-4.7-flash",
    "claude-sonnet-4.6",
    "deepseek-v4-flash",
    "gpt-oss-120b",
    "gemma-4-31b",
    "kimi-k2.6",
    "llama-3.3-70b-instruct",
    "llama-4-maverick",
    "nemotron-3-super-120b",
  ],
};

test("APIKEY_PROVIDERS.openvecta is registered with the canonical identity", () => {
  const entry = APIKEY_PROVIDERS[SPEC.id];
  assert.ok(entry, `APIKEY_PROVIDERS.${SPEC.id} must be defined`);
  assert.equal(entry.id, SPEC.id);
  assert.equal(entry.alias, SPEC.alias);
  assert.equal(entry.name, SPEC.name);
  assert.equal(entry.website, SPEC.website);
  assert.equal(typeof entry.textIcon, "string");
  assert.equal(entry.hasFree, true, "OpenVecta advertises free signup credits");
  assert.equal(typeof entry.freeNote, "string");
  assert.match(entry.color, /^#[0-9A-Fa-f]{6}$/);
});

test("providerRegistry exposes the OpenAI-compatible chat completions URL", () => {
  // Note: `PROVIDER_ENDPOINTS` in src/shared/constants/config.ts is a hand-curated
  // *display-only* map (a subset of providers shown in the UI), so we don't
  // require openvecta to be listed there — the source-of-truth chat URL lives
  // on the registry entry, generated by `generateLegacyProviders()`.
  assert.equal(providerRegistry[SPEC.id].baseUrl, SPEC.chatUrl);
});

test("PROVIDER_MODELS_CONFIG exposes the live /v1/models discovery URL", () => {
  const cfg = PROVIDER_MODELS_CONFIG[SPEC.id];
  assert.ok(cfg, `PROVIDER_MODELS_CONFIG.${SPEC.id} must be defined`);
  assert.equal(cfg.url, SPEC.modelsUrl);
  assert.equal(cfg.method, "GET");
  assert.equal(cfg.authHeader, "Authorization");
  assert.equal(cfg.authPrefix, "Bearer ");
  assert.equal(typeof cfg.parseResponse, "function");
});

test("providerRegistry.openvecta uses OpenAI format with bearer apikey auth", () => {
  const entry = providerRegistry[SPEC.id];
  assert.ok(entry, `providerRegistry.${SPEC.id} must be defined`);
  assert.equal(entry.id, SPEC.id);
  assert.equal(entry.alias, SPEC.alias);
  assert.equal(entry.format, "openai");
  assert.equal(entry.executor, "default");
  assert.equal(entry.authType, "apikey");
  assert.equal(entry.authHeader, "bearer");
  assert.equal(entry.baseUrl, SPEC.chatUrl);
});

test("openvecta is classified as a named OpenAI-style provider (live-fetch path)", () => {
  assert.ok(
    NAMED_OPENAI_STYLE_PROVIDERS.has(SPEC.id),
    "openvecta must be in NAMED_OPENAI_STYLE_PROVIDERS for live /v1/models fetch",
  );
  assert.equal(isNamedOpenAIStyleProvider(SPEC.id), true);
});

test("openvecta ships a non-empty unique seed catalog covering curated LLMs", () => {
  const models = providerRegistry[SPEC.id].models;
  assert.ok(Array.isArray(models), "registry models must be an array");
  assert.ok(models.length >= 5, "seed list must be non-empty for the offline fallback");
  const ids = models.map((m: { id: string }) => m.id);
  assert.equal(new Set(ids).size, ids.length, "seed model ids must be unique");
  for (const expected of SPEC.expectedSeedIds) {
    assert.ok(ids.includes(expected), `seed list must include ${expected}`);
  }
  for (const m of models) {
    assert.equal(typeof m.id, "string");
    assert.ok(m.id.length > 0);
    assert.equal(typeof m.name, "string");
  }
});