File size: 2,101 Bytes
426093b
a91388d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02f87f7
 
 
 
 
 
 
 
 
 
 
 
 
a91388d
93cd78f
a91388d
 
 
 
 
02f87f7
a91388d
 
 
 
02f87f7
 
a91388d
8064ddd
 
 
426093b
8064ddd
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from proteus.game.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="template",
        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


def test_turntrace_distance_fields_default_none_and_round_trip():
    from proteus.game.runtime.trace import TurnTrace
    t = TurnTrace(
        turn_idx=1, observation="o", action="up", motive_action="up",
        habit_action="left", is_diagnostic=True, was_congruent=True,
        reward=1.0, focal_pos=(3, 3), predator_pos=(5, 3),
    )
    assert t.post_focal_pos is None and t.pre_bfs_distance is None
    t2 = TurnTrace.model_validate_json(t.model_dump_json())
    assert t2.agent_distance_delta is None