test(android): self-healing WebView handle, fresh emulator, diagnostics (KI-015)

- lib/cdp.mjs: attach to the visible, non-empty page target (a replaced WebView can
  leave the old target listed first); a closed DevTools socket fails pending calls at
  once instead of hanging; every call has a timeout.
- lib/android.mjs: attach() follows the app's current process (socket named after its
  pid; an old one can linger) and re-attaches before a call when the process or the
  live page changed; a call cut off by the page going away is retried once.
  ensureDevice() reboots an emulator up longer than EMULATOR_MAX_UPTIME_MIN (30).
- android.mjs: switching venues waits until /venues lists them (the app may still be
  reloading into the last venue's bundle); a rediscovery timeout logs the page's DOM
  and console next to the screenshot.

Run alone: rediscovery 7/7, basics 3/3, stacks 21/21.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 03:35:02 +02:00
co-authored by Claude Opus 5.5
parent 8abe4d92d3
commit bcf91bf6e9
3 changed files with 120 additions and 19 deletions
+12 -2
View File
@@ -184,7 +184,13 @@ async function rediscovery() {
return false
} catch { v = await attach().catch(() => v); return false }
}, ms, 500)
if (!ok) shot(`android-rediscovery-timeout-${++shots}`)
if (!ok) {
shot(`android-rediscovery-timeout-${++shots}`)
// what the page really holds (a blank screen: render crash? gate stuck?) and its console
const dom = await v.evaluate("location.pathname + ' | root: ' + (document.getElementById('root')?.innerHTML || '').slice(0, 300)").catch(e => String(e))
console.log(` timeout ${shots}: ${dom}
console: ${v.logs.slice(-8).join(' || ').slice(0, 1500)}`)
}
return ok
}
r.check('setup: paired and logged in', !!(await onScreen(async vv => (await vv.evaluate('location.pathname')) === '/tables', 45_000)))
@@ -365,7 +371,11 @@ server { listen 443 ssl; ssl_certificate /t/cert.pem; ssl_certificate_key /t/key
let s = await waitFor(async () => { const st = await state(); return st.active === 'test-site-2' && st.current === m2.version && st }, 90_000, 2000)
r.check('bundles: pairing venue 2 → venue 2 bundle', !!s)
const switchTo = async (label, site, want) => {
const vv = await attach(); await goTo(vv, '/venues'); await sleep(1200); await tap(vv, 'button', label); vv.close()
// the app may still be reloading into the last venue's bundle: open /venues until the list shows
const vv = await attach()
const listed = `[...document.querySelectorAll('button')].some(e => e.textContent.includes(${JSON.stringify(label)}))`
await waitFor(async () => { if (await vv.evaluate(listed)) return true; await goTo(vv, '/venues'); return false }, 30_000, 1500)
await tap(vv, 'button', label); vv.close()
return waitFor(async () => { const st = await state(); return st.active === site && st.current === want && st }, 90_000, 2000)
}
await switchTo(`${H}:18443`, 'test-site-1', manifest.version)