Files
OmniRoute/tests/unit/free-models-isfree.test.ts
Diego Rodrigues de Sa e Souza 3b752f9d4c chore(quality): type the 55 no-explicit-any sites frozen under #11924 (#11975)
Production (open-sse/utils/socksConnectorWithFamily.ts, 4 sites): every cast was
redundant — undici's buildConnector.BuildOptions already has `timeout?: number | null`,
socks' SocksClientOptions has `timeout?: number`, and Agent.Options' `connect` /
`connectTimeout` narrow to the connector's parameter types on their own. Behaviour
unchanged; check:open-sse-typecheck stays at the frozen 5.

Tests (51 sites): the socks-timeout mocks now carry the real types — the patched
SocksClient.createConnection is typed as the static it replaces, the fake
buildConnector returns buildConnector.connector, the proxy is a SocksProxy, the
dynamic import is typed as the module it loads; the e2e suite passes a SocksProxy and
Agent.Options and no longer casts undici's fetch init (its RequestInit already has
`dispatcher`); the isFree suites narrow getCustomModels()' JSON to a declared row
shape, feed deliberately-wrong values through `unknown`, and stop casting for
zod's safeParse, which takes unknown.

The six files' suppression entries are removed: 1238 → 1232 files, 5487 → 5432
suppressed. ESLint without the suppressions file reports 0 problems on all six;
with it, no stale entry is left. The five suites pass (4, 2, 5, 4, 4).
2026-08-29 03:06:50 -03:00

31 lines
1.4 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { isFreeModel, providerHasFreeModels } from "../../src/shared/utils/freeModels.ts";
describe("isFreeModel isFree opt-in", () => {
it("isFree:true → free even without :free/pricing/catalog", () => {
assert.equal(isFreeModel("any", { id: "x", isFree: true }), true);
assert.equal(isFreeModel("openai", { id: "gpt-4o", isFree: true }), true);
assert.equal(isFreeModel("local", { id: "my-model", isFree: true }), true);
});
it("isFree:false/null/undefined/1/'true' → not free (strict ===true)", () => {
const junk: unknown[] = [false, null, undefined, 1, "true"];
for (const v of junk) {
assert.equal(
isFreeModel("any", { id: "x", isFree: v as boolean }),
false,
`isFree=${String(v)} should be false`
);
}
});
it("providerHasFreeModels unchanged by custom isFree", () => {
assert.equal(providerHasFreeModels("local"), false);
assert.equal(providerHasFreeModels("openai"), providerHasFreeModels("openai"));
});
it(":free and pricing 0 still work when isFree absent", () => {
assert.equal(isFreeModel("any", { id: "foo:free" }), true);
assert.equal(isFreeModel("any", { id: "foo", pricing: { prompt: 0, completion: 0 } }), true);
assert.equal(isFreeModel("any", { id: "foo", pricing: { prompt: 0, completion: 1 } }), false);
});
});