import asyncio from warehouse_allocation.infrastructure.inventory import InMemoryInventoryRepository async def test_feasibility_requires_every_sku() -> None: repository = InMemoryInventoryRepository() await repository.set_levels("w1", {"A": 3, "B": 1}) await repository.set_levels("w2", {"A": 4, "B": 5}) feasible = await repository.feasible_warehouses(["w1", "w2", "w3"], {"A": 2, "B": 2}) assert feasible == {"w2"} async def test_concurrent_reservations_do_not_oversell() -> None: repository = InMemoryInventoryRepository() await repository.set_levels("w1", {"A": 5}) results = await asyncio.gather( repository.reserve("w1", {"A": 4}), repository.reserve("w1", {"A": 4}), ) assert sorted(results) == [False, True] assert await repository.feasible_warehouses(["w1"], {"A": 2}) == set() assert await repository.ping() is True