Skip to content

Commit f64f3fd

Browse files
committed
test: isolate base vitest thread blockers
1 parent 8b02ef1 commit f64f3fd

File tree

8 files changed

+886
-329
lines changed

8 files changed

+886
-329
lines changed

src/agents/pi-embedded-runner/compact.hooks.harness.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,47 @@ export async function loadCompactHooksHarness(): Promise<{
334334
splitSdkTools: vi.fn(() => ({ builtInTools: [], customTools: [] })),
335335
}));
336336

337+
vi.doMock("./compaction-safety-timeout.js", () => ({
338+
compactWithSafetyTimeout: vi.fn(
339+
async (
340+
compact: () => Promise<unknown>,
341+
_timeoutMs?: number,
342+
opts?: { abortSignal?: AbortSignal; onCancel?: () => void },
343+
) => {
344+
const abortSignal = opts?.abortSignal;
345+
if (!abortSignal) {
346+
return await compact();
347+
}
348+
const cancelAndCreateError = () => {
349+
opts?.onCancel?.();
350+
const reason = "reason" in abortSignal ? abortSignal.reason : undefined;
351+
if (reason instanceof Error) {
352+
return reason;
353+
}
354+
const err = new Error("aborted");
355+
err.name = "AbortError";
356+
return err;
357+
};
358+
if (abortSignal.aborted) {
359+
throw cancelAndCreateError();
360+
}
361+
return await Promise.race([
362+
compact(),
363+
new Promise<never>((_, reject) => {
364+
abortSignal.addEventListener(
365+
"abort",
366+
() => {
367+
reject(cancelAndCreateError());
368+
},
369+
{ once: true },
370+
);
371+
}),
372+
]);
373+
},
374+
),
375+
resolveCompactionTimeoutMs: vi.fn(() => 30_000),
376+
}));
377+
337378
vi.doMock("./wait-for-idle-before-flush.js", () => ({
338379
flushPendingToolResultsAfterIdle: vi.fn(async () => {}),
339380
}));

0 commit comments

Comments
 (0)