mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-19 05:32:19 +03:00
* feat(db): cc discovery alias gate storage + EXPOSE_CC_DISCOVERY_ALIASES flag
Adds the gate for claude/<provider>/<model> discovery-alias mirror ids on
the /v1/models catalog: a new runtime feature flag (env forces on and wins
over the dashboard DB override), per-provider and per-model "on"/"off"/null
overrides stored in key_value under the ccDiscoveryAliases namespace, and a
pure precedence resolver (model > provider > global). Catalog wiring is a
separate follow-up task; this only lands the gate + storage.
* feat(sse): synthesize claude/ discovery aliases for the model catalog
* feat(api): advertise cc discovery aliases on /v1/models behind the 3-level gate
* feat(sse): resolve claude/ discovery aliases on the request path
* fix(sse): import getComboByName from db/combos, not the localDb barrel
* fix(sse): cover custom-node prefixes and the Codex WS bridge in cc discovery alias resolution
* feat(dashboard): cc discovery alias toggles + flag-screen env warning
Adds the operator-facing UI/API layer for the Claude Code discovery-alias
gate (claude/<provider>/<model> mirror ids on /v1/models): REST endpoint
for provider/model overrides, a provider-detail card with 3-state
(inherit/on/off) toggles, an info button on the Claude Code tool card
linking to Feature Flags, and an env-source warning on the
EXPOSE_CC_DISCOVERY_ALIASES flag card when it's forced on via env.
* feat(api): cc discovery usage metrics
* fix(api): record cc alias metric in the production wrapper + atomic counter upsert
* docs: document cc discovery aliases (Claude Code guide + feature flag catalog)
* fix(sse): don't mirror built-in auto/* combos as discovery aliases (advertised-but-unroutable)
* i18n(vi): translate the discovery-alias strings instead of shipping placeholders
vi is the one locale with a strict "no internal missing markers" test, so the 17
__MISSING__ entries this branch added (the provider ccAlias panel, the info
button, the feature-flag description and the env warning) would have turned that
test red the moment the base itself was repaired. Translated, keeping every ICU
placeholder ({modelId}, {error}) and the literal claude/<provider>/<model> id
shape intact.
* chore(quality): raise the frozen caps this feature legitimately grows
catalog.ts 1615 -> 1639: the alias synthesis is wired into the catalog builder,
which is where the per-key-filtered list is assembled — the only place the mirror
entries can be appended after model hiding has been applied.
localDb.ts 808 -> 810: two re-export lines for the new ccDiscoveryAliases db
module, which is exactly what the "Adding a New DB Module" recipe prescribes.
* refactor(dashboard,api): keep the complexity ratchets flat
The feature added four cyclomatic violations and one cognitive one, which the
ratchets reject — the baseline only moves when a metric improves. Split the new
code instead:
- appendCcDiscoveryAliases: the four skip-guards become isMirrorableId().
- resolveCcDiscoveryAliasStripWith: alias parsing and gate resolution become
parseCcAliasTarget() and resolveGateFor(), replacing a chain of ternaries that
each re-tested isComboAlias.
- FeatureFlagCard: the env-precedence warning becomes its own component instead
of a conditional branch inside an already-large render.
- ProviderCcAliasSection: the loader moves to useCcAliasData(), and the override
list and add-row become ModelOverrideList / AddOverrideRow, bringing both
oversized functions back under the 80-line rule.
Behavior unchanged — the 74 discovery-alias tests pass untouched. Both ratchets
now sit exactly at baseline (2188 / 971).
99 lines
4.2 KiB
TypeScript
99 lines
4.2 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { resolveCcDiscoveryAliasStripWith } from "../../src/lib/ccDiscoveryAliasResolve.ts";
|
|
|
|
/**
|
|
* These tests exercise the async request-path resolver by injecting all of its
|
|
* DB/registry lookups, so no SQLite handle is opened (pure logic, no resetDb).
|
|
* The branch matrix of the underlying pure `stripCcDiscoveryAlias` already has
|
|
* its own suite (cc-discovery-alias-strip.test.ts); here we focus on the wiring
|
|
* the resolver adds on top: custom-node prefixes (Gap 1) and the gate snapshot.
|
|
*/
|
|
|
|
const baseDeps = {
|
|
claudeModelIds: new Set<string>(["claude-fable-5", "claude-opus-5"]),
|
|
isRegistryProvider: (prefix: string) => prefix === "kimi" || prefix === "openai",
|
|
customProviderPrefixes: new Set<string>(),
|
|
getCombo: async (_name: string) => null as { models?: unknown[] } | null,
|
|
gateGlobal: () => true,
|
|
gateProvider: (_providerId: string) => null as "on" | "off" | null,
|
|
gateModel: (_providerId: string, _modelId: string) => null as "on" | "off" | null,
|
|
};
|
|
|
|
test("non-'claude/' id is a no-op without any DB lookup", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("kimi/kimi-k2.6", baseDeps);
|
|
assert.deepEqual(result, { model: "kimi/kimi-k2.6", stripped: false });
|
|
});
|
|
|
|
test("legitimate claude provider model is left intact", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("claude/claude-fable-5", baseDeps);
|
|
assert.deepEqual(result, { model: "claude/claude-fable-5", stripped: false });
|
|
});
|
|
|
|
test("registry provider prefix strips when the gate is globally on", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("claude/kimi/kimi-k2.6", baseDeps);
|
|
assert.deepEqual(result, { model: "kimi/kimi-k2.6", stripped: true });
|
|
});
|
|
|
|
test("Gap 1: a custom DB-node provider prefix is recognized and strips", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("claude/mycustom/model-x", {
|
|
...baseDeps,
|
|
isRegistryProvider: () => false,
|
|
customProviderPrefixes: new Set<string>(["mycustom"]),
|
|
});
|
|
assert.deepEqual(result, { model: "mycustom/model-x", stripped: true });
|
|
});
|
|
|
|
test("unknown provider prefix (neither registry nor custom) is left intact", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("claude/desconhecido/x", {
|
|
...baseDeps,
|
|
isRegistryProvider: () => false,
|
|
});
|
|
assert.deepEqual(result, { model: "claude/desconhecido/x", stripped: false });
|
|
});
|
|
|
|
test("combo alias strips when the combo exists (non-empty models) and gate on", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("claude/combo/custo-otimizado", {
|
|
...baseDeps,
|
|
getCombo: async (name) => (name === "custo-otimizado" ? { models: [{ id: "a" }] } : null),
|
|
});
|
|
assert.deepEqual(result, { model: "custo-otimizado", stripped: true });
|
|
});
|
|
|
|
test("combo alias is left intact when the combo has no models", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("claude/combo/empty", {
|
|
...baseDeps,
|
|
getCombo: async () => ({ models: [] }),
|
|
});
|
|
assert.deepEqual(result, { model: "claude/combo/empty", stripped: false });
|
|
});
|
|
|
|
test("gate precedence: model 'off' beats provider/global on", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("claude/kimi/kimi-k2.6", {
|
|
...baseDeps,
|
|
gateModel: (providerId, modelId) =>
|
|
providerId === "kimi" && modelId === "kimi-k2.6" ? "off" : null,
|
|
});
|
|
assert.deepEqual(result, { model: "claude/kimi/kimi-k2.6", stripped: false });
|
|
});
|
|
|
|
test("gate precedence: provider 'on' strips even when global is off", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("claude/kimi/kimi-k2.6", {
|
|
...baseDeps,
|
|
gateGlobal: () => false,
|
|
gateProvider: (providerId) => (providerId === "kimi" ? "on" : null),
|
|
});
|
|
assert.deepEqual(result, { model: "kimi/kimi-k2.6", stripped: true });
|
|
});
|
|
|
|
test("combo gate uses the virtual 'combo' provider key", async () => {
|
|
const result = await resolveCcDiscoveryAliasStripWith("claude/combo/x", {
|
|
...baseDeps,
|
|
gateGlobal: () => false,
|
|
getCombo: async () => ({ models: [{ id: "a" }] }),
|
|
gateProvider: (providerId) => (providerId === "combo" ? "on" : null),
|
|
});
|
|
assert.deepEqual(result, { model: "x", stripped: true });
|
|
});
|