Files
TheTree_mock/tests/s4/test_original_relationship_runtime.gd

79 lines
4.6 KiB
GDScript

extends SceneTree
const Fixtures = preload("res://tests/s4/test_original_relationship_model.gd")
var _checks := 0
var _failures := 0
func _initialize() -> void:
call_deferred("_run")
func _expect(value: bool, message: String) -> void:
_checks += 1
if not value:
_failures += 1
push_error(message)
func _run() -> void:
var clock = load("res://autoload/game_clock.gd").new()
var state = load("res://autoload/game_state.gd").new()
var runtime = load("res://autoload/simulation_runtime.gd").new()
clock.reset(1, 6, 0)
state.reset()
_expect(runtime.initialize(clock, state, 18001)[&"valid"], "Runtime initialized")
clock.set_paused(true)
var fixture := Fixtures.fixture()
_expect(not runtime.relationship_service.register_original_relationship(fixture).is_success(), "unhired subject rejected by service boundary")
_expect(runtime.submit_command(&"hire_staff_candidate", {&"candidate_id": &"heroine_anri"}).is_success(), "actual approved Anri hire")
var read_before := var_to_bytes(runtime.create_snapshot())
var report: Dictionary = runtime.get_staff_management_report()
var found := false
for row: Dictionary in report[&"staff"]:
if row[&"staff_id"] == &"heroine_anri":
found = true
_expect(not row[&"original_relationship"][&"configured"] and row[&"original_relationship"][&"affection"] == null, "actual report exposes unset")
_expect(found, "hired staff appears in actual report")
_expect(var_to_bytes(runtime.create_snapshot()) == read_before, "unset report read has no mutation")
var old_events: Array = runtime.domain_events.create_snapshot()["recent_events"]
_expect(runtime.submit_command(&"register_original_relationship", fixture).is_success(), "registered Runtime command stores explicit fixture")
var new_events: Array = runtime.domain_events.create_snapshot()["recent_events"]
_expect(new_events.size() == old_events.size() + 1 and new_events[-1][&"event_type"] == "COMMAND_COMPLETED", "only existing command completion event is emitted")
_expect(runtime.relationship_service.create_relationship(&"legacy", &"heroine_anri", &"player", {&"affinity": 44}).is_success(), "legacy service remains usable")
var saved: Dictionary = runtime.create_snapshot()
var input := var_to_bytes(saved)
_expect(runtime.restore_snapshot(saved), "mixed Runtime snapshot restores")
_expect(var_to_bytes(runtime.create_snapshot()) == input, "Runtime snapshot exact round trip")
_expect(var_to_bytes(saved) == input, "restore preserves caller bytes")
read_before = var_to_bytes(runtime.create_snapshot())
report = runtime.get_staff_management_report()
for row: Dictionary in report[&"staff"]:
if row[&"staff_id"] == &"heroine_anri":
var original: Dictionary = row[&"original_relationship"]
_expect(original[&"configured"] and original["affection"] == 142.5 and original["shield_max"] == 142.5, "restored report equals stored original values")
original["affection"] = -99
_expect(var_to_bytes(runtime.create_snapshot()) == read_before, "configured report owns projection containers")
for patch: Dictionary in [{"subject_id": "missing"}, {"protagonist_id": "rival_rai"}, {"rival_id": "missing"}, {"shield_current": 999}, {"lust": "bad"}]:
var corrupt := saved.duplicate(true)
corrupt[&"systems"][&"runtime"][&"relationships"][&"original_relationships"][0].merge(patch, true)
var bad_bytes := var_to_bytes(corrupt)
var service_before: Variant = runtime.relationship_service
_expect(not runtime.restore_snapshot(corrupt), "bad original Runtime restore rejected")
_expect(runtime.relationship_service == service_before, "failed restore preserves service identity")
_expect(var_to_bytes(runtime.create_snapshot()) == read_before, "failed restore preserves whole Runtime")
_expect(var_to_bytes(corrupt) == bad_bytes, "failed restore preserves input")
var v1 := saved.duplicate(true)
v1[&"systems"][&"runtime"][&"relationships"] = saved[&"systems"][&"runtime"][&"relationships"][&"legacy"].duplicate(true)
_expect(runtime.restore_snapshot(v1), "Runtime accepts genuine v1 relationship payload")
_expect(not runtime.relationship_service.get_original_relationship(&"heroine_anri")[&"configured"], "v1 restore does not map legacy affection")
var invalid := fixture.duplicate(true)
invalid["rival_id"] = "missing"
_expect(not runtime.relationship_service.register_original_relationship(invalid).is_success(), "restore rebind keeps identity validator")
_expect(runtime.relationship_service.register_original_relationship(fixture).is_success(), "restored service accepts correct identities")
runtime.free()
clock.free()
state.free()
print("Original relationship runtime: %d checks, %d failures" % [_checks, _failures])
quit(_failures)