Files
TheTree_mock/tests/special/test_peeping_room_evidence.gd
T

41 lines
3.2 KiB
GDScript

extends "res://tests/special/peeping_room_fixture.gd"
func _run() -> void:
var f := fixture()
var runtime: Variant = f[&"runtime"]
var room := place(f)
var other := place(f, Vector3i(-4, 1, 1))
var service: Variant = runtime.peeping_room_service
var minute: int = f[&"clock"].absolute_minute
expect(service.record_evidence(room, &"", minute)[&"reason"] == &"SOURCE_EVENT_KEY_REQUIRED", "named source key required first")
expect(service.controlled_fixture_record_evidence(room, &"fixture.event", minute)[&"reason"] == &"STOPPED", "initial stopped state rejects even fixture ledger")
enable_fixture(f, room)
enable_fixture(f, other)
var target: FacilityInstance = runtime.facility_service.get_instance(f[&"target"])
target.power_available = false
target.operator_open = false
expect(service.record_evidence(room, &"fixture.event", minute)[&"reason"] == &"NO_POWER", "power rejection precedes closed")
target.power_available = true
expect(service.record_evidence(room, &"fixture.event", minute)[&"reason"] == &"CLOSED", "closed target rejects")
target.operator_open = true
# CONTROLLED_FIXTURE temporarily omit construction authority, leaving live target.
var empty_construction := ConstructionService.new(runtime.world_service)
service.configure(runtime.world_service, runtime.facility_service, empty_construction, runtime.path_service, runtime.id_generator)
expect(service.record_evidence(room, &"fixture.event", minute)[&"reason"] == &"UNDER_CONSTRUCTION", "uncompleted construction authority rejects collection")
service.configure(runtime.world_service, runtime.facility_service, runtime.construction_service, runtime.path_service, runtime.id_generator)
var before := var_to_bytes(service.create_snapshot())
expect(service.record_evidence(room, &"fixture.event", minute)[&"reason"] == &"RECORDER_ELIGIBILITY_PENDING_D04_D08_P16", "production collection never invents eligibility")
expect(before == var_to_bytes(service.create_snapshot()), "production collection leaves ledger unchanged")
var first: Dictionary = service.controlled_fixture_record_evidence(room, &"fixture.event", minute)
var replay: Dictionary = service.controlled_fixture_record_evidence(room, &"fixture.event", minute + 1)
expect(first[&"ok"] and not first[&"duplicated"] and replay[&"duplicated"] and replay[&"evidence_id"] == first[&"evidence_id"], "tuple replay returns exactly one stable ID")
var second: Dictionary = service.controlled_fixture_record_evidence(other, &"fixture.event", minute)
var third: Dictionary = service.controlled_fixture_record_evidence(room, &"fixture:event:日本語", minute)
expect(second[&"evidence_id"] != first[&"evidence_id"] and third[&"evidence_id"] != first[&"evidence_id"], "different room/key distinct, delimiter and UTF-8 input supported")
expect(service.create_snapshot()[&"evidence"].size() == 3, "replay adds no ledger record")
var snapshot: Dictionary = runtime.create_snapshot()
expect(runtime.restore_snapshot(snapshot), "active fixture evidence restores")
var restored: Dictionary = runtime.peeping_room_service.controlled_fixture_record_evidence(room, &"fixture.event", minute)
expect(restored[&"duplicated"] and restored[&"evidence_id"] == first[&"evidence_id"], "evidence stable across restore")
finish("Peeping room evidence")