Bug fix · ~30 min
Inventory: orders oversell
src/ is a small warehouse service: stock levels per SKU and the units each open order holds. Support filed two tickets this week:
- Two customers each got "the last mug". The service let an order reserve units that another order already held.
- A cancellation was sent twice, and afterwards the dashboard showed more free mugs than were on the shelf.
Fix both without changing the public API. This is the contract of Inventory:
restock(sku, quantity)adds units and returns the units now available.quantitymust be a positive integer, otherwiseValueError.reserve(order_id, sku, quantity)holds units for an order.UnknownSkufor a SKU that was never stocked,OutOfStockwhen fewer thanquantityunits are available,ValueErrorfor a quantity that is not a positive integer,InventoryErrorwhen the order already holds a reservation. A failed call holds nothing.release(order_id)cancels a reservation and returnsTrue. Releasing an unknown or already released order changes nothing and returnsFalse.ship(order_id)takes the reserved units out of stock. An unknown or released order raisesInventoryError.available(sku)is units on hand minus units reserved.
tests/ holds the public suite. A hidden suite checks the whole contract above; you only see how many of its tests pass. Add tests for the cases you fix before you trust a change, yours or the AI's.