mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 12:52:11 +03:00
* fix(routing): honor modePack weights in combo fallback ranking * fix(routing): make effective post-override modePack drive fallback weights parseAutoConfig() already resolves `weights` from a combo's own STORED modePack, but resolveAutoStrategyOrder() also supports a per-request X-OmniRoute-Mode header override (#6024/#6025) that can select a DIFFERENT mode pack than the one stored on the combo, for that single request only. selectAutoProvider() (engine.ts) already re-derives weights internally from the modePack it receives, so it correctly reacts to the override -- but scoreAutoTargets(), which ranks the fallback tail, had no such re-derivation and only ever saw the stale pre-override weights from parseAutoConfig(). Net effect: a request overriding e.g. "quality-first" to "ship-fast" would select its primary target under ship-fast weights but rank every fallback under quality-first weights -- the identical "select under one policy, rank fallbacks under another" bug this module's original fix (honoring the combo's own stored modePack) set out to close. Recompute `weights` from the effective (post-override) `modePack` right after it's resolved, so both selectAutoProvider and scoreAutoTargets consume the same weight vector. Adds a regression test proving a request-level X-OmniRoute-Mode override produces IDENTICAL fallback-ranking weights to a combo natively configured with that same modePack. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
97 lines
3.0 KiB
TypeScript
97 lines
3.0 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { parseAutoConfig } from "@omniroute/open-sse/services/combo/autoConfig.ts";
|
|
import { DEFAULT_WEIGHTS } from "@omniroute/open-sse/services/autoCombo/scoring.ts";
|
|
import { MODE_PACKS } from "@omniroute/open-sse/services/autoCombo/modePacks.ts";
|
|
|
|
// Split guard for Block J Task 2: parseAutoConfig was extracted verbatim from
|
|
// handleComboChat's inline auto-strategy config block. These assertions pin the
|
|
// pure derivation so the extraction stays behavior-identical.
|
|
|
|
const target = (provider: string, modelStr: string) =>
|
|
({ provider, modelStr, executionKey: `${provider}>${modelStr}` }) as never;
|
|
|
|
test("defaults: rules strategy, provider-derived pool, default weights", () => {
|
|
const cfg = parseAutoConfig({ name: "c", config: {} } as never, [
|
|
target("openai", "gpt-4o"),
|
|
target("anthropic", "claude-3"),
|
|
target("openai", "gpt-4o-mini"),
|
|
]);
|
|
assert.equal(cfg.routingStrategy, "rules");
|
|
assert.deepEqual(cfg.candidatePool, ["openai", "anthropic"]);
|
|
assert.equal(cfg.weights, DEFAULT_WEIGHTS);
|
|
assert.equal(cfg.explorationRate, 0.05);
|
|
assert.equal(cfg.budgetCap, undefined);
|
|
assert.equal(cfg.modePack, undefined);
|
|
});
|
|
|
|
test("routerStrategy takes precedence over routingStrategy/strategyName", () => {
|
|
const cfg = parseAutoConfig(
|
|
{
|
|
name: "c",
|
|
autoConfig: {
|
|
routerStrategy: "lkgp",
|
|
routingStrategy: "cost",
|
|
strategyName: "p2c",
|
|
},
|
|
} as never,
|
|
[]
|
|
);
|
|
assert.equal(cfg.routingStrategy, "lkgp");
|
|
});
|
|
|
|
test("explicit candidatePool, weights, exploration and budget are honored", () => {
|
|
const customWeights = { latency: 1 } as never;
|
|
const cfg = parseAutoConfig(
|
|
{
|
|
name: "c",
|
|
autoConfig: {
|
|
candidatePool: ["glm", "openai"],
|
|
weights: customWeights,
|
|
explorationRate: 0.3,
|
|
budgetCap: 5,
|
|
modePack: "coding",
|
|
},
|
|
} as never,
|
|
[target("ignored", "x")]
|
|
);
|
|
assert.deepEqual(cfg.candidatePool, ["glm", "openai"]);
|
|
assert.equal(cfg.weights, customWeights);
|
|
assert.equal(cfg.explorationRate, 0.3);
|
|
assert.equal(cfg.budgetCap, 5);
|
|
assert.equal(cfg.modePack, "coding");
|
|
});
|
|
|
|
test("valid modePack overrides configured weights for fallback scoring", () => {
|
|
const cfg = parseAutoConfig(
|
|
{
|
|
name: "c",
|
|
autoConfig: {
|
|
weights: { ...DEFAULT_WEIGHTS, latencyInv: 0 },
|
|
modePack: "ship-fast",
|
|
},
|
|
} as never,
|
|
[]
|
|
);
|
|
|
|
assert.equal(cfg.modePack, "ship-fast");
|
|
assert.equal(cfg.weights, MODE_PACKS["ship-fast"]);
|
|
});
|
|
|
|
test("config.auto is preferred over top-level config", () => {
|
|
const cfg = parseAutoConfig(
|
|
{ name: "c", config: { auto: { routerStrategy: "cost" }, routerStrategy: "rules" } } as never,
|
|
[]
|
|
);
|
|
assert.equal(cfg.routingStrategy, "cost");
|
|
});
|
|
|
|
test("non-finite explorationRate falls back to 0.05", () => {
|
|
const cfg = parseAutoConfig(
|
|
{ name: "c", autoConfig: { explorationRate: "not-a-number" } } as never,
|
|
[]
|
|
);
|
|
assert.equal(cfg.explorationRate, 0.05);
|
|
});
|