"""Record all approved viewport/motion combinations against actual product controls.""" import json from playwright.sync_api import expect def record_motion(page, data, out): base = "http://127.0.0.1:18740" checks = [] screenshots = out / "motion" screenshots.mkdir(exist_ok=True) (data / "control.json").write_text("{}") def geometry(): return page.evaluate( """()=>{const media=document.querySelector('.stage-media .print').getBoundingClientRect(),dock=document.querySelector('.studio-form').getBoundingClientRect(),button=document.querySelector('.gen').getBoundingClientRect();return {mediaHeight:media.height,mediaBottom:media.bottom,dockTop:dock.top,gap:dock.top-media.bottom,generateBottom:button.bottom,viewport:innerHeight}}""" ) for width, height in [(1440, 900), (1366, 768), (1280, 720)]: page.set_viewport_size({"width": width, "height": height}) for mode, label in [("full", "完整"), ("calm", "克制"), ("off", "关闭")]: page.goto(base + "/image") page.locator(".stage-media .print img").wait_for() page.locator("#desk-prompt").fill("保留我的输入,柔和侧光") page.get_by_role("button", name="主题", exact=True).click() page.get_by_role("dialog").get_by_role( "button", name=label, exact=True ).click() page.keyboard.press("Escape") before = geometry() page.locator(".pt-buttons").first.get_by_role("button").first.click() page.locator(".pt-res").wait_for() opened = geometry() expect(page.locator("#desk-prompt")).to_have_value("保留我的输入,柔和侧光") page.screenshot(path=str(screenshots / f"{width}-{mode}-result.png")) page.get_by_role("button", name="关闭提示词结果").click() page.wait_for_timeout(100) after = geometry() assert opened["gap"] >= 47 and opened["generateBottom"] <= height assert abs(before["mediaHeight"] - after["mediaHeight"]) <= 1 checks.append( { "viewport": [width, height], "mode": mode, "before": before, "opened": opened, "after": after, } ) print(f"verified motion {width} {mode}", flush=True) page.set_viewport_size({"width": 1440, "height": 900}) for mode, label in [("full", "完整"), ("calm", "克制"), ("off", "关闭")]: page.goto(base + "/agents") page.get_by_role("button", name="主题", exact=True).click() page.get_by_role("dialog").get_by_role("button", name=label, exact=True).click() page.keyboard.press("Escape") # Full mode restarts only on a new page/task trigger by the approved existing policy. page.reload() page.wait_for_timeout(1000) assert page.locator(".orb .ring").count() == 2 rings = page.locator(".orb .ring").evaluate_all( "(nodes)=>nodes.map(n=>({animation:getComputedStyle(n).animationName,duration:getComputedStyle(n).animationDuration,display:getComputedStyle(n).display}))" ) page.screenshot(path=str(screenshots / f"agent-rings-{mode}.png")) checks.append({"agent": mode, "rings": rings}) (out / "motion-checks.json").write_text( json.dumps(checks, ensure_ascii=False, indent=2) )