Skip to content

fix(shopping): complete checkouts with a buyer and check the outcome - #138

Open
segiodongo wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
segiodongo:upstream/u1-complete-with-buyer
Open

segiodongo wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
segiodongo:upstream/u1-complete-with-buyer

Conversation

@segiodongo

Copy link
Copy Markdown
Collaborator

Description

Fixes several assumptions in the shopping checkout creation, update, and completion helpers that caused tests to fail or crash before reaching their assertions against spec-compliant servers outside the bundled Flower Shop sample:

  • Complete checkouts with a buyer and check the outcome: A business may require a buyer email to place an order (the specification's Create Checkout example returns status: "incomplete" with a recoverable error at $.buyer.email when none is supplied). Previously, create_completed_order and complete_checkout_session created checkouts without a buyer, asserted only HTTP 200 on Complete Checkout, and indexed ["order"]["id"] unconditionally — turning any recoverable completion refusal into KeyError: 'order'.
    • Hoists DEFAULT_BUYER to ShoppingIntegrationTestBase. create_completed_order passes it on Create Checkout; complete_checkout_session adds it via Update Checkout when absent, polls Get Checkout if the server returns status: "complete_in_progress", and fails with an actionable message quoting the server's status and messages[] when no order is placed. Tests that inspect raw completion responses use attempt_complete_checkout.
    • test_idempotency_complete now completes a checkout that actually places an order and verifies that an order resulted, rather than passing when two completions return identical refusals.
    • test_payment_failure creates its checkout with a buyer so servers that require one reach payment validation instead of failing earlier on missing buyer info.
  • Send only Create Checkout request inputs with spec field names: create_checkout_payload previously sent locality / region instead of address_locality / address_region (also fixed in test_update_checkout), preselected the sample server's "std-ship" option ID, and attached response-only fields (id, status, currency, totals, links, invented line-item and group IDs). It now sends only valid Create Checkout request inputs and logs any unexpected type: "error" messages via note_error_messages.
  • Cope with omitted optional payment and carried-over instruments on Update Checkout: Extracts checkout_update_payload (converting carried-over response SelectedPaymentInstrument models to JSON so PaymentUpdateRequest validation succeeds) and uses it where tests previously read checkout_obj.payment.instruments directly without guarding payment is None.
  • Skip test_webhook_event_stream when /testing/simulate-shipping/{id} is absent: Matches test_update_event_is_full_order_entity in webhook_structure_test.py by skipping on 404/405 (no simulation hook) or 403 (mismatched --simulation_secret).
  • Unit tests: Adds tests/strict_store.py (an in-memory httpx.MockTransport store requiring a buyer, omitting optional payment, generating its own shipping options, and supporting complete_in_progress) and tests/completion_test.py, and wires uv run pytest tests into CI while keeping bare pytest scoped to core, common, and shopping.

Verification

  • uv run pytest tests: 21 passed
  • uv run ucp-conformance --suite=all against the Flower Shop sample server: 83 executed, 81 passed, 2 skipped, 0 failures, 0 errors

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Nov 18, 2026
Hoist DEFAULT_BUYER to ShoppingIntegrationTestBase, ensure a buyer and poll complete_in_progress in complete_checkout_session, fail with the server's own status and messages[] when no order is placed, send only Create Checkout request inputs with spec field names, guard omitted optional payment on Update Checkout via checkout_update_payload, skip test_webhook_event_stream when /testing/simulate-shipping is absent, and add strict-store unit tests.
@segiodongo
segiodongo force-pushed the upstream/u1-complete-with-buyer branch from 53887b7 to 7e1f914 Compare November 18, 2026 20:15
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.

2 participants