feat: log the game's high-score report as a gameplay event
When the game builds its high-score table report for Stern's agent (/api/v1/game/high_score_events - the endpoint the Insider gate already sits on), the logger writes an HSTD line with all four players' scores. This is the report the game sends when a game has changed the table, so the line marks a high-score event with no new per-game RE. The entries themselves (initials, position) live deeper in the report body and stay uncaptured for now - that needs locating the report builder or the in-memory table. Tests: the endpoint trigger and the HSTD line lift into the host harness (the endpoint pointer is a 32-bit register, so the harness maps its string below 4 GiB and the tests run on the Linux leg like the port-gate ones). Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -406,3 +406,85 @@ def test_gl_switch_log_writes_the_ports_buttons(tmp_path):
|
||||
'2026-10-13T12:00:00.000Z SW 62 "RIGHT FLIPPER BUTTON" level=1 hit=1 game=1',
|
||||
'2026-10-13T12:00:00.000Z SW 36 "START BUTTON" level=0 hit=0 game=0',
|
||||
], text
|
||||
|
||||
|
||||
# ---- the high-score report event ------------------------------------------------------
|
||||
|
||||
_HSTD_PRELUDE = r"""
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/mman.h>
|
||||
static void event_line(const char *s) { (void)s; }
|
||||
static void lamp_line(const char *s) { (void)s; }
|
||||
static void rule_line(const char *s) { (void)s; }
|
||||
static void port_line(const char *s) { (void)s; }
|
||||
static void say(const char *fmt, ...) { (void)fmt; }
|
||||
static void on_agent_header(unsigned *r);
|
||||
static void gl_rfc3339(char *buf, unsigned cap) { snprintf(buf, cap, "2026-10-22T23:59:01.123Z"); }
|
||||
int pm_snprintf(char *out, unsigned long cap, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int n;
|
||||
va_start(ap, fmt);
|
||||
n = vsnprintf(out, cap, fmt, ap);
|
||||
va_end(ap);
|
||||
return n;
|
||||
}
|
||||
void pm_log(const char *fmt, ...)
|
||||
{
|
||||
char b[256];
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(b, sizeof b, fmt, ap);
|
||||
va_end(ap);
|
||||
printf("PMLOG %s\n", b);
|
||||
}
|
||||
static void pm_commas(char *out, unsigned cap, unsigned long long v)
|
||||
{
|
||||
snprintf(out, cap, "%llu", (unsigned long long)v);
|
||||
}
|
||||
static unsigned long long pm_score(unsigned player) { return player == 1 ? 137615960 : 0; }
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
static unsigned r[4];
|
||||
/* the runtime reads the endpoint pointer as a 32-bit register: the path must live below 4 GiB */
|
||||
char *path = mmap((void *)0x08000000, 4096, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON | MAP_FIXED, -1, 0);
|
||||
if (path == (char *)-1) { printf("mmap failed\n"); return 1; }
|
||||
snprintf(path, 4096, "%s", argv[1]);
|
||||
r[1] = (unsigned)(unsigned long)path;
|
||||
on_agent_header(r);
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def _hstd_source():
|
||||
src = _src()
|
||||
helpers = "\n".join(_lift(src, s) for s in (
|
||||
"static int str_eq(", "static void str_copy(", "static int hexval(", "static uint64_t number("))
|
||||
insider = _between(src, "#define INSIDER_ENDPOINT_MAX", "static void on_agent_header(unsigned *r)")
|
||||
fn = "\n".join(_lift(src, s) for s in (
|
||||
"static void gl_hstd_report(void)", "static void on_agent_header(unsigned *r)"))
|
||||
return _HSTD_PRELUDE + helpers + "\n" + insider + "\n" + fn
|
||||
|
||||
|
||||
def test_a_high_score_report_logs_an_hstd_event_with_the_scores(tmp_path):
|
||||
if sys.platform == "darwin":
|
||||
pytest.skip("the runtime's pointers are 32-bit registers; darwin arm64 maps nothing "
|
||||
"below 4 GiB - the Linux leg runs these")
|
||||
out = _host_run(tmp_path, _hstd_source(),
|
||||
args=("/api/v1/game/high_score_events",))
|
||||
assert "HSTD high-score report" in out, out
|
||||
assert "P1=137615960 P2=0 P3=0 P4=0" in out, out
|
||||
|
||||
|
||||
def test_other_agent_reports_log_no_hstd_event(tmp_path):
|
||||
if sys.platform == "darwin":
|
||||
pytest.skip("32-bit pointer registers: see the first HSTD test")
|
||||
for path in ("/api/v3/game/session_start", "/ingest/v1/game/game_events", "junk", ""):
|
||||
out = _host_run(tmp_path, _hstd_source(), args=(path,))
|
||||
assert "HSTD" not in out, "%s logged an HSTD event" % path
|
||||
|
||||
Reference in New Issue
Block a user