Files
TheTree_mock/tests/mvp/test_approved_free_unique_arrears.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

220 lines
15 KiB
GDScript

extends SceneTree
## Candidate only; not compiled or executed. No new production tuning values.
## The only cash fixture is a disclosed ledger spend at 23:59. Production
## reception cost, build time and upkeep rates remain exactly unchanged.
class ExplicitHireCatalog:
extends MvpContentCatalog
var fixture_payload: Dictionary = {}
func staff_hire_payload(candidate_id: StringName) -> Dictionary:
return fixture_payload.duplicate(true) if candidate_id == &"heroine_anri" else super.staff_hire_payload(candidate_id)
class GateReasonFixture:
extends OperationsCoordinator
var reason: StringName = &"UNPAID_EXPENSES"
func can_start_construction_or_investment() -> Dictionary:
return {&"allowed":false,&"reason":reason,&"arrears_total":1}
var checks := 0
var failures := 0
var next_direct_id := 980_000
func _initialize() -> void:
call_deferred("run")
func expect(ok: bool, label: String) -> void:
checks += 1
if not ok:
failures += 1
push_error("FREE_UNIQUE: " + label)
func direct_command(payload: Dictionary) -> SimulationCommand:
next_direct_id += 1
return SimulationCommand.new(next_direct_id,0,0,0,&"hire_staff_candidate",&"player",&"",payload)
func fixture() -> Dictionary:
var runtime: Variant = load("res://autoload/simulation_runtime.gd").new()
var clock: Variant = load("res://autoload/game_clock.gd").new()
var state: Variant = load("res://autoload/game_state.gd").new()
clock.reset(1,6,0)
state.reset()
expect(runtime.initialize(clock,state,424242)[&"valid"],"canonical content initializes")
clock.set_paused(true)
expect(runtime.enable_production_operations()[&"ok"],"real production Operations enabled")
var built: CommandResult = runtime.submit_command(&"build_facility",{&"definition_id":&"reception",&"origin":Vector3i(-6,0,0)})
expect(built.is_success(),"normal construction command creates reception")
if not built.is_success():
return {&"runtime":runtime,&"clock":clock,&"state":state,&"ok":false}
clock.advance_minutes(runtime.definition_registry.get_facility(&"reception").build_minutes)
clock.advance_minutes(1439-clock.absolute_minute)
var cash: int = runtime.economy_service.get_balance(runtime.PLAYER_CASH_ACCOUNT)
# Disclosed economic boundary fixture, not evidence of natural spending.
var spent: CommandResult = runtime.economy_service.transfer(runtime.PLAYER_CASH_ACCOUNT,&"CONSTRUCTION_EXPENSE",cash,clock.absolute_minute,&"CONSTRUCTION",&"",&"acceptance.free_unique.cash_fixture")
expect(spent.is_success(),"controlled ledger spend leaves no available cash")
clock.advance_one_minute()
expect(clock.absolute_minute == 1440 and runtime.economy_service.get_balance(runtime.PLAYER_CASH_ACCOUNT) == 0,"real first midnight reached with zero cash")
expect(runtime.upkeep_settlement.get_arrears_total() > 0 and runtime.operations_coordinator.get_arrears_total() == runtime.upkeep_settlement.get_arrears_total(),"actual approved upkeep produces reconciled unpaid balance")
expect(not runtime.operations_coordinator.is_terminal() and not runtime._operations_should_block_tick(),"ordinary unpaid Operations remain running")
return {&"runtime":runtime,&"clock":clock,&"state":state,&"ok":true}
func free_fixture(value: Dictionary) -> void:
value[&"runtime"].free()
value[&"clock"].free()
value[&"state"].free()
func rejected_atomic(runtime: Variant, payload: Dictionary, label: String) -> CommandResult:
var before: Dictionary = runtime.create_snapshot()
var result: CommandResult = runtime._execute_hire_staff_candidate(direct_command(payload))
expect(not result.is_success() and runtime.create_snapshot() == before,label + " rejects before any Runtime state mutation")
return result
func strict_factory_and_state_guards(runtime: Variant) -> void:
var paid_payload := {&"candidate_id":&"staff_tessa",&"staff_id":&"heroine_anri",&"signing_cost":0,&"daily_wage":0,&"employment_kind":&"UNIQUE",&"options":{&"employment_kind":&"UNIQUE",&"daily_wage":0}}
var paid := rejected_atomic(runtime,paid_payload,"forged free fields on paid Tessa")
expect(paid.details.get(&"reason") == &"ARREARS_REMAIN","paid canonical costs retain arrears gate")
for payload: Dictionary in [{&"candidate_id":&"heroine_amelia"},{&"candidate_id":&"rival_rai"},{&"candidate_id":true},{&"candidate_id":&"unknown",&"staff_id":&"heroine_anri",&"employment_kind":&"UNIQUE"}]:
rejected_atomic(runtime,payload,"unapproved identity cannot claim Anri exception")
for payload: Dictionary in [{&"candidate_id":&"heroine_anri",&"current_cell":Vector3i(99999,99999,0)},{&"candidate_id":&"heroine_anri",&"current_cell":"bad"},{&"candidate_id":&"heroine_anri",&"facility_id":&"absent-workplace"}]:
rejected_atomic(runtime,payload,"free cost cannot bypass placement or path validation")
var source_catalog: MvpContentCatalog = runtime.mvp_content_catalog
var canonical := source_catalog.staff_hire_payload(&"heroine_anri")
var alterations: Array[Dictionary] = []
for field: StringName in [&"signing_cost",&"daily_wage"]:
for invalid: Variant in [1,0.0,"0",false,null]:
var changed := canonical.duplicate(true)
changed[field] = invalid
alterations.append(changed)
for invalid: Variant in [1,0.0,"0",false,null]:
var changed := canonical.duplicate(true)
changed[&"options"][&"daily_wage"] = invalid
alterations.append(changed)
for fields: Dictionary in [{&"staff_id":&"staff_tessa"},{&"role_id":&"receptionist"},{&"adult_verified":false}]:
var changed := canonical.duplicate(true)
changed.merge(fields,true)
alterations.append(changed)
var generic := canonical.duplicate(true)
generic[&"options"][&"employment_kind"] = &"FREE_HIRE"
alterations.append(generic)
for changed: Dictionary in alterations:
var replacement := ExplicitHireCatalog.new()
expect(replacement.rebuild()[&"valid"],"factory override starts from otherwise valid catalog")
replacement.fixture_payload = changed
var before: Dictionary = runtime.create_snapshot()
runtime.mvp_content_catalog = replacement
var denied: CommandResult = runtime._execute_hire_staff_candidate(direct_command({&"candidate_id":&"heroine_anri"}))
runtime.mvp_content_catalog = source_catalog
expect(not denied.is_success() and runtime.create_snapshot() == before,"nonzero/mistyped/identity/employment/adult canonical payload cannot use exemption")
var invalid_catalog := ExplicitHireCatalog.new() # deliberately not rebuilt
invalid_catalog.fixture_payload = canonical
var invalid_before: Dictionary = runtime.create_snapshot()
runtime.mvp_content_catalog = invalid_catalog
var invalid_result: CommandResult = runtime._execute_hire_staff_candidate(direct_command({&"candidate_id":&"heroine_anri"}))
runtime.mvp_content_catalog = source_catalog
expect(not invalid_result.is_success() and runtime.create_snapshot() == invalid_before,"invalid catalog cannot qualify despite a copied free payload")
# Injected safety boundaries are executor guards only, not valid-save or
# normal-production fixture claims. Restore fields before canonical snapshots.
var coordinator: OperationsCoordinator = runtime.operations_coordinator
for field: String in ["pause_requested","_external_quarantined"]:
var previous: Variant = coordinator.get(field)
var staff_before: Dictionary = runtime.staff_service.create_snapshot()
var economy_before: Dictionary = runtime.economy_service.create_snapshot()
coordinator.set(field,true)
var denied: CommandResult = runtime._execute_hire_staff_candidate(direct_command({&"candidate_id":&"heroine_anri"}))
coordinator.set(field,previous)
expect(not denied.is_success() and runtime.staff_service.create_snapshot() == staff_before and runtime.economy_service.create_snapshot() == economy_before,"paused/quarantined Operations do not permit free joining")
var prior_failure: bool = runtime._operations_runtime_failure_latched
runtime._operations_runtime_failure_latched = true
var failure_denied: CommandResult = runtime._execute_hire_staff_candidate(direct_command({&"candidate_id":&"heroine_anri"}))
runtime._operations_runtime_failure_latched = prior_failure
expect(not failure_denied.is_success(),"latched Runtime failure never hides behind free expense")
var reason_fixture := GateReasonFixture.new()
runtime.operations_coordinator = reason_fixture
var canonical_free: bool = runtime._is_approved_free_unique_hire(&"heroine_anri",canonical)
expect(canonical_free,"actual canonical approved payload qualifies for exact free policy")
for reason: StringName in [&"BANKRUPT",&"EXTERNAL_ROLLBACK_FAILED",&"FUTURE_BLOCK"]:
reason_fixture.reason = reason
var denied: CommandResult = runtime._execute_hire_staff_candidate(direct_command({&"candidate_id":&"heroine_anri"}))
expect(not denied.is_success() and denied.details.get(&"reason") == reason,"only explicit unpaid reasons may be exempted")
runtime.operations_coordinator = coordinator
var unpaid_expenses_before: Dictionary = runtime.create_snapshot()
reason_fixture.reason = &"UNPAID_EXPENSES"
runtime.operations_coordinator = reason_fixture
var zero_cost: CommandResult = runtime._execute_hire_staff_candidate(direct_command({&"candidate_id":&"heroine_anri"}))
runtime.operations_coordinator = coordinator
expect(zero_cost.is_success() and zero_cost.details.get(&"employment_kind") == &"UNIQUE","explicit UNPAID_EXPENSES gate permits canonical zero-cost joining")
expect(runtime.restore_snapshot(unpaid_expenses_before) and runtime.create_snapshot() == unpaid_expenses_before,"synthetic gate proof restores the original valid unpaid Runtime")
var callback := Callable(runtime,"_on_staff_registered")
expect(runtime.staff_service.staff_registered.is_connected(callback),"normal employee projection callback exists")
if runtime.staff_service.staff_registered.is_connected(callback):
var before: Dictionary = runtime.create_snapshot()
runtime.staff_service.staff_registered.disconnect(callback)
var failed: CommandResult = runtime._execute_hire_staff_candidate(direct_command({&"candidate_id":&"heroine_anri"}))
runtime.staff_service.staff_registered.connect(callback)
expect(not failed.is_success() and runtime.create_snapshot() == before,"post-creation projection failure atomically rolls free Staff/Shift/Path/history/ledger back")
func run() -> void:
var current := fixture()
if not current[&"ok"]:
free_fixture(current)
quit(failures)
return
var runtime: Variant = current[&"runtime"]
var clock: Variant = current[&"clock"]
strict_factory_and_state_guards(runtime)
var economy_before: Dictionary = runtime.economy_service.create_snapshot()
var arrears_before: int = runtime.upkeep_settlement.get_arrears_total()
var key: StringName = &"acceptance.approved_anri.unpaid"
var joined: CommandResult = runtime.submit_command(&"hire_staff_candidate",{&"candidate_id":&"heroine_anri",&"employment_kind":&"FREE_HIRE",&"daily_wage":999,&"signing_cost":999},&"player",&"heroine_anri",75,-1,key)
expect(joined.is_success(),"zero-cash unpaid player joins approved Anri through real command queue")
if not joined.is_success():
free_fixture(current)
quit(failures)
return
var anri: StaffRuntime = runtime.staff_service.get_staff(&"heroine_anri")
expect(anri != null and anri.employment_kind == StaffRuntime.EmploymentKind.UNIQUE and anri.daily_wage == 0,"caller-paid aliases cannot change canonical free UNIQUE employee")
expect(joined.details.get(&"employment_kind") == &"UNIQUE" and joined.details.get(&"signing_cost") == 0 and joined.details.get(&"daily_wage") == 0,"successful public result describes actual zero-cost UNIQUE contract")
expect(runtime.economy_service.create_snapshot() == economy_before and runtime.upkeep_settlement.get_arrears_total() == arrears_before,"free recruitment neither spends cash nor forgives debt")
var hire_events := 0
for event: SimulationDomainEvent in runtime.domain_events.recent_events():
if event.event_type == &"STAFF_CANDIDATE_HIRED" and &"heroine_anri" in event.entity_ids:
hire_events += 1
expect(event.payload.get(&"employment_kind") == &"UNIQUE" and event.payload.get(&"signing_cost") == 0,"one emitted hire event matches canonical mode and amount")
expect(hire_events == 1,"one successful joining event")
var committed: Dictionary = runtime.create_snapshot()
var resent: CommandResult = runtime.submit_command(&"hire_staff_candidate",{&"candidate_id":&"heroine_anri"},&"player",&"heroine_anri",75,-1,key)
expect(not resent.is_success() and resent.code == CommandResult.Code.DUPLICATE_IDEMPOTENCY_KEY and runtime.create_snapshot() == committed,"same queued request cannot join or charge twice")
var stored: CommandResult = runtime.command_queue.get_result_by_idempotency_key(key)
expect(stored != null and stored.is_success() and stored.is_replay and stored.details.get(&"employment_kind") == &"UNIQUE","persisted result replay retains corrected UNIQUE mode")
rejected_atomic(runtime,{&"candidate_id":&"heroine_anri"},"different request cannot duplicate employee")
expect(not runtime.staff_service.remove_staff(&"heroine_anri",&"SOLD").is_success() and not runtime.staff_service.retire_staff(&"heroine_anri").is_success() and runtime.create_snapshot() == committed,"free joining retains original sale/retirement protection")
var copy := fixture_shell()
var resumed: Variant = copy[&"runtime"]
expect(resumed.restore_snapshot(committed) and resumed.create_snapshot() == committed,"new Runtime instance restores complete unpaid joined state exactly")
var replay: CommandResult = resumed.command_queue.get_result_by_idempotency_key(key)
expect(replay != null and replay.details.get(&"employment_kind") == &"UNIQUE" and resumed.get_staff_management_report()[&"staff"][0][&"daily_wage"] == 0,"load retains queue result mode and management zero upkeep")
var corrupted := committed.duplicate(true)
for row: Dictionary in corrupted[&"systems"][&"runtime"][&"staff"][&"staff"]:
if row[&"staff_id"] == "heroine_anri":
row[&"employment_kind"] = "FREE_HIRE"
expect(not resumed.restore_snapshot(corrupted) and resumed.create_snapshot() == committed,"saved employee cannot be downgraded to removable ordinary hire")
free_fixture(copy)
clock.advance_minutes(2880-clock.absolute_minute)
expect(runtime.operations_coordinator.get_day_summary(2)[&"category_totals"][&"wages"] == 0 and runtime.staff_service.get_daily_payroll_total() == 0,"following actual midnight creates no unique salary")
clock.advance_minutes(4320-clock.absolute_minute)
expect(runtime.operations_coordinator.is_terminal(),"actual third operating loss reaches existing BANKRUPT")
var terminal: Dictionary = runtime.create_snapshot()
var denied: CommandResult = runtime.submit_command(&"hire_staff_candidate",{&"candidate_id":&"heroine_anri"})
expect(not denied.is_success() and denied.details.get(&"reason") == &"BANKRUPT" and runtime.create_snapshot() == terminal,"terminal normal API stays blocked before command acceptance")
free_fixture(current)
print("APPROVED_FREE_UNIQUE checks=%d failures=%d" % [checks,failures])
quit(failures)
func fixture_shell() -> Dictionary:
var runtime: Variant = load("res://autoload/simulation_runtime.gd").new()
var clock: Variant = load("res://autoload/game_clock.gd").new()
var state: Variant = load("res://autoload/game_state.gd").new()
clock.reset(1,6,0)
state.reset()
expect(runtime.initialize(clock,state,424242)[&"valid"],"separate restore Runtime initializes")
clock.set_paused(true)
return {&"runtime":runtime,&"clock":clock,&"state":state}