#!/usr/bin/env python3 """t1184: new and received blocks avoid a departing rocket stack. Usage: python3 test/t1184-departing-playwright.py URL TAG Logged-out solo game: launch a 3-wide rocket in columns 3-5, let it rise past 75% of the field, then (game clock paused, rendering live) spawn blocks and ingest garbage aimed at the rocket columns. Screenshots the moment and checks every new block is outside the rocket columns. """ import json, sys from pathlib import Path from playwright.sync_api import sync_playwright URL = sys.argv[1] if len(sys.argv) > 1 else "https://projects.timfalken.com/meteors/" TAG = sys.argv[2] if len(sys.argv) > 2 else "live" SHOTS = Path("/workspace/meteors-shots") fails = [] def check(c, m): print(("OK " if c else "FAIL ") + m) if not c: fails.append(m) with sync_playwright() as pw: br = pw.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader"]) for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)): ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1) page = ctx.new_page() errors = [] page.on("pageerror", lambda e: errors.append(str(e))) page.goto(URL + ("" if URL.endswith("/") else "/") + "index.html?t1184=" + TAG, wait_until="networkidle") check(page.evaluate("() => typeof GameCore.prototype.departingColumns === 'function'"), f"{name}: departingColumns in served game.js") page.locator("#btn-survival").click() page.wait_for_selector("#planet-select:not([hidden])", timeout=8000) page.wait_for_timeout(200) page.locator("#btn-planet-go").click() page.wait_for_function("() => window.app && app.mode === 'playing' && app.core", timeout=10000) page.wait_for_timeout(300) # t1187/t1188: spawning speeds up 0.3% per block, from 1 s. page.wait_for_timeout(3200) sp = page.evaluate("() => ({ f: GameCore.SPAWN_SPEEDUP, min: GameCore.SPAWN_INTERVAL_MIN, iv: app.core.spawnInterval })") n = round(__import__("math").log(sp["iv"]) / __import__("math").log(0.997)) if sp["iv"] < 1 else 0 check(sp["f"] == 0.997 and sp["min"] == 0.1 and 0.97 < sp["iv"] < 1, f"{name}: spawn interval {sp['iv']:.4f} s after ~3.5 s of play ({n} spawns × 0.997)") page.evaluate("""() => { const g = app.core; g.spawnInterval = 1e9; for (const b of g.blocks.slice()) g.removeBlock(b); [[0, 2], [1, 3]].forEach(([c, k]) => g.place(c, 0, k)); const row = [3, 4, 5].map(c => g.place(c, 0, 1)); window.__rocket = { row, cluster: g.launchCluster(row, 30) }; }""") page.wait_for_function("""() => { const r = window.__rocket; const live = r.row.filter(b => app.core.blocks.includes(b)); return live.length && Math.max(...live.map(b => b.y)) >= 10.0; }""", timeout=10000, polling="raf") res = page.evaluate("""() => { const g = app.core; g.__tick = g.tick; g.tick = function () {}; const top = Math.max(...window.__rocket.row.map(b => b.y)); const dep = Object.keys(g.departingColumns()).map(Number).sort(); const spawned = []; for (let i = 0; i < 6; i++) { const b = g.trySpawn(); if (b) { b.y = 12 - (i % 3) * 0.2; spawned.push(b.col); } } const garbage = []; for (const c of [3, 4, 5, 4]) { const b = g.ingestGarbage(c); if (b) { b.y = 11; garbage.push(b.col); } } return { top, dep, spawned, garbage, line: g.DEPART_LINE() }; }""") page.wait_for_timeout(120) shot = SHOTS / f"t1184-{TAG}-{name}-departing.png" page.screenshot(path=str(shot)) # Resume: rocket leaves, spawning into those columns is allowed again. after = page.evaluate("""async () => { const g = app.core; g.tick = g.__tick; await new Promise(r => setTimeout(r, 1500)); const left = !window.__rocket.row.some(b => g.blocks.includes(b)); return { left, dep: Object.keys(g.departingColumns()).length }; }""") page.screenshot(path=str(SHOTS / f"t1184-{TAG}-{name}-after-leaving.png")) print(name, json.dumps(res), json.dumps(after)) check(res["top"] >= res["line"] and res["dep"] == [3, 4, 5], f"{name}: rocket top {res['top']:.2f} past 75% ({res['line']}), departing cols {res['dep']}") check(len(res["spawned"]) == 6 and not set(res["spawned"]) & {3, 4, 5}, f"{name}: spawned in {res['spawned']} (not 3-5)") check(len(res["garbage"]) == 4 and not set(res["garbage"]) & {3, 4, 5}, f"{name}: garbage aimed at 3/4/5 landed in {res['garbage']}") check(after["left"] and after["dep"] == 0, f"{name}: rocket left the screen, columns open again") check(not errors, f"{name}: no page errors {errors[:2]}") ctx.close() br.close() print("ALL OK" if not fails else f"{len(fails)} FAIL") sys.exit(1 if fails else 0)