Feature: dynamic command discovery for JSON-RPC and enhanced testing
Some checks failed
Smoke tests / Build and smoke test (push) Failing after 1m2s
Some checks failed
Smoke tests / Build and smoke test (push) Failing after 1m2s
This commit is contained in:
17
TESTING.md
17
TESTING.md
@@ -238,6 +238,13 @@ Run through the checks below before every commit to ensure consistent feature co
|
|||||||
- [ ] ←→ switches player on Attitudes tab
|
- [ ] ←→ switches player on Attitudes tab
|
||||||
- [ ] 'q' exits TUI
|
- [ ] 'q' exits TUI
|
||||||
|
|
||||||
|
## JSON-RPC Interface
|
||||||
|
- [ ] `list_commands` returns the currently handleable command list
|
||||||
|
- [ ] New commands added in `commands.rs` are automatically discovered
|
||||||
|
- [ ] `login` accepts an existing player name (requires character to be created first)
|
||||||
|
- [ ] Command output is stripped of ANSI color codes for API consumption
|
||||||
|
- [ ] Verify manually with: `echo '{"_jsonrpc": "2.0", "method": "list_commands", "params": {}, "id": 1}' | nc localhost 2223`
|
||||||
|
|
||||||
## 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.
|
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.
|
||||||
@@ -312,8 +319,18 @@ quit
|
|||||||
EOF
|
EOF
|
||||||
# Verify XP changed (combat happened via ticks)
|
# Verify XP changed (combat happened via ticks)
|
||||||
|
|
||||||
|
# Test 7: JSON-RPC interface and dynamic command list
|
||||||
|
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 rpctest@localhost <<'EOF'
|
||||||
|
1
|
||||||
|
1
|
||||||
|
quit
|
||||||
|
EOF
|
||||||
|
echo '{"_jsonrpc": "2.0", "method": "login", "params": {"username": "rpctest"}, "id": 1}' | nc -w 2 localhost 2223
|
||||||
|
echo '{"_jsonrpc": "2.0", "method": "list_commands", "params": {}, "id": 2}' | nc -w 2 localhost 2223
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
./target/debug/mudtool -d "$TEST_DB" settings set registration_open true
|
./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 smoketest
|
||||||
|
./target/debug/mudtool -d "$TEST_DB" players delete rpctest
|
||||||
kill $SERVER_PID
|
kill $SERVER_PID
|
||||||
```
|
```
|
||||||
|
|||||||
20
run-tests.sh
20
run-tests.sh
@@ -88,6 +88,26 @@ EOF
|
|||||||
echo "quit"
|
echo "quit"
|
||||||
) | ssh_mud smoketest@localhost
|
) | 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)
|
# Cleanup (trap handles server kill)
|
||||||
./target/debug/mudtool -d "$TEST_DB" settings set registration_open true
|
./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 smoketest
|
||||||
|
./target/debug/mudtool -d "$TEST_DB" players delete rpctest
|
||||||
|
|||||||
@@ -157,6 +157,15 @@ pub async fn execute(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_command_list() -> Vec<&'static str> {
|
||||||
|
vec![
|
||||||
|
"look", "go", "north", "south", "east", "west", "up", "down",
|
||||||
|
"say", "who", "take", "drop", "inventory", "equip", "use",
|
||||||
|
"examine", "talk", "attack", "defend", "flee", "cast",
|
||||||
|
"spells", "skills", "guild", "stats", "help", "shop",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn send(session: &mut Session, channel: ChannelId, text: &str) -> Result<(), russh::Error> {
|
fn send(session: &mut Session, channel: ChannelId, text: &str) -> Result<(), russh::Error> {
|
||||||
session.data(channel, CryptoVec::from(text.as_bytes()))?;
|
session.data(channel, CryptoVec::from(text.as_bytes()))?;
|
||||||
|
|||||||
@@ -126,12 +126,7 @@ async fn handle_request(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"list_commands" => {
|
"list_commands" => {
|
||||||
json!([
|
json!(commands::get_command_list())
|
||||||
"look", "go", "north", "south", "east", "west", "up", "down",
|
|
||||||
"say", "who", "take", "drop", "inventory", "equip", "use",
|
|
||||||
"examine", "talk", "attack", "defend", "flee", "cast",
|
|
||||||
"spells", "skills", "guild", "stats", "help"
|
|
||||||
])
|
|
||||||
},
|
},
|
||||||
"execute" => {
|
"execute" => {
|
||||||
if let Some(pid) = *current_player_id {
|
if let Some(pid) = *current_player_id {
|
||||||
|
|||||||
Reference in New Issue
Block a user