Files
TheTree_mock/tests/s2/test_original_facility_parameters.gd
T
Takeshi 5dde0c5ec2 Record original-alignment implementation and traceability checkpoint
Capture current source, content data, tests, asset licenses, and original-specification traceability. Original implementation remains incomplete. The accepted matching UI generation passed 154 suites and 12,253 checks, with eight rendered staff-contract screens reviewed. Latest native Windows and full-original acceptance remain outstanding.
2026-09-30 23:52:24 +09:00

73 lines
4.7 KiB
GDScript

extends SceneTree
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 service := FacilityService.new()
for id: StringName in [&"a", &"b", &"c"]:
expect(service.create_instance({&"instance_id": id, &"definition_id": &"test", &"capacity": 100, &"customer_capacity": 3, &"queue_capacity": 10, &"base_service_minutes": 10}).is_success(), "register")
var a := service.get_instance(&"a")
expect(service.set_operational_status(&"a", {&"related_facility_id": &"b"}).is_success(), "set dependency")
expect(service.set_operational_status(&"b", {&"related_facility_id": &"c"}).is_success(), "set nested dependency")
expect(not service.set_operational_status(&"c", {&"related_facility_id": &"a"}).is_success(), "reject cycle")
service.set_operational_status(&"c", {&"power_available": false})
expect(a.operation_state == FacilityInstance.OperationState.INACTIVE and not a.related_facility_operating, "nested dependency checks actual operation")
service.set_operational_status(&"c", {&"power_available": true})
expect(a.operation_state == FacilityInstance.OperationState.OPERATING, "chain reopens deterministically")
var first := service.create_request(&"first", &"a", [&"g1", &"g2"], &"test", 0)
expect(service.enqueue_request(first).is_success(), "group enqueues")
expect(service.start_next_service(&"a").is_success(), "first group starts")
expect(a.customer_count() == 2 and a.available_slots() == 1, "count customers, not service instances or storage capacity")
var second := service.create_request(&"second", &"a", [&"g3", &"g4"], &"test", 0)
service.enqueue_request(second)
expect(not service.start_next_service(&"a").is_success(), "group cannot exceed simultaneous customer capacity")
expect(a.customer_count() == 2 and a.queue_entries.size() == 1, "waiting customers excluded")
service.set_operational_status(&"c", {&"operator_open": false})
service.advance_one_minute(1)
var active: ServiceInstance = a.active_services.values()[0]
expect(active.elapsed_minutes == 0, "dependent service pauses without progress")
service.set_operational_status(&"c", {&"operator_open": true})
service.advance_one_minute(2)
expect(active.elapsed_minutes == 1, "service resumes after dependency operates")
service.set_operational_status(&"a", {&"durability": 0})
service.set_operational_status(&"a", {&"durability": 10000, &"operator_open": true})
expect(a.operation_state == FacilityInstance.OperationState.SUSPENDED, "repair or opening does not release destruction suspension")
expect(not service.set_operational_status(&"a", {&"suspension_reason": &""}).is_success(), "reject undefined recovery")
service.advance_one_minute(3)
expect(a.active_services.is_empty(), "suspended facility terminates service")
var before_invalid := service.create_snapshot()
expect(not service.set_operational_status(&"c", {&"related_facility_id": &"missing"}, 1000).is_success() and service.create_snapshot() == before_invalid, "invalid dependency cannot advance facility clock")
service.set_opening_hours(&"c", 60, 120)
expect(not service.get_instance(&"b").related_facility_operating, "opening schedule immediately updates dependents")
var snapshot := service.create_snapshot()
var restored := FacilityService.new()
expect(restored.restore_snapshot(snapshot), "roundtrip")
expect(restored.create_snapshot() == snapshot, "saved data preserved")
expect(restored.get_instance(&"a").operation_state == FacilityInstance.OperationState.SUSPENDED, "suspension survives load")
var bad := snapshot.duplicate(true)
bad[&"instances"][0][&"customer_capacity"] = "3"
expect(not restored.restore_snapshot(bad) and restored.create_snapshot() == snapshot, "invalid capacity rejected atomically")
bad = snapshot.duplicate(true)
bad[&"instances"][2][&"related_facility_id"] = "a"
expect(not restored.restore_snapshot(bad), "saved cycle rejected")
var legacy := FacilityInstance.new().configure(&"legacy", &"warehouse", {&"capacity": 100})
expect(legacy.customer_capacity == -1, "generic capacity never defines customer maximum")
var quote := FacilityPricing.quote_service(100, {}, &"appetite", [&"appetite"], 25)
expect(quote[&"total"] == 125 and quote[&"resolved"], "matching deficit adds specified surcharge")
quote = FacilityPricing.quote_service(100, {}, &"appetite", [&"relaxation"], 25)
expect(quote[&"total"] == 100 and quote[&"eligible"], "mismatch remains usable without surcharge")
quote = FacilityPricing.quote_service(100, {}, &"appetite", [&"appetite"])
expect(not quote[&"resolved"], "unspecified surcharge does not invent a rate")
print("%s: %d checks" % ["PASS" if failures == 0 else "FAIL", checks])
quit(failures)