Files
TheTree_mock/docs/plans/original-completion-2026-10-02/checkpoints/current-phase-diagnostic-r338-r02/000-diagnostic.gd
T

59 lines
6.6 KiB
GDScript

extends "/Users/korizatou114/Projects/とりにく工房ゲーム制作部/artifacts/original-completion-2026-10-02/p23-02-build-preview-monitor-compressed-r06.gd"
# One instrumented current r333/library334 tick; nested inclusive timing only.
func run() -> void:
output = OS.get_environment("THE_TREE_RUNTIME_MONITOR_OUTPUT")
var input_path := OS.get_environment("THE_TREE_REPLAY_SNAPSHOT")
var candidate := OS.get_environment("THE_TREE_PAIRED_CANDIDATE")
if not output.is_absolute_path() or not input_path.is_absolute_path() or candidate != "r333-diagnostic": quit(98); return
var original := FileAccess.get_file_as_bytes(input_path).decompress(11411840, FileAccess.COMPRESSION_ZSTD)
var initial: Dictionary = bytes_to_var(original)
runtime = root.get_node("SimulationRuntime")
clock = root.get_node("GameClock")
runtime.initialize(clock, root.get_node("GameState"), int(initial[&"systems"][&"runtime"][&"world_seed"]))
check(runtime.restore_snapshot(initial), "fixed646 public restore")
check(var_to_bytes(runtime.create_snapshot()) == original, "complete input bytes identical")
check(clock.absolute_minute == 646 and clock.paused and clock.speed == 1, "same paused646 speed1")
var path_listeners: Array = runtime.path_service.get_signal_connection_list(&"path_query_measured")
check(path_listeners.size() == 1 and path_listeners[0]["callable"] == Callable(runtime, "_on_path_query_measured") and int(path_listeners[0]["flags"]) == 0, "only builtin path listener")
check(clock.performance_budget.get_signal_connection_list(&"budget_exceeded").is_empty(), "no external budget listener")
check(clock.get_signal_connection_list(&"tick_phase_started").is_empty() and clock.get_signal_connection_list(&"tick_completed").is_empty(), "no phase or completion instrumentation")
check(runtime.path_service.cache_hits == 0 and runtime.path_service.cache_misses == 0 and runtime.path_service.cached_path_count() == 0, "same cold derived cache")
check(runtime.path_service._query_batch.is_empty() and runtime.path_service._guest_tree_workspace.is_empty() and runtime.path_service._guest_step_connector_memo.is_empty(), "same cold tree/native-edge/step workspace")
check(runtime._guest_access_batch_can_select(), "both candidates active fast guard")
check(runtime.path_service.get_script().get_source_code().sha256_text() == OS.get_environment("THE_TREE_EXPECTED_PATH_SHA") and FileAccess.get_sha256("res://scripts/core/performance_budget.gd") == OS.get_environment("THE_TREE_EXPECTED_BUDGET_SHA"), "actual loaded original Path and same candidate Budget sources")
var declared: Dictionary = {"runtime": ["_advance_construction", "_preflight_proxy_completions", "_validate_infrastructure_crosslinks", "_advance_inventory_and_logistics", "_advance_facilities", "_advance_staff_ai", "_advance_guest_ai_decisions", "_project_guest_candidates", "_decide_guest_with_log", "_publish_snapshot", "_execute_create_logistics_request", "_validate_service_start", "_complete_service_transaction", "_apply_service_transaction"], "inventory": ["process_expired", "create_snapshot", "_find_stack", "reserve_item"], "facility": ["advance_one_minute", "refresh_operating_dependencies", "start_next_service", "_complete_service"], "supply": ["advance_auto_purchases", "ensure_deliveries", "_connection_distance", "_purchase_paid"], "logistics": ["tick"], "kitchen": ["advance_one_minute"], "kernel_phases": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]}
var targets: Dictionary = {"runtime":runtime, "inventory":runtime.inventory_service, "facility":runtime.facility_service, "supply":runtime.supply_management, "logistics":runtime.supply_logistics, "kitchen":runtime.kitchen_production, "kernel_phases":clock}
for group: String in declared:
targets[group]._p23r338_metrics.clear()
for key: String in declared[group]: targets[group]._p23r338_metrics[key] = {"calls":0,"inclusive_us":0,"max_us":0}
var started := Time.get_ticks_usec()
clock.advance_minutes(1)
var elapsed := Time.get_ticks_usec() - started
var metrics: Dictionary = {}
for group: String in declared: metrics[group] = targets[group]._p23r338_metrics.duplicate(true)
check(clock.absolute_minute == 647 and clock.paused, "tick returns at paused647")
var after: Dictionary = runtime.create_snapshot()
var oracle := FileAccess.get_file_as_bytes(OS.get_environment("THE_TREE_CANDIDATE_ORACLE")).decompress(11487732, FileAccess.COMPRESSION_ZSTD)
check(var_to_bytes(after) == oracle, "complete after647 equals pinned r32 oracle")
var after_pin := typed("after647", after)
check(after_pin["uncompressed_sha256"] == "9df3c1b6f65dfd8be944cd5cab8c631f7533530dfef3820d9fa5d74a5b1ac30f", "complete output digest identical")
var metrics_valid := true
for group: String in declared:
metrics_valid = metrics_valid and metrics[group].size() == declared[group].size()
for key: String in declared[group]:
var row: Dictionary = metrics[group][key]
metrics_valid = metrics_valid and int(row["calls"]) >= 0 and int(row["inclusive_us"]) >= int(row["max_us"]) and int(row["max_us"]) >= 0
if int(row["calls"]) == 0: metrics_valid = metrics_valid and int(row["inclusive_us"]) == 0 and int(row["max_us"]) == 0
for key: String in declared["kernel_phases"]: metrics_valid = metrics_valid and int(metrics["kernel_phases"][key]["calls"]) == 1
check(metrics_valid, "finite nested metric schema and one call per kernel phase")
var metrics_pin := typed("metrics",metrics)
var decoded := FileAccess.open(output.path_join("metrics.json"),FileAccess.WRITE)
if decoded == null: quit(98); return
decoded.store_string(JSON.stringify(metrics,"\t")); decoded.close()
var report := {"plan_id":"P23-02", "candidate":candidate, "sample":OS.get_environment("THE_TREE_PAIRED_SAMPLE"), "pid":OS.get_process_id(), "manual_tick_us":elapsed,"metrics":metrics_pin,"diagnostic_only":true, "after647":after_pin, "cache_hits":runtime.path_service.cache_hits, "cache_misses":runtime.path_service.cache_misses, "checks":checks, "failures":failures, "passed":failures.is_empty(), "unit_accepted":false, "performance_budget_accepted":false, "normal_OS_accepted":false, "Windows_accepted":false, "candidate_adopted":false, "limits":["One instrumented r333/library334 cold646 tick; nested inclusive metrics, no sums or subtraction as pure CPU, no uninstrumented speed comparison or acceptance.", "No Main, rendering, OS input or realtime x3. Timed interval contains builtin production callbacks; snapshot verification and compression occur after timing."]}
var file := FileAccess.open(output.path_join("report.json"), FileAccess.WRITE)
if file == null: quit(98); return
file.store_string(JSON.stringify(report, "\t")); file.close()
print("Phase diagnostic whole647: %d checks, %d failures" % [checks, failures.size()])
quit(0 if failures.is_empty() else 1)