Files
TheTree_mock/tests/s2/test_mana_power_projection.gd
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

44 lines
2.9 KiB
GDScript

extends SceneTree
const PowerProjector = preload("res://scripts/mana/mana_power_projection.gd")
var checks := 0
var failures := 0
func expect(ok: bool, message: String) -> void:
checks += 1
if not ok:
failures += 1
push_error(message)
func _initialize() -> void:
var facilities := FacilityService.new()
var network := ManaNetworkService.new()
for id: StringName in [&"zero_cost", &"powered", &"damaged", &"closed"]:
facilities.create_instance({&"instance_id": id, &"definition_id": &"standard_room", &"staff_min": 0})
facilities.set_operational_status(&"damaged", {&"suspension_reason": &"RAIDED"}, 0)
facilities.set_operational_status(&"closed", {&"operator_open": false}, 0)
network.register_source(&"source", 8)
network.register_consumer(&"powered", 10)
network.connect_nodes(&"source", &"powered")
network.evaluate_now(0)
var result := PowerProjector.apply(facilities, network, 10, 0)
expect(result[&"ok"] and facilities.get_instance(&"powered").degraded_reasons.has(&"MANA_BROWNOUT"), "partial network supply retains brownout reason")
result = PowerProjector.apply(facilities, network, 0, 1)
expect(result[&"ok"] and result[&"changed_facilities"].size() == 4, "zero reserve stops every facility including zero-demand facilities")
for facility: FacilityInstance in facilities.get_instances():
expect(not facility.power_available and facility.operation_state != FacilityInstance.OperationState.OPERATING, "no facility operates with zero reserve: " + String(facility.instance_id))
expect(PowerProjector.apply(facilities, network, 0, 1)[&"changed_facilities"].is_empty(), "unchanged projection emits no repeated status changes")
var checkpoint := facilities.create_snapshot()
var restored := FacilityService.new()
expect(restored.restore_snapshot(checkpoint), "power and suspension conditions survive service checkpoint")
PowerProjector.apply(restored, network, 4, 2)
expect(restored.get_instance(&"zero_cost").power_available, "zero-demand facility recovers supply")
expect(restored.get_instance(&"damaged").suspension_reason == &"RAIDED" and restored.get_instance(&"damaged").operation_state == FacilityInstance.OperationState.SUSPENDED, "reserve recovery never releases raid suspension")
expect(not restored.get_instance(&"closed").operator_open, "recovery never reopens player-closed facility")
expect(restored.get_instance(&"powered").degraded_reasons.has(&"MANA_BROWNOUT"), "recovery retains actual network brownout")
network.set_source_output(&"source", 0)
network.evaluate_now(3)
PowerProjector.apply(restored, network, 4, 3)
expect(not restored.get_instance(&"powered").power_available, "positive reserve does not override absent network supply")
var before := restored.create_snapshot()
expect(not PowerProjector.apply(restored, network, -1, 4)[&"ok"] and restored.create_snapshot() == before, "invalid reserve rejected without changes")
print("%s: %d checks" % ["PASS" if failures == 0 else "FAIL", checks])
quit(failures)