Nobody has started this yet — be first.
Business impact
A warehouse-integration script or admin tool that occasionally computes a restock delta of exactly zero (nothing changed since the last sync) -- a perfectly normal, meaningless no-op -- gets back a 500 Internal Server Error with a raw Postgres constraint-violation message instead of a clean rejection. Anyone integrating against this API has to specifically special-case "don't send zero" rather than trusting the API to handle it gracefully, and every occurrence pollutes error-rate monitoring with a 5xx that isn't actually a server problem.
Problem
POST /v1/skus with {"sku_id": "x", "quantity": 0} returns 500 Internal Server Error with a body like {"error":"restock: ledger: ERROR: new row for relation \"stock_ledger\" violates check constraint \"stock_ledger_delta_check\" (SQLSTATE 23514)"}.
Current behavior
Restock's guard checks qty < 0 instead of qty <= 0, so 0 slips past validation and reaches the database, where stock_ledger's own CHECK (delta > 0) constraint rejects the ledger insert.
Expected behavior
A quantity of 0 should be rejected the same clean way a negative quantity already is: a 400/422 with ErrInvalidQuantity's message, never reaching the database at all.
Steps to reproduce
go test ./tickets/tests/... -run TestTicket04 -vWhy this matters
Restock's doc comment describes it as "creates the SKU ... or adds qty" -- a quantity of zero is a meaningless restock and should be rejected up front, exactly like a negative one. Its guard checks qty < 0 instead of qty <= 0, so 0 slips past validation and reaches the database, surfacing as an opaque, unrelated-looking database error mapped to a bare 500.
Suggested approach
Look at the comparison operator in Restock's quantity guard in pkg/inventory/service.go, right next to ErrInvalidQuantity's own message ("quantity must be positive"). Zero is not positive.
Acceptance criteria
Verification
TEST_DATABASE_URL=postgresql://... go test ./tickets/tests/... -run TestTicket04 -v
Hints (0/2)
Try it without hints first — the reading is the exercise.
Working on this ticket
Work on a branch named for the ticket — that's what you'll submit.
Branch off your fork
Sign in to create it automatically, or do it yourself:
$git checkout -b fix/restock-zero-quantity-boundaryFix it and commit
Meet every acceptance criterion, and add a test that would have caught this.
Push the branch
$git push -u origin fix/restock-zero-quantity-boundarySubmit it below
Paste your fork URL and the branch name, with a short write-up of the root cause.
Questions
Ask about anything unclear in the ticket — the maintainer and anyone who has solved it can answer. Please don't post full solutions.
Sign in to ask a question or reply.
Sign inSKIP LOCKEDhttp://localhost:8081localhost:5434flash-saleeveryday-widgetcurl localhost:8081/healthzgo run ./cmd/loadtest -url http://localhost:8081 -sku flash-sale -concurrency 10000Work the tickets in tickets/docs/ (ordered easy → hard); each names one dedicated Go test in tickets/tests/:
export TEST_DATABASE_URL=postgresql://inventory:inventory@localhost:5432/inventory_test?sslmode=disable
go test ./tickets/tests/... -run TestTicket24 -v # a single ticket
./tickets/run_tickets.sh # all 25, clean pass/fail summary
Tickets that don't touch Postgres (02, 07, 17, 19) run fine without TEST_DATABASE_URL; the rest t.Skip cleanly, not fail, if it's unset.
Level 1
Fix a bug
Read existing behaviour, correct it.