import asyncio, json from playwright.async_api import async_playwright async def main(): async with async_playwright() as p: b = await p.chromium.launch(args=["--no-sandbox"]) pg = await b.new_page(viewport={"width": 1600, "height": 1100}, device_scale_factor=1.5) errs = [] pg.on("pageerror", lambda e: errs.append(f"PAGEERR {e}")) pg.on("console", lambda m: errs.append(f"CONSOLE {m.text}") if m.type == "error" else None) await pg.goto("https://parastoo.zebellkhan.com/", wait_until="networkidle", timeout=90000) await pg.wait_for_timeout(3500) # --- 1) health gate must report OFFLINE (reachable=false) --- await pg.click('#tabs button[data-view="sync"]') await pg.wait_for_timeout(3500) health = await pg.evaluate("""() => ({ box: document.getElementById('jiraHealthBox')?.innerText.trim().slice(0,140), status: document.getElementById('jiraStatus')?.innerText, reachable: window.__lastProbe || null })""") # --- 2) confirm gate: inject a pending task, then invoke syncSheet() --- gate = await pg.evaluate("""async () => { // seed one unsynced task exactly like the UI would const t = {id:'gate-test-1', title:'تست دروازه تایید — طراحی استوری', cat:'instagram', est:1, act:1.5, status:'done', pri:'mid', note:'', adhoc:true, date: new Date().toISOString().slice(0,10), synced_jira:true, synced_sheet:false}; // use the dashboard's own state if reachable, else fall back to a local probe let target = null; try { target = tasks; } catch(e) {} if (Array.isArray(target)) { target.push(t); if (typeof renderSync==='function') renderSync(); } // now call the real function and observe the modal const p = syncSheet(); await new Promise(r => setTimeout(r, 1200)); const ov = document.querySelector('.overlay'); const res = { modalShown: !!ov, title: ov ? ov.querySelector('.modal-title')?.innerText : null, body: ov ? ov.querySelector('.modal-body')?.innerText.slice(0,180) : null, hasConfirm: !!ov?.querySelector('#cfmOk'), hasCancel: !!ov?.querySelector('#cfmNo'), seeded: Array.isArray(target) }; return res; }""") await pg.wait_for_timeout(500) await pg.screenshot(path="/workspace/parastoo_dashboard/audit/gate_modal.png", full_page=False) # --- 3) click CANCEL and assert nothing was written --- cancelled = await pg.evaluate("""() => { const ov = document.querySelector('.overlay'); if (!ov) return {clicked:false}; ov.querySelector('#cfmNo')?.click(); return {clicked:true, stillOpen: !!document.querySelector('.overlay')}; }""") await pg.wait_for_timeout(800) after = await pg.evaluate("""() => ({ stillOpen: !!document.querySelector('.overlay'), sheetStatus: document.getElementById('sheetStatus')?.innerText })""") print(json.dumps({"health": health, "gate": gate, "cancelled": cancelled, "after": after, "errors": errs[:6]}, ensure_ascii=False, indent=2)) await b.close() asyncio.run(main())