exec(open('ui_test.py').read().split("with sync_playwright() as pw:")[0])
with sync_playwright() as pw:
    b = pw.chromium.launch(); ctx = b.new_context(viewport={'width': 390, 'height': 844}, is_mobile=True, has_touch=True); p, errs = login(ctx)
    p.goto(BASE + '#/settings/sample'); p.wait_for_selector('#smpLoad'); ok(noscroll(p), 'phone: sample page fits'); p.screenshot(path='/tmp/ph-sample.png')
    p.click('#smpLoad')
    if p.query_selector('text=Replace the sample agents?'): p.click('text=Replace sample data')
    p.wait_for_url('**#/team', timeout=20000); p.wait_for_timeout(1500)
    ok(int(sql("SELECT COUNT(*) FROM agents WHERE agent_code LIKE 'DEMO%'")) == 20, 'phone: button loads 20 sample agents')
    ok(noscroll(p), 'phone: All agents fits'); p.screenshot(path='/tmp/ph-team.png')
    a = sql("SELECT id FROM agents WHERE agent_code='DEMO8'")
    for nm, path in [('ov', f'#/agents/{a}/overview'), ('vis', f'#/agents/{a}/vision'), ('pipe', f'#/agents/{a}/pipeline')]:
        p.goto(BASE + path); p.wait_for_timeout(1800); ok(noscroll(p), f'phone: {nm} fits'); p.screenshot(path=f'/tmp/ph-{nm}.png')
    ok(not errs, 'no script errors', errs[:2])
print(f"{sum(R)} passed, {len(R)-sum(R)} failed")
