Files
TheTree_mock/tests/staff/test_dormitory_shift_cycle.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

55 lines
3.8 KiB
GDScript

extends SceneTree
var checks := 0
var failures := 0
var runtime: Variant
var clock: Variant
var state: Variant
func _initialize() -> void: call_deferred("run")
func expect(ok: bool, message: String) -> void:
checks += 1
if not ok: failures += 1; push_error(message)
func command(kind: StringName, payload: Dictionary) -> bool:
var result: CommandResult = runtime.submit_command(kind, payload)
expect(result.is_success(), "%s: %s" % [kind, result.message])
return result.is_success()
func run() -> void:
runtime=load("res://autoload/simulation_runtime.gd").new()
clock=load("res://autoload/game_clock.gd").new()
state=load("res://autoload/game_state.gd").new()
clock.reset(1,6,0);state.reset();runtime.initialize(clock,state,42505);clock.set_paused(true)
expect(runtime.enable_production_operations()[&"ok"], "enable production operations")
for row: Array in [[&"warehouse",Vector3i(-6,0,1)],[&"staff_dormitory",Vector3i(-6,2,1)],[&"service_stairs",Vector3i(-7,1,1)],[&"service_stairs",Vector3i(-7,2,1)]]:
if not command(&"build_facility",{&"definition_id":row[0],&"origin":row[1]}): finish();return
clock.advance_minutes(runtime.definition_registry.get_facility(row[0]).build_minutes)
var warehouse_id: StringName = &""
for facility: FacilityInstance in runtime.facility_service.get_instances():
if facility.definition_id == &"warehouse": warehouse_id = facility.instance_id
if not command(&"register_staff",{&"staff_id":&"dorm_night_worker",&"role_id":&"porter",&"options":{&"current_cell":Vector3i(5,0,0),&"role_tags":[&"porter"]}}): finish();return
if not command(&"set_staff_work_assignment",{&"staff_id":&"dorm_night_worker",&"facility_id":warehouse_id,&"template_id":&"NIGHT"}): finish();return
clock.advance_minutes(1110-clock.absolute_minute)
var worker: StaffRuntime = runtime.staff_service.get_staff(&"dorm_night_worker")
var shift: ShiftInstance = runtime.staff_service.get_shift(worker.shift_id)
expect(worker.state == StaffRuntime.State.AVAILABLE and shift != null and shift.actual_started_at >= 1080, "night worker reaches warehouse for normal shift")
clock.advance_minutes(1799-clock.absolute_minute)
expect(worker.state == StaffRuntime.State.AVAILABLE and worker.assigned_facility_id == warehouse_id, "worker remains on assigned shift until its final minute")
clock.advance_minutes(1)
expect(worker.state == StaffRuntime.State.OFF_DUTY, "06:00 naturally ends night shift")
var before_rest: Dictionary = runtime.create_snapshot()
clock.advance_minutes(60)
var rest_report: Dictionary = runtime.get_staff_rest_report(worker.staff_id)
expect(rest_report.get(&"resting",false) and rest_report.get(&"label","") == "宿舎で休憩中" and worker.current_cell == Vector3i(-7,2,1), "shift-ended worker physically reaches dormitory through service stairs")
var after_rest: Dictionary = runtime.create_snapshot()
expect(runtime.restore_snapshot(before_rest), "restore shift-end movement checkpoint")
clock.advance_minutes(60)
expect(runtime.create_snapshot() == after_rest, "shift-end commute and rest replay exactly")
clock.advance_minutes(2550-clock.absolute_minute)
worker=runtime.staff_service.get_staff(&"dorm_night_worker")
shift=runtime.staff_service.get_shift(worker.shift_id)
expect(worker.state == StaffRuntime.State.AVAILABLE and worker.assigned_facility_id == warehouse_id and shift != null and shift.start_at == 2520, "next repeating night shift returns rested worker to workplace")
expect(not runtime.get_staff_rest_report(worker.staff_id).get(&"resting",false), "working employee is no longer reported as resting")
expect(runtime.staff_service.validate_invariants()[&"ok"], "full shift-rest-shift preserves staff invariants")
finish()
func finish() -> void:
runtime.free();clock.free();state.free()
print("Dormitory shift cycle: %d checks, %d failures" % [checks,failures]);quit(failures)