Validate vendor stock records at the adapter boundary
The vendor sent quantity as an empty string and the importer stored zero, hiding a data problem. Validate a versioned stock response before mapping it into internal records.
- Focused work estimate
- 1h 15m + prerequisites
- Priority in the scenario
- Medium
- Engineering practice
- Contract validation · Adapter design · Data quality
Estimated field mix
- Integrations70%
- Data engineering30%
Field percentages are editorial estimates of the ticket's engineering focus. They total 100%; they are not measured time, proficiency scores, or ownership evidence.
Pattern topics
- AdapterRefactor
Keep vendor payloads outside the internal stock model; compare a small mapping function with an object adapter while preserving boundary validation.
Review it, then add it to your workspace.
The board opens an editable draft; nothing is saved until you confirm it. Sign-in and workspace permissions apply, and Demo boards remain ephemeral.
Project context
A fictional retailer receives stock from two vendor warehouses. The vendor API paginates snapshots and emits change events, but retries and deleted products have caused unexplained stock drift. Work against a local vendor simulator.
Setup prerequisites
- Create a local vendor API simulator with cursor pages and stock events.
- Use synthetic tenants, SKUs, and warehouse records; no vendor account is required.
Preceding work
No earlier ticket is required. Complete the project setup above.
Acceptance criteria
- Records require vendor item ID, warehouse ID, nonnegative integer quantity, revision, and updated timestamp.
- Missing, empty, fractional, or out-of-range quantities are rejected with a safe record reference.
- Unknown optional vendor fields do not silently become internal domain fields.
Implementation constraints
- Keep vendor DTOs separate from internal stock types.
Verification to include
- Accept a valid zero-stock record and a positive quantity record.
- Reject empty-string, negative, fractional, and unsafe-integer quantities without writing stock.
Deliverables
- Vendor response schema and malformed-record fixtures
Rollout and recovery
Start validation in the simulator; malformed records go to an inspection queue rather than defaulting to zero.
Value of the work
For the engineer: Practice external contracts, cursor recovery, mapping conflicts, and reconciliation under partial failure.
For the team: Inspect whether integration changes protect inventory correctness and give operators a clear recovery path.
Evidence boundaries
Outcome Evidence: Tests, patches, and runbooks are requested deliverables. They become Outcome Evidence only through a qualified Mission and immutable Evidence IDs.
Ownership Evidence: Independent adaptation must be observed under a declared verification policy and cite immutable Evidence IDs. Completing a planning ticket establishes no Ownership Evidence.