Add supply auto-purchase and preserve save recovery state

This commit is contained in:
Takeshi
2026-10-02 07:35:03 +09:00
parent 285528b7a3
commit 39f6068461
44 changed files with 2625 additions and 61 deletions
@@ -0,0 +1,48 @@
extends SceneTree
## A corrupt transit ID must reject the entire save projection without losing
## real cabin occupants or making the infrastructure collision check fail open.
var checks := 0
var failures := 0
func _initialize() -> void:
call_deferred("run")
func expect(ok: bool, label: String) -> void:
checks += 1
if not ok:
failures += 1
push_error(label)
func run() -> void:
var path := PathService.new()
var cells: Array[Vector3i] = [Vector3i.ZERO, Vector3i(0, 1, 0)]
expect(path.rebuild_graph(cells), "build a normal graph")
expect(path.configure_elevator(&"lift", cells[0], cells[1], {&"cabin_capacity": 2}), "configure a real cabin")
for actor: StringName in [&"guest:a", &"guest:b"]:
expect(path.project_actor_position(actor, cells[0], 10), "position cabin passenger")
expect(path.enqueue_elevator_request(&"lift", {
&"request_id": StringName("ride." + String(actor)), &"unit_id": actor,
&"floor_from": 0, &"floor_to": 1, &"enqueued_at": 10,
})[&"ok"], "queue real passenger")
expect(path.dequeue_elevator_boarding(&"lift", 0, 11, 2).size() == 2, "board both passengers")
var valid: Dictionary = path.create_snapshot()
expect(valid[&"transit_actor_ids"].size() == 2, "normal save keeps both cabin occupants")
for bad_id: Variant in [123, true, 1.25, Vector3i(3, 2, 1), null]:
path._transit_actor_ids[bad_id] = true
var before := var_to_bytes(path._transit_actor_ids)
var saved: Dictionary = path.create_snapshot()
expect(saved.is_empty(), "unsupported transit ID rejects the whole projection")
expect(var_to_bytes(path._transit_actor_ids) == before, "refusal preserves all transit IDs")
expect(FacilityInfrastructureProjector._has_managed_namespace_collision(SpatialSubslotService.new(), path, {}), "consumer refuses rejected snapshot")
saved[&"caller"] = true
expect(path.create_snapshot().is_empty(), "repeat refusal returns a new empty projection")
path._transit_actor_ids.erase(bad_id)
expect(var_to_bytes(path.create_snapshot()) == var_to_bytes(valid), "correction recovers both original occupants")
var restored := PathService.new()
expect(restored.restore_snapshot(valid) and restored.rebuild_graph(cells), "save restores real passenger references")
expect(var_to_bytes(restored.create_snapshot()) == var_to_bytes(valid), "restored full save matches original")
print("Path snapshot transit guard: %d checks, %d failures" % [checks, failures])
quit(1 if failures else 0)
@@ -0,0 +1 @@
uid://cqhxb665hdby6
@@ -1,6 +1,6 @@
extends SceneTree
const RUNTIME_SNAPSHOT_VERSION := 13
const RUNTIME_SNAPSHOT_VERSION := 14
const INFRASTRUCTURE_SNAPSHOT_KEYS: Array[StringName] = [
&"excavation",
&"spatial_subslots",
@@ -186,7 +186,7 @@ func _test_runtime_surface(fixture: Dictionary) -> bool:
var snapshot: Dictionary = runtime.create_snapshot()
var runtime_data: Dictionary = snapshot[&"systems"][&"runtime"]
var current_version := int(runtime_data.get(&"runtime_schema_version", -1)) == RUNTIME_SNAPSHOT_VERSION
_expect(current_version, "Runtime emits schema v13 with infrastructure and weather state")
_expect(current_version, "Runtime emits schema v14 with infrastructure and weather state")
ready = ready and current_version
for key: StringName in INFRASTRUCTURE_SNAPSHOT_KEYS:
var valid_dictionary := runtime_data.get(key, null) is Dictionary
@@ -923,7 +923,7 @@ func _test_v5_proxy_migration_determinism() -> void:
_expect(first_runtime.restore_snapshot(legacy), "v5 proxy snapshot migrates through Runtime restore")
var first_migrated: Dictionary = first_runtime.create_snapshot()
_expect(
int(first_migrated[&"systems"][&"runtime"][&"runtime_schema_version"]) == 13,
int(first_migrated[&"systems"][&"runtime"][&"runtime_schema_version"]) == 14,
"v5 migration is immediately re-emitted as v9"
)
_expect(