t1184: Playwright check for departing columns and spawn speed-up
@@ -0,0 +1,84 @@
1
#!/usr/bin/env python3
2
"""t1184: new and received blocks avoid a departing rocket stack.
3
4
Usage: python3 test/t1184-departing-playwright.py URL TAG
5
Logged-out solo game: launch a 3-wide rocket in columns 3-5, let it rise
6
past 75% of the field, then (game clock paused, rendering live) spawn
7
blocks and ingest garbage aimed at the rocket columns. Screenshots the
8
moment and checks every new block is outside the rocket columns.
9
"""
10
import json, sys
11
from pathlib import Path
12
from playwright.sync_api import sync_playwright
13
14
URL = sys.argv[1] if len(sys.argv) > 1 else "https://projects.timfalken.com/meteors/"
15
TAG = sys.argv[2] if len(sys.argv) > 2 else "live"
16
SHOTS = Path("/workspace/meteors-shots")
17
fails = []
18
19
def check(c, m):
20
print(("OK " if c else "FAIL ") + m)
21
if not c: fails.append(m)
22
23
with sync_playwright() as pw:
24
br = pw.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader"])
25
for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):
26
ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)
27
page = ctx.new_page()
28
errors = []
29
page.on("pageerror", lambda e: errors.append(str(e)))
30
page.goto(URL + ("" if URL.endswith("/") else "/") + "index.html?t1184=" + TAG, wait_until="networkidle")
31
check(page.evaluate("() => typeof GameCore.prototype.departingColumns === 'function'"), f"{name}: departingColumns in served game.js")
32
page.locator("#btn-play").click()
33
page.wait_for_selector("#planet-select:not([hidden])", timeout=8000)
34
page.wait_for_timeout(200)
35
page.locator("#btn-planet-go").click()
36
page.wait_for_function("() => window.app && app.mode === 'playing' && app.core", timeout=10000)
37
page.wait_for_timeout(300)
38
# t1187/t1188: spawning speeds up 0.3% per block, from 1 s.
39
page.wait_for_timeout(3200)
40
sp = page.evaluate("() => ({ f: GameCore.SPAWN_SPEEDUP, min: GameCore.SPAWN_INTERVAL_MIN, iv: app.core.spawnInterval })")
41
n = round(__import__("math").log(sp["iv"]) / __import__("math").log(0.997)) if sp["iv"] < 1 else 0
42
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)")
43
page.evaluate("""() => {
44
const g = app.core;
45
g.spawnInterval = 1e9;
46
for (const b of g.blocks.slice()) g.removeBlock(b);
47
[[0, 2], [1, 3]].forEach(([c, k]) => g.place(c, 0, k));
48
const row = [3, 4, 5].map(c => g.place(c, 0, 1));
49
window.__rocket = { row, cluster: g.launchCluster(row, 30) };
50
}""")
51
page.wait_for_function("""() => { const r = window.__rocket; const live = r.row.filter(b => app.core.blocks.includes(b));
52
return live.length && Math.max(...live.map(b => b.y)) >= 10.0; }""", timeout=10000, polling="raf")
53
res = page.evaluate("""() => {
54
const g = app.core;
55
g.__tick = g.tick; g.tick = function () {};
56
const top = Math.max(...window.__rocket.row.map(b => b.y));
57
const dep = Object.keys(g.departingColumns()).map(Number).sort();
58
const spawned = [];
59
for (let i = 0; i < 6; i++) { const b = g.trySpawn(); if (b) { b.y = 12 - (i % 3) * 0.2; spawned.push(b.col); } }
60
const garbage = [];
61
for (const c of [3, 4, 5, 4]) { const b = g.ingestGarbage(c); if (b) { b.y = 11; garbage.push(b.col); } }
62
return { top, dep, spawned, garbage, line: g.DEPART_LINE() };
63
}""")
64
page.wait_for_timeout(120)
65
shot = SHOTS / f"t1184-{TAG}-{name}-departing.png"
66
page.screenshot(path=str(shot))
67
# Resume: rocket leaves, spawning into those columns is allowed again.
68
after = page.evaluate("""async () => {
69
const g = app.core; g.tick = g.__tick;
70
await new Promise(r => setTimeout(r, 1500));
71
const left = !window.__rocket.row.some(b => g.blocks.includes(b));
72
return { left, dep: Object.keys(g.departingColumns()).length };
73
}""")
74
page.screenshot(path=str(SHOTS / f"t1184-{TAG}-{name}-after-leaving.png"))
75
print(name, json.dumps(res), json.dumps(after))
76
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']}")
77
check(len(res["spawned"]) == 6 and not set(res["spawned"]) & {3, 4, 5}, f"{name}: spawned in {res['spawned']} (not 3-5)")
78
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']}")
79
check(after["left"] and after["dep"] == 0, f"{name}: rocket left the screen, columns open again")
80
check(not errors, f"{name}: no page errors {errors[:2]}")
81
ctx.close()
82
br.close()
83
print("ALL OK" if not fails else f"{len(fails)} FAIL")
84
sys.exit(1 if fails else 0)
@@ -0,0 +1,84 @@1
#!/usr/bin/env python32
"""t1184: new and received blocks avoid a departing rocket stack.3
4
Usage: python3 test/t1184-departing-playwright.py URL TAG5
Logged-out solo game: launch a 3-wide rocket in columns 3-5, let it rise6
past 75% of the field, then (game clock paused, rendering live) spawn7
blocks and ingest garbage aimed at the rocket columns. Screenshots the8
moment and checks every new block is outside the rocket columns.9
"""10
import json, sys11
from pathlib import Path12
from playwright.sync_api import sync_playwright13
14
URL = sys.argv[1] if len(sys.argv) > 1 else "https://projects.timfalken.com/meteors/"15
TAG = sys.argv[2] if len(sys.argv) > 2 else "live"16
SHOTS = Path("/workspace/meteors-shots")17
fails = []18
19
def check(c, m):20
print(("OK " if c else "FAIL ") + m)21
if not c: fails.append(m)22
23
with sync_playwright() as pw:24
br = pw.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader"])25
for name, vp, mobile in (("desktop", {"width": 1280, "height": 800}, False), ("mobile", {"width": 390, "height": 844}, True)):26
ctx = br.new_context(viewport=vp, is_mobile=mobile, has_touch=mobile, device_scale_factor=3 if mobile else 1)27
page = ctx.new_page()28
errors = []29
page.on("pageerror", lambda e: errors.append(str(e)))30
page.goto(URL + ("" if URL.endswith("/") else "/") + "index.html?t1184=" + TAG, wait_until="networkidle")31
check(page.evaluate("() => typeof GameCore.prototype.departingColumns === 'function'"), f"{name}: departingColumns in served game.js")32
page.locator("#btn-play").click()33
page.wait_for_selector("#planet-select:not([hidden])", timeout=8000)34
page.wait_for_timeout(200)35
page.locator("#btn-planet-go").click()36
page.wait_for_function("() => window.app && app.mode === 'playing' && app.core", timeout=10000)37
page.wait_for_timeout(300)38
# t1187/t1188: spawning speeds up 0.3% per block, from 1 s.39
page.wait_for_timeout(3200)40
sp = page.evaluate("() => ({ f: GameCore.SPAWN_SPEEDUP, min: GameCore.SPAWN_INTERVAL_MIN, iv: app.core.spawnInterval })")41
n = round(__import__("math").log(sp["iv"]) / __import__("math").log(0.997)) if sp["iv"] < 1 else 042
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)")43
page.evaluate("""() => {44
const g = app.core;45
g.spawnInterval = 1e9;46
for (const b of g.blocks.slice()) g.removeBlock(b);47
[[0, 2], [1, 3]].forEach(([c, k]) => g.place(c, 0, k));48
const row = [3, 4, 5].map(c => g.place(c, 0, 1));49
window.__rocket = { row, cluster: g.launchCluster(row, 30) };50
}""")51
page.wait_for_function("""() => { const r = window.__rocket; const live = r.row.filter(b => app.core.blocks.includes(b));52
return live.length && Math.max(...live.map(b => b.y)) >= 10.0; }""", timeout=10000, polling="raf")53
res = page.evaluate("""() => {54
const g = app.core;55
g.__tick = g.tick; g.tick = function () {};56
const top = Math.max(...window.__rocket.row.map(b => b.y));57
const dep = Object.keys(g.departingColumns()).map(Number).sort();58
const spawned = [];59
for (let i = 0; i < 6; i++) { const b = g.trySpawn(); if (b) { b.y = 12 - (i % 3) * 0.2; spawned.push(b.col); } }60
const garbage = [];61
for (const c of [3, 4, 5, 4]) { const b = g.ingestGarbage(c); if (b) { b.y = 11; garbage.push(b.col); } }62
return { top, dep, spawned, garbage, line: g.DEPART_LINE() };63
}""")64
page.wait_for_timeout(120)65
shot = SHOTS / f"t1184-{TAG}-{name}-departing.png"66
page.screenshot(path=str(shot))67
# Resume: rocket leaves, spawning into those columns is allowed again.68
after = page.evaluate("""async () => {69
const g = app.core; g.tick = g.__tick;70
await new Promise(r => setTimeout(r, 1500));71
const left = !window.__rocket.row.some(b => g.blocks.includes(b));72
return { left, dep: Object.keys(g.departingColumns()).length };73
}""")74
page.screenshot(path=str(SHOTS / f"t1184-{TAG}-{name}-after-leaving.png"))75
print(name, json.dumps(res), json.dumps(after))76
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']}")77
check(len(res["spawned"]) == 6 and not set(res["spawned"]) & {3, 4, 5}, f"{name}: spawned in {res['spawned']} (not 3-5)")78
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']}")79
check(after["left"] and after["dep"] == 0, f"{name}: rocket left the screen, columns open again")80
check(not errors, f"{name}: no page errors {errors[:2]}")81
ctx.close()82
br.close()83
print("ALL OK" if not fails else f"{len(fails)} FAIL")84
sys.exit(1 if fails else 0)