From a44fffb6b0e0ace92e815d635bbd149b34f178b9 Mon Sep 17 00:00:00 2001 From: Nik Wattse <255182715+n-watts@users.noreply.github.com> Date: Thu, 15 Jan 2026 14:40:08 -0800 Subject: [PATCH 1/3] Improve happy path logs with cart snapshots --- .../flower_shop/simple_happy_path_client.py | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/rest/python/client/flower_shop/simple_happy_path_client.py b/rest/python/client/flower_shop/simple_happy_path_client.py index c8a11b2..c6c3802 100644 --- a/rest/python/client/flower_shop/simple_happy_path_client.py +++ b/rest/python/client/flower_shop/simple_happy_path_client.py @@ -53,7 +53,7 @@ from ucp_sdk.models.schemas.shopping.types.token_credential_resp import ( TokenCredentialResponse, ) - +from typing import Dict def get_headers() -> dict[str, str]: """Generate necessary headers for UCP requests.""" @@ -148,6 +148,30 @@ def log_interaction( f.write(f"export {var_name}=$(echo $RESPONSE | jq -r '{jq_expr}')\n") f.write("```\n\n") +def log_cart_snapshot(logger, step_label: str, checkout_data: Dict) -> None: + """ + Logs a compact snapshot of the cart contents. + Safe for samples: no PII, no payment data. + """ + items = [] + for li in checkout_data.get("line_items", []) or []: + item = li.get("item", {}) or {} + title = item.get("title") or item.get("name") or item.get("id") or "unknown-item" + qty = li.get("quantity") + items.append(f"{title} x{qty}") + + total = None + totals = checkout_data.get("totals") or [] + if totals: + total = totals[-1].get("amount") + + logger.info( + "%s | total_cents=%s items=%s", + step_label, + total, + items, + ) + def main() -> None: """Run the happy path client.""" @@ -349,9 +373,7 @@ def main() -> None: logger.info("Successfully created checkout session: %s", checkout_id) - logger.info( - "Current Total: %s cents", checkout_data["totals"][-1]["amount"] - ) + log_cart_snapshot(logger, "STEP 1 snapshot (created)", checkout_data) # ========================================================================== @@ -444,7 +466,7 @@ def main() -> None: logger.info("New Total: %s cents", checkout_data["totals"][-1]["amount"]) - logger.info("Item Count: %d", len(checkout_data["line_items"])) + log_cart_snapshot(logger, "STEP 2 snapshot (items added)", checkout_data) # ========================================================================== @@ -550,6 +572,10 @@ def main() -> None: else: logger.warning("No discounts applied!") + log_cart_snapshot( + logger, "STEP 3 snapshot (discount applied)", checkout_data + ) + # ========================================================================== # STEP 4: Select Fulfillment Option From 2416d4fe5cc8b2db2da966e024e3c063f9d7bc54 Mon Sep 17 00:00:00 2001 From: Nik Wattse <255182715+n-watts@users.noreply.github.com> Date: Thu, 15 Jan 2026 14:45:35 -0800 Subject: [PATCH 2/3] Ignore IntelliJ project files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e10ddfd..97d23f8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .ruff_cache uv.lock .venv +.idea/ From 498951f4589fd39f38530ce110d70f4339fcf431 Mon Sep 17 00:00:00 2001 From: Nik Wattse <255182715+n-watts@users.noreply.github.com> Date: Thu, 15 Jan 2026 18:14:53 -0800 Subject: [PATCH 3/3] Fix docstring style for cart snapshot helper --- .../client/flower_shop/simple_happy_path_client.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/rest/python/client/flower_shop/simple_happy_path_client.py b/rest/python/client/flower_shop/simple_happy_path_client.py index c6c3802..b927cd7 100644 --- a/rest/python/client/flower_shop/simple_happy_path_client.py +++ b/rest/python/client/flower_shop/simple_happy_path_client.py @@ -53,7 +53,7 @@ from ucp_sdk.models.schemas.shopping.types.token_credential_resp import ( TokenCredentialResponse, ) -from typing import Dict + def get_headers() -> dict[str, str]: """Generate necessary headers for UCP requests.""" @@ -148,15 +148,18 @@ def log_interaction( f.write(f"export {var_name}=$(echo $RESPONSE | jq -r '{jq_expr}')\n") f.write("```\n\n") -def log_cart_snapshot(logger, step_label: str, checkout_data: Dict) -> None: - """ - Logs a compact snapshot of the cart contents. + +def log_cart_snapshot(logger, step_label: str, checkout_data: dict) -> None: + """Log a compact snapshot of the cart contents. + Safe for samples: no PII, no payment data. """ items = [] for li in checkout_data.get("line_items", []) or []: item = li.get("item", {}) or {} - title = item.get("title") or item.get("name") or item.get("id") or "unknown-item" + title = ( + item.get("title") or item.get("name") or item.get("id") or "unknown-item" + ) qty = li.get("quantity") items.append(f"{title} x{qty}")