Files
OmniRoute/tests/unit/virtual-auto-combo.test.ts
Diego Rodrigues de Sa e Souza 929caeb910 Release v3.8.15 (#3373)
* chore(release): open v3.8.15 development cycle

Version bump 3.8.14 -> 3.8.15 (root + electron + open-sse + openapi + lockfiles)
and seed the v3.8.15 changelog placeholder (root + 41 i18n mirrors).

* fix(catalog): add getTokenLimit fallback for combo targets with unknown context (#3369)

Integrated into release/v3.8.15. Fixes applied on the contributor's branch: removed duplicate JSDoc opening in accountFallback.ts and dropped a test asserting unreachable catalog behavior (models with no registry/spec/synced source are filtered before the getTokenLimit fallback at catalog.ts:499).

* fix(combo): add 429 to PROVIDER_FAILURE_ERROR_CODES to prevent infinite retry loop (#3366)

Integrated into release/v3.8.15. Comment block reconciled on the contributor's branch to remove the contradictory 'intentionally excluded' text that remained from the original code.

* fix(auto-combo): include no-auth providers declaratively (#3365)

Integrated into release/v3.8.15. Cleanup applied on contributor's branch: removed duplicate migration 095 (already exists from PR #3338), reverted CHANGELOG.md and i18n changelogs to release versions (release process owns these), dropped package version-bump noise from stale fork base. Core feature — declarative no-auth via serviceKinds metadata, declarative VEO as 'video' provider, anonymousFallback flag for opencode-zen/opencode-go — integrated cleanly.

* fix(migrations): restore 095_provider_node_custom_headers migration

The squash merge of PR #3365 accidentally deleted this migration because
the cleanup commit on the contributor's branch included 'git rm' for the
file (which was a duplicate on their branch). The migration was merged
in v3.8.14 via PR #3338 and must be present in the release branch.

Restoring from git history.

* fix: update Command Code base URL from /alpha/ to /provider/v1/ (#3372)

Integrated into release/v3.8.15.

* feat(error-rules): provider-specific error classification with scope (#3370)

Integrated into release/v3.8.15. PR has genuine value beyond #3369: (1) getProviderErrorRuleMatch now accepts native Headers objects from fetch(); (2) checkFallbackError also uses the provider rule registry — the real end-to-end wiring in the combo fallback path; (3) S4 end-to-end test proving the wiring fires. Merge commit on contributor branch resolved the add/add conflict by taking the #3370 version throughout.

* fix(auto-combo): validate web-session credentials (#3371)

Integrated into release/v3.8.15. Core feature: provider-aware web-session credential validation — hasUsableWebSessionCredential() replaces the broad Object.keys check in virtualFactory.ts, ensuring only sessions with the required storageKeys are included in auto-combo. Cleanup: removed duplicate 095 migration, reverted CHANGELOG/i18n, dropped package bump noise.

* fix(migrations): restore 095_provider_node_custom_headers (deleted again by #3371 squash)

Same issue as after #3365: git rm in the contributor cleanup commit
was included in the squash, deleting this migration from release.
Permanent fix needed: use 'git checkout origin/release -- <file>'
instead of 'git rm' when cleaning up duplicate files in contributor branches.

* fix(kiro): probe Windows %APPDATA%\kiro\storage.db in auto-import (#3363) (#3375)

Integrated into release/v3.8.15. Test fix applied: kiro-windows-auto-import-3363.test.ts now sets DATA_DIR to a fresh temp dir before importing app modules, ensuring isAuthRequired() sees an empty settings DB (no password → auth not required). This fixed test 4 (synthetic SQLite) which was getting 401 due to settings DB state leakage.

* chore(release): finalize v3.8.15 changelog — 2026-06-07

---------

Co-authored-by: Hernan Javier Ardila Sanchez <hjasgr@gmail.com>
Co-authored-by: Paijo <14921983+oyi77@users.noreply.github.com>
Co-authored-by: Muhammad Nabil Muyassar Rahman <65392758+TapZe@users.noreply.github.com>
Co-authored-by: kiro-agent[bot] <245459735+kiro-agent[bot]@users.noreply.github.com>
2026-06-07 12:16:33 -03:00

189 lines
7.1 KiB
TypeScript

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-virtual-auto-"));
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 virtualFactory = await import("../../open-sse/services/autoCombo/virtualFactory.ts");
type VirtualComboResult = Awaited<ReturnType<typeof virtualFactory.createVirtualAutoCombo>>;
async function resetStorage() {
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
}
test.beforeEach(async () => {
await resetStorage();
});
test.after(async () => {
await resetStorage();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
if (ORIGINAL_DATA_DIR === undefined) {
delete process.env.DATA_DIR;
} else {
process.env.DATA_DIR = ORIGINAL_DATA_DIR;
}
});
test("createVirtualAutoCombo returns an executable auto combo for API-key connections", async () => {
await providersDb.createProviderConnection({
provider: "openai",
authType: "apikey",
name: "OpenAI",
apiKey: "sk-test-openai",
defaultModel: "gpt-4o-mini",
});
const combo: VirtualComboResult = await virtualFactory.createVirtualAutoCombo("fast");
assert.equal(combo.strategy, "auto");
assert.ok(combo.models.length >= 1);
assert.equal(combo.models[0].kind, "model");
assert.equal(combo.models[0].model, "openai/gpt-4o-mini");
assert.equal(combo.models[0].providerId, "openai");
assert.equal(combo.autoConfig.routerStrategy, "lkgp");
assert.ok(combo.autoConfig.candidatePool.includes("openai"));
});
test("createVirtualAutoCombo includes OAuth accessToken connections with real expiry fields", async () => {
await providersDb.createProviderConnection({
provider: "anthropic",
authType: "oauth",
email: "oauth@example.com",
accessToken: "oauth-access-token",
tokenExpiresAt: new Date(Date.now() + 60_000).toISOString(),
defaultModel: "claude-sonnet-4-5",
});
const combo: VirtualComboResult = await virtualFactory.createVirtualAutoCombo("coding");
assert.equal(combo.strategy, "auto");
assert.ok(combo.models.length >= 1);
assert.equal(combo.models[0].model, "anthropic/claude-sonnet-4-5");
assert.ok(combo.autoConfig.candidatePool.includes("anthropic"));
});
test("createVirtualAutoCombo includes configured web-session providers without apiKey fields", async () => {
await providersDb.createProviderConnection({
provider: "qwen-web",
authType: "apikey",
name: "Qwen Web Session",
providerSpecificData: { token: "qwen-web-session-token" },
defaultModel: "qwen3-coder-plus",
});
const combo: VirtualComboResult = await virtualFactory.createVirtualAutoCombo("coding");
const qwenWeb = combo.models.find((model) => model.providerId === "qwen-web");
assert.ok(qwenWeb, "configured web-session providers should be auto-combo candidates");
assert.equal(qwenWeb.model, "qwen-web/qwen3-coder-plus");
assert.ok(combo.autoConfig.candidatePool.includes("qwen-web"));
});
test("createVirtualAutoCombo excludes web-session providers with empty required token data", async () => {
await providersDb.createProviderConnection({
provider: "qwen-web",
authType: "apikey",
name: "Qwen Web Empty Session",
providerSpecificData: { token: " " },
defaultModel: "qwen3-coder-plus",
});
const combo: VirtualComboResult = await virtualFactory.createVirtualAutoCombo("coding");
assert.equal(
combo.models.some((model) => model.providerId === "qwen-web"),
false,
"web-session providers with empty required token data must not be auto-combo candidates"
);
assert.equal(combo.autoConfig.candidatePool.includes("qwen-web"), false);
});
test("createVirtualAutoCombo excludes web-session providers with irrelevant providerSpecificData", async () => {
await providersDb.createProviderConnection({
provider: "chatgpt-web",
authType: "apikey",
name: "ChatGPT Web Invalid Session",
providerSpecificData: { unrelated: "value" },
defaultModel: "gpt-4o",
});
const combo: VirtualComboResult = await virtualFactory.createVirtualAutoCombo("coding");
assert.equal(
combo.models.some((model) => model.providerId === "chatgpt-web"),
false,
"web-session providers with irrelevant providerSpecificData must not be auto-combo candidates"
);
assert.equal(combo.autoConfig.candidatePool.includes("chatgpt-web"), false);
});
test("createVirtualAutoCombo includes cookie web-session providers with required cookie data", async () => {
await providersDb.createProviderConnection({
provider: "chatgpt-web",
authType: "apikey",
name: "ChatGPT Web Session",
providerSpecificData: { cookie: "__Secure-next-auth.session-token=chatgpt-session" },
defaultModel: "gpt-4o",
});
const combo: VirtualComboResult = await virtualFactory.createVirtualAutoCombo("coding");
const chatgptWeb = combo.models.find((model) => model.providerId === "chatgpt-web");
assert.ok(chatgptWeb, "cookie web-session providers with required cookie data should be candidates");
assert.equal(chatgptWeb.model, "chatgpt-web/gpt-4o");
assert.ok(combo.autoConfig.candidatePool.includes("chatgpt-web"));
});
test("createVirtualAutoCombo includes no-auth OpenCode Free without provider_connections rows", async () => {
const combo: VirtualComboResult = await virtualFactory.createVirtualAutoCombo("fast");
const opencode = combo.models.find((model) => model.providerId === "opencode");
assert.ok(
opencode,
"OpenCode Free should appear in auto/* even when it has no provider_connections row"
);
assert.equal(opencode.connectionId, "noauth");
assert.equal(opencode.model, "oc/big-pickle");
assert.ok(combo.autoConfig.candidatePool.includes("opencode"));
});
test("createVirtualAutoCombo includes all chat-capable no-auth providers without connections", async () => {
const combo: VirtualComboResult = await virtualFactory.createVirtualAutoCombo("fast");
const byProvider = new Map(combo.models.map((model) => [model.providerId, model]));
assert.equal(byProvider.get("duckduckgo-web")?.connectionId, "noauth");
assert.equal(byProvider.get("duckduckgo-web")?.model, "ddgw/gpt-4o-mini");
assert.equal(byProvider.get("theoldllm")?.connectionId, "noauth");
assert.equal(byProvider.get("theoldllm")?.model, "tllm/GPT_5_4");
assert.equal(byProvider.get("chipotle")?.connectionId, "noauth");
assert.equal(byProvider.get("chipotle")?.model, "pepper/pepper-1");
assert.equal(
byProvider.has("veoaifree-web"),
false,
"video-only no-auth providers must not be inserted into chat auto-combos"
);
});
test("createVirtualAutoCombo keeps credential-required providers out when disconnected", async () => {
const combo: VirtualComboResult = await virtualFactory.createVirtualAutoCombo("fast");
assert.equal(
combo.models.some((model) => model.providerId === "openai"),
false,
"OpenAI should still require a real active connection"
);
});