Analyze code to suggest and add Design by Contract specifications (preconditions, postconditions, invariants, semantic invariants) in any language. Trigger on: "Design by Contract", "DBC", "preconditions", "postconditions", "class invariants", "code contracts", "formal specifications", "document assumptions", "add contracts", "make this function safer", "define what this function guarantees", "add assertions to document behavior", Bertrand Meyer, Eiffel contracts, or when discussing invariants that should always hold. Do NOT skip for non-Eiffel code — DBC applies everywhere via assertions, type guards, properties.
92
90%
Does it follow best practices?
Impact
95%
1.05xAverage score across 5 eval scenarios
Passed
No known issues
A Go HTTP service reserves inventory for orders. A handler currently accepts partially invalid requests and sometimes returns success with missing reservation details. Add contract-oriented documentation and enforcement so callers and maintainers understand exactly what the reservation operation requires and guarantees.
Produce reservation_contract_analysis.md, reservation.go, and reservation_contract_tests.md.
=============== FILE: reservation.go ===============
package inventory
type Line struct {
SKU string
Qty int
}
type Reservation struct {
ID string
Lines []Line
}
func ReserveInventory(orderID string, lines []Line) (*Reservation, error) {
if len(lines) == 0 {
return nil, nil
}
return &Reservation{ID: orderID, Lines: lines}, nil
}