Spaces:
Sleeping
Sleeping
Client: size canvas to viewport, 100% zoom, patch blit no longer clears the screen
Browse files- test_ui_cdp.py +33 -2
test_ui_cdp.py
CHANGED
|
@@ -106,7 +106,16 @@ async def drive():
|
|
| 106 |
with open(os.path.join(HERE, "ui_framebuffer.png"), "wb") as f:
|
| 107 |
f.write(png)
|
| 108 |
img = Image.open(io.BytesIO(png)).convert("RGB")
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
|
| 112 |
def reg(a, x, y, w, h):
|
|
@@ -131,7 +140,7 @@ def main():
|
|
| 131 |
stdout=open(chromelog, "wb"), stderr=subprocess.STDOUT)
|
| 132 |
|
| 133 |
try:
|
| 134 |
-
img, stats = asyncio.run(drive())
|
| 135 |
except SystemExit as e:
|
| 136 |
with open(chromelog, "r", errors="replace") as f:
|
| 137 |
print("chrome log:\n" + f.read()[-3000:])
|
|
@@ -157,6 +166,28 @@ def main():
|
|
| 157 |
assert mae < 14, f"client framebuffer diverged from server (MAE {mae:.1f})"
|
| 158 |
assert coarse < 0.05, f"structural divergence from server ({coarse:.2%})"
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
a = sa # assert fidelity against the authoritative composite
|
| 161 |
|
| 162 |
ex, ey, ew, eh = EXPLORER
|
|
|
|
| 106 |
with open(os.path.join(HERE, "ui_framebuffer.png"), "wb") as f:
|
| 107 |
f.write(png)
|
| 108 |
img = Image.open(io.BytesIO(png)).convert("RGB")
|
| 109 |
+
|
| 110 |
+
# Force a SMALL, patch-only update, then read the VISIBLE <canvas> (not
|
| 111 |
+
# the offscreen buffer). Regression: the partial blit used to clear the
|
| 112 |
+
# whole canvas, blacking out everything except the patched tiles.
|
| 113 |
+
await c.js("window.NeuralOS.send({type:'move',x:300,y:300})")
|
| 114 |
+
await asyncio.sleep(0.8)
|
| 115 |
+
vis = await c.js("document.getElementById('fb').toDataURL('image/png')")
|
| 116 |
+
assert vis and vis.startswith("data:image/png;base64,"), \
|
| 117 |
+
"visible canvas dump failed"
|
| 118 |
+
return img, stats, vis
|
| 119 |
|
| 120 |
|
| 121 |
def reg(a, x, y, w, h):
|
|
|
|
| 140 |
stdout=open(chromelog, "wb"), stderr=subprocess.STDOUT)
|
| 141 |
|
| 142 |
try:
|
| 143 |
+
img, stats, vis = asyncio.run(drive())
|
| 144 |
except SystemExit as e:
|
| 145 |
with open(chromelog, "r", errors="replace") as f:
|
| 146 |
print("chrome log:\n" + f.read()[-3000:])
|
|
|
|
| 166 |
assert mae < 14, f"client framebuffer diverged from server (MAE {mae:.1f})"
|
| 167 |
assert coarse < 0.05, f"structural divergence from server ({coarse:.2%})"
|
| 168 |
|
| 169 |
+
# --- visible on-screen canvas (what the user actually sees) --------- #
|
| 170 |
+
vpng = base64.b64decode(vis.split(",", 1)[1])
|
| 171 |
+
with open(os.path.join(HERE, "ui_visible.png"), "wb") as f:
|
| 172 |
+
f.write(vpng)
|
| 173 |
+
vimg = Image.open(io.BytesIO(vpng)).convert("RGB")
|
| 174 |
+
va = np.asarray(vimg)
|
| 175 |
+
nonblack = (va.sum(axis=2) > 30).mean()
|
| 176 |
+
print(f"visible canvas {vimg.size}, non-black {nonblack:.1%}")
|
| 177 |
+
# The backing store must be sized to the viewport, not left at the
|
| 178 |
+
# 300x150 <canvas> default and stretched by CSS (that is the "starts
|
| 179 |
+
# zoomed in / resolution too big" bug).
|
| 180 |
+
assert min(vimg.size) >= 900, \
|
| 181 |
+
f"visible canvas backing store is {vimg.size}, not the viewport " \
|
| 182 |
+
"(layout() did not run)"
|
| 183 |
+
assert nonblack > 0.5, \
|
| 184 |
+
"visible canvas went blank after a patch-only update (blit cleared it)"
|
| 185 |
+
vband = va[int(va.shape[0] * 0.90):, :, :]
|
| 186 |
+
blueish = ((vband[:, :, 2].astype(int) > vband[:, :, 0].astype(int) + 25)).mean()
|
| 187 |
+
print(f"visible bottom-blue: {blueish:.1%}")
|
| 188 |
+
assert blueish > 0.2, \
|
| 189 |
+
"visible canvas lost the taskbar (patch blit wiped the screen)"
|
| 190 |
+
|
| 191 |
a = sa # assert fidelity against the authoritative composite
|
| 192 |
|
| 193 |
ex, ey, ew, eh = EXPLORER
|