Files
OmniRoute/tests/unit/probe-origin.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

39 lines
1.4 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import Bottleneck from "bottleneck";
const { runAsProbe, isProbeContext } = await import("../../src/shared/utils/probeOrigin.ts");
test("runAsProbe propagates through nested async/await; false outside", async () => {
assert.equal(isProbeContext(), false);
await runAsProbe(async () => {
assert.equal(isProbeContext(), true);
await Promise.resolve();
const inner = async () => {
await Promise.resolve();
return isProbeContext();
};
assert.equal(await inner(), true);
await new Promise((r) => setTimeout(r, 5));
assert.equal(isProbeContext(), true);
});
assert.equal(isProbeContext(), false);
});
test("queued scheduler job wrapped in runAsProbe keeps the probe context", async () => {
const limiter = new Bottleneck({ maxConcurrent: 1, minTime: 50 });
let insideQueuedJob: boolean | null = null;
// Schedule job 1 WITHOUT awaiting it so job 2 really queues behind it
// (maxConcurrent 1 + minTime 50) — the queued job must execute with the
// probe context established at scheduling time.
const job1 = limiter.schedule(() => new Promise((r) => setTimeout(r, 30)));
const job2 = limiter.schedule(() =>
runAsProbe(() => {
insideQueuedJob = isProbeContext();
return Promise.resolve();
})
);
await Promise.all([job1, job2]);
assert.equal(insideQueuedJob, true);
});