test(fase2): assert BudgetMiddleware short-circuits a real chat call + the debate

This commit is contained in:
Kjell Tore Guttormsen 2026-06-26 00:42:51 +02:00
commit 7b08b37da3
2 changed files with 49 additions and 3 deletions

View file

@ -169,6 +169,36 @@ async def test_g_validated_proposal_derives_from_debate(
assert isinstance(result.outcome, ValidatedProposal)
async def test_h_tiny_budget_halts_via_debate_middleware(
docs_dir, make_client_factory, fresh_store, monkeypatch
) -> None:
"""F8 (debate-path half): a tiny budget must short-circuit in the DEBATE middleware, not the
later generate loop. Fence generation if generate_via_llm is reached, the debate did NOT
short-circuit, so fail. Because generate_via_llm independently raises BudgetExceeded, a plain
pytest.raises would pass even with the debate middleware detached; the fence makes this test
load-bearing (detaching the middleware fails it)."""
from portfolio_optimiser import run as run_mod
async def _forbidden(*args, **kwargs):
raise AssertionError(
"generate_via_llm reached — debate did not short-circuit via middleware"
)
monkeypatch.setattr(run_mod, "generate_via_llm", _forbidden)
with pytest.raises(BudgetExceeded):
await run_project(
"FV42-GSV-E1",
"local",
docs_dir=docs_dir,
verdict_input=_VI,
client_factory=make_client_factory(
_VALID, tokens=100
), # 100 > cap 10, on the FIRST debate call
store=fresh_store,
max_tokens=10,
)
async def test_f_malformed_contract_raises_before_any_chat(docs_dir, make_client_factory) -> None:
calls = {"n": 0}
base = make_client_factory(_VALID)