Expose Arena ELO sync in feature flags (#3821)

Adds ARENA_ELO_SYNC_ENABLED to the Dashboard Feature Flags registry (DB-overridable),
routes Arena ELO startup/status checks through the shared feature-flag resolver while
preserving the existing env fallback, and refreshes env docs (adds the missing
STREAM_READINESS_TIMEOUT_MS example) so env/doc sync stays green.

Integrated into release/v3.8.25.

Co-authored-by: R.D. <rogerproself@gmail.com>
This commit is contained in:
Randi
2026-06-14 07:45:02 -04:00
committed by GitHub
parent ebf06b5e6c
commit 31e4e46ef9
11 changed files with 143 additions and 41 deletions

View File

@@ -88,9 +88,10 @@ describe("Pipeline Wiring — instrumentation-node.ts", () => {
it("should initialize Arena ELO sync on the live startup path (on by default, opt-out)", () => {
// The Next standalone runtime boots through instrumentation-node, NOT server-init.ts.
// The Arena ELO sync (which feeds the Free Provider Rankings page) must be wired here,
// or it never runs in production regardless of ARENA_ELO_SYNC_ENABLED.
// or it never runs in production. initArenaEloSync self-gates through the feature flag
// resolver so ARENA_ELO_SYNC_ENABLED and dashboard overrides still apply.
assert.match(src, /initArenaEloSync/);
assert.match(src, /ARENA_ELO_SYNC_ENABLED !== "false"/);
assert.match(src, /const started = await initArenaEloSync\(\)/);
});
it("should initialize pricing + models.dev sync on the live startup path (self-gated, opt-in)", () => {

View File

@@ -35,8 +35,11 @@ const {
fetchArenaLeaderboards,
syncArenaElo,
getArenaEloSyncStatus,
initArenaEloSync,
stopArenaEloSync,
} = await import("../../src/lib/arenaEloSync.ts");
const { setFeatureFlagOverride, removeFeatureFlagOverride } =
await import("../../src/lib/db/featureFlags.ts");
import type {
ArenaLeaderboardData,
@@ -102,6 +105,14 @@ function createTestAdapter(): SqliteAdapter {
"\n synced_at TEXT NOT NULL"
);
const adapter = tryOpenSync(":memory:")!;
adapter.exec(`
CREATE TABLE IF NOT EXISTS key_value (
namespace TEXT NOT NULL,
key TEXT NOT NULL,
value TEXT NOT NULL,
PRIMARY KEY (namespace, key)
);
`);
adapter.exec(patchedSql);
return adapter;
}
@@ -124,12 +135,14 @@ beforeEach(() => {
testAdapter = createTestAdapter();
globalThis.__omnirouteDb = testAdapter as never;
stopArenaEloSync();
delete process.env.ARENA_ELO_SYNC_ENABLED;
});
afterEach(() => {
restoreFetch();
stopArenaEloSync();
delete globalThis.__omnirouteDb;
delete process.env.ARENA_ELO_SYNC_ENABLED;
});
// ═══════════════════════════════════════════════════════════
@@ -767,6 +780,26 @@ describe("getArenaEloSyncStatus()", () => {
delete process.env.ARENA_ELO_SYNC_ENABLED;
}
});
it("reflects dashboard feature flag DB overrides before env values", () => {
process.env.ARENA_ELO_SYNC_ENABLED = "true";
try {
setFeatureFlagOverride("ARENA_ELO_SYNC_ENABLED", "false");
const status = getArenaEloSyncStatus();
assert.strictEqual(status.enabled, false);
} finally {
removeFeatureFlagOverride("ARENA_ELO_SYNC_ENABLED");
}
});
it("falls back to the env value if the feature flag store is unavailable", () => {
testAdapter.exec("DROP TABLE key_value");
process.env.ARENA_ELO_SYNC_ENABLED = "false";
const status = getArenaEloSyncStatus();
assert.strictEqual(status.enabled, false);
});
});
// ═══════════════════════════════════════════════════════════
@@ -774,6 +807,16 @@ describe("getArenaEloSyncStatus()", () => {
// ═══════════════════════════════════════════════════════════
describe("stopArenaEloSync()", () => {
it("initArenaEloSync returns false when disabled by feature flag", async () => {
try {
setFeatureFlagOverride("ARENA_ELO_SYNC_ENABLED", "false");
const started = await initArenaEloSync();
assert.strictEqual(started, false);
} finally {
removeFeatureFlagOverride("ARENA_ELO_SYNC_ENABLED");
}
});
it("does not throw when no timer is running", () => {
assert.doesNotThrow(() => stopArenaEloSync());
});

View File

@@ -26,19 +26,20 @@ const {
isRequireApiKeyEnabled,
isCcCompatibleProviderEnabled,
isModelCatalogNamesEnabled,
isArenaEloSyncEnabled,
} = await import("../../src/shared/utils/featureFlags.ts");
// ──────────────────────────────────────────────────────
// Test group 1 — Flag definitions registry
// ──────────────────────────────────────────────────────
describe("featureFlagDefinitions", () => {
it("has exactly 31 flag definitions", () => {
assert.strictEqual(FEATURE_FLAG_DEFINITIONS.length, 31);
it("has exactly 32 flag definitions", () => {
assert.strictEqual(FEATURE_FLAG_DEFINITIONS.length, 32);
});
it("has unique keys for all flags", () => {
const keys = FEATURE_FLAG_DEFINITIONS.map((d) => d.key);
assert.strictEqual(new Set(keys).size, 31);
assert.strictEqual(new Set(keys).size, 32);
});
it("has valid categories for all flags", () => {
@@ -96,6 +97,15 @@ describe("featureFlagDefinitions", () => {
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");
@@ -241,9 +251,9 @@ describe("resolveFeatureFlag", () => {
});
describe("resolveAllFeatureFlags", () => {
it("returns all 31 flags", () => {
it("returns all 32 flags", () => {
const all = resolveAllFeatureFlags();
assert.strictEqual(all.length, 31);
assert.strictEqual(all.length, 32);
});
it("marks DB-overridden flags with source 'db'", () => {
@@ -306,6 +316,16 @@ describe("resolveFeatureFlag", () => {
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");
}
});
});
});