Files
mudserver/run-tests.sh
AI Agent 2689f9e29e
Some checks failed
Smoke tests / Build and smoke test (push) Has been cancelled
Smoke tests / Build and smoke test (pull_request) Successful in 1m23s
Add tests for weather and time of day system
2026-03-19 17:01:31 -06:00

124 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -ex
ROOT="$(cd "$(dirname "$0")" && pwd)"
cd "$ROOT"
TEST_DB=${MUD_TEST_DB:-./mudserver.db.test}
SERVER_PID=
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=$!
bash "$ROOT/scripts/ci/wait-for-tcp.sh" 127.0.0.1 2222
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
ssh_mud smoketest@localhost <<'EOF' > weather_test.out
go south
go down
look
quit
EOF
if ! grep -q "The sky is\|raining\|storm\|snow\|fog" weather_test.out; then
echo "Error: Weather info not found in look output"
cat weather_test.out
exit 1
fi
if ! grep -q "\[Night\]\|\[Morning\]\|\[Afternoon\]\|\[Evening\]" weather_test.out; then
echo "Error: Time of day info not found in look output"
cat weather_test.out
exit 1
fi
rm weather_test.out
ssh_mud smoketest@localhost <<'EOF'
look
stats
quit
EOF
./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
ssh_mud smoketest@localhost <<'EOF'
admin help
admin list
admin registration on
admin info smoketest
quit
EOF
./target/debug/mudtool -d "$TEST_DB" settings set registration_open false
ssh_mud newplayer@localhost <<'EOF'
quit
EOF
./target/debug/mudtool -d "$TEST_DB" settings set registration_open true
./target/debug/mudtool -d "$TEST_DB" players delete smoketest
(
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
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
./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