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.0 KB
Raw Blame
/**
 * #7622 — no-auth provider "Excluded Models" field is stored + enforced at
 * dispatch time (src/sse/services/auth.ts) but IGNORED by the auto-combo/fusion
 * candidate pool builder (`getNoAuthCandidates()` in
 * open-sse/services/autoCombo/virtualFactory.ts). An excluded no-auth model must
 * never be advertised/selected in `auto/*` combos in the first place — it should
 * only fail over after being picked instead.
 */
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-7622-noauth-exclude-"));
const ORIGINAL_DATA_DIR = process.env.DATA_DIR;

process.env.DATA_DIR = TEST_DATA_DIR;

const core = await import("../../src/lib/db/core.ts");
const providersDb = await import("../../src/lib/db/providers.ts");
const settingsDb = await import("../../src/lib/db/settings.ts");
const virtualFactory = await import("../../open-sse/services/autoCombo/virtualFactory.ts");

async function resetStorage() {
  core.resetDbInstance();
  fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
  fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
}

test.beforeEach(async () => {
  await resetStorage();
  // #15059: excludeTosAvoid defaults to true and every duckduckgo-web model is tos:avoid;
  // these tests exercise the no-auth pool builder, so opt out of the ToS filter.
  await settingsDb.updateSettings({ excludeTosAvoid: false });
});

test.after(async () => {
  await resetStorage();
  fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });

  if (ORIGINAL_DATA_DIR === undefined) {
    delete process.env.DATA_DIR;
  } else {
    process.env.DATA_DIR = ORIGINAL_DATA_DIR;
  }
});

test("#7622: a no-auth model excluded via providerSpecificData.excludedModels is ABSENT from the auto-combo candidate pool", async () => {
  const conn = await providersDb.createProviderConnection({
    provider: "duckduckgo-web",
    authType: "no-auth",
    name: "DuckDuckGo Account 1",
    providerSpecificData: { excludedModels: "gpt-5.4-mini" },
  });
  assert.ok(conn.id, "connection must be created");

  const combo = await virtualFactory.createVirtualAutoCombo(undefined);

  const modelStrings = combo.models.map((m: { model: string }) => m.model);
  assert.ok(
    !modelStrings.some((model: string) => model === "ddgw/gpt-5.4-mini"),
    "BUG #7622: the excluded model 'gpt-5.4-mini' must not appear in the auto-combo " +
      `candidate pool, but it did. Pool: ${JSON.stringify(modelStrings)}`
  );
});

test("#7622: a non-excluded no-auth model from the same connection remains in the auto-combo candidate pool", async () => {
  await providersDb.createProviderConnection({
    provider: "duckduckgo-web",
    authType: "no-auth",
    name: "DuckDuckGo Account 1",
    providerSpecificData: { excludedModels: "gpt-5.4-mini" },
  });

  const combo = await virtualFactory.createVirtualAutoCombo(undefined);

  const modelStrings = combo.models.map((m: { model: string }) => m.model);
  assert.ok(
    modelStrings.some((model: string) => model === "ddgw/gpt-5.6-luna"),
    `a non-excluded model ("gpt-5.6-luna") must remain in the pool. Pool: ${JSON.stringify(modelStrings)}`
  );
});

test("#7622 regression guard: with no excludedModels set, all duckduckgo-web models remain in the pool (baseline unchanged)", async () => {
  await providersDb.createProviderConnection({
    provider: "duckduckgo-web",
    authType: "no-auth",
    name: "DuckDuckGo Account 1",
    providerSpecificData: { fingerprints: ["11111111111111111111111111111111"] },
  });

  const combo = await virtualFactory.createVirtualAutoCombo(undefined);

  const modelStrings = combo.models.map((m: { model: string }) => m.model);
  assert.ok(
    modelStrings.some((model: string) => model === "ddgw/gpt-5.4-mini"),
    `baseline: no exclusion set, gpt-5.4-mini must still be present. Pool: ${JSON.stringify(modelStrings)}`
  );
});