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

66 lines
6.3 KiB
GDScript

extends SceneTree
const Routes=preload("res://scripts/construction/facility_resize_routes.gd")
var checks:=0
var failures:=0
var runtime: Variant
var clock: Variant
var state: Variant
func expect(ok: bool, message: String) -> void:
checks+=1
if not ok: failures+=1;push_error(message)
func _initialize() -> void: call_deferred("run")
func build(id: StringName, origin: Vector3i) -> bool:
var result: CommandResult=runtime.submit_command(&"build_facility",{&"definition_id":id,&"origin":origin})
expect(result.is_success(),"build legacy fixture %s: %s" % [id,result.message])
if not result.is_success(): return false
clock.advance_minutes(runtime.definition_registry.get_facility(id).build_minutes)
return true
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);runtime.enable_production_operations()
var paths: Array[String]=FacilityCatalog.FACILITY_PATHS+FacilityCatalog.INFRASTRUCTURE_FACILITY_PATHS+FacilityCatalog.RESCUE_FACILITY_PATHS+FacilityCatalog.ORIGINAL_FACILITY_PATHS
paths.erase("res://data/facilities/expansion/staff_dormitory.tres");paths.append("res://tests/fixtures/legacy_staff_dormitory.tres")
expect(runtime.definition_registry.rebuild_from_paths(paths)[&"valid"],"register explicit legacy dormitory fixture")
if not build(&"warehouse",Vector3i(-6,0,1)) or not build(&"staff_dormitory",Vector3i(-6,2,1)) or not build(&"service_stairs",Vector3i(-7,1,1)) or not build(&"service_stairs",Vector3i(-7,2,1)) or not build(&"service_stairs",Vector3i(-7,3,1)): finish();return
var id: StringName=&""
for room: FacilityInstance in runtime.facility_service.get_instances():
if room.definition_id==&"staff_dormitory": id=room.instance_id
expect(runtime.submit_command(&"register_staff",{&"staff_id":&"legacy_sleeper",&"role_id":&"porter",&"options":{&"current_cell":Vector3i(-7,3,1),&"health":20,&"fatigue":20,&"state":StaffRuntime.State.OFF_DUTY}}).is_success(),"old resting worker starts on a valid upper landing")
paths.erase("res://tests/fixtures/legacy_staff_dormitory.tres");paths.append("res://data/facilities/expansion/staff_dormitory.tres")
expect(runtime.definition_registry.rebuild_from_paths(paths)[&"valid"],"switch to canonical two-by-one definition")
var before: Dictionary=runtime.create_snapshot()
expect(runtime.get_staff_rest_report(&"legacy_sleeper")[&"resting"],"legacy worker rests beside the original upper row")
runtime.path_service.set_cell_temporary_block(Vector3i(-7,2,1),true)
var blocked: Dictionary=runtime.create_snapshot()
var rejected: Dictionary=runtime.prepare_facility_dimension_snapshot(id)
expect(not rejected[&"ok"] and rejected.get(&"routes",{}).get(&"errors",[]).any(func(error: Variant): return error is Dictionary and error[&"code"]==&"STAFF_ACCESS_LOST"), "blocked lower entrance rejects loss of off-duty rest access")
expect(runtime.create_snapshot()==blocked and runtime.restore_snapshot(before),"failed route candidate preserves source then valid fixture restores")
var task_result: CommandResult=runtime.staff_service.create_task(&"maintenance",10,clock.absolute_minute,{&"target_entity_id":id,&"target_cell":Vector3i(-7,3,1)},&"legacy_dorm_task")
expect(task_result.is_success() and runtime.restore_snapshot(runtime.create_snapshot()),"pending old-entry task is a valid Runtime source")
var task_source: Dictionary=runtime.create_snapshot()
rejected=runtime.prepare_facility_dimension_snapshot(id)
expect(not rejected[&"ok"] and rejected.get(&"routes",{}).get(&"errors",[]).any(func(error: Variant): return error is Dictionary and error[&"code"]==&"TASK_DESTINATION_CHANGED"),"old-entry task requires coordinated retargeting rather than silently surviving resize")
expect(runtime.create_snapshot()==task_source and runtime.restore_snapshot(before),"task rejection preserves source state")
task_result=runtime.staff_service.create_task(&"maintenance",10,clock.absolute_minute,{&"target_entity_id":id,&"target_cell":Vector3i(-7,2,1)},&"retained_dorm_task")
expect(runtime.submit_command(&"register_staff",{&"staff_id":&"dorm_maintainer",&"role_id":&"porter",&"options":{&"current_cell":Vector3i(-7,1,1),&"state":StaffRuntime.State.AVAILABLE}}).is_success(),"register worker for retained task")
expect(runtime.staff_service.assign_task_to_staff(&"retained_dorm_task",&"dorm_maintainer",clock.absolute_minute).is_success(),"assign retained task through normal Staff service")
var valid_task: Dictionary=runtime.staff_service.get_task(&"retained_dorm_task").create_snapshot()
var with_task: Dictionary=runtime.prepare_facility_dimension_snapshot(id)
expect(task_result.is_success() and with_task[&"ok"],"task at retained entrance permits migration")
if with_task[&"ok"]:
expect(runtime.restore_snapshot(with_task[&"snapshot"]) and runtime.staff_service.get_task(&"retained_dorm_task").create_snapshot()==valid_task,"accepted task retains exact ownership progress and destination")
expect(runtime.restore_snapshot(before),"restore original geometry before successful rest migration replay")
var prepared: Dictionary=runtime.prepare_facility_dimension_snapshot(id)
expect(prepared[&"ok"] and prepared.get(&"routes",{}).get(&"checked_routes",0)==2,"migration validates off-duty rest access independently of work assignment")
expect(runtime.create_snapshot()==before,"preparing candidate preserves original worker and all live state")
if not prepared[&"ok"]: print(prepared);finish();return
expect(runtime.restore_snapshot(prepared[&"snapshot"]),"full candidate with resting worker restores")
var worker: StaffRuntime=runtime.staff_service.get_staff(&"legacy_sleeper")
expect(worker.current_cell==Vector3i(-7,3,1) and not runtime.get_staff_rest_report(worker.staff_id)[&"resting"],"migration preserves position and requires real movement to resized dormitory")
clock.advance_minutes(2)
expect(worker.current_cell==Vector3i(-7,2,1) and runtime.get_staff_rest_report(worker.staff_id)[&"resting"],"rest driver physically descends to new access after migration")
expect(runtime.restore_snapshot(runtime.create_snapshot()),"post-migration rest travel remains saveable")
finish()
func finish() -> void:
runtime.free();clock.free();state.free();print("Dormitory dimension migration: %d checks, %d failures" % [checks,failures]);quit(failures)