Something went wrong. Try again.
cyberpunk mmo roguelike built on atproto protokill.sh
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139#!/usr/bin/env bash# Prove service auth end to end against a local testnet.set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
# Never touch the default instance: other agents may be using it.PROTOKILL_TESTNET_INSTANCE="${PROTOKILL_TESTNET_INSTANCE:-auth-e2e}"[ "$PROTOKILL_TESTNET_INSTANCE" != default ] \ || { echo "auth-gate: set PROTOKILL_TESTNET_INSTANCE to a name, not default" >&2; exit 1; }export PROTOKILL_TESTNET_INSTANCE
. "$ROOT/testnet/lib.sh"
for tool in cargo curl python3 setsid; do command -v "$tool" >/dev/null || die "$tool is required"done
SERVER_LOG="$TESTNET_STATE/server.log"SERVER_BIN="$TESTNET_ROOT/target/debug/protokill-server"BOT_BIN="$TESTNET_ROOT/target/debug/protokill-bot"ACCOUNTS="$TESTNET_STATE/accounts.json"PIDS=()
# Each process runs in a session of its own, so a signal can stop it together# with anything it started.stop() { local pid=$1 kill -TERM -- "-$pid" 2>/dev/null || kill -TERM "$pid" 2>/dev/null || return 0 for _ in $(seq 1 100); do kill -0 -- "-$pid" 2>/dev/null || break sleep 0.1 done kill -KILL -- "-$pid" 2>/dev/null || kill -KILL "$pid" 2>/dev/null || true wait "$pid" 2>/dev/null || true}
cleanup() { local status=$? trap - EXIT INT TERM local index for ((index = ${#PIDS[@]} - 1; index >= 0; index--)); do stop "${PIDS[index]}" done if [ "$status" -ne 0 ] && [ -f "$SERVER_LOG" ]; then echo echo "== server log" tail -n 40 "$SERVER_LOG" fi PROTOKILL_TESTNET_INSTANCE="$TESTNET_INSTANCE" "$ROOT/testnet/down.sh" >/dev/null 2>&1 || true exit "$status"}trap cleanup EXITtrap 'exit 130' INTtrap 'exit 143' TERM
account() { python3 -c 'import json,sys; a=json.load(open(sys.argv[1]))["accounts"][sys.argv[2]]; print(a[sys.argv[3]])' \ "$ACCOUNTS" "$1" "$2"}
service() { python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["services"][sys.argv[2]][sys.argv[3]])' \ "$ACCOUNTS" "$1" "$2"}
say "building protokill-server and protokill-bot"(cd "$ROOT" && nice -n 10 cargo build -p protokill_server -p protokill_bots)[ -x "$SERVER_BIN" ] || die "no protokill-server at $SERVER_BIN"[ -x "$BOT_BIN" ] || die "no protokill-bot at $BOT_BIN"
say "starting testnet instance $TESTNET_INSTANCE""$ROOT/testnet/up.sh"
SERVICE_DID=$(account game-service did)DIDBOT_CA=$(service didbot ca)SERVER_PORT=$(python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1",0)); print(s.getsockname()[1]); s.close()')SERVER_URL="http://127.0.0.1:$SERVER_PORT"WORK="$TESTNET_STATE/gate"mkdir -p "$WORK"
say "starting the game service on $SERVER_URL"setsid "$SERVER_BIN" \ --bind "127.0.0.1:$SERVER_PORT" \ --store "$TESTNET_STATE/server.sqlite3" \ --service-did "$SERVICE_DID" \ --plc-url "$PLC_ORIGIN" \ --extra-roots-pem "$DIDBOT_CA" \ --resolve "*.agents.localhost=127.0.0.1:$TESTNET_DIDBOT_PORT" \ > "$SERVER_LOG" 2>&1 &SERVER_PID=$!PIDS+=("$SERVER_PID")
for _ in $(seq 1 200); do curl -fsS -o /dev/null "$SERVER_URL/v1/health" 2>/dev/null && break kill -0 "$SERVER_PID" 2>/dev/null || die "the game service exited during startup" sleep 0.1donecurl -fsS -o /dev/null "$SERVER_URL/v1/health" || die "the game service did not answer"
bot() { setsid "$BOT_BIN" "$@" --server "$SERVER_URL" --identity "$ACCOUNTS" & local pid=$! PIDS+=("$pid") wait "$pid"}
say "player-one plays a mission"if ! bot play --account player-one --floors 1 > "$WORK/player-one.out" 2> "$WORK/player-one.err"; then cat "$WORK/player-one.out" "$WORK/player-one.err" die "player-one could not play"ficat "$WORK/player-one.out" "$WORK/player-one.err"MISSION=$(sed -n 's/^mission //p' "$WORK/player-one.out")[ -n "$MISSION" ] || die "player-one's play printed no mission id"
say "player-one observes mission $MISSION"bot observe --account player-one --mission "$MISSION"
say "player-one reads the settled replay"bot verify --account player-one --mission "$MISSION"
say "player-two is refused player-one's mission"if bot observe --account player-two --mission "$MISSION" > "$WORK/player-two.out" 2>&1; then cat "$WORK/player-two.out" die "player-two read player-one's mission"ficat "$WORK/player-two.out"grep -q 'status: 404' "$WORK/player-two.out" || die "player-two was refused for another reason"
say "the didbot AI account plays a mission"if ! bot play --account ai --floors 1 > "$WORK/ai.out" 2> "$WORK/ai.err"; then cat "$WORK/ai.out" "$WORK/ai.err" die "the AI account could not play"ficat "$WORK/ai.out" "$WORK/ai.err"
say "auth gate passed"