mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-15 11:22:15 +03:00
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host. Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean. Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
77 lines
3.4 KiB
TypeScript
77 lines
3.4 KiB
TypeScript
/**
|
|
* Issue #3061 — No-auth providers (opencode / opencode-zen) infinite
|
|
* account-fallback loop on a persistent upstream error → unbounded DB growth /
|
|
* disk exhaustion.
|
|
*
|
|
* For a no-auth provider, getProviderCredentials early-returns synthetic
|
|
* credentials with connectionId "noauth" BEFORE honoring the exclusion set
|
|
* (src/sse/services/auth.ts: the NOAUTH_PROVIDERS block and the opencode-zen
|
|
* keyless fallback). So when the chat fallback loop marks the failed "noauth"
|
|
* connection and excludes it, the selector hands "noauth" right back → it loops
|
|
* forever, writing key-health + request logs every iteration until the disk
|
|
* fills (see @paraflu's "failure #320" trace in discussion #3038).
|
|
*
|
|
* Loop-breaking invariant under test: once "noauth" is in excludeConnectionIds,
|
|
* the selector MUST return null (no remaining candidate) so the chat handler
|
|
* stops after a single attempt instead of re-selecting the same synthetic
|
|
* connection. The happy-path (nothing excluded → synthetic noauth) must stay
|
|
* intact so keyless access still works.
|
|
*/
|
|
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-noauth-loop-3061-"));
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../src/lib/db/core.ts");
|
|
const { getProviderCredentials } = await import("../../src/sse/services/auth.ts");
|
|
|
|
test.after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
});
|
|
|
|
// ── Happy path preserved: first selection (nothing excluded) still works ──
|
|
|
|
test("#3061 opencode no-auth: first selection returns synthetic noauth (happy path preserved)", async () => {
|
|
const creds = await getProviderCredentials("opencode", null, null, "minimax-m2.5-free");
|
|
assert.ok(creds, "opencode must resolve to synthetic no-auth credentials on first selection");
|
|
assert.equal((creds as { connectionId?: string }).connectionId, "noauth");
|
|
assert.equal((creds as { apiKey?: unknown }).apiKey, null);
|
|
});
|
|
|
|
test("#3061 opencode-zen no-auth: first selection returns synthetic noauth (happy path preserved)", async () => {
|
|
const creds = await getProviderCredentials("opencode-zen");
|
|
assert.ok(creds, "opencode-zen must resolve to synthetic no-auth credentials on first selection");
|
|
assert.equal((creds as { connectionId?: string }).connectionId, "noauth");
|
|
});
|
|
|
|
// ── The fix: once "noauth" is excluded, selection MUST stop (return null) ──
|
|
|
|
test("#3061 opencode no-auth: excluding 'noauth' returns null (breaks the fallback loop)", async () => {
|
|
const creds = await getProviderCredentials("opencode", null, null, "minimax-m2.5-free", {
|
|
excludeConnectionIds: ["noauth"],
|
|
});
|
|
assert.equal(
|
|
creds,
|
|
null,
|
|
"after the synthetic noauth connection failed and was excluded, the selector must return " +
|
|
"null instead of handing back 'noauth' (which would loop forever and fill the disk)"
|
|
);
|
|
});
|
|
|
|
test("#3061 opencode-zen no-auth: excluding 'noauth' returns null (breaks the fallback loop)", async () => {
|
|
const creds = await getProviderCredentials("opencode-zen", null, null, null, {
|
|
excludeConnectionIds: ["noauth"],
|
|
});
|
|
assert.equal(
|
|
creds,
|
|
null,
|
|
"excluded synthetic noauth must not be re-selected for the opencode-zen keyless path"
|
|
);
|
|
});
|
|
|