From c48a7b9f7ea71df290fc1a25fee11645f62a7794 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Feb 2026 11:09:10 -0800 Subject: [PATCH] Fix dev-electron bundle readiness race in CI Co-authored-by: codex --- apps/desktop/scripts/dev-electron.mjs | 39 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/apps/desktop/scripts/dev-electron.mjs b/apps/desktop/scripts/dev-electron.mjs index 5e513e431e..625a25e6b9 100644 --- a/apps/desktop/scripts/dev-electron.mjs +++ b/apps/desktop/scripts/dev-electron.mjs @@ -27,20 +27,51 @@ async function canConnect(host, probePort, timeoutMs = 1_000) { function waitForDesktopBundles(timeoutMs) { const startedAt = Date.now(); - const bundleFiles = ["dist-electron/main.js", "dist-electron/preload.js", "../server/dist/index.mjs"]; + const bundleFiles = [ + { path: "dist-electron/main.js", requireFresh: true }, + { path: "dist-electron/preload.js", requireFresh: true }, + { path: "../server/dist/index.mjs", requireFresh: false }, + ]; return new Promise((resolve, reject) => { const tick = () => { - const missing = bundleFiles.filter((filePath) => !fs.existsSync(filePath)); - if (missing.length === 0) { + const missing = []; + const stale = []; + + for (const bundleFile of bundleFiles) { + if (!fs.existsSync(bundleFile.path)) { + missing.push(bundleFile.path); + continue; + } + if (!bundleFile.requireFresh) { + continue; + } + try { + const stat = fs.statSync(bundleFile.path); + if (stat.mtimeMs < startedAt) { + stale.push(bundleFile.path); + } + } catch { + missing.push(bundleFile.path); + } + } + + if (missing.length === 0 && stale.length === 0) { resolve(); return; } if (Date.now() - startedAt >= timeoutMs) { + const parts = []; + if (missing.length > 0) { + parts.push(`missing: ${missing.join(", ")}`); + } + if (stale.length > 0) { + parts.push(`stale: ${stale.join(", ")}`); + } reject( new Error( - `[dev-electron] timed out after ${timeoutMs}ms waiting for bundles: ${missing.join(", ")}`, + `[dev-electron] timed out after ${timeoutMs}ms waiting for bundles (${parts.join("; ")})`, ), ); return;