Reserved stock becomes available again

Unranked practice · 100 points

Ticket

Warehouse availability must subtract active reservations from on-hand stock so two reservations cannot oversell an item. Releasing a reservation must make its quantity available exactly once.

Workspace rules

Edit surface
src/inventory.js
Protected
test/inventory.public.test.js
Public tests
test/inventory.public.test.js

Rubric

Gates: inventory-basic-contract

Editorial

Show editorial (spoiler)

## What is wrong Availability ignores active reservations, so two callers can reserve the last unit. Releasing a reservation can also add stock back more than once. ## Fix Compute availability as on-hand stock minus the quantities of all active reservations for the SKU. When reserving, check that quantity against that availability before recording the reservation. When releasing, mark only an active reservation as released and leave on-hand stock unchanged. Its quantity becomes available again because released reservations are no longer counted.

Open practice workspace →

Sign in to open the account-gated workspace. The practice agent and submissions arrive in the next slices; this workspace is untimed and unranked.