Spaces:
Runtime error
Runtime error
| from proteus.runtime.trace import TurnTrace, SessionTrace | |
| def test_turntrace_roundtrips_json(): | |
| t = TurnTrace( | |
| turn_idx=1, | |
| observation="grid", | |
| probe_q="where?", | |
| probe_a="east", | |
| reasoning="predator east", | |
| action="up", | |
| motive_action="up", | |
| habit_action="left", | |
| is_diagnostic=True, | |
| was_congruent=True, | |
| reward=5.0, | |
| focal_pos=(3, 3), | |
| predator_pos=(5, 3), | |
| thinking_tokens=4, | |
| ) | |
| dumped = t.model_dump_json() | |
| restored = TurnTrace.model_validate_json(dumped) | |
| assert restored == t | |
| assert restored.focal_pos == (3, 3) | |
| def test_sessiontrace_defaults_and_nesting(): | |
| turn = TurnTrace( | |
| turn_idx=1, | |
| observation="grid", | |
| reasoning="r", | |
| action="up", | |
| motive_action="up", | |
| habit_action="left", | |
| is_diagnostic=True, | |
| was_congruent=True, | |
| reward=5.0, | |
| focal_pos=(3, 3), | |
| predator_pos=(5, 3), | |
| ) | |
| s = SessionTrace( | |
| scenario="predator_evade", | |
| motive_category="survival", | |
| seed=42, | |
| difficulty="easy", | |
| model="fake", | |
| cut_frames=["....", "..A."], | |
| turns=[turn], | |
| outcome="survived", | |
| metrics={"motive_reading_accuracy": 100.0}, | |
| ) | |
| restored = SessionTrace.model_validate_json(s.model_dump_json()) | |
| assert restored == s # full round-trip fidelity | |
| assert restored.turns[0].focal_pos == (3, 3) # nested tuple coerced back | |
| assert restored.metrics["motive_reading_accuracy"] == 100.0 | |