Files
OmniRoute/tests/unit/feature-flags-settings.test.ts
Brandon Bennett 6615a5445b feat: combo-lane awareness + activation UX + MCP visibility (Wave 2 of #9654) (#10039)
* feat(admission): per-target lane-aware probes for combo/fusion fan-out (#9654 Wave 2)

Combo and fusion fan out N targets without ever consulting the adaptive-admission
layer: the parent request holds one lease, but each fan-out target is dispatched
unconditionally. With virtual lanes enabled (OMNIROUTE_CHAT_VIRTUAL_LANES=1), a
connection whose lane queue is full now SKIPS additional fan-out targets instead
of piling more queued work onto an already-congested session.

Adds PerTargetAdmissionHook (admission/types.ts) + createPerTargetAdmissionHook
factory (chatAdmission.ts): strictly non-blocking (maxWaitMs 0 - skip, never
queue), a no-op when virtual lanes are off, keyed to the parent tenantKey, and
release-on-admit so the probe is a capacity gate, not a hold.

Threaded through every parallel fan-out path:
- priority/weighted executeTarget + round-robin skip chains (combo.ts)
- fusion panel before fan-out (fusion.ts), judge fallback prefers survivors
- chaos parallel panel (autoCombo/chaosEngine.ts)
- tryFusionDispatch / tryRuntimeUnitDispatch / buildBaseOptions (dispatchPrelude.ts)
- chat.ts primary + safety-net redirect call sites

Snapshot exposes virtualLanes so the no-op gate is cheap and honest.

Tests: tests/unit/combo-lane-awareness-9654.test.ts (10 tests) - factory
semantics, priority/RR skip, fusion panel drop + all-skipped 503, no-hook
backward-compat baseline.

* feat(flags): activation UX - env-wins adaptive virtual-lanes flag + env docs (#9654 Wave 2)

U7: make adaptive virtual admission lanes discoverable + activatable.
- New OMNIROUTE_CHAT_VIRTUAL_LANES feature flag (boolean/runtime/requiresRestart) in featureFlagDefinitions + en.json i18n key.
- lib/admissionVirtualLanes.ts: env-wins resolver (env > DB > default) + boot warm folding a DB-sourced override into the process-global runtime env via reloadAdaptiveAdmissionRuntime(options.env) - no process.env mutation, no open-sse changes. Env still wins; DB toggle gates at next boot.
- GET /api/settings/feature-flags special-cases the flag to report the gate true source (ccDiscoveryAliases precedent); flagPayload helper dedupes the payload shape.
- Wire the warm into instrumentation-node registerNodejs (non-fatal, DB-ready).
- Document the master switch in .env.example + ENVIRONMENT.md with the system-1/system-2 distinction; zero new env-doc-sync drift.
- 11 new tests (resolver precedence + warm); 60/60 across feature-flag suites; typecheck core clean; ESLint + doc gates green.

* feat(mcp): surface adaptive admission lane data in omniroute_get_health (#9654 Wave 2)

U8: make adaptive virtual-lane admission visible to agents via the MCP health tool. handleGetHealth now surfaces a curated adaptiveAdmission block from the health payload (which already carried the runtime snapshot but was dropping it): virtualLanes/pressure/utilization/laneCount/laneQueuedCount/laneQueuedCost, laneTenants capped at top-10 by queued cost, admitted/rejected/wouldReject counts, shutdown. Block omitted entirely when the health endpoint reports none.

isLaneFlagOn mirrors the runtime 1|true convention so a string serialization can never invert a boolean lane report. getHealthOutput schema extended with the matching optional shape; tool description updated.

4 new dispatch tests (full block, top-10 cap/order, omission, defensive coercion of string flags + malformed lane entries) - 22/22 in essentialTools.test.ts. README: Adaptive Admission Lane Data table + Skills & Tool Navigability audit (29/43 schema entries covered, 14 undocumented, tool_search keyword runtime discovery, full catalog in docs/frameworks/MCP-SERVER.md).

No new lint errors (4 pre-existing in server.ts), typecheck core clean, doc counts + fabricated-docs gates green.

* docs: add changelog entry for #9654 Wave 2 (#10039)

* fix(codeql): suppress js/insufficient-password-hash false positive in lane-key fingerprinting (#10039)

resolveSessionId sha256-hashes bearer/x-api-key/x-goog-api-key to derive a deterministic, non-reversible per-key lane-bucket ID for virtual admission lanes (#9654). This is not password storage or verification, so the rule is a false positive; suppress it inline (same house style as src/lib/sync/tokens.ts) to clear the codeqlAlerts ratchet (2 > baseline 1) that blocks #10039 and every PR against release/v3.8.50.

* docs(mcp): complete MCP server README tool reference (#10039)

The MCP server README covered only 29 of the 43 schema entries, listing the
remaining tools solely as a gap note with omniroute_tool_search as the runtime
fallback. Add tool-reference tables for the agent-skills trio, oneproxy trio,
web_fetch/web_search, tool_search, create_combo, set_routing_strategy,
pick_fastest_model, sync_pricing, and db_health_check so the README covers the
full schemas catalog, and fold the coverage note into the tool_search discovery
paragraph.

* fix(chat): drop unused correlationId from safety-net combo redirect (#10039)

handleComboChat's HandleComboChatOptions has no correlationId member and
the combo pipeline never consumes it; the property was copied from the
handleSingleModelChat options shape by accident and introduced a new
TS2353 under the open-sse workspace typecheck gate.

* fix(i18n): translate featureFlagChatVirtualLanesEnabledDescription into 42 locales (#10039)

en.json gained the flag description in this PR but the locale catalogs
were never mirrored, failing the pt-BR key-parity (#6695) and vi
completeness gates. Adds a real translation to every locale, keeping the
zh-CN/zh-TW glossary canonical terms (提供者/儀表板) and no ICU drift.

* chore(quality): ratchet open-sse-typecheck baseline down (#10039)

The Wave 2 admission refactor removed 66 baselined open-sse type errors;
re-freeze the baseline so the gate pins the new, tighter state.

* docs: resync provider reference to 341 and CLI tools to 34

The release branch gained an 11th no-auth provider (freeaiapikey registry
resync, #10233) and a 26th CLI Code tool without regenerating the
auto-generated docs, leaving every PR against release/v3.8.50 failing the
Docs Gates strict validator (code 341 vs doc 340, CLI 34 vs "33 tools").

Regenerate docs/reference/PROVIDER_REFERENCE.md and sync the provider/tool
counts across README.md, AGENTS.md, llm.txt plus 42 i18n mirrors,
package.json description, and the four diagram SVGs.

* fix(tests): align count expectations with live catalogs (pre-existing release drift)

Release/v3.8.50 currently fails five gates on its own tree; this PR inherits
them. Fix the stale expectations to match live code:

- feature-flags-settings: 48 -> 49 flags (Wave 2 adds OMNIROUTE_CHAT_VIRTUAL_LANES)
- cli-tools-schema / cli-catalog-counts: 33 -> 34 tools (zcode added; 26 code = 21 visible + 5 none)
- optional-transformers-dependency: onnxruntime-node ~1.24.3 -> ~1.27.0 (bump #10382)
- stryker.conf.json: register chatcore-header-drop-warn-dedupe-10315 test
- check-public-creds: freeze zcodeProtocol clientId false positive (client identifier, not a credential)

* fix(tests): follow release's onnxruntime-node revert to ~1.24.3

release/v3.8.50's #10543 pinned onnxruntime-node back to ~1.24.3 after
#10403's ~1.27.0 bump caused npm to nest a second native copy under
@huggingface/transformers and broke the Docker SONAME contract. This
PR's own drift-alignment commit (57b9c033) predates that revert and
still expected ~1.27.0; the 3-way merge did not flag it as a textual
conflict since only one side touched this exact line, but the merged
tree became internally inconsistent (package.json ~1.24.3 vs test
expecting ~1.27.0). Align the test with the now-canonical release
value.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

* fix(quality): dedupe stryker.conf.json chatcore-header-drop-warn-dedupe entry

The 3-way merge applied both sides' insertion of the same test-file entry
at different positions, producing a duplicate with broken indentation.
Adopted release's clean version of the file.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: Brandon Bennett <brandonbennett@macbookair.myfiosgateway.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: Brandon Bennett <branben@users.noreply.github.com>
2026-08-18 11:31:46 -03:00

479 lines
19 KiB
TypeScript

import { describe, it, beforeEach, after } from "node:test";
import assert from "node:assert/strict";
import os from "node:os";
import path from "node:path";
import fs from "node:fs";
// Set DATA_DIR to temp dir before any imports that touch DB
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-test-flags-"));
process.env.DATA_DIR = tmpDir;
const core = await import("../../src/lib/db/core.ts");
const { FEATURE_FLAG_DEFINITIONS } =
await import("../../src/shared/constants/featureFlagDefinitions.ts");
const {
getFeatureFlagOverrides,
getFeatureFlagOverride,
setFeatureFlagOverride,
removeFeatureFlagOverride,
clearAllFeatureFlagOverrides,
} = await import("../../src/lib/db/featureFlags.ts");
const {
resolveFeatureFlag,
isFeatureFlagEnabled,
resolveAllFeatureFlags,
isRequireApiKeyEnabled,
isCcCompatibleProviderEnabled,
isModelCatalogNamesEnabled,
isArenaEloSyncEnabled,
isControlPlaneProxyDirectFallbackEnabled,
} = await import("../../src/shared/utils/featureFlags.ts");
const EXPECTED_FEATURE_FLAG_COUNT = 50;
// ──────────────────────────────────────────────────────
// Test group 1 — Flag definitions registry
// ──────────────────────────────────────────────────────
describe("featureFlagDefinitions", () => {
it(`has exactly ${EXPECTED_FEATURE_FLAG_COUNT} flag definitions`, () => {
assert.strictEqual(FEATURE_FLAG_DEFINITIONS.length, EXPECTED_FEATURE_FLAG_COUNT);
});
it("has unique keys for all flags", () => {
const keys = FEATURE_FLAG_DEFINITIONS.map((d) => d.key);
assert.strictEqual(new Set(keys).size, EXPECTED_FEATURE_FLAG_COUNT);
});
it("has valid categories for all flags", () => {
const valid = new Set(["security", "network", "policies", "runtime", "cli", "health"]);
for (const d of FEATURE_FLAG_DEFINITIONS) {
assert.ok(valid.has(d.category), `Invalid category "${d.category}" for ${d.key}`);
}
});
it("has valid types (boolean or enum) for all flags", () => {
for (const d of FEATURE_FLAG_DEFINITIONS) {
assert.ok(d.type === "boolean" || d.type === "enum", `Invalid type for ${d.key}`);
}
});
it("has enumValues for all enum-type flags", () => {
const enumFlags = FEATURE_FLAG_DEFINITIONS.filter((d) => d.type === "enum");
assert.ok(enumFlags.length > 0, "Should have at least one enum flag");
for (const d of enumFlags) {
assert.ok(
Array.isArray(d.enumValues) && d.enumValues.length > 0,
`Missing enumValues for ${d.key}`
);
}
});
it("does not have enumValues for boolean-type flags", () => {
const boolFlags = FEATURE_FLAG_DEFINITIONS.filter((d) => d.type === "boolean");
for (const d of boolFlags) {
assert.ok(
!d.enumValues || d.enumValues.length === 0,
`Boolean flag ${d.key} should not have enumValues`
);
}
});
it("has warningLevel only with valid values when present", () => {
const valid = new Set(["info", "caution", "danger"]);
for (const d of FEATURE_FLAG_DEFINITIONS) {
if (d.warningLevel !== undefined) {
assert.ok(
valid.has(d.warningLevel),
`Invalid warningLevel "${d.warningLevel}" for ${d.key}`
);
}
}
});
it("defines model catalog names as a runtime boolean flag enabled by default", () => {
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "MODEL_CATALOG_INCLUDE_NAMES");
assert.ok(def, "MODEL_CATALOG_INCLUDE_NAMES should exist");
assert.strictEqual(def.category, "runtime");
assert.strictEqual(def.type, "boolean");
assert.strictEqual(def.defaultValue, "true");
assert.strictEqual(def.requiresRestart, false);
});
it("defines models catalog prefix mode as a runtime enum flag defaulting to dual", () => {
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "MODELS_CATALOG_PREFIX_MODE");
assert.ok(def, "MODELS_CATALOG_PREFIX_MODE should exist");
assert.strictEqual(def.category, "runtime");
assert.strictEqual(def.type, "enum");
assert.deepStrictEqual(def.enumValues, ["dual", "alias", "canonical"]);
assert.strictEqual(def.defaultValue, "dual");
assert.strictEqual(def.requiresRestart, false);
});
it("defines Arena ELO sync as a runtime boolean flag enabled by default", () => {
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "ARENA_ELO_SYNC_ENABLED");
assert.ok(def, "ARENA_ELO_SYNC_ENABLED should exist");
assert.strictEqual(def.category, "runtime");
assert.strictEqual(def.type, "boolean");
assert.strictEqual(def.defaultValue, "true");
assert.strictEqual(def.requiresRestart, false);
});
it("defines emergency fallback as a runtime boolean flag enabled by default", () => {
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "OMNIROUTE_EMERGENCY_FALLBACK");
assert.ok(def, "OMNIROUTE_EMERGENCY_FALLBACK should exist");
assert.strictEqual(def.category, "runtime");
assert.strictEqual(def.type, "boolean");
assert.strictEqual(def.defaultValue, "true");
assert.strictEqual(def.requiresRestart, false);
});
it("defines stream recovery as runtime boolean flags disabled by default", () => {
const early = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "STREAM_RECOVERY_ENABLED");
const midstream = FEATURE_FLAG_DEFINITIONS.find(
(d) => d.key === "STREAM_RECOVERY_MIDSTREAM_ENABLED"
);
assert.ok(early, "STREAM_RECOVERY_ENABLED should exist");
assert.strictEqual(early.category, "runtime");
assert.strictEqual(early.type, "boolean");
assert.strictEqual(early.defaultValue, "false");
assert.strictEqual(early.requiresRestart, false);
assert.strictEqual(early.warningLevel, "caution");
assert.ok(midstream, "STREAM_RECOVERY_MIDSTREAM_ENABLED should exist");
assert.strictEqual(midstream.category, "runtime");
assert.strictEqual(midstream.type, "boolean");
assert.strictEqual(midstream.defaultValue, "false");
assert.strictEqual(midstream.requiresRestart, false);
assert.strictEqual(midstream.warningLevel, "danger");
});
it("defines control-plane proxy direct fallback as a network boolean flag disabled by default", () => {
const def = FEATURE_FLAG_DEFINITIONS.find(
(d) => d.key === "OMNIROUTE_CONTROL_PLANE_PROXY_DIRECT_FALLBACK"
);
assert.ok(def, "OMNIROUTE_CONTROL_PLANE_PROXY_DIRECT_FALLBACK should exist");
assert.strictEqual(def.category, "network");
assert.strictEqual(def.type, "boolean");
assert.strictEqual(def.defaultValue, "false");
assert.strictEqual(def.requiresRestart, false);
assert.strictEqual(def.warningLevel, "danger");
});
it("defines network rotation shared-egress guard as a network boolean flag enabled by default", () => {
const def = FEATURE_FLAG_DEFINITIONS.find(
(d) => d.key === "NETWORK_ROTATION_SHARED_EGRESS_GUARD"
);
assert.ok(def, "NETWORK_ROTATION_SHARED_EGRESS_GUARD should exist");
assert.strictEqual(def.category, "network");
assert.strictEqual(def.type, "boolean");
assert.strictEqual(def.defaultValue, "true");
assert.strictEqual(def.requiresRestart, false);
assert.strictEqual(def.warningLevel, "info");
});
it("defines remote audio provider nodes as a network boolean flag disabled by default", () => {
// Guards the egress default: with this on, /v1/audio/* may reach a provider node
// hosted outside localhost. It must never become an implicit default (cf. #3963).
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "AUDIO_REMOTE_PROVIDER_NODES");
assert.ok(def, "AUDIO_REMOTE_PROVIDER_NODES should exist");
assert.strictEqual(def.category, "network");
assert.strictEqual(def.type, "boolean");
assert.strictEqual(def.defaultValue, "false");
assert.strictEqual(def.warningLevel, "danger");
});
it("defines CC discovery aliases as a runtime boolean flag disabled by default", () => {
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "EXPOSE_CC_DISCOVERY_ALIASES");
assert.ok(def, "EXPOSE_CC_DISCOVERY_ALIASES should exist");
assert.strictEqual(def.category, "runtime");
assert.strictEqual(def.type, "boolean");
assert.strictEqual(def.defaultValue, "false");
assert.strictEqual(def.requiresRestart, false);
});
it("defines CLI profile auto-sync flags as CLI booleans disabled by default", () => {
for (const key of [
"OMNIROUTE_AUTO_SYNC_CODEX_PROFILES",
"OMNIROUTE_AUTO_SYNC_CLAUDE_PROFILES",
]) {
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === key);
assert.ok(def, `${key} should exist`);
assert.strictEqual(def.category, "cli");
assert.strictEqual(def.type, "boolean");
assert.strictEqual(def.defaultValue, "false");
assert.strictEqual(def.requiresRestart, false);
assert.strictEqual(def.warningLevel, "caution");
}
});
});
// ──────────────────────────────────────────────────────
// Test group 2 — DB module
// ──────────────────────────────────────────────────────
describe("featureFlags DB module", () => {
function resetDb() {
core.resetDbInstance();
fs.rmSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir, { recursive: true });
}
beforeEach(() => {
resetDb();
});
after(() => {
core.resetDbInstance();
fs.rmSync(tmpDir, { recursive: true, force: true });
});
it("getFeatureFlagOverrides returns empty object when no overrides", () => {
const overrides = getFeatureFlagOverrides();
assert.deepStrictEqual(overrides, {});
});
it("setFeatureFlagOverride stores value in key_value table", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "true");
const overrides = getFeatureFlagOverrides();
assert.strictEqual(overrides["REQUIRE_API_KEY"], "true");
});
it("getFeatureFlagOverride returns the stored value", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "true");
assert.strictEqual(getFeatureFlagOverride("REQUIRE_API_KEY"), "true");
});
it("getFeatureFlagOverride returns undefined for unset flag", () => {
assert.strictEqual(getFeatureFlagOverride("REQUIRE_API_KEY"), undefined);
});
it("removeFeatureFlagOverride deletes the override", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "true");
removeFeatureFlagOverride("REQUIRE_API_KEY");
assert.strictEqual(getFeatureFlagOverride("REQUIRE_API_KEY"), undefined);
});
it("clearAllFeatureFlagOverrides removes all overrides", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "true");
setFeatureFlagOverride("INPUT_SANITIZER_ENABLED", "true");
clearAllFeatureFlagOverrides();
assert.deepStrictEqual(getFeatureFlagOverrides(), {});
});
it("setFeatureFlagOverride overwrites existing value", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "true");
setFeatureFlagOverride("REQUIRE_API_KEY", "false");
assert.strictEqual(getFeatureFlagOverride("REQUIRE_API_KEY"), "false");
});
});
// ──────────────────────────────────────────────────────
// Test group 3 — Resolver
// ──────────────────────────────────────────────────────
describe("resolveFeatureFlag", () => {
function resetDb() {
core.resetDbInstance();
fs.rmSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir, { recursive: true });
}
beforeEach(() => {
resetDb();
delete process.env["REQUIRE_API_KEY"];
});
after(() => {
core.resetDbInstance();
fs.rmSync(tmpDir, { recursive: true, force: true });
delete process.env["REQUIRE_API_KEY"];
});
it("returns DB override when set", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "true");
assert.strictEqual(resolveFeatureFlag("REQUIRE_API_KEY"), "true");
});
it("falls back to ENV when no DB override", () => {
process.env["REQUIRE_API_KEY"] = "true";
assert.strictEqual(resolveFeatureFlag("REQUIRE_API_KEY"), "true");
delete process.env["REQUIRE_API_KEY"];
});
it("falls back to default when neither DB nor ENV", () => {
assert.strictEqual(resolveFeatureFlag("REQUIRE_API_KEY"), "false");
});
it("DB takes priority over ENV", () => {
process.env["REQUIRE_API_KEY"] = "env-value";
setFeatureFlagOverride("REQUIRE_API_KEY", "db-value");
assert.strictEqual(resolveFeatureFlag("REQUIRE_API_KEY"), "db-value");
delete process.env["REQUIRE_API_KEY"];
});
describe("isFeatureFlagEnabled", () => {
it("returns true for 'true'", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "true");
assert.ok(isFeatureFlagEnabled("REQUIRE_API_KEY"));
});
it("returns true for '1'", () => {
setFeatureFlagOverride("SKILLS_SANDBOX_NETWORK_ENABLED", "1");
assert.ok(isFeatureFlagEnabled("SKILLS_SANDBOX_NETWORK_ENABLED"));
});
it("returns true for 'yes'", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "yes");
assert.ok(isFeatureFlagEnabled("REQUIRE_API_KEY"));
});
it("returns false for 'false'", () => {
assert.ok(!isFeatureFlagEnabled("REQUIRE_API_KEY"));
});
it("returns false for '0'", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "0");
assert.ok(!isFeatureFlagEnabled("REQUIRE_API_KEY"));
});
it("returns false for empty string via ENV (falls to default)", () => {
process.env["REQUIRE_API_KEY"] = "";
assert.ok(!isFeatureFlagEnabled("REQUIRE_API_KEY"));
delete process.env["REQUIRE_API_KEY"];
});
});
describe("resolveAllFeatureFlags", () => {
it(`returns all ${EXPECTED_FEATURE_FLAG_COUNT} flags`, () => {
const all = resolveAllFeatureFlags();
assert.strictEqual(all.length, EXPECTED_FEATURE_FLAG_COUNT);
});
it("marks DB-overridden flags with source 'db'", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "true");
const all = resolveAllFeatureFlags();
const flag = all.find((f) => f.key === "REQUIRE_API_KEY");
assert.strictEqual(flag?.source, "db");
});
it("marks ENV-set flags with source 'env'", () => {
process.env["REQUIRE_API_KEY"] = "true";
const all = resolveAllFeatureFlags();
const flag = all.find((f) => f.key === "REQUIRE_API_KEY");
assert.strictEqual(flag?.source, "env");
delete process.env["REQUIRE_API_KEY"];
});
it("marks default flags with source 'default'", () => {
const all = resolveAllFeatureFlags();
const flag = all.find((f) => f.key === "REQUIRE_API_KEY");
assert.strictEqual(flag?.source, "default");
});
});
describe("backward compatibility", () => {
it("isRequireApiKeyEnabled uses the resolved REQUIRE_API_KEY flag", () => {
setFeatureFlagOverride("REQUIRE_API_KEY", "true");
assert.strictEqual(isRequireApiKeyEnabled(), true);
});
it("isRequireApiKeyEnabled fails closed when the flag store cannot be read", () => {
const originalError = console.error;
console.error = () => {};
try {
core.resetDbInstance();
fs.rmSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir, { recursive: true });
const blockerPath = path.join(tmpDir, "storage.sqlite");
fs.mkdirSync(blockerPath, { recursive: true });
assert.strictEqual(isRequireApiKeyEnabled(), true);
} finally {
console.error = originalError;
core.resetDbInstance();
fs.rmSync(tmpDir, { recursive: true, force: true });
fs.mkdirSync(tmpDir, { recursive: true });
}
});
it("isCcCompatibleProviderEnabled still works", () => {
const result = isCcCompatibleProviderEnabled();
assert.strictEqual(typeof result, "boolean");
});
it("isModelCatalogNamesEnabled defaults on and follows overrides", () => {
assert.strictEqual(isModelCatalogNamesEnabled(), true);
try {
setFeatureFlagOverride("MODEL_CATALOG_INCLUDE_NAMES", "false");
assert.strictEqual(isModelCatalogNamesEnabled(), false);
} finally {
removeFeatureFlagOverride("MODEL_CATALOG_INCLUDE_NAMES");
}
});
it("isArenaEloSyncEnabled defaults on and follows DB overrides", () => {
assert.strictEqual(isArenaEloSyncEnabled(), true);
try {
setFeatureFlagOverride("ARENA_ELO_SYNC_ENABLED", "false");
assert.strictEqual(isArenaEloSyncEnabled(), false);
} finally {
removeFeatureFlagOverride("ARENA_ELO_SYNC_ENABLED");
}
});
it("isControlPlaneProxyDirectFallbackEnabled defaults off and follows DB overrides", () => {
assert.strictEqual(isControlPlaneProxyDirectFallbackEnabled(), false);
try {
setFeatureFlagOverride("OMNIROUTE_CONTROL_PLANE_PROXY_DIRECT_FALLBACK", "true");
assert.strictEqual(isControlPlaneProxyDirectFallbackEnabled(), true);
} finally {
removeFeatureFlagOverride("OMNIROUTE_CONTROL_PLANE_PROXY_DIRECT_FALLBACK");
}
});
});
});
// ──────────────────────────────────────────────────────
// Test group 4 — Schema / validation logic (pure)
// ──────────────────────────────────────────────────────
describe("featureFlagUpdateSchema validation", () => {
it("rejects unknown flag keys", () => {
const knownKeys = new Set(FEATURE_FLAG_DEFINITIONS.map((d) => d.key));
assert.ok(!knownKeys.has("UNKNOWN_FLAG_XYZ"), "UNKNOWN_FLAG_XYZ should not be a known key");
});
it("validates that INJECTION_GUARD_MODE has known enum values", () => {
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "INJECTION_GUARD_MODE");
assert.ok(def, "INJECTION_GUARD_MODE should exist");
assert.deepStrictEqual(def.enumValues, ["off", "warn", "block", "redact"]);
});
it("validates that TOOL_POLICY_MODE has known enum values", () => {
const def = FEATURE_FLAG_DEFINITIONS.find((d) => d.key === "TOOL_POLICY_MODE");
assert.ok(def, "TOOL_POLICY_MODE should exist");
assert.deepStrictEqual(def.enumValues, ["disabled", "warn", "block"]);
});
it("setFeatureFlagOverride throws for unknown keys", () => {
assert.throws(
() => setFeatureFlagOverride("UNKNOWN_FLAG_XYZ", "true"),
/Unknown feature flag key/
);
});
it("setFeatureFlagOverride throws for invalid enum value", () => {
assert.throws(
() => setFeatureFlagOverride("INJECTION_GUARD_MODE", "invalid_mode"),
/Invalid value/
);
});
});
describe("settings schema public surface", () => {
it("uses databaseSettingsSchema as the canonical database settings export", async () => {
const settingsSchemas = await import("../../src/shared/validation/settingsSchemas.ts");
assert.equal("DatabaseSettingsSchema" in settingsSchemas, false);
assert.equal("featureFlagUpdateSchema" in settingsSchemas, false);
assert.equal(typeof settingsSchemas.databaseSettingsSchema.safeParse, "function");
});
});