import json from proteus.game.runtime import SessionRunner, SessionTrace from proteus.providers import FakeProvider from proteus.game.agents import VanillaAgent # Self-captured deterministic snapshot for template (seed=42, EASY, 8 turns, # the agent always answers "up"). template has no ToM divergence, so the model's # "up" matches the optimal escape and motive-reading accuracy is perfect. EXPECTED_MRA = 100.0 def test_full_session_serializes_to_jsonl_and_reloads(): agent = VanillaAgent(FakeProvider(responses=["ACTION: up"], model_name="fake-1")) trace = SessionRunner( "template", agent, seed=42, play_turns=8, use_probe=True, ).run() # Serialize the whole session as one JSON line, reload, and verify. line = trace.model_dump_json() reloaded = SessionTrace.model_validate_json(line) # Full round-trip fidelity: every field survives serialization unchanged. assert reloaded.model_dump() == trace.model_dump() assert reloaded.model == "fake-1" # Deterministic self-captured snapshot (regression guard): the agent always # answers "up", so the first committed action is "up". assert reloaded.turns[0].motive_action == "up" # Concrete metric anchor (regression guard, not a vacuous >= 0 check). assert reloaded.metrics["motive_reading_accuracy"] == EXPECTED_MRA # Per-turn JSONL is also valid line-by-line. for t in trace.turns: assert json.loads(t.model_dump_json())["turn_idx"] == t.turn_idx