Files
CyberGril/samples/companion/tools/check_races.py
T
2026-10-21 02:03:02 +08:00

66 lines
2.8 KiB
Python

"""Cancel during ICE/offer, then verify a late old error cannot stop a new turn."""
import asyncio
import json
import pathlib
import sys
from playwright.async_api import async_playwright
OUT = pathlib.Path(sys.argv[1]) if len(sys.argv) > 1 else pathlib.Path(__file__).resolve().parents[1] / "evidence"
OUT.mkdir(parents=True, exist_ok=True)
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(
args=["--no-sandbox", "--autoplay-policy=no-user-gesture-required"]
)
context = await browser.new_context(ignore_https_errors=True)
page = await context.new_page()
errors = []
page.on("pageerror", lambda e: errors.append(str(e)))
try:
await page.goto("https://192.168.200.12:8014")
await page.wait_for_function(
"document.querySelector('#status').textContent.includes('就绪')"
)
await page.click("#enter")
await page.wait_for_function(
"document.querySelector('#status').textContent.includes('正在听')", timeout=40000
)
await page.fill("#text", "这一轮马上取消。")
await page.click("button[type=submit]")
await page.wait_for_timeout(100)
await page.click("#cancel")
await page.fill("#text", "新一轮只回复:你好。")
await page.click("button[type=submit]")
await page.wait_for_function(
"window.sampleEvents.some(e=>e.event==='first-audible')", timeout=45000
)
await page.wait_for_timeout(10000)
events = await page.evaluate("window.sampleEvents")
failures = [
e for e in events if e["event"] == "status" and "媒体协商超时" in str(e["detail"])
]
result = {"pageerrors": errors, "late_error_failures": failures, "events": events}
(OUT / "race-check.json").write_text(json.dumps(result, ensure_ascii=False, indent=2))
assert not failures
await page.click("#back")
await page.wait_for_timeout(4000)
finally:
(OUT / "race-page-state.json").write_text(json.dumps({
"url": page.url,
"status": await page.locator('#status').inner_text(),
"events": await page.evaluate('window.sampleEvents'),
"pageerrors": errors,
"media": await page.locator('video').evaluate_all(
'(vs)=>vs.map(v=>({id:v.id, ready:v.readyState, paused:v.paused, time:v.currentTime}))'),
}, ensure_ascii=False, indent=2))
await page.screenshot(path=str(OUT / 'race-final.png'))
await browser.close()
print("ICE cancellation race passed", flush=True)
asyncio.run(main())