"""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 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 print("Instance visit retention, inherited group-target hold and formation leave protection passed.")