mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 13:52:09 +03:00
* refactor(sse): extract applyStrategyOrdering leaf from handleComboChat
Block J Task 3: the ~177-line else-if chain covering every non-auto combo
strategy (lkgp / strict-random / random / fill-first / p2c / least-used /
cost-optimized / reset-aware / reset-window / context-optimized / headroom /
quota-share) is extracted into
open-sse/services/combo/applyStrategyOrdering.ts::applyStrategyOrdering.
Each branch only reorders orderedTargets (no early returns, no other mutable
state), so the extraction is a clean verbatim move returning the reordered list;
the host replaces the chain with `else { orderedTargets = await
applyStrategyOrdering(strategy, orderedTargets, deps); }`. Semantic diff vs the
original chain = only the leading `if` (was `} else if`), the trailing return
and the deeper getLKGP import path — no logic line changed. None of the 13 strategy
helpers live in combo.ts, so no DI/cycle (unlike the auto branch).
combo.ts 3065->2883 LOC (3309->2883 across Task 2+3). typecheck:core + check:cycles
clean; 9 dead host imports removed (targetSorters block emptied). 47/47 consumer
tests (router-strategies / combo-strategy-fallbacks / rr-session-stickiness /
tag-routing) cover the DB-backed branches end-to-end; new
tests/unit/combo-apply-strategy-ordering-split.test.ts pins random / fill-first /
unknown exits.
* test(sse): point #2359 modelStr-guard scans at applyStrategyOrdering leaf
The LKGP fallback + non-auto strategy ordering (the two target.modelStr string-
method call sites) were extracted verbatim from combo.ts into the
applyStrategyOrdering leaf (Block J Task 3). The #2359 source scans now read the
leaf that owns those usages; the guard and the no-unguarded-usage assertions are
unchanged in intent.
* chore(ci): scan combo strategy leaves in check:known-symbols
Block J decomposed the combo dispatch: the `strategy === "..."` branches for
the 12 non-auto strategies moved to combo/applyStrategyOrdering.ts and the auto
branch to combo/resolveAutoStrategy.ts. The known-symbols gate previously scanned
only combo.ts, so it would report those strategies as canonicalNotHandled. Scan
all three dispatch files. Verified: 18/18 canonical strategies via dispatch.
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
import { test, after } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { applyStrategyOrdering } from "@omniroute/open-sse/services/combo/applyStrategyOrdering.ts";
|
|
import { resetDbInstance } from "@/lib/db/core.ts";
|
|
|
|
// Split guard for Block J Task 3: the non-`auto` strategy-ordering chain
|
|
// (lkgp / strict-random / random / fill-first / p2c / ... / quota-share) was
|
|
// extracted verbatim into applyStrategyOrdering. These tests pin the exits that
|
|
// need no DB/deck state (random / fill-first / unknown); the DB-backed branches
|
|
// (lkgp, reset-*, quota-share) are covered end-to-end by the 47 consumer tests
|
|
// (router-strategies / combo-strategy-fallbacks / rr-session-stickiness).
|
|
|
|
after(() => {
|
|
// some branches (lkgp/quota-share) may touch the DB singleton; release handles.
|
|
resetDbInstance();
|
|
});
|
|
|
|
const noopLog = { info() {}, warn() {}, error() {}, debug() {} } as never;
|
|
|
|
const target = (provider: string, modelStr: string): never =>
|
|
({
|
|
kind: "model",
|
|
stepId: "s1",
|
|
executionKey: `${provider}>${modelStr}`,
|
|
modelStr,
|
|
provider,
|
|
providerId: null,
|
|
connectionId: null,
|
|
weight: 1,
|
|
label: null,
|
|
}) as never;
|
|
|
|
const deps = () =>
|
|
({
|
|
combo: { id: "c1", name: "c1", config: {} },
|
|
config: {},
|
|
body: { messages: [] },
|
|
log: noopLog,
|
|
apiKeyAllowedConnections: null,
|
|
}) as never;
|
|
|
|
const keys = (arr: Array<{ executionKey: string }>) => arr.map((t) => t.executionKey).sort();
|
|
|
|
test("exports applyStrategyOrdering", () => {
|
|
assert.equal(typeof applyStrategyOrdering, "function");
|
|
});
|
|
|
|
test("unknown strategy -> input order unchanged (same reference contents)", async () => {
|
|
const input = [target("openai", "gpt-4o"), target("anthropic", "claude-3")];
|
|
const out = await applyStrategyOrdering("no-such-strategy", input, deps());
|
|
assert.deepEqual(
|
|
out.map((t: { executionKey: string }) => t.executionKey),
|
|
["openai>gpt-4o", "anthropic>claude-3"]
|
|
);
|
|
});
|
|
|
|
test("fill-first -> preserves priority order", async () => {
|
|
const input = [target("a", "m1"), target("b", "m2"), target("c", "m3")];
|
|
const out = await applyStrategyOrdering("fill-first", input, deps());
|
|
assert.deepEqual(
|
|
out.map((t: { executionKey: string }) => t.executionKey),
|
|
["a>m1", "b>m2", "c>m3"]
|
|
);
|
|
});
|
|
|
|
test("random -> same multiset of targets (a permutation)", async () => {
|
|
const input = [target("a", "m1"), target("b", "m2"), target("c", "m3")];
|
|
const out = await applyStrategyOrdering("random", input, deps());
|
|
assert.equal(out.length, 3);
|
|
assert.deepEqual(keys(out), keys(input));
|
|
});
|