Files
OmniRoute/tests/unit/probe-policy.test.ts
Dizzle bb98e9a345 fix(probe): isolate probe-origin failures from all deactivation sites (#10694)
Merged — locally validated (23/23 focused probe-isolation tests, typecheck:core clean, file-size/changelog gates green). Reconciled with today's #8367 (codexAccount module extraction, merged earlier): the persistCodexQuotaState closure this PR touched had been extracted into persistCodexChildQuotaResponse — applied the same probe-origin isolation guard (!shouldIsolateProbeFailures()) at its new call site instead of reintroducing the old inline closure. Thanks for closing this real gap!
2026-08-20 10:30:29 -03:00

62 lines
2.2 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-probe-policy-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const core = await import("../../src/lib/db/core.ts");
const settingsDb = await import("../../src/lib/db/settings.ts");
const { runAsProbe, shouldIsolateProbeFailures, isProbeContext } =
await import("../../src/shared/utils/probeOrigin.ts");
test.after(() => {
delete process.env.PROBE_CAN_DISABLE;
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
});
test("outside a probe context the decision is always false (real path)", async () => {
await settingsDb.updateSettings({ probeCanDisable: true });
assert.equal(await shouldIsolateProbeFailures(), false);
});
test("probe + default settings => isolation ON (probe never disables)", async () => {
await settingsDb.updateSettings({ probeCanDisable: false });
await runAsProbe(async () => {
assert.equal(await shouldIsolateProbeFailures(), true);
});
});
test("probe + opt-in setting probeCanDisable => isolation OFF (historical behavior)", async () => {
await settingsDb.updateSettings({ probeCanDisable: true });
await runAsProbe(async () => {
assert.equal(await shouldIsolateProbeFailures(), false);
});
});
test("probe + env feature flag PROBE_CAN_DISABLE=true => isolation OFF", async () => {
process.env.PROBE_CAN_DISABLE = "true";
await settingsDb.updateSettings({ probeCanDisable: false });
await runAsProbe(async () => {
assert.equal(await shouldIsolateProbeFailures(), false);
});
});
test("probe + flag false + setting true => setting wins (flag must not re-enable isolation)", async () => {
process.env.PROBE_CAN_DISABLE = "false";
await settingsDb.updateSettings({ probeCanDisable: true });
await runAsProbe(async () => {
assert.equal(await shouldIsolateProbeFailures(), false);
});
});
test("probe context propagation is still pinned (policy uses the same gate)", async () => {
assert.equal(isProbeContext(), false);
await runAsProbe(async () => {
assert.equal(isProbeContext(), true);
});
});