"""Guard the two fallback invariants that previously caused live intent loops.""" from pathlib import Path root = Path(__file__).resolve().parents[2] source = (root / "src/server/game/World/AdventureBehaviorMgr.cpp").read_text() start = source.index("void AdventureBehaviorMgr::Fallback(") end = source.index("void AdventureBehaviorMgr::ResetMicro(", start) fallback = source[start:end] instance_guard = fallback.index("r.Instance.Stage==AdventureInstancePolicy::Phase::Travel") ordinary_reselection = fallback.index("r.Tried.insert(r.Location)") assert instance_guard < ordinary_reselection assert "FinishInstance(player,r)" not in fallback[instance_guard:ordinary_reselection] assert "INSTANCE_TRAVEL_RETRY" in fallback[instance_guard:ordinary_reselection] assert "r.Instance.Location" in fallback[instance_guard:ordinary_reselection] follower_guard = fallback.index("sAdventureGroupMgr->BotLed(player)") assert follower_guard < ordinary_reselection follower_hold = fallback[follower_guard:ordinary_reselection] assert "r.GroupOverride" in follower_hold assert "r.Dirty=false" in follower_hold assert "GROUP_MEMBER_FALLBACK_HOLD" in follower_hold begin_start = source.index("void AdventureBehaviorMgr::Begin(") begin_end = source.index("void AdventureBehaviorMgr::Fallback(", begin_start) begin = source[begin_start:begin_end] assert '"portal_at_"+std::to_string(r.Instance.Entry)+"_source"' in begin assert 'Queue(player,r,"travel_to_node","node"' in begin update_start = source.index("void AdventureBehaviorMgr::Update(Player * player") update_end = source.index("void AdventureBehaviorMgr::FinishInstance(", update_start) update = source[update_start:update_end] assert 'arrivalContract="native-area-trigger"' in update assert "player->IsInAreaTriggerRadius(entrance)" in update assert "INTENT_ARRIVAL_REJECT" in update protect_start = source.index("bool AdventureBehaviorMgr::ProtectGroupLeave(") protect_end = source.index("void AdventureBehaviorMgr::InterruptForInteraction(", protect_start) protection = source[protect_start:protect_end] for invariant in ( 'r.Intent=="groupformation"', 'r.WantedIntent=="groupformation"', "r.Gathering", "r.Departure.Active(now)", "r.State==Phase::Switching", "r.State==Phase::Handover", ): assert invariant in protection flight = (root / "src/server/game/World/ClientlessFlightMgr.cpp").read_text() assert "OpenColumnFrom" in flight assert "overheadSurface" in flight assert "flight-departure-overhead-surface" in flight print("Instance graph entrance/arrival contract, visit retention, flight overhead handling, group-target hold and formation leave protection passed.")