irregular6612 Claude Sonnet 4.6 commited on
Commit
6cf09d6
·
1 Parent(s): fa9db09

feat(web): expose health + turns_left in InteractiveSession.state()

Browse files

Adds two additive keys to the state() dict: health (= game.health, 0
for non-health scenarios) and turns_left (= play_turns - len(turns)).
Covered by tests/web/test_errand_web.py (3 new tests); all 34 web
tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

proteus/game/runtime/interactive.py CHANGED
@@ -72,6 +72,8 @@ class InteractiveSession:
72
  "phase": phase,
73
  "turn_idx": played,
74
  "play_turns": self._play_turns,
 
 
75
  "grid": core.grid_to_list(self._game.current_grid()),
76
  "legend": {str(k): v for k, v in self._scenario.legend().items()},
77
  "actions": list(self._scenario.action_set),
 
72
  "phase": phase,
73
  "turn_idx": played,
74
  "play_turns": self._play_turns,
75
+ "health": self._game.health,
76
+ "turns_left": max(0, self._play_turns - len(self._turns)),
77
  "grid": core.grid_to_list(self._game.current_grid()),
78
  "legend": {str(k): v for k, v in self._scenario.legend().items()},
79
  "actions": list(self._scenario.action_set),
tests/web/test_errand_web.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """errand_runner over the web: state exposes health/turns_left + interact action;
2
+ the handover memory renders frames (visual-only objects)."""
3
+ from proteus.web.local.server import handle_request
4
+
5
+
6
+ def test_session_state_exposes_health_and_turns_left():
7
+ registry = {}
8
+ status, payload, _ = handle_request(
9
+ "POST", "/session",
10
+ {"scenario": "errand_runner", "seed": 7, "play_turns": 30}, registry,
11
+ )
12
+ assert status == 200
13
+ st = payload["state"]
14
+ assert st["health"] == 6
15
+ assert st["turns_left"] == 30
16
+ assert "interact" in st["actions"]
17
+
18
+
19
+ def test_errand_memory_frames_present():
20
+ registry = {}
21
+ _s, payload, _c = handle_request(
22
+ "POST", "/session",
23
+ {"scenario": "errand_runner", "seed": 7, "play_turns": 30}, registry,
24
+ )
25
+ mem = payload["memory"]
26
+ assert mem["attached"] is True
27
+ assert len(mem["frames"]) >= 1 # the persona demonstration replays
28
+ assert mem["persona"] in {"civic", "opportunist", "warm_outlaw", "timid"}
29
+
30
+
31
+ def test_interact_step_is_accepted():
32
+ registry = {}
33
+ _s, payload, _c = handle_request(
34
+ "POST", "/session",
35
+ {"scenario": "errand_runner", "seed": 7, "play_turns": 30}, registry,
36
+ )
37
+ sid = payload["session_id"]
38
+ status, body, _c = handle_request("POST", f"/session/{sid}/act",
39
+ {"action": "interact"}, registry)
40
+ assert status == 200 # interact is a valid errand_runner action (not a 400)