Spaces:
Sleeping
Sleeping
Client: size canvas to viewport, 100% zoom, patch blit no longer clears the screen
Browse files105 unmodified lines10610710810911011111218 unmodified lines13113213313413513613719 unmodified lines157158159160161162105 unmodified lineswith open(os.path.join(HERE, "ui_framebuffer.png"), "wb") as f:f.write(png)img = Image.open(io.BytesIO(png)).convert("RGB")return img, statsdef reg(a, x, y, w, h):18 unmodified linesstdout=open(chromelog, "wb"), stderr=subprocess.STDOUT)try:img, stats = asyncio.run(drive())except SystemExit as e:with open(chromelog, "r", errors="replace") as f:print("chrome log:\n" + f.read()[-3000:])19 unmodified linesassert mae < 14, f"client framebuffer diverged from server (MAE {mae:.1f})"assert coarse < 0.05, f"structural divergence from server ({coarse:.2%})"a = sa # assert fidelity against the authoritative compositeex, ey, ew, eh = EXPLORER105 unmodified lines10610710810911011111211311411511611711811912012118 unmodified lines14014114214314414514619 unmodified lines166167168169170171172173174175176177178179180181182183184185186187188189190191192193105 unmodified lineswith open(os.path.join(HERE, "ui_framebuffer.png"), "wb") as f:f.write(png)img = Image.open(io.BytesIO(png)).convert("RGB")# Force a SMALL, patch-only update, then read the VISIBLE <canvas> (not# the offscreen buffer). Regression: the partial blit used to clear the# whole canvas, blacking out everything except the patched tiles.await c.js("window.NeuralOS.send({type:'move',x:300,y:300})")await asyncio.sleep(0.8)vis = await c.js("document.getElementById('fb').toDataURL('image/png')")assert vis and vis.startswith("data:image/png;base64,"), \"visible canvas dump failed"return img, stats, visdef reg(a, x, y, w, h):18 unmodified linesstdout=open(chromelog, "wb"), stderr=subprocess.STDOUT)try:img, stats, vis = asyncio.run(drive())except SystemExit as e:with open(chromelog, "r", errors="replace") as f:print("chrome log:\n" + f.read()[-3000:])19 unmodified linesassert mae < 14, f"client framebuffer diverged from server (MAE {mae:.1f})"assert coarse < 0.05, f"structural divergence from server ({coarse:.2%})"# --- visible on-screen canvas (what the user actually sees) --------- #vpng = base64.b64decode(vis.split(",", 1)[1])with open(os.path.join(HERE, "ui_visible.png"), "wb") as f:f.write(vpng)vimg = Image.open(io.BytesIO(vpng)).convert("RGB")va = np.asarray(vimg)nonblack = (va.sum(axis=2) > 30).mean()print(f"visible canvas {vimg.size}, non-black {nonblack:.1%}")# The backing store must be sized to the viewport, not left at the# 300x150 <canvas> default and stretched by CSS (that is the "starts# zoomed in / resolution too big" bug).assert min(vimg.size) >= 900, \f"visible canvas backing store is {vimg.size}, not the viewport " \"(layout() did not run)"assert nonblack > 0.5, \"visible canvas went blank after a patch-only update (blit cleared it)"vband = va[int(va.shape[0] * 0.90):, :, :]blueish = ((vband[:, :, 2].astype(int) > vband[:, :, 0].astype(int) + 25)).mean()print(f"visible bottom-blue: {blueish:.1%}")assert blueish > 0.2, \"visible canvas lost the taskbar (patch blit wiped the screen)"a = sa # assert fidelity against the authoritative compositeex, ey, ew, eh = EXPLORER
test_ui_cdp.py+33-2