Files
transcience/tools/smoke.sh
T
claude 4765bbce28
ci / verify (push) Successful in 47s
Stage 2: accounts, characters, permadeath, levels and experience
Identity is shaped like Steamworks so swapping to it is one subclass and no
schema change: the client presents an opaque ticket, the server validates it
into a stable 64-bit account id, and nothing downstream sees anything else.
LocalAuthProvider takes any ticket at face value -- insecure on purpose, and
labelled as such everywhere, because the point is the shape rather than the
security. Do not ship it.

Characters persist as JSON keyed by account. Account ids are written as decimal
strings because they are 64-bit and JSON numbers are doubles, which would
silently round them. A corrupt store aborts the server rather than starting
empty: starting empty looks like it worked and then saves over every character
on the first level-up.

Levels 1-15, +10 max health each, level DERIVED from lifetime experience rather
than stored beside it, so a hand-edited save cannot produce a level 12 character
with a level 3's experience. Experience is shared undivided across everyone
alive in the instance -- splitting it would make bringing a friend cost you
progress. A level-up heals by what it added, so gaining one mid-fight is relief
rather than a bar that moved further from full.

Death is permanent and unbinds the character entirely: no "return to the hub as
the character who just died", because the run is over. The record is retired,
never deleted. The five-character cap counts LIVING characters only -- counting
the dead would lock a player out of their own account after five deaths.

Verified by tools/diag_progression.tscn, which drives the real server through
kill -> xp -> level -> health and death -> retire -> roster. The bot smoke test
cannot cover that: bots are poor shots and rarely kill anything. Writing it
caught two real ordering bugs -- the death event was dispatched before the
payload that tells the player they died, and the dead character stayed bound to
the peer.

Also added --account and --store so several clients and test runs can coexist
on one machine. The smoke test now uses a scratch store; without it a rerun
resumed the previous run's characters and "a character was created" quietly
stopped being true.

193 tests. check.sh, test.sh, smoke.sh, diag_progression and diag_prediction
all pass.
2026-09-04 00:44:34 +02:00

140 lines
5.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# End-to-end integration test: boot a dedicated server, connect two scripted
# bot clients over a real ENet socket, and assert that the whole loop happened --
# handshake, lobby, portal into a dungeon, and the emergency escape back.
#
# This is the test that catches everything unit tests structurally cannot: RPC
# wiring, codec round-trips over the wire, instance transfers, and the client's
# reconciliation loop. Run it before calling any networking change done.
#
# tools/smoke.sh # ~35s
# KEEP=1 tools/smoke.sh # keep the logs and print where they are
set -uo pipefail
cd "$(dirname "$0")/.."
GODOT="${GODOT:-godot}"
PORT="${PORT:-27099}"
SERVER_TICKS="${SERVER_TICKS:-2000}"
CLIENT_TICKS="${CLIENT_TICKS:-1700}"
OUT="$(mktemp -d -t transcience-smoke-XXXXXX)"
PIDS=()
cleanup() {
for pid in "${PIDS[@]:-}"; do
kill "$pid" 2>/dev/null
done
wait 2>/dev/null
if [[ "${KEEP:-0}" == "1" ]]; then
echo "logs kept in $OUT"
else
rm -rf "$OUT"
fi
}
trap cleanup EXIT
echo "smoke: server on port $PORT, logs in $OUT"
# A scratch character store: without it a rerun resumes the characters the
# previous run created, and "a character was created" stops being true.
"$GODOT" --headless --path . -- --server --port "$PORT" --autoquit "$SERVER_TICKS" \
--store "$OUT/characters.json" \
> "$OUT/server.log" 2>&1 &
PIDS+=($!)
for _ in $(seq 1 60); do
grep -q "SERVER_READY" "$OUT/server.log" 2>/dev/null && break
sleep 0.25
done
if ! grep -q "SERVER_READY" "$OUT/server.log" 2>/dev/null; then
echo "FAIL: server never became ready"; cat "$OUT/server.log"; exit 1
fi
for n in 1 2; do
"$GODOT" --headless --path . -- --bot --host 127.0.0.1 --port "$PORT" \
--name "bot$n" --account "$((7000 + n))" \
--autoquit "$CLIENT_TICKS" > "$OUT/bot$n.log" 2>&1 &
PIDS+=($!)
sleep 0.4
done
# A fourth bot that leaves *politely* -- the same Net.shutdown() the in-game
# menu's "Disconnect" button calls. The escape channel is keyed on the socket
# closing, not on how it closed, so a clean exit must be caught exactly like the
# SIGKILL below. If someone ever adds a "clean leave" message that bypasses the
# channel, this is what catches it.
"$GODOT" --headless --path . -- --bot --host 127.0.0.1 --port "$PORT" \
--name "leavebot" --account 7101 --leave-after 120 --autoquit "$CLIENT_TICKS" \
> "$OUT/leavebot.log" 2>&1 &
PIDS+=($!)
sleep 0.4
# A third bot that gets SIGKILLed the moment it is inside a dungeon. This is the
# anti-disconnect-cheese path: the server must keep its body in the world,
# channel it out over the same one second the escape button costs, and only then
# forget the peer -- never delete it instantly on socket close.
"$GODOT" --headless --path . -- --bot --host 127.0.0.1 --port "$PORT" \
--name "dropbot" --account 7102 --autoquit "$CLIENT_TICKS" > "$OUT/dropbot.log" 2>&1 &
DROP_PID=$!
for _ in $(seq 1 80); do
grep -q "entered instance .*DUNGEON" "$OUT/dropbot.log" 2>/dev/null && break
sleep 0.25
done
if grep -q "entered instance .*DUNGEON" "$OUT/dropbot.log" 2>/dev/null; then
# Reaped here so bash does not print its own "Killed" job-control line; the
# kill is the point of the test, not a failure.
{ kill -9 "$DROP_PID"; wait "$DROP_PID"; } 2>/dev/null || true
else
echo " WARN dropbot never reached a dungeon; drop assertions will fail"
PIDS+=("$DROP_PID")
fi
wait 2>/dev/null
fails=0
check() { # check <label> <file> <pattern>
if grep -qE "$3" "$2"; then
echo " ok $1"
else
echo " FAIL $1 (no match for /$3/ in $(basename "$2"))"
fails=$((fails + 1))
fi
}
refute() { # refute <label> <file> <pattern>
local hits
hits=$(grep -cE "$3" "$2" || true)
if [[ "$hits" == "0" ]]; then
echo " ok $1"
else
echo " FAIL $1 ($hits line(s) matched /$3/ in $(basename "$2"))"
grep -E "$3" "$2" | head -5 | sed 's/^/ /'
fails=$((fails + 1))
fi
}
echo "assertions:"
check "bot1 authenticated" "$OUT/server.log" "authenticated as account 7001"
check "bot2 authenticated" "$OUT/server.log" "authenticated as account 7002"
check "a character was created" "$OUT/server.log" "created 'bot1'"
check "and persisted to the store" "$OUT/characters.json" "bot1"
check "and are played" "$OUT/server.log" "playing 'bot1'"
check "a dungeon instance opened" "$OUT/server.log" "opened dungeon instance"
check "emergency escape completed" "$OUT/server.log" "escaped to lobby"
check "bot1 reached a dungeon" "$OUT/bot1.log" "entered instance .*DUNGEON"
check "bot1 returned to the lobby" "$OUT/bot1.log" "entered instance .*LOBBY"
check "a hard drop is channelled, not instant" \
"$OUT/server.log" "dropped in instance [0-9]+, channelling out"
check "the dropped body is released" "$OUT/server.log" "released from instance [0-9]+ after drop"
check "a polite disconnect leaves too" "$OUT/leavebot.log" "BOT_GRACEFUL_LEAVE"
check "a polite disconnect is also channelled" \
"$OUT/server.log" "'leavebot' dropped in instance [0-9]+, channelling out"
refute "no server script errors" "$OUT/server.log" "SCRIPT ERROR|Parse Error|USER ERROR"
refute "no client script errors" "$OUT/bot1.log" "SCRIPT ERROR|Parse Error|USER ERROR"
echo
if [[ $fails -eq 0 ]]; then
echo "SMOKE PASS"
else
echo "SMOKE FAIL ($fails)"
echo "--- server.log (tail) ---"; tail -40 "$OUT/server.log"
echo "--- bot1.log (tail) ---"; tail -40 "$OUT/bot1.log"
fi
exit $fails