Skip to content

test: add discount capability conformance module#62

Merged
damaz91 merged 3 commits into
Universal-Commerce-Protocol:mainfrom
vishkaty:feat/discount-conformance
Jul 24, 2026
Merged

test: add discount capability conformance module#62
damaz91 merged 3 commits into
Universal-Commerce-Protocol:mainfrom
vishkaty:feat/discount-conformance

Conversation

@vishkaty

Copy link
Copy Markdown
Contributor

What

Adds discount_test.py, a conformance module for the discount capability
(dev.ucp.shopping.discount). It complements the discount coverage already in
business_logic_test.py (discount flow, multiple-code accept/reject,
fixed-amount) by asserting discount MUSTs from discount.md that the suite does
not yet check:

Test Requirement
test_code_matches_case_insensitively codes are matched case-insensitively
test_discount_total_is_negative a discount's totals[] entry is negative (total.json exclusiveMaximum: 0)
test_codes_replace_previous_set a new codes[] set replaces the previous one
test_empty_codes_removes_discount an empty codes[] removes all discounts
test_allocations_sum_to_applied_amount an applied discount's allocations[] sum to its amount (a cross-field invariant the JSON schema cannot express)
test_client_applied_does_not_change_price client-supplied discounts.applied[] (response-only, ucp_request: omit) does not change the priced total

Why

These are the discount behaviours most likely to differ silently between
implementations — case-folding, the sign convention on totals[], code-set
replacement vs. accumulation, and the allocation/amount reconciliation. They are
currently unverified at the conformance level, so a merchant can regress them
and still pass. The last test also locks in that discounts are priced
server-side: a client cannot inject a cheaper order via the response-only
applied[] field.

Design

Consistent with the conformance_input-driven approach in #58: assertions are
relative (a discount reduced the total; the applied code is echoed; the
discount total is negative; an empty set clears it; allocations reconcile)
rather than tied to a specific discount value, so any conformant business passes
regardless of the discount amounts it offers. Codes are read from
conformance_input.json under test_fixtures
(valid_discount_code / second_discount_code). The module skips honestly when
no code is configured, the business does not advertise the capability, or the
server emits no allocations[].

Verification

  • All 6 tests green against the reference Flower Shop server.
  • Full suite green alongside the new module (no regression).
  • pre-commit run --all-files clean (ruff, ruff-format, prettier, codespell).

@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Jul 22, 2026
@carolinerg1 carolinerg1 added status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Jul 23, 2026
Complements business_logic_test.py by covering discount MUSTs the suite does
not assert: case-insensitive code matching (DSC-005), the negative sign of a
discount's totals[] entry (DSC-021; total.json exclusiveMaximum: 0), codes[]
replacement (DSC-003) and removal (DSC-004), the cross-field invariant that an
applied discount's allocations[] sum to its amount (DSC-022), and that
client-supplied discounts.applied[] (response-only, ucp_request: omit) does not
change the priced total (DSC-027).

Uses the fixture_ctx discount-code helpers (get_test_discount_code /
get_test_discount_code_2) and the valid_discount_code / valid_discount_code_2
conformance_input keys, consistent with business_logic_test after Universal-Commerce-Protocol#63. Skips
honestly when the business does not advertise the capability or emits no
allocations[].
@vishkaty
vishkaty force-pushed the feat/discount-conformance branch from a81a893 to fa5c649 Compare July 24, 2026 04:19
damaz91 added 2 commits July 24, 2026 08:33
TAG=agy
CONV=ba2601d2-c9f2-44dd-b597-7f95df69075a
TAG=agy
CONV=ba2601d2-c9f2-44dd-b597-7f95df69075a
@damaz91
damaz91 merged commit 35fef8b into Universal-Commerce-Protocol:main Jul 24, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants