Files
aetherbound-guild/runtime/tests/fg2/p100_adapter_test.gd
T

80 lines
4.8 KiB
GDScript

extends SceneTree
const Adapter = preload("res://campaign/p100_adapter.gd")
const Fixture = preload("res://campaign/fg2_fixture.gd")
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
verify_canonical_victory()
verify_wounded_recovery()
if failures.is_empty():
print("ABG_FG2_P100_ADAPTER_OK canonical=risk0 victory=true market2=true wounded=risk2 defeat=true fallen=3 recovery=protected+hire source_hash=exact event_hash=exact authority=p10.0")
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func verify_canonical_victory() -> void:
var source: Dictionary = Fixture.canonical_market_state()
var source_hash := Adapter.hash_value(source)
var adapter = Adapter.new()
var configured: Dictionary = adapter.configure(source)
expect(configured.ok, "canonical Market snapshot configures")
expect(String(configured.source_snapshot_hash) == source_hash, "adapter binds the exact source snapshot")
expect(Adapter.hash_value(source) == source_hash, "configuration does not mutate the caller snapshot")
var market_view: Dictionary = adapter.view_state("zh_CN")
expect(market_view.company.size() == 2, "canonical Company has the exact opening pair")
expect(market_view.company.all(func(row): return String(row.profession_id) == "PF-B01"), "canonical pair retains the two Aegis Profession fixtures")
expect(market_view.routes.size() == 3, "Market exposes the exact three route authorities")
var route_id := Fixture.route_id(source, 0)
var committed: Dictionary = adapter.start_route(route_id)
expect(committed.ok, "risk-zero route commits through MarketService")
var terminal: Dictionary = adapter.run_battle_to_terminal("zh_CN")
expect(terminal.ok and bool(terminal.battle.terminal), "canonical battle reaches a terminal")
expect(String(terminal.battle.outcome) == "victory", "canonical risk-zero route wins without result mutation")
var raw_battle: Dictionary = adapter.battle.snapshot()
expect(String(terminal.event_log_hash) == String(raw_battle.event_log_hash), "adapter preserves the authoritative event-log hash")
expect(String(terminal.battle_snapshot_hash) == String(raw_battle.snapshot_hash), "adapter preserves the authoritative battle snapshot hash")
expect(Adapter.hash_value(terminal.events) == Adapter.hash_value(raw_battle.event_log), "normalized event rows are byte-equivalent to the six-field authority")
for event in terminal.events:
expect(event.keys().size() == 6 and event.has("event_id") and event.has("tick") and event.has("kind") and event.has("source_id") and event.has("target_id") and event.has("detail"), "every normalized event has the exact presentation fields")
var settled: Dictionary = adapter.settle_terminal("zh_CN")
expect(settled.ok and not settled.view.reward.is_empty(), "victory settles into the authoritative reward decision")
var claimed: Dictionary = adapter.claim_coin_reward("zh_CN")
expect(claimed.ok, "Coin reward claims through ResolutionService")
expect(int(claimed.view.market_index) == 2 and int(claimed.view.cleared_rounds) == 1, "reward reaches saved Market 2")
expect(String(claimed.view.phase) == "market" and claimed.view.reward.is_empty(), "Market 2 has no stale reward draft")
func verify_wounded_recovery() -> void:
var source: Dictionary = Fixture.wounded_high_risk_market_state()
var source_hash := Adapter.hash_value(source)
var adapter = Adapter.new()
expect(adapter.configure(source).ok, "wounded Market snapshot configures")
var route_id := Fixture.route_id(source, 2)
expect(adapter.start_route(route_id).ok, "high-risk wounded route commits through MarketService")
var terminal: Dictionary = adapter.run_battle_to_terminal("zh_CN")
expect(terminal.ok and String(terminal.battle.outcome) == "defeat", "wounded high-risk fixture produces a real defeat")
expect(terminal.battle.fallen_recruit_ids.size() == 3, "the real battle permanently drops the exact three deployed Recruits")
expect(Adapter.hash_value(source) == source_hash, "failure path does not mutate the caller snapshot")
var settled: Dictionary = adapter.settle_terminal("zh_CN")
expect(settled.ok and bool(settled.view.recovery_required), "defeat settlement installs bounded recovery")
expect(settled.view.company.size() == 2, "living Reserve remains while Fallen Recruits stay absent")
expect(not String(settled.view.protected_recovery_offer_id).is_empty(), "recovery exposes the authoritative protected offer")
var recovered: Dictionary = adapter.hire_protected_recovery("zh_CN")
expect(recovered.ok and not bool(recovered.view.recovery_required), "protected hire clears recovery through MarketService")
expect(recovered.view.company.size() == 3, "recovery adds one new Recruit and never resurrects the three Fallen")
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append("FG-2 P10.0 adapter: %s" % message)