sometests

This commit is contained in:
AI Agent
2026-03-14 17:54:12 -06:00
parent 98967ebe59
commit 09ff51c2b0
2 changed files with 31 additions and 16 deletions

View File

@@ -1,6 +1,16 @@
# Pre-Commit Test Checklist # Pre-Commit Test Checklist
Run through these checks before every commit to ensure consistent feature coverage. **Automated smoke test (same as CI):** run from the repo root:
```bash
./run-tests.sh
```
This builds the server and mudtool, starts the server with a temporary DB, runs the smoke test below (new player, persistence, admin, registration gate, combat), then cleans up. Use it locally to match what Gitea Actions run on push/pull_request. The script uses `MUD_TEST_DB` (default `./mudserver.db.test`) so it does not overwrite your normal `mudserver.db`.
---
Run through the checks below before every commit to ensure consistent feature coverage.
## Build ## Build
- [ ] `cargo build` succeeds with no errors - [ ] `cargo build` succeeds with no errors
@@ -227,9 +237,12 @@ Run through these checks before every commit to ensure consistent feature covera
## Quick Smoke Test Script ## Quick Smoke Test Script
The canonical implementation is **`./run-tests.sh`** (see top of this file). The following is the same sequence for reference; when writing or extending tests, keep `run-tests.sh` and this section in sync.
```bash ```bash
# Start server in background # Start server in background (use -d for test DB so you don't overwrite mudserver.db)
RUST_LOG=info ./target/debug/mudserver & TEST_DB=./mudserver.db.test
RUST_LOG=info ./target/debug/mudserver -d "$TEST_DB" &
SERVER_PID=$! SERVER_PID=$!
sleep 2 sleep 2
@@ -256,12 +269,12 @@ stats
quit quit
EOF EOF
# Test 3: Admin via mudtool # Test 3: Admin via mudtool (use same test DB)
./target/debug/mudtool players list ./target/debug/mudtool -d "$TEST_DB" players list
./target/debug/mudtool players set-admin smoketest true ./target/debug/mudtool -d "$TEST_DB" players set-admin smoketest true
./target/debug/mudtool players show smoketest ./target/debug/mudtool -d "$TEST_DB" players show smoketest
./target/debug/mudtool settings set registration_open false ./target/debug/mudtool -d "$TEST_DB" settings set registration_open false
./target/debug/mudtool settings list ./target/debug/mudtool -d "$TEST_DB" settings list
# Test 4: Admin commands in-game # Test 4: Admin commands in-game
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF'
@@ -273,14 +286,14 @@ quit
EOF EOF
# Test 5: Registration gate # Test 5: Registration gate
./target/debug/mudtool settings set registration_open false ./target/debug/mudtool -d "$TEST_DB" settings set registration_open false
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 newplayer@localhost <<'EOF' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 newplayer@localhost <<'EOF'
quit quit
EOF EOF
# Test 6: Tick-based combat (connect and wait for ticks) # Test 6: Tick-based combat (connect and wait for ticks)
./target/debug/mudtool settings set registration_open true ./target/debug/mudtool -d "$TEST_DB" settings set registration_open true
./target/debug/mudtool players delete smoketest ./target/debug/mudtool -d "$TEST_DB" players delete smoketest
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 smoketest@localhost <<'EOF'
1 1
1 1
@@ -297,7 +310,7 @@ EOF
# Verify XP changed (combat happened via ticks) # Verify XP changed (combat happened via ticks)
# Cleanup # Cleanup
./target/debug/mudtool settings set registration_open true ./target/debug/mudtool -d "$TEST_DB" settings set registration_open true
./target/debug/mudtool players delete smoketest ./target/debug/mudtool -d "$TEST_DB" players delete smoketest
kill $SERVER_PID kill $SERVER_PID
``` ```

View File

@@ -157,7 +157,8 @@ pub fn resolve_npc_race_class(
if candidates.is_empty() { if candidates.is_empty() {
world.races.first().map(|r| r.id.clone()).unwrap_or_default() world.races.first().map(|r| r.id.clone()).unwrap_or_default()
} else { } else {
let idx = rng.next_range(0, candidates.len() as i32) as usize; let len = candidates.len() as i32;
let idx = rng.next_range(0, len.saturating_sub(1)) as usize;
candidates[idx].id.clone() candidates[idx].id.clone()
} }
} }
@@ -187,7 +188,8 @@ pub fn resolve_npc_race_class(
if candidates.is_empty() { if candidates.is_empty() {
world.classes.first().map(|c| c.id.clone()).unwrap_or_default() world.classes.first().map(|c| c.id.clone()).unwrap_or_default()
} else { } else {
let idx = rng.next_range(0, candidates.len() as i32) as usize; let len = candidates.len() as i32;
let idx = rng.next_range(0, len.saturating_sub(1)) as usize;
candidates[idx].id.clone() candidates[idx].id.clone()
} }
} }