brad-did-something / tests /probe_coherence.py
qFelix's picture
Brad Did Something - Gradio/FastAPI Space on HF
78c0f6e
Raw
History Blame Contribute Delete
1.44 kB
"""Live check: after a big-loss crisis, the event_log and applied revenue
agree (no phantom dollar figures). Set MODAL_URL/MODAL_TOKEN/BDS_LLM_TIMEOUT.
"""
import re
import sys
sys.path.insert(0, ".")
from game import events # noqa: E402
from game.state import GameState # noqa: E402
s = GameState(session_id="probe", phase="free_roam")
print(f"opening revenue: ${s.revenue:,}")
# force a Brad pitch and capitulate (Fine Whatever → big loss)
ev = events._normal_pitch(s)
s.current_event = {**ev, "kind": "crisis", "special": None,
"affected_npc": ev["affected_npc"], "crisis_number": 1}
s.crisis_number = 1
s.phase = "crisis"
before = s.revenue
out = events.respond(s, "quick_fine", "")
applied = out["revenue_delta"]
log = s.event_log[-1]
print(f"headline : {ev['headline']}")
print(f"applied : {applied:+,} (revenue ${before:,} -> ${s.revenue:,})")
print(f"log entry: {log}")
# extract the dollar figure the log claims and compare to applied
m = re.search(r"([-+])\$(\d[\d,]*)K", log)
ok = True
if m:
claimed = int(m.group(2).replace(",", "")) * 1000 * (-1 if m.group(1) == "-" else 1)
ok = abs(claimed - applied) < 1000
print(f"log claims {claimed:+,} | matches applied: {ok}")
elif "no revenue impact" in log.lower():
ok = applied == 0
print(f"log says 'no revenue impact' | applied==0: {ok}")
print("PASS" if ok else "FAIL — log disagrees with applied revenue")
sys.exit(0 if ok else 1)