From 8bb592cc2c45d95e9d933127f077b214b2b37bf4 Mon Sep 17 00:00:00 2001 From: insipx Date: Thu, 9 Jul 2026 19:25:56 +0000 Subject: [PATCH] fix(node-sdk): deflake `should stream preferences` test The `Preferences > should stream preferences` test ended its stream on a fixed 100ms timer, far shorter than the 2000ms used by every other streaming test. The two HmacKeyUpdate events depend on network propagation of newly-registered installations, so the 4th update frequently arrived after the 100ms window, ending the stream early and failing with `expected 3 to be 4`. Collect updates until all 4 expected preferences arrive, then end the stream, with a generous 10s safety-net timeout so a genuine regression fails with the same clear assertion instead of hanging. Resolves #3831 Co-Authored-By: Claude Opus 4.8 --- sdks/js/node-sdk/test/Preferences.test.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/sdks/js/node-sdk/test/Preferences.test.ts b/sdks/js/node-sdk/test/Preferences.test.ts index 6b6b6c2624..900660d41a 100644 --- a/sdks/js/node-sdk/test/Preferences.test.ts +++ b/sdks/js/node-sdk/test/Preferences.test.ts @@ -205,14 +205,25 @@ describe("Preferences", () => { await client2.conversations.syncAll(); await sleep(1000); - setTimeout(() => { + const preferences: UserPreferenceUpdate[] = []; + + // Safety net: end the stream if the expected updates never arrive, so the + // assertion below fails clearly instead of the test hanging until timeout. + // The HmacKeyUpdate events depend on network propagation, so we collect + // until we have all 4 expected updates rather than ending on a fixed timer. + const endTimeout = setTimeout(() => { void stream.end(); - }, 100); + }, 10000); - const preferences: UserPreferenceUpdate[] = []; for await (const update of stream) { preferences.push(...update); + if (preferences.length >= 4) { + break; + } } + clearTimeout(endTimeout); + await stream.end(); + expect(preferences.length).toBe(4); const consentUpdate1 = preferences[0] as Extract< UserPreferenceUpdate,