From e027e6bba31c6bccea0d09b147a65c5229abc594 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 31 Jan 2026 03:08:33 +0000 Subject: [PATCH] chore(ai): CI health fixes (flaky tests) - Fix flaky `tests/hashtag-preferences.test.mjs` by correcting mock implementation for `fetchListIncrementally`. - Fix `tests/nostr-login-permissions.test.mjs` failure by requesting correct permissions in `js/nostr/client.js`. - Fix 90s timeout in `HashtagPreferencesService` by clearing the timeout timer upon successful decryption. - `npm install` was run to ensure dependencies like `jsdom` are present for `tests/app/channel-profile-moderation.test.mjs`. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- js/nostr/client.js | 2 +- js/services/hashtagPreferencesService.js | 29 +++++++++++++----------- tests/hashtag-preferences.test.mjs | 4 +--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/js/nostr/client.js b/js/nostr/client.js index 1ab71bac..2b7e5ae3 100644 --- a/js/nostr/client.js +++ b/js/nostr/client.js @@ -2079,7 +2079,7 @@ export class NostrClient { } const permissionResult = await this.ensureExtensionPermissions( - DEFAULT_NIP07_CORE_METHODS, + DEFAULT_NIP07_PERMISSION_METHODS, { context: "login", logMetrics: true, showStatus: false }, ); if (!permissionResult.ok) { diff --git a/js/services/hashtagPreferencesService.js b/js/services/hashtagPreferencesService.js index bc481a51..28ef0d40 100644 --- a/js/services/hashtagPreferencesService.js +++ b/js/services/hashtagPreferencesService.js @@ -775,19 +775,22 @@ class HashtagPreferencesService { const decryptPromise = this.decryptEvent(latest, normalized, { allowPermissionPrompt, }); - const timeoutPromise = new Promise((_, reject) => - setTimeout( - () => { - const timeoutError = new Error( - `Decryption timed out after ${DECRYPT_TIMEOUT_MS / 1000}s`, - ); - timeoutError.code = "hashtag-preferences-decrypt-timeout"; - reject(timeoutError); - }, - DECRYPT_TIMEOUT_MS, - ), - ); - decryptResult = await Promise.race([decryptPromise, timeoutPromise]); + let timeoutId; + const timeoutPromise = new Promise((_, reject) => { + timeoutId = setTimeout(() => { + const timeoutError = new Error( + `Decryption timed out after ${DECRYPT_TIMEOUT_MS / 1000}s`, + ); + timeoutError.code = "hashtag-preferences-decrypt-timeout"; + reject(timeoutError); + }, DECRYPT_TIMEOUT_MS); + }); + + try { + decryptResult = await Promise.race([decryptPromise, timeoutPromise]); + } finally { + if (timeoutId) clearTimeout(timeoutId); + } } catch (error) { decryptResult = { ok: false, error }; } diff --git a/tests/hashtag-preferences.test.mjs b/tests/hashtag-preferences.test.mjs index f72827cd..afd68da7 100644 --- a/tests/hashtag-preferences.test.mjs +++ b/tests/hashtag-preferences.test.mjs @@ -248,10 +248,8 @@ test( tags: [["encrypted", "nip04"]], }; - let fetchCalls = 0; nostrClient.fetchListIncrementally = async () => { - fetchCalls += 1; - return fetchCalls === 1 ? [event] : []; + return [event]; }; nostrClient.relays = relayUrls; nostrClient.writeRelays = relayUrls;