# tests/runtime/test_director_resource_race.py from proteus.game.runtime.multiagent_director import author_resource_race def _run(): return author_resource_race( seed=3, agent_starts=[(8, 52), (20, 10), (40, 50), (55, 20), (30, 30)], resource=(54, 12), ) def test_deterministic(): assert _run().model_dump_json() == _run().model_dump_json() def test_ends_when_chosen_collects_resource(): ck = _run() last = ck.memory_turns[-1] assert any("got resource" in e for e in last.events) chosen = next(a for a in last.agents if a.id == "a0") rx, ry = (54, 12) # chosen footprint covers the resource cell assert chosen.pos[0] <= rx < chosen.pos[0] + chosen.size assert chosen.pos[1] <= ry < chosen.pos[1] + chosen.size assert ck.chosen_agent_id == "a0" and ck.persona_weight_id == "greedy" def test_resource_present_until_collected(): ck = _run() # Every turn except the last carries the resource; the last records pickup. for t in ck.memory_turns[:-1]: assert t.resources == [(54, 12)] def test_pickup_frame_drops_resource(): ck = _run() last = ck.memory_turns[-1] assert any("got resource" in e for e in last.events) # Collected -> the resource is gone from the field on the final frame. assert last.resources == [] # Every earlier frame still shows it (unchanged contract). for t in ck.memory_turns[:-1]: assert t.resources == [(54, 12)]