Files
OmniRoute/tests/unit/autoCombo/suffixComposition-4517.test.ts
Diego Rodrigues de Sa e Souza 37c49781a7 fix(release): resolve inherited base-reds surfaced by v3.8.35 release CI
Cycle base-reds that only run on PR→main (not the PR→release fast-path):

- test(autoCombo): suffixComposition-4517 used node:test in a vitest-only dir
  (#4753) → vitest found no suite. Switch to the vitest API. (Vitest job)
- test(agentSkills): openapiParser fixture wrote docs/reference/openapi.yaml;
  parser reads docs/openapi.yaml since #4781 → point fixture at the new path.
  (Unit/Coverage/Node24/Node26 shard 4)
- test(integration): proxy-pipeline source-scan expected inline streaming-cost
  code that #4790/#3501 extracted to the recordStreamingCost leaf → assert the
  delegation instead. (Integration 1/2)
- fix(chatCore): derive the log trace id from crypto, not Math.random
  (CodeQL js/insecure-randomness — log-correlation id, not a secret).
- test(resilience): circuit-breaker invalid-cooldown fallback asserted t>29000,
  flaking on slow CI where ~1.6s elapsed gave t=28401 → tolerate wall-clock
  drift (t>25000). (Unit 6/8)
2026-06-23 15:54:05 -03:00

99 lines
4.4 KiB
TypeScript

/**
* Unit tests for the `auto/<category>:<tier>` suffix composition filter.
*
* See: `open-sse/services/autoCombo/suffixComposition.ts`
*
* Focus: the `:free` tier filter. Regression test for the bug where
* opencode (noAuth, free) and mimocode (noAuth, free) were NOT being
* included in the free pool because the legacy `freeProviders` list
* only contained paid-API-key providers with free tiers (kiro, qoder, ...).
*
* #4517.
*/
// NOTE: tests/unit/autoCombo/ is a vitest-only scope (the node:test runner in
// test:unit:ci does not walk this dir), so this suite uses the vitest API even
// though it asserts via node:assert. (#4753 originally landed it with node:test
// imports → vitest reported "No test suite found" and the test ran nowhere.)
import { describe, it, beforeAll, afterAll, beforeEach } from "vitest";
import assert from "node:assert/strict";
import {
buildAutoCandidateFilter,
parseAutoSuffix,
} from "../../../open-sse/services/autoCombo/suffixComposition";
describe("suffixComposition :free tier (#4517)", () => {
const ORIGINAL_ENV = { ...process.env };
beforeAll(() => {
// Snapshot env so we can restore it after each test.
});
beforeEach(() => {
// Reset env to a known state so OMNIROUTE_AUTO_FREE_FALLBACK_TO_FULL_POOL
// doesn't leak between cases.
process.env = { ...ORIGINAL_ENV };
});
afterAll(() => {
process.env = ORIGINAL_ENV;
});
it("parseAutoSuffix recognizes coding:free", () => {
assert.deepEqual(parseAutoSuffix("coding:free"), {
valid: true,
category: "coding",
tier: "free",
});
});
it("buildAutoCandidateFilter keeps noAuth free providers", () => {
// Regression: opencode and mimocode are noAuth and free, but the
// pre-fix `freeProviders` list omitted them, so the filter rejected
// their candidates even though they ARE free upstream.
const filter = buildAutoCandidateFilter("coding", "free");
assert.notEqual(filter, null);
assert.equal(filter!({ provider: "opencode", model: "big-pickle" }), true);
assert.equal(filter!({ provider: "opencode", model: "minimax-m3-free" }), true);
assert.equal(filter!({ provider: "mimocode", model: "mimo-auto" }), true);
assert.equal(filter!({ provider: "duckduckgo-web", model: "gpt-4o-mini" }), true);
});
it("buildAutoCandidateFilter keeps legacy free providers", () => {
// Don't break the existing list — kiro, qoder, groq, etc. must still pass.
const filter = buildAutoCandidateFilter("coding", "free");
assert.equal(filter!({ provider: "kiro", model: "claude-sonnet-4-5" }), true);
assert.equal(filter!({ provider: "groq", model: "llama-3.3-70b" }), true);
assert.equal(filter!({ provider: "qoder", model: "qwen3-coder-plus" }), true);
});
it("buildAutoCandidateFilter rejects paid models under :free", () => {
// The bug: opencode-go/glm-5.1 was being picked because the filter
// fell back to the full pool when no free candidate was found.
// After the fix, glm-5.1 must be rejected by the :free filter.
const filter = buildAutoCandidateFilter("coding", "free");
assert.equal(filter!({ provider: "opencode-go", model: "glm-5.1" }), false);
assert.equal(filter!({ provider: "openai", model: "gpt-4o" }), false);
assert.equal(filter!({ provider: "anthropic", model: "claude-sonnet-4-6" }), false);
assert.equal(filter!({ provider: "deepseek", model: "deepseek-chat" }), false);
});
it("buildAutoCandidateFilter returns null for category-only (no tier)", () => {
// "coding" with no tier must NOT filter by tier — pass-through.
const filter = buildAutoCandidateFilter("coding", undefined);
assert.equal(filter, null);
});
it("buildAutoCandidateFilter keeps free candidates alongside capability checks", () => {
// The category and tier checks are AND-combined. For "coding:free" the
// category check is a pass-through (no vision/reasoning filter), so
// any free model should be kept.
const filter = buildAutoCandidateFilter("coding", "free");
assert.equal(filter!({ provider: "opencode", model: "minimax-m3-free" }), true);
// The "reasoning" category also pairs with ":free" and keeps free models.
const reasoningFilter = buildAutoCandidateFilter("reasoning", "free");
// big-pickle (model_capabilities: reasoning=1) should pass the reasoning check.
assert.equal(reasoningFilter!({ provider: "opencode", model: "big-pickle" }), true);
});
});