Skip to content

test: add totals integrity conformance module#64

Open
vishkaty wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
vishkaty:feat/totals-conformance
Open

test: add totals integrity conformance module#64
vishkaty wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
vishkaty:feat/totals-conformance

Conversation

@vishkaty

Copy link
Copy Markdown
Contributor

What

Adds totals_test.py, a conformance module for the structural invariants of the
totals[] array. business_logic_test.py checks totals arithmetic (via
existence lookups), but nothing asserts the cardinality and sign rules
the spec places on the array itself:

Test Requirement (types/totals.json, types/total.json)
test_single_subtotal_entry exactly one subtotal entry (contains + minContains:1/maxContains:1)
test_single_total_entry exactly one total entry
test_entries_have_type_and_amount every entry carries type and amount (required)
test_additive_entries_non_negative additive well-known types (subtotal, fulfillment, tax, fee) have amount >= 0
test_discount_entry_is_negative subtractive well-known types (discount, items_discount) have amount < 0

Why

Cardinality ("exactly one subtotal/total") and per-type sign are load-bearing
for any platform rendering a receipt, and the SDK model only enforces presence
of type/amount, not these array-level invariants — so a server can regress
them and still pass. These cut across checkout, fulfillment, and discount
responses.

Design

Server-agnostic relative assertions read from the raw response (consistent with
the other modules). test_entries_have_type_and_amount asserts on the raw wire
(int amount, non-empty type) rather than the parsed model, so it catches what
the model's lax coercion would mask. Sub-line (lines[]) and per-entry-currency
cases are intentionally omitted — the spec's totals amount is a bare
signed_amount (no currency), and the reference emits no sub-lines, so testing
them would be vacuous.

Verification

  • New module green against the reference; full suite green alongside it (14
    files, no regression).
  • pre-commit run clean (ruff, ruff-format, codespell).

Adds totals_test.py asserting the structural invariants of the totals[] array
that the suite does not yet check (business_logic only checks arithmetic via
existence lookups):

- exactly one subtotal entry (totals.json contains/minContains/maxContains)
- exactly one total entry
- every entry carries both type and amount (total.json required)
- additive well-known types (subtotal, fulfillment, tax, fee) are non-negative
- subtractive well-known types (discount, items_discount) are negative

Server-agnostic relative assertions read from the raw response, so any
conformant business passes. Sub-line and per-entry-currency cases are omitted
because the reference emits neither (they would be vacuous).
@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:needs-triage Signal that the PR is ready for human triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants