Files
OmniRoute/tests/unit/auto-disable-banned.test.ts
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
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.
2026-08-23 11:45:01 -03:00

165 lines
3.7 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { updateAutoDisableAccountsSchema } from "../../src/shared/validation/schemas/settings.ts";
import {
isSubscriptionStyleConnection,
normalizeAutoDisableBannedScope,
shouldAutoDisableBannedConnection,
} from "../../src/shared/utils/autoDisableBanned.ts";
test("normalizeAutoDisableBannedScope defaults unknown values to all", () => {
assert.equal(normalizeAutoDisableBannedScope(undefined), "all");
assert.equal(normalizeAutoDisableBannedScope("all"), "all");
assert.equal(normalizeAutoDisableBannedScope("subscription"), "subscription");
assert.equal(normalizeAutoDisableBannedScope("nope"), "all");
});
test("shouldAutoDisableBannedConnection is off when the feature is disabled", () => {
assert.equal(
shouldAutoDisableBannedConnection({
enabled: false,
scope: "all",
authType: "oauth",
}),
false
);
});
test("scope=all deactivates API keys and OAuth connections", () => {
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "all",
authType: "apikey",
}),
true
);
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
authType: "oauth",
}),
true
);
});
test("scope=subscription skips prepaid API keys", () => {
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "subscription",
authType: "apikey",
providerId: "jina-ai",
}),
false
);
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "subscription",
authType: "api_key",
}),
false
);
});
test("scope=subscription still deactivates OAuth and cookie accounts", () => {
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "subscription",
authType: "oauth",
}),
true
);
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "subscription",
authType: "cookie",
}),
true
);
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "subscription",
authType: "access_token",
}),
true
);
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "subscription",
authType: "session",
}),
true
);
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "subscription",
authType: "web",
}),
true
);
});
test("scope=subscription treats web-cookie providers as subscriptions even when authType is apikey", () => {
assert.equal(
isSubscriptionStyleConnection({
authType: "apikey",
providerId: "grok-web",
webCookieProviderIds: { "grok-web": {} },
}),
true
);
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "subscription",
authType: "apikey",
providerId: "grok-web",
webCookieProviderIds: { "grok-web": {} },
}),
true
);
});
test("auto-disable settings schema accepts scope and rejects unknown values", () => {
assert.equal(
updateAutoDisableAccountsSchema.safeParse({
enabled: true,
threshold: 2,
scope: "subscription",
}).success,
true
);
assert.equal(
updateAutoDisableAccountsSchema.safeParse({
enabled: true,
scope: "all",
}).success,
true
);
assert.equal(
updateAutoDisableAccountsSchema.safeParse({
enabled: true,
scope: "provider",
}).success,
false
);
});
test("unknown auth types stay conservative and still auto-disable", () => {
assert.equal(
shouldAutoDisableBannedConnection({
enabled: true,
scope: "subscription",
authType: "mystery",
}),
true
);
});