"""Spike B tests — Magentic unbounded footgun (G1/B4) + fan-out state isolation (G2/B7). These drive the real GA builders with the fake client (no endpoint), de-risked by the Step 2 builder smoke. Pattern: tests/test_backends.py. """ from portfolio_optimiser.reference_domain import load_reference_projects from spikes.b_footguns import ( bounded_magentic_terminates, fresh_instance_call_counts, shared_instance_max_calls, unbounded_magentic_self_terminates, ) async def test_unbounded_magentic_does_not_self_terminate() -> None: # max_round_count=None never finalizes — only the external guard stops it (B4). self_terminated = await unbounded_magentic_self_terminates(guard_rounds=8) assert self_terminated is False # the guard fired, not a natural stop async def test_bounded_magentic_terminates_within_limit() -> None: # An explicit max_round_count makes the same never-satisfied manager stop cleanly. assert await bounded_magentic_terminates(max_round_count=2) is True async def test_shared_instance_bleeds_state_across_projects() -> None: ids = [p.id for p in load_reference_projects()] assert len(ids) == 3 bled = await shared_instance_max_calls(ids) # One shared instance reused across all 3 projects -> calls accumulate -> bleed. assert bled == len(ids) async def test_fresh_instance_zero_bleed_across_projects() -> None: ids = [p.id for p in load_reference_projects()] counts = await fresh_instance_call_counts(ids) # A fresh instance per project -> each run sees exactly one call -> zero bleed. assert counts == [1, 1, 1]