Five new .msgpack fixtures: snapshot_minimal, snapshot_full, player_input_move, player_input_interact, malformed. Rust generator in gen_fixtures.rs, 7 Rust validation tests in serialization.rs, GDScript cross-language test in test_ipc_fixtures.gd (22 assertions). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
183 lines
6.9 KiB
GDScript
183 lines
6.9 KiB
GDScript
## D-030 Layer 1: Cross-language IPC fixture tests (#271)
|
|
## Validates that Protocol.gd decodes the #271 named fixtures identically to Rust.
|
|
## Fixtures generated by: cargo test --test gen_fixtures -- --ignored
|
|
## Rust validation: server/tests/serialization.rs (fixture_* tests)
|
|
class_name TestIpcFixtures
|
|
extends GdUnitTestSuite
|
|
|
|
const FIXTURE_DIR = "res://tests/fixtures/msgpack/"
|
|
|
|
|
|
func _load_fixture(name: String) -> PackedByteArray:
|
|
var path = FIXTURE_DIR + name + ".msgpack"
|
|
var file = FileAccess.open(path, FileAccess.READ)
|
|
assert_that(file).is_not_null().override_failure_message(
|
|
"Fixture not found: %s — run 'make fixtures' to regenerate" % path
|
|
)
|
|
return file.get_buffer(file.get_length())
|
|
|
|
|
|
# -- snapshot_minimal ----------------------------------------------------------
|
|
|
|
func test_fixture_snapshot_minimal_version() -> void:
|
|
var bytes = _load_fixture("snapshot_minimal")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot).is_not_null()
|
|
assert_that(snapshot.version).is_equal(Protocol.PROTOCOL_VERSION)
|
|
|
|
|
|
func test_fixture_snapshot_minimal_tick() -> void:
|
|
var bytes = _load_fixture("snapshot_minimal")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.tick).is_equal(0)
|
|
|
|
|
|
func test_fixture_snapshot_minimal_entity_count() -> void:
|
|
var bytes = _load_fixture("snapshot_minimal")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.entities.size()).is_equal(1)
|
|
|
|
|
|
func test_fixture_snapshot_minimal_entity_kind() -> void:
|
|
var bytes = _load_fixture("snapshot_minimal")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
var entity = snapshot.entities[0]
|
|
assert_that(entity.entity_id).is_equal(1)
|
|
# entity.kind is {"variant": "Player", "data": null} from _decode_enum_variant
|
|
assert_that(entity.kind.variant).is_equal("Player")
|
|
|
|
|
|
func test_fixture_snapshot_minimal_no_monologue() -> void:
|
|
var bytes = _load_fixture("snapshot_minimal")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.current_monologue).is_null()
|
|
|
|
|
|
func test_fixture_snapshot_minimal_no_dialogue() -> void:
|
|
var bytes = _load_fixture("snapshot_minimal")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.dialogue_response).is_null()
|
|
|
|
|
|
# -- snapshot_full -------------------------------------------------------------
|
|
|
|
func test_fixture_snapshot_full_tick() -> void:
|
|
var bytes = _load_fixture("snapshot_full")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot).is_not_null()
|
|
assert_that(snapshot.tick).is_equal(42)
|
|
|
|
|
|
func test_fixture_snapshot_full_monologue_id() -> void:
|
|
var bytes = _load_fixture("snapshot_full")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.current_monologue).is_not_null()
|
|
assert_that(snapshot.current_monologue.id).is_equal("test_monologue_001")
|
|
|
|
|
|
func test_fixture_snapshot_full_monologue_text() -> void:
|
|
var bytes = _load_fixture("snapshot_full")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.current_monologue.text).is_equal("Something feels off about this place.")
|
|
|
|
|
|
func test_fixture_snapshot_full_dialogue_speaker() -> void:
|
|
var bytes = _load_fixture("snapshot_full")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.dialogue_response).is_not_null()
|
|
# dialogue_response has: line_id, text, speaker_entity_id (per protocol.gd v8 decode)
|
|
assert_that(snapshot.dialogue_response.speaker_entity_id).is_equal(99)
|
|
|
|
|
|
func test_fixture_snapshot_full_inventory() -> void:
|
|
var bytes = _load_fixture("snapshot_full")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.player_inventory.size()).is_equal(1)
|
|
assert_that(snapshot.player_inventory[0].name).is_equal("Forged Customs Cert")
|
|
|
|
|
|
func test_fixture_snapshot_full_poi_list() -> void:
|
|
var bytes = _load_fixture("snapshot_full")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.poi_list.size()).is_equal(1)
|
|
assert_that(snapshot.poi_list[0].poi_id).is_equal("docking_bay_7")
|
|
|
|
|
|
func test_fixture_snapshot_full_player_knowledge_entity() -> void:
|
|
var bytes = _load_fixture("snapshot_full")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.player_knowledge).is_not_null()
|
|
assert_that(snapshot.player_knowledge.entities.size()).is_equal(1)
|
|
assert_that(snapshot.player_knowledge.entities[0].name).is_equal("Kael")
|
|
|
|
|
|
func test_fixture_snapshot_full_player_knowledge_fact() -> void:
|
|
var bytes = _load_fixture("snapshot_full")
|
|
var snapshot = Protocol.decode_snapshot(bytes)
|
|
assert_that(snapshot.player_knowledge.facts.size()).is_equal(1)
|
|
assert_that(snapshot.player_knowledge.facts[0].fact_id).is_equal("poi.docking_bay_7")
|
|
|
|
|
|
# -- player_input_move ---------------------------------------------------------
|
|
|
|
func test_fixture_player_input_move_tick() -> void:
|
|
var bytes = _load_fixture("player_input_move")
|
|
var input = Protocol.decode_player_input(bytes)
|
|
assert_that(input).is_not_null()
|
|
assert_that(input.tick).is_equal(1)
|
|
|
|
|
|
func test_fixture_player_input_move_action() -> void:
|
|
var bytes = _load_fixture("player_input_move")
|
|
var input = Protocol.decode_player_input(bytes)
|
|
# action is {"variant": "MoveNorth", "data": null} from _decode_enum_variant
|
|
assert_that(input.action.variant).is_equal("MoveNorth")
|
|
|
|
|
|
# -- player_input_interact -----------------------------------------------------
|
|
|
|
func test_fixture_player_input_interact_tick() -> void:
|
|
var bytes = _load_fixture("player_input_interact")
|
|
var input = Protocol.decode_player_input(bytes)
|
|
assert_that(input).is_not_null()
|
|
assert_that(input.tick).is_equal(2)
|
|
|
|
|
|
func test_fixture_player_input_interact_action() -> void:
|
|
var bytes = _load_fixture("player_input_interact")
|
|
var input = Protocol.decode_player_input(bytes)
|
|
# Interact is a struct variant: {"variant": "Interact", "data": {"target_entity_id": 99, "verb": "Talk"}}
|
|
assert_that(input.action.variant).is_equal("Interact")
|
|
|
|
|
|
func test_fixture_player_input_interact_target() -> void:
|
|
var bytes = _load_fixture("player_input_interact")
|
|
var input = Protocol.decode_player_input(bytes)
|
|
assert_that(input.action.data.target_entity_id).is_equal(99)
|
|
|
|
|
|
func test_fixture_player_input_interact_verb() -> void:
|
|
var bytes = _load_fixture("player_input_interact")
|
|
var input = Protocol.decode_player_input(bytes)
|
|
assert_that(input.action.data.verb).is_equal("Talk")
|
|
|
|
|
|
# -- malformed -----------------------------------------------------------------
|
|
|
|
func test_fixture_malformed_snapshot_fails() -> void:
|
|
var bytes = _load_fixture("malformed")
|
|
# Intentionally truncated — decode_snapshot must return null (not crash)
|
|
var result = Protocol.decode_snapshot(bytes)
|
|
assert_that(result).is_null().override_failure_message(
|
|
"malformed fixture should not decode as a valid ObserverSnapshot"
|
|
)
|
|
|
|
|
|
func test_fixture_malformed_input_fails() -> void:
|
|
var bytes = _load_fixture("malformed")
|
|
# Intentionally truncated — decode_player_input must return null (not crash)
|
|
var result = Protocol.decode_player_input(bytes)
|
|
assert_that(result).is_null().override_failure_message(
|
|
"malformed fixture should not decode as a valid PlayerInput"
|
|
)
|