From c96d612393dd6c59e6e4a3982d31662e950b98bf Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 3 Nov 2026 13:34:13 +0000 Subject: [PATCH] test(ui-react): await recording commits by event instead of a 1 s poll The native-capture precondition in recording-limits.offline.tsx waited for two committed chunks inside expect.poll's default 1 s window, so a loaded runner failed before the stop-normalization assertions ran (#3475). recordingCell now exposes committed(count), which resolves on the store's committed event; the test timeout stays the only failure bound. All five native-capture waits in the file use it; assertions are unchanged. Refs #3475 Co-Authored-By: Claude Opus 5.5 --- .../tests/browser/offline/recording-cell.ts | 19 ++++++++++++++++++- .../browser/recording-limits.offline.tsx | 11 +++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/packages/ui-react/tests/browser/offline/recording-cell.ts b/packages/ui-react/tests/browser/offline/recording-cell.ts index 07b3a50574..6382d30a5d 100644 --- a/packages/ui-react/tests/browser/offline/recording-cell.ts +++ b/packages/ui-react/tests/browser/offline/recording-cell.ts @@ -13,6 +13,23 @@ export function recordingCell(ctx: TestContext) { const events: RecordingEvent[] = []; const cleanup: Array<() => void> = []; store.onEvent((event) => events.push(event)); + const committedCount = () => events.filter((event) => event.kind === "committed").length; + /** + * Resolves when the store has emitted at least `count` committed events. + * Native capture commits in real time, so a fixed polling window measures + * runner load rather than the precondition; the test timeout stays the + * only failure bound. The recorder above runs first, so `events` already + * holds the event a later listener is told about. + */ + const committed = (count: number) => new Promise((resolve) => { + if (committedCount() >= count) return resolve(); + const unsubscribe = store.onEvent(() => { + if (committedCount() < count) return; + unsubscribe(); + resolve(); + }); + cleanup.push(unsubscribe); + }); ctx.onTestFinished(async () => { const failures: unknown[] = []; for (const finish of [...cleanup.reverse(), () => store.stop("interrupted"), () => store.dispose(), () => root.dispose()]) { @@ -20,5 +37,5 @@ export function recordingCell(ctx: TestContext) { } if (failures.length) throw new AggregateError(failures, "Recording fixture cleanup failed"); }); - return { root, partitions, store, events, cleanup, account: (key: string | null) => { held = key; root.stores.connection.getState().setVpnStatus(key ? "connected" : "unauthorized", key); } }; + return { root, partitions, store, events, committed, committedCount, cleanup, account: (key: string | null) => { held = key; root.stores.connection.getState().setVpnStatus(key ? "connected" : "unauthorized", key); } }; } diff --git a/packages/ui-react/tests/browser/recording-limits.offline.tsx b/packages/ui-react/tests/browser/recording-limits.offline.tsx index 66dadbdf7c..879a2c2d58 100644 --- a/packages/ui-react/tests/browser/recording-limits.offline.tsx +++ b/packages/ui-react/tests/browser/recording-limits.offline.tsx @@ -25,7 +25,7 @@ test("registered production warning and deadline finalize short native audio and // real time. Invoking a registered callback proves its real stop path; the // separate controlled-timer test proves when it is scheduled. Neither this // short recording nor synthetic boundary blobs prove ten-minute endurance. - await expect.poll(() => c.events.filter((event) => event.kind === "committed").length).toBeGreaterThanOrEqual(2); + await c.committed(2); expect(registered.has(540_000), "production warning registered at nine minutes").toBe(true); expect(registered.has(599_750), "production deadline registered at ten minutes").toBe(true); expect(updateHeld(c.root)).toBe(true); @@ -181,12 +181,11 @@ test("source starvation reports only encoded audio", async (ctx) => { c.cleanup.push(() => mic.restore()); const start = performance.now(); const capture = await c.store.start({ timesliceMs: 250 }); - await expect.poll(() => c.events.filter(e => e.kind === "committed").length).toBeGreaterThanOrEqual(2); + await c.committed(2); await mic.contexts[0]!.suspend(); await new Promise(resolve => setTimeout(resolve, 1200)); await mic.contexts[0]!.resume(); - const before = c.events.filter(e => e.kind === "committed").length; - await expect.poll(() => c.events.filter(e => e.kind === "committed").length).toBeGreaterThanOrEqual(before + 2); + await c.committed(c.committedCount() + 2); await capture.stop("user"); const elapsed = performance.now() - start; const row = (await c.store.list("account:odysseus"))[0]!; @@ -311,7 +310,7 @@ test("registered wall backstop finalizes native audio as interrupted", async (ct // real time. Invoking a registered callback proves its real stop path; the // separate controlled-timer test proves when it is scheduled. Neither this // short recording nor synthetic boundary blobs prove ten-minute endurance. - await expect.poll(() => c.events.filter((event) => event.kind === "committed").length).toBeGreaterThanOrEqual(2); + await c.committed(2); expect(registered.has(540_000), "production warning registered at nine minutes").toBe(true); expect(registered.has(599_750), "production deadline registered at ten minutes").toBe(true); expect(updateHeld(c.root)).toBe(true); @@ -374,7 +373,7 @@ test("late limit at the committed flush target stops without a zero-delay re-arm test("caller stop at expired wall deadline normalizes before first-stop-wins", async (ctx) => { const c = recordingCell(ctx); const capture = await c.store.start({ timesliceMs: 250 }); - await expect.poll(() => c.events.filter(e => e.kind === "committed").length).toBeGreaterThanOrEqual(2); + await c.committed(2); const descriptor = Object.getOwnPropertyDescriptor(performance, "now"); Object.defineProperty(performance, "now", { configurable: true, value: () => 1e12 }); c.cleanup.push(() => { if (descriptor) Object.defineProperty(performance, "now", descriptor); else delete (performance as { now?: unknown }).now; });