F6: Headless server entry point and smoke test

`tools/godot.sh -- --server` runs a headless dedicated server with
--seed, --port, --players, --bots, --ticks, --unthrottled and
--log-every. ServerLoop drives the simulation and times every tick
without a scene tree, so tests run it directly. A placeholder WanderBot
gives smoke runs realistic load until the v0.4 bots land.

Logs are JSON lines that all carry the seed. An ErrorCounter logger
makes any engine or script error exit 1; a bad command line exits 2.

`make smoke` (now part of `make check`) runs 1,000 ticks with 24 bots,
prints min/mean/p50/p95/p99/max tick time against the 12 ms budget,
reruns to confirm the state hash reproduces, and proves a deliberate
script error and a bad config both exit non-zero.

Closes #6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 20:07:39 -05:00
co-authored by Claude Opus 5.5
parent 46b131fe84
commit d9d4c04312
18 changed files with 621 additions and 3 deletions
Executable
+75
View File
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
# Boots the headless server, runs a full-size match for 1,000 ticks, prints the timing
# statistics, and checks that the server:
# - exits 0 and logs start, stats and stop lines that all carry the seed,
# - produces the same state hash when run again with the same seed,
# - exits non-zero when a script error happens (a deliberate --fault),
# - exits non-zero on a bad command line.
#
# tools/smoke.sh unthrottled, so it finishes in seconds
# SMOKE_REALTIME=1 tools/smoke.sh at the real 30 Hz tick rate (about 34 seconds)
set -uo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
seed="${SMOKE_SEED:-20261109}"
ticks="${SMOKE_TICKS:-1000}"
pace="--unthrottled"
[[ "${SMOKE_REALTIME:-0}" == "1" ]] && pace=""
status=0
code=0
# run <args...>: runs the server, sets $output (JSON lines only) and $code.
run() {
local raw
raw="$(timeout --signal=KILL 300 tools/godot.sh -- --server "$@" 2>&1)"
code=$?
output="$(grep '^{' <<<"$raw")"
stderr_tail="$(grep -v '^{' <<<"$raw" | tail -n 15)"
}
# field <event> <key>: prints a value from the first log line of that event.
field() {
grep -m1 "\"event\":\"$1\"" <<<"$output" | sed -E "s/.*\"$2\":(\"[^\"]*\"|[^,}]*).*/\1/" | tr -d '"'
}
fail() {
echo "smoke FAIL: $*"
status=1
}
run --seed="$seed" --bots=24 --ticks="$ticks" --log-every=250 $pace
if [[ "$code" -ne 0 ]]; then
fail "server exited $code"
echo "$output"
echo "$stderr_tail"
fi
for event in start stats stop; do
grep -q "\"event\":\"$event\"" <<<"$output" || fail "no '$event' log line"
done
lines="$(wc -l <<<"$output")"
seeded="$(grep -c "\"seed\":$seed[,}]" <<<"$output")"
[[ "$lines" -eq "$seeded" ]] || fail "only $seeded of $lines log lines carry the seed"
[[ "$(field stats ticks)" == "$ticks" ]] || fail "ran $(field stats ticks) ticks, expected $ticks"
hash="$(field stats state_hash)"
echo "smoke: $ticks ticks, 24 bots, seed $seed"
echo "smoke: tick us min $(field stats min_us) mean $(field stats mean_us) p50 $(field stats p50_us)" \
"p95 $(field stats p95_us) p99 $(field stats p99_us) max $(field stats max_us)," \
"$(field stats over_budget) over the $(field stats budget_us) us budget"
echo "smoke: state hash $hash"
run --seed="$seed" --bots=24 --ticks="$ticks" --unthrottled
[[ "$code" -eq 0 && "$(field stats state_hash)" == "$hash" ]] \
|| fail "a second run with the same seed gave a different state hash"
run --seed="$seed" --bots=2 --ticks=50 --unthrottled --fault=script-error
[[ "$code" -eq 1 ]] || fail "a script error exited $code, expected 1"
[[ "$(field stop errors)" -ge 1 ]] || fail "a script error wasn't counted in the stop line"
run --bots=99 --nonsense
[[ "$code" -eq 2 ]] || fail "a bad command line exited $code, expected 2"
grep -q '"event":"config_error"' <<<"$output" || fail "a bad command line logged no config_error"
if [[ "$status" -eq 0 ]]; then
echo "smoke: ok (clean run, reproducible hash, script error exits 1, bad config exits 2)"
fi
exit "$status"