#!/usr/bin/env bash set -ex TEST_DB=${MUD_TEST_DB:-./mudserver.db.test} SERVER_PID= # SSH returns 255 when MUD closes connection after quit — treat as success ssh_mud() { set +e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 "$@" r=$? set -e [[ $r -eq 0 || $r -eq 255 ]] || exit 1 } cleanup() { if [ -n "${SERVER_PID:-}" ]; then kill $SERVER_PID 2>/dev/null || true fi } trap cleanup EXIT cargo build RUST_LOG=info ./target/debug/mudserver -d "$TEST_DB" & SERVER_PID=$! sleep 2 # Test 1: New player creation + basic commands ssh_mud smoketest@localhost <<'EOF' 1 1 look stats go south go down go north talk barkeep go south go south examine thief attack thief flee quit EOF # Test 2: Persistence - reconnect ssh_mud smoketest@localhost <<'EOF' look stats quit EOF # Test 3: Admin via mudtool (use same test DB) ./target/debug/mudtool -d "$TEST_DB" players list ./target/debug/mudtool -d "$TEST_DB" players set-admin smoketest true ./target/debug/mudtool -d "$TEST_DB" players show smoketest ./target/debug/mudtool -d "$TEST_DB" settings set registration_open false ./target/debug/mudtool -d "$TEST_DB" settings list # Test 4: Admin commands in-game ssh_mud smoketest@localhost <<'EOF' admin help admin list admin registration on admin info smoketest quit EOF # Test 5: Registration gate ./target/debug/mudtool -d "$TEST_DB" settings set registration_open false ssh_mud newplayer@localhost <<'EOF' quit EOF # Test 6: Tick-based combat (connect and wait for ticks) ./target/debug/mudtool -d "$TEST_DB" settings set registration_open true ./target/debug/mudtool -d "$TEST_DB" players delete smoketest # Use subshell to pipe commands with a delay between them while staying connected ( echo "1" echo "1" echo "go south" echo "go down" echo "go south" echo "attack thief" sleep 8 echo "stats" echo "quit" ) | ssh_mud smoketest@localhost # Test 7: JSON-RPC interface and dynamic command list # We need an active player for the login to succeed in mud-mcp style # (though list_commands doesn't require session, the MCP does login on startup) ssh_mud rpctest@localhost <<'EOF' 1 1 quit EOF echo '{"_jsonrpc": "2.0", "method": "login", "params": {"username": "rpctest"}, "id": 1}' | nc -w 2 localhost 2223 > rpc_resp.json echo '{"_jsonrpc": "2.0", "method": "list_commands", "params": {}, "id": 2}' | nc -w 2 localhost 2223 >> rpc_resp.json if ! grep -q '"shop"' rpc_resp.json; then echo "Error: 'shop' command missing from JSON-RPC list_commands" cat rpc_resp.json exit 1 fi rm rpc_resp.json # Cleanup (trap handles server kill) ./target/debug/mudtool -d "$TEST_DB" settings set registration_open true ./target/debug/mudtool -d "$TEST_DB" players delete smoketest ./target/debug/mudtool -d "$TEST_DB" players delete rpctest