107 lines
5.7 KiB
GDScript
107 lines
5.7 KiB
GDScript
extends SceneTree
|
|
|
|
const Content = preload("res://content/p9_9_content.gd")
|
|
const ProfileState = preload("res://p9_9/profile_state.gd")
|
|
const CharterService = preload("res://p9_9/charter_service.gd")
|
|
const Fixture = preload("res://tests/p9_9/runtime_fixture.gd")
|
|
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_test")
|
|
|
|
|
|
func run_test() -> void:
|
|
verify_content()
|
|
var closed := Fixture.closed_p98()
|
|
verify_reconciliation(closed)
|
|
verify_catalog_claim(closed)
|
|
verify_threat_claim(closed)
|
|
verify_rejections(closed)
|
|
if failures.is_empty():
|
|
print("ABG_P9_9_PROFILE_CHARTER_OK regions=8 claims=2 renown=3_to_14 reconciliation_once=true catalog_cost=4 threat_cost=6 no_power=true duplicate=true stale=true conflict=true")
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func verify_content() -> void:
|
|
var content := Content.snapshot()
|
|
var validation := Content.validate(content)
|
|
expect(validation.ok, "content validates")
|
|
expect(Content.canonical_first_clear_renown(1, 1) == 14, "canonical first clear is 14")
|
|
expect(content.region_seals.size() == 8 and content.charter_claims.size() == 2, "eight seals and two claims")
|
|
var tampered := content.duplicate(true)
|
|
tampered.charter_claims["CH-RG01-CATALOG-01"].no_power = false
|
|
expect(not Content.validate(tampered).ok, "permanent power boundary rejects")
|
|
|
|
|
|
func verify_reconciliation(closed: Dictionary) -> void:
|
|
var state = ProfileState.new()
|
|
expect(state.initialize_from_p98(closed), "closed P9.8 activates P9.9")
|
|
expect(state.persistent_renown == 14, "three Renown reconciles to fourteen")
|
|
expect(state.renown_reconciliation_receipts.size() == 1, "reconciliation receipt exists once")
|
|
var receipt: Dictionary = state.renown_reconciliation_receipts[0]
|
|
expect(receipt.renown_before == 3 and receipt.renown_delta == 11 and receipt.renown_after == 14, "reconciliation receipt is exact")
|
|
var already := closed.duplicate(true)
|
|
already.persistent_renown = 14
|
|
var canonical = ProfileState.new()
|
|
expect(canonical.initialize_from_p98(already), "already-canonical P9.8 state is accepted")
|
|
expect(canonical.renown_reconciliation_receipts.is_empty() and canonical.persistent_renown == 14, "canonical state gets no second grant")
|
|
var unexplained := closed.duplicate(true)
|
|
unexplained.persistent_renown = 9
|
|
var invalid = ProfileState.new()
|
|
expect(not invalid.initialize_from_p98(unexplained), "unexplained Renown rejects")
|
|
|
|
|
|
func verify_catalog_claim(closed: Dictionary) -> void:
|
|
var service = CharterService.new(closed)
|
|
var preview: Dictionary = service.preview_claim("CH-RG01-CATALOG-01")
|
|
expect(preview.ok and preview.renown_before == 14 and preview.renown_after == 10, "catalog preview shows balance")
|
|
expect(preview.effect_family == "catalog_pool_packet" and preview.no_permanent_combat_power, "catalog preview is breadth-only")
|
|
var revision: int = service.state.revision
|
|
var result: Dictionary = service.claim("p99-catalog", "CH-RG01-CATALOG-01", revision)
|
|
expect(result.ok and service.state.revision == revision + 1, "catalog claim increments once")
|
|
expect(service.state.persistent_renown == 10 and service.state.selected_charter_claim_id == "CH-RG01-CATALOG-01", "catalog claim persists")
|
|
var after: Dictionary = service.state.snapshot()
|
|
var duplicate: Dictionary = service.claim("p99-catalog", "CH-RG01-CATALOG-01", revision)
|
|
expect(duplicate.ok and duplicate.duplicate and service.state.snapshot() == after, "catalog retry returns original without mutation")
|
|
|
|
|
|
func verify_threat_claim(closed: Dictionary) -> void:
|
|
var service = CharterService.new(closed)
|
|
var preview: Dictionary = service.preview_claim("CH-RG01-THREAT-01")
|
|
expect(preview.ok and preview.renown_after == 8 and preview.effect_family == "threat_archive_upgrade", "threat preview is exact")
|
|
var result: Dictionary = service.claim("p99-threat", "CH-RG01-THREAT-01", service.state.revision)
|
|
expect(result.ok and service.state.persistent_renown == 8, "threat claim spends six")
|
|
expect(result.receipt.no_permanent_combat_power, "threat receipt states no power")
|
|
|
|
|
|
func verify_rejections(closed: Dictionary) -> void:
|
|
var service = CharterService.new(closed)
|
|
var before: Dictionary = service.state.snapshot()
|
|
expect(service.claim("p99-stale", "CH-RG01-CATALOG-01", service.state.revision + 1).code == "stale_revision", "stale claim rejects")
|
|
expect(service.state.snapshot() == before, "stale claim preserves snapshot")
|
|
expect(service.claim("p99-unknown", "CH-RG09-NONE", service.state.revision).code == "charter_claim_unknown", "unknown claim rejects")
|
|
expect(service.state.snapshot() == before, "unknown claim preserves snapshot")
|
|
var claimed := service.claim("p99-one", "CH-RG01-CATALOG-01", service.state.revision)
|
|
expect(claimed.ok, "first claim succeeds")
|
|
var after: Dictionary = service.state.snapshot()
|
|
expect(service.claim("p99-two", "CH-RG01-THREAT-01", service.state.revision).code == "charter_first_claim_already_applied", "second first-claim rejects")
|
|
expect(service.state.snapshot() == after, "second claim preserves snapshot")
|
|
var conflict: Dictionary = service.claim("p99-one", "CH-RG01-THREAT-01", service.state.revision)
|
|
expect(conflict.code == "operation_id_conflict" and service.state.snapshot() == after, "operation ID conflict preserves snapshot")
|
|
var insufficient = CharterService.new(closed)
|
|
insufficient.state.persistent_renown = 0
|
|
var invalid_before: Dictionary = insufficient.state.snapshot()
|
|
expect(insufficient.claim("p99-insufficient", "CH-RG01-THREAT-01").code == "charter_renown_insufficient", "insufficient Renown rejects")
|
|
expect(insufficient.state.snapshot() == invalid_before, "insufficient rejection has zero delta")
|
|
|
|
|
|
func expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append("P9.9 profile/Charter: %s" % message)
|