import json import pytest from solomon_mlx.budget import Budget def test_budget_reserves_before_dispatch_and_exhausts(tmp_path): path = tmp_path / "budget.json" budget = Budget(path, 20) with budget.reserve(15, "one"): assert json.loads(path.read_text())["entries"][0]["status"] == "reserved" with pytest.raises(RuntimeError), budget.reserve(1, "concurrent"): pass with pytest.raises(RuntimeError), budget.reserve(6, "too expensive"): pass def test_uncertain_dispatch_blocks_followups(tmp_path): budget = Budget(tmp_path / "budget.json") with pytest.raises(TimeoutError), budget.reserve(20, "uncertain"): raise TimeoutError() with pytest.raises(RuntimeError), budget.reserve(20, "retry"): pass