OmniRoute/tests/unit/proxy-refusal-memory-default.test.ts
Dizzle c3391e528f
fix(proxies): skip recently failed proxies by default (#14688)
Flips PROXY_SKIP_RECENTLY_FAILED to default on (=false restores plain rotation). Maintainer rework: reconciled with release/v3.8.51 after #14809 (kept its lastResort429 spare alongside the default-on comment) and #14802/#14755 (their flag-off test cases re-pinned from 'delete env' to an explicit =false, since unset now means on). Red->green: proxy-refusal-memory-default 2/3 red on base, 3/3 green. Focused proxy/opencode/refusal-memory suites 258/261 then 36/36 on the 3 reruns, plus 127/127 after the #14802 merge; typecheck:core and open-sse typecheck clean; file-size only the inherited opencode.ts tip ceiling (1354>1338, red on the pure tip). Thank you @maxmad64bis!
2026-09-25 18:26:38 -03:00

46 lines
1.6 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
// Default of the refusal-memory flag: on unless explicitly opted out.
// Resolution priority DB > env > definition; these cases pin the default and
// the circuit breaker with env/DB absent.
const flags = await import("../../src/shared/utils/featureFlags.ts");
const definitions = await import("../../src/shared/constants/featureFlagDefinitions.ts");
function withCleanEnv(fn: () => void) {
const saved = process.env.PROXY_SKIP_RECENTLY_FAILED;
delete process.env.PROXY_SKIP_RECENTLY_FAILED;
try {
fn();
} finally {
if (saved !== undefined) process.env.PROXY_SKIP_RECENTLY_FAILED = saved;
else delete process.env.PROXY_SKIP_RECENTLY_FAILED;
}
}
test("definition defaults PROXY_SKIP_RECENTLY_FAILED to true", () => {
const def = definitions.FEATURE_FLAG_DEFINITIONS.find(
(d) => d.key === "PROXY_SKIP_RECENTLY_FAILED",
);
assert.ok(def, "PROXY_SKIP_RECENTLY_FAILED should exist");
assert.strictEqual(def.defaultValue, "true");
});
test("wrapper resolves to enabled with neither env nor DB override", () => {
withCleanEnv(() => {
assert.strictEqual(flags.resolveFeatureFlag("PROXY_SKIP_RECENTLY_FAILED"), "true");
assert.strictEqual(flags.isProxySkipRecentlyFailedEnabled(), true);
});
});
test("explicit opt-out restores the plain selection", () => {
for (const value of ["false", "0"]) {
process.env.PROXY_SKIP_RECENTLY_FAILED = value;
try {
assert.strictEqual(flags.isProxySkipRecentlyFailedEnabled(), false, `env=${value}`);
} finally {
delete process.env.PROXY_SKIP_RECENTLY_FAILED;
}
}
});