Cross-room transition tests (server/tests/cross_room_transitions.rs): - T1: sprint suppresses interaction buffer, restores on Walk (D-055) - T2: CarriedBy survives room transition — no TilePosition leak (D-065) - T3: pause mid-corridor discards movement, Unpause resumes (D-031) - T4: KnowledgeGraph persists across player position change (D-041) - T5: entity knowledge downgrades Direct→KnowsDetails on LOS exit (D-060) - T6: eavesdrop cut immediately on first movement out of corner (D-071) - T7: confrontation verb disappears on retreat beyond MID_RANGE=5 (D-057/D-070) - T8: Sprint blocks eavesdrop accumulation, Careful enables it (D-055+D-071) All 8 tests pass. Test suite grows from 545 → 563 (18 tests added across sprint). Tests use direct ECS World + Schedule pattern; T3 uses full App + SimulationPlugin. Test suite expansion: - content_scaling.rs: max_npc_pack_behavioral_regression + stress tests (#513) - golden/proof_room_tick_10.json: updated golden file for gauntlet world changes - golden_suite.rs, serialization.rs, bridge_ipc.rs, bridge_tcp.rs: adapted to new world entity count and wire types - gen_fixtures.rs, perf_bench.rs, content_runtime.rs: minor test adaptations Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
151 lines
4.8 KiB
Rust
151 lines
4.8 KiB
Rust
//! Integration tests for LocalBridge over Unix sockets (D-030 Layer 2: IPC roundtrip).
|
|
|
|
use settled_reach_server::bridge::framing::{read_framed, write_framed};
|
|
use settled_reach_server::bridge::local::LocalBridge;
|
|
use settled_reach_server::bridge::types::*;
|
|
use settled_reach_server::bridge::SimBridge;
|
|
use settled_reach_server::simulation::time::{DayPhase, TickRate};
|
|
use std::os::unix::net::UnixStream;
|
|
use std::path::PathBuf;
|
|
use std::thread;
|
|
use std::time::Duration;
|
|
|
|
/// Generate unique socket path for test isolation
|
|
fn test_socket_path(test_name: &str) -> PathBuf {
|
|
let pid = std::process::id();
|
|
let timestamp = std::time::SystemTime::now()
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
.unwrap()
|
|
.as_millis();
|
|
PathBuf::from(format!(
|
|
"/tmp/sr-test-{}-{}-{}.sock",
|
|
test_name, pid, timestamp
|
|
))
|
|
}
|
|
|
|
#[test]
|
|
fn snapshot_roundtrip_over_unix_socket() {
|
|
let socket_path = test_socket_path("snapshot");
|
|
|
|
// Server thread: accept connection and send snapshot
|
|
let server_path = socket_path.clone();
|
|
let server_handle = thread::spawn(move || {
|
|
let bridge = LocalBridge::accept(&server_path).expect("failed to accept");
|
|
|
|
let snapshot = ObserverSnapshot {
|
|
version: PROTOCOL_VERSION,
|
|
tick: 42,
|
|
game_time: GameTime {
|
|
day: 0,
|
|
time_of_day: 0,
|
|
day_phase: DayPhase::Morning,
|
|
tick_rate: TickRate::Full,
|
|
},
|
|
player_facing: FacingDirection::North,
|
|
player_stance: MovementStance::default(),
|
|
player_inventory: vec![],
|
|
entities: vec![VisibleEntity {
|
|
entity_id: 100,
|
|
x: 10.5,
|
|
y: 20.3,
|
|
z: 0,
|
|
kind: EntityKind::Npc,
|
|
visibility: VisibilitySector::Forward,
|
|
relationship: RelationshipState::Unknown,
|
|
observation: EntityVisibility::Visible,
|
|
}],
|
|
visible_tiles: vec![],
|
|
nearby_interactions: vec![],
|
|
current_monologue: None,
|
|
pending_recognitions: vec![],
|
|
dialogue_response: None,
|
|
blocked_entities: vec![],
|
|
scan_events: vec![],
|
|
};
|
|
|
|
bridge
|
|
.send_snapshot(&snapshot)
|
|
.expect("failed to send snapshot");
|
|
});
|
|
|
|
// Give server time to bind
|
|
thread::sleep(Duration::from_millis(50));
|
|
|
|
// Client: connect and receive snapshot
|
|
let stream = UnixStream::connect(&socket_path).expect("failed to connect");
|
|
let mut reader = std::io::BufReader::new(stream);
|
|
|
|
let payload = read_framed(&mut reader)
|
|
.expect("failed to read frame")
|
|
.expect("unexpected EOF");
|
|
|
|
let snapshot: ObserverSnapshot =
|
|
rmp_serde::from_slice(&payload).expect("failed to deserialize");
|
|
|
|
assert_eq!(snapshot.tick, 42);
|
|
assert_eq!(snapshot.entities.len(), 1);
|
|
assert_eq!(snapshot.entities[0].entity_id, 100);
|
|
assert_eq!(snapshot.entities[0].x, 10.5);
|
|
assert_eq!(snapshot.entities[0].y, 20.3);
|
|
|
|
server_handle.join().expect("server thread panicked");
|
|
}
|
|
|
|
#[test]
|
|
fn input_roundtrip_over_unix_socket() {
|
|
let socket_path = test_socket_path("input");
|
|
|
|
// Server thread: accept connection and receive inputs
|
|
let server_path = socket_path.clone();
|
|
let server_handle = thread::spawn(move || {
|
|
let bridge = LocalBridge::accept(&server_path).expect("failed to accept");
|
|
|
|
let inputs = bridge.receive_inputs().expect("failed to receive inputs");
|
|
|
|
assert_eq!(inputs.len(), 2);
|
|
assert_eq!(inputs[0].tick, 10);
|
|
assert_eq!(inputs[1].tick, 11);
|
|
|
|
inputs
|
|
});
|
|
|
|
// Give server time to bind
|
|
thread::sleep(Duration::from_millis(50));
|
|
|
|
// Client: connect and send inputs
|
|
let stream = UnixStream::connect(&socket_path).expect("failed to connect");
|
|
let mut writer = std::io::BufWriter::new(stream);
|
|
|
|
let inputs = vec![
|
|
PlayerInput {
|
|
tick: 10,
|
|
action: PlayerAction::MoveNorth,
|
|
},
|
|
PlayerInput {
|
|
tick: 11,
|
|
action: PlayerAction::Interact {
|
|
target_entity_id: None,
|
|
verb: None,
|
|
},
|
|
},
|
|
];
|
|
|
|
let payload = rmp_serde::to_vec_named(&inputs).expect("failed to serialize");
|
|
write_framed(&mut writer, &payload).expect("failed to write frame");
|
|
|
|
// Drop writer to close connection and signal EOF to server
|
|
drop(writer);
|
|
|
|
let received_inputs = server_handle.join().expect("server thread panicked");
|
|
|
|
// Verify actions survived the round-trip
|
|
match &received_inputs[0].action {
|
|
PlayerAction::MoveNorth => {}
|
|
_ => panic!("expected MoveNorth action"),
|
|
}
|
|
match &received_inputs[1].action {
|
|
PlayerAction::Interact { .. } => {}
|
|
_ => panic!("expected Interact action"),
|
|
}
|
|
}
|