Files
Open_Ultra_SAST/tests/test_search_budget.py
T
Marius CiepluchandClaude Fable 5.2 b975acb7e0 refactor(memory): the memory store and the spend meter leave the plane package (C1)
openultrasast.plane.memory and openultrasast.plane.budget are now
openultrasast.memory and openultrasast.budget; every importer follows. A pure move:
no behaviour changes. The two renames themselves were swept into 1aad435 by mistake
(they were staged when that spec commit was made), so the three commits between it
and this one do not import; this commit completes the move.

memory.py still reaches into the plane in two lazy imports (results_root in
open_store, the reconciler in seed); the cut of the plane has to settle both.

Checked: ruff, ruff format, mypy; 163 test files around memory, budget, plane, learn
and hunt passed across three runs by the implementing agent, and the six closest
files again before this commit. The whole suite was not run locally.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-30 10:56:25 +01:00

59 lines
1.7 KiB
Python

from concurrent.futures import ThreadPoolExecutor
import pytest
from openultrasast.budget import BudgetExhausted, SpendBudget
from openultrasast.search.budget import SearchBudget
def test_reserve_settle_release():
meter = SpendBudget(1)
reservation = meter.reserve(0.7)
with pytest.raises(BudgetExhausted):
meter.reserve(0.4)
reservation.settle(0.2)
assert meter.spent == 0.2 and meter.reserved == 0
other = meter.reserve(0.8)
other.release()
assert meter.reserved == 0
with pytest.raises(ValueError):
reservation.settle(0.1)
for bad in [-1, float("nan"), float("inf")]:
with pytest.raises(ValueError):
meter.reserve(bad)
def test_concurrent_reservations_cannot_overrun():
meter = SpendBudget(1)
def reserve(_):
try:
return meter.reserve(0.3)
except BudgetExhausted:
return None
with ThreadPoolExecutor(max_workers=12) as pool:
reservations = list(pool.map(reserve, range(20)))
assert sum(r is not None for r in reservations) == 3
assert meter.reserved <= 1
def test_config_validation():
assert SearchBudget().task_wall_seconds == 900
for kwargs in [dict(retries=-1), dict(memory_bytes=0), dict(wall_seconds=float("nan"))]:
with pytest.raises(ValueError):
SearchBudget(**kwargs)
def test_settlement_bound_and_release_then_readmission():
meter = SpendBudget(0.5)
reserved = meter.reserve(0.5)
with pytest.raises(ValueError, match="exceeds reservation"):
reserved.settle(0.6)
assert meter.reserved == 0.5 and meter.spent == 0
reserved.release()
meter.reserve(0.5).settle(0.5)
assert meter.spent == 0.5
with pytest.raises(BudgetExhausted):
meter.reserve(0.001)