Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(bounded-exec): keep the dropped-event simulation inside its own test
garrytan3af6b215768d
diff --git a/test/bounded-child-exec.test.ts b/test/bounded-child-exec.test.tsindex 9f99d5a91f..e1ad5378df 100644--- a/test/bounded-child-exec.test.ts+++ b/test/bounded-child-exec.test.ts@@ -13,17 +13,25 @@ afterAll(() => rmSync(dir, { recursive: true, force: true }));* pipe events of the same poll batch (still on 1.4.2) and, before 1.3.14, the* exit events too (oven-sh/bun#30301), which is how managed-maintenance, persistence-reconcile* and google-attachments hung behind a persistence consumer's git probe.+ * It returns only after its nested tick has returned and every one of its+ * children has exited, so the nested tick cannot land in a later test and+ * drop that test's pipe events. Awaiting the exits alone is not enough: the+ * nested tick runs this function's continuation from inside itself.*/-function nestedTickDuring<T>(work: () => Promise<T>[]): Promise<T[]> {+async function nestedTickDuring<T>(work: () => Promise<T>[]): Promise<T[]> {+ const nestedTick = Promise.withResolvers<void>();let nested = false;- for (let i = 0; i < 20; i++) {- Bun.spawn(['true'], { stdio: ['ignore', 'ignore', 'ignore'], onExit() {- if (nested) return;- nested = true;- void expect(Bun.sleep(1)).resolves.toBeUndefined();- } });+ const children = Array.from({ length: 20 }, () => Bun.spawn(['true'], { stdio: ['ignore', 'ignore', 'ignore'], onExit() {+ if (nested) return;+ nested = true;+ void expect(Bun.sleep(1)).resolves.toBeUndefined();+ nestedTick.resolve();+ } }));+ try {+ return await Promise.all(work());+ } finally {+ await Promise.all([nestedTick.promise, ...children.map(child => child.exited)]);}- return Promise.all(work());}function within<T>(ms: number, promise: Promise<T>): Promise<T | 'unsettled'> {@@ -53,6 +61,14 @@ test('bounded execution keeps execFile exit codes and stdout', async () => {expect(await execFileBounded('sh', ['-c', 'printf ok'], { timeout: 10_000 })).toEqual({ error: null, stdout: 'ok', stderr: '' });});+test('a dropped-event simulation ends before the next child starts', async () => {+ for (let i = 0; i < 100; i++) {+ await nestedTickDuring(() => []);+ expect(await execFileBounded('sh', ['-c', 'printf example; printf refusal >&2; exit 3'], { timeout: 10_000 }))+ .toMatchObject({ stdout: 'example', stderr: 'refusal', error: { code: 3 } });+ }+});+test('bounded execution stops a running child on abort and at its deadline', async () => {const abort = new AbortController();const started = performance.now();