// Carry the two harness fixes (a8adce0, 9bfbcfc) into a snapshot: the attach // retry in cdp.mjs, and the wait-for-the-app block in smoke.mjs. cdp.mjs is // copied wholesale (no round touches it); smoke.mjs is edited in place, // because rounds applied to the snapshot own the rest of that file. const fs = require('fs'); const snap = process.argv[process.argv.length - 1]; const repo = 'F:/Coding/SoulStream'; fs.copyFileSync(repo + '/tests/mobile/cdp.mjs', snap + '/tests/mobile/cdp.mjs'); const f = snap + '/tests/mobile/smoke.mjs'; let s = fs.readFileSync(f, 'utf8'); const anchor = ` console.log("attached to the phone's WebView (pid " + pid + ")");`; if (s.includes('the app never came up on the phone')) { console.log('already carries the wait'); } else if (!s.includes(anchor)) { throw new Error('anchor missing in ' + f); } else { const block = anchor + ` /* A walk follows a fresh install, so the app is always cold here: the shell mounts, the library loads, Soulseek logs in and the share index is built. Attaching only proves the WebView answers — it says nothing about the app being up. Starting anyway means the first steps run against a half-mounted page and get reported as broken features, which is exactly how an hour went once. Wait for the handle the walk actually drives. */ const upFrom = Date.now(); let up = false; while (Date.now() - upFrom < 90_000) { try { if (await cdp.evaluate(\`!!(window.__ss && document.querySelector('.app'))\`) === true) { up = true; break; } } catch { /* a page mid-navigation answers nothing; ask again */ } await sleep(1000); } if (!up) throw new Error("the app never came up on the phone (no __ss and no .app after 90s)"); console.log("the app is up (" + ((Date.now() - upFrom) / 1000).toFixed(1) + "s after attaching)");`; s = s.replace(anchor, () => block); fs.writeFileSync(f, s); console.log('wait inserted'); }