A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(tools): web_check rejoins a console line any module's log line was spliced into
eyalgolanca3e76e585de
diff --git a/tools/tests/test_web_check_shots.py b/tools/tests/test_web_check_shots.pyindex 01b6b56d5..4142ec71e 100644--- a/tools/tests/test_web_check_shots.py+++ b/tools/tests/test_web_check_shots.py@@ -130,3 +130,29 @@ def test_chrome_keeps_its_page_content_agent_quiet_so_it_cannot_split_a_console_# Chrome 153's --v=1 log of ai_page_content_agent.cc ("GetAIPageContent SYNC MainFrame") was written into the middle of# an 8000-character SHOT line on stderr, so that part failed to parse (Task 10: hero06judea 165-166 of 167, three runs).assert "--vmodule=ai_page_content_agent=0" in wc.chrome_flags("/tmp/p", swiftshader=False)+++SPLICE = "[8471:92424315:1010/172052.176598:VERBOSE1:gpu/command_buffer/service/gles2_cmd_decoder.cc:77] Some GPU note\n"+++def test_a_log_line_from_another_thread_spliced_into_a_shot_line_is_cut_out_and_the_line_rejoined():+ # Chrome writes a long console line to stderr in pieces; another thread's --v=1 line (any module) can land between+ # them, ending the console line early and pushing its tail onto the next stderr line (Task 10 fix round 1, m6).+ text = "SHOT hero06judea 11/167 " + "AbCd+/" * 40+ head, tail = text[:100], text[100:]+ raw = [f'[1010/172052.1:INFO:CONSOLE:2] "{head}{SPLICE}', f'{tail}", source: http://localhost:1/index.html (2)\n']+ rejoin = wc.Rejoin()+ out = [l for r in raw for l in rejoin.feed(r)]+ assert len(out) == 1 and wc.CONSOLE.search(out[0]).group(1) == text+++def test_rejoin_holds_an_open_line_across_batches_and_leaves_ordinary_lines_alone():+ rejoin = wc.Rejoin()+ plain = '[1010/1.1:INFO:CONSOLE:2] "GOLDEN OK 1950 a", source: x (2)\n'+ multi = '[1010/1.1:INFO:CONSOLE:9] "SMOKE OK 5 turns 1949-01-01\n' # a multi-line message: first line only, as before+ other = "[8471:1:1010/1.1:VERBOSE1:foo.cc:1] unrelated\n"+ assert rejoin.feed(plain) == [plain] and rejoin.feed(multi) == [multi] and rejoin.feed(other) == [other]+ assert rejoin.feed(f'[1010/1.1:INFO:CONSOLE:2] "SHOT a 1/2 AAAA{SPLICE}') == []+ joined = rejoin.feed('BBBB", source: x (2)\n')+ assert [wc.CONSOLE.search(l).group(1) for l in joined] == ["SHOT a 1/2 AAAABBBB"]+ assert rejoin.flush() == []diff --git a/tools/web_check.py b/tools/web_check.pyindex 4041e2d90..bfd9060a3 100644--- a/tools/web_check.py+++ b/tools/web_check.py@@ -101,6 +101,37 @@ class Handler(http.server.SimpleHTTPRequestHandler):print("http:", fmt % args)+# A Chrome log line ("[pid:tid:MMDD/HHMMSS.micro:LEVEL:file.cc:line] text") ending a raw stderr line.+SPLICED = re.compile(r"\[\d+:\d+:\d{4}/\d{6}\.\d+:[A-Z]+\d*:[^\]\s]+:\d+\] [^\n]*\n?$")+++class Rejoin:+ """Repairs console lines another thread's log line was spliced into. Chrome writes a long console message (a SHOT+ part is 8000 characters) to stderr in pieces, and any module's --v=1 line can land between two pieces: the console+ line then ends with that log line, and the message's tail (with its '", source:' end) starts the next stderr line.+ feed(raw) cuts the log line out and joins the tail back on; it returns the lines ready to scan (none while a line is+ open). A line that ends in its source, or that holds no spliced log line (a multi-line message's first line), passes+ through unchanged."""++ def __init__(self):+ self.head: str | None = None++ def feed(self, raw: str) -> list[str]:+ if self.head is not None:+ raw, self.head = self.head + raw, None+ m = CONSOLE.search(raw)+ if m and '", source: ' not in raw[m.start(1):]:+ s = SPLICED.search(raw, m.start(1))+ if s:+ self.head = raw[:s.start()]+ return []+ return [raw]++ def flush(self) -> list[str]:+ head, self.head = self.head, None+ return [head] if head is not None else []++class ShotCollector:"""Reassembles the PNGs Statecraft.Game.Map.VisualShots logs: "SHOT <pose> begin <n> <sha256>" then n lines"SHOT <pose> <i>/<n> <base64>" (any order). A finished shot is checked against its SHA-256 and written to@@ -176,8 +207,8 @@ def find_chrome() -> Path:def chrome_flags(profile: str, swiftshader: bool, dpr: float = 1.0) -> list[str]:"""Headless Chrome at the device pixel ratio (1 unless asked), frame rate uncapped (so frame times are not thedisplay's), never throttled, with a DevTools port for the viewport override."""- # --vmodule: Chrome's page content agent logs at --v=1 from another thread, and its line can land inside a long- # console line (a SHOT part) on stderr, which then fails to parse.+ # --vmodule: Chrome's page content agent logs at --v=1 from another thread, often enough to split a long console+ # line (a SHOT part) on stderr every run; Rejoin repairs such a split from any module.flags = ["--headless=new", "--enable-logging=stderr", "--v=1", "--vmodule=ai_page_content_agent=0", "--no-first-run", "--no-default-browser-check","--autoplay-policy=no-user-gesture-required", "--window-size=1920,1080", f"--force-device-scale-factor={dpr:g}","--disable-frame-rate-limit", "--disable-gpu-vsync", *KEEP_AWAKE, "--remote-debugging-port=0",@@ -361,7 +392,15 @@ def main() -> int:proc = subprocess.Popen([str(chrome), *chrome_flags(profile, a.swiftshader, a.dpr), "about:blank"],stderr=subprocess.PIPE, stdout=subprocess.DEVNULL, text=True, errors="replace")inbox: queue.Queue = queue.Queue()- reader = threading.Thread(target=lambda: [inbox.put(l) for l in iter(proc.stderr.readline, "")], daemon=True)+ rejoin = Rejoin()++ def read():+ for raw in iter(proc.stderr.readline, ""):+ for line in rejoin.feed(raw):+ inbox.put(line)+ for line in rejoin.flush():+ inbox.put(line)+ reader = threading.Thread(target=read, daemon=True)reader.start()try:page = Page(profile, url, w, h, a.dpr)