diff --git a/apps/desktop/scripts/smoke-window.mjs b/apps/desktop/scripts/smoke-window.mjs index e0a6ceaf2..0165de37e 100644 --- a/apps/desktop/scripts/smoke-window.mjs +++ b/apps/desktop/scripts/smoke-window.mjs @@ -224,12 +224,16 @@ export async function smokeWindow({ window, host, getLocale }) { await waitFor(() => window.webContents.executeJavaScript( "!!document.querySelector('.od-sidebar-project-select:not([aria-current]):not(:disabled)')"), 'No other editable project was available for rapid switching'); + const rapidSwitchDeadline = performance.now() + 40_000; for (let attempt = 0; attempt < 8; attempt++) { + const remaining = Math.floor(rapidSwitchDeadline - performance.now()); + if (remaining <= 0) throw new Error('Rapid project switching exceeded its total wait budget'); + const switchTimeout = Math.min(10_000, remaining); const switched = await window.webContents.executeJavaScript(`(async () => { const target = document.querySelector('.od-sidebar-project-select:not([aria-current]):not(:disabled)'); const canvas = document.querySelector('.react-flow'); for (let click = 0; click < 5; click++) target.click(); - const deadline = performance.now() + 5000; + const deadline = performance.now() + ${switchTimeout}; do { await new Promise(requestAnimationFrame); if (document.querySelector('.canvas-loading-screen') || @@ -241,7 +245,9 @@ export async function smokeWindow({ window, host, getLocale }) { } while (performance.now() < deadline); return false; })()`); - if (!switched) throw new Error('Rapid project switching did not settle'); + if (!switched) { + throw new Error(`Rapid project switching did not settle on switch ${attempt + 1} of 8 within ${switchTimeout} ms`); + } } result.sidebarFinallyOpen = process.env.OPENDIRECTOR_DESKTOP_SMOKE_SIDEBAR === 'open'; if (await window.webContents.executeJavaScript("document.querySelector('.cw-workspace').dataset.desktopSidebar === 'open'") !== result.sidebarFinallyOpen) {