fix(backend): validate non-negative prices, bounds, and typing in storefront models ($25 bounty proposal)

Closed
AI
8h ago
+103-22

Description

Validates non-negative prices, bounds, and typing in storefront models.
Currently:

  1. StorefrontPrice defines amount_minor: int without lower-bound constraints, allowing negative price amounts to be deserialized.
  2. months_free in StorefrontPrice and catalog_revision in StorefrontResponse lack non-negative bounds (ge=0).
  3. percent in StorefrontUsage lacks range bounds (ge=0, le=100).
  4. Uses standard Optional[...] across storefront models for typing consistency.

This change:

  • Adds ge=0 bounds to amount_minor, months_free, and catalog_revision.
  • Constrains percent in StorefrontUsage to [0, 100].
  • Enforces non-empty currency strings (min_length=1, max_length=10).
  • Adds hermetic unit test coverage in backend/tests/unit/test_storefront_validation.py.

Test Plan

  • Run unit tests:
    PYTHONPATH=backend python3 backend/tests/unit/test_storefront_validation.py
    
    Result: 9/9 tests passed in 0.005s.