Skip to content

Modular logistics and supply chain operating system (LSOS)

ci(api-contract): find variables nothing sets, and close three of them (#610)

Ron422b55aefef7
diff --git a/.github/actions/postman-contract/action.yml b/.github/actions/postman-contract/action.yml
index ac04345a..cff7a6b9 100644
--- a/.github/actions/postman-contract/action.yml
+++ b/.github/actions/postman-contract/action.yml
@@ -329,6 +329,10 @@ runs:
# Update Authenticated Customer is a no-op rename rather than a surprise.
# verification_code must equal what mint-api-key.php seeded — both read the same
# action input, so they cannot drift.
+ # base64_file_data / from_datetime / to_datetime were referenced by requests but
+ # set by nothing — see scripts/ci/find-unsourced-variables.py. An unresolved
+ # variable is sent literally, so those requests were exercising the API with the
+ # string "{{base64_file_data}}" rather than a payload.
# proof_photo_base64 / proof_signature_base64 are an 8x8 PNG. Capture Photo
# validates with base64_decode($value, true), so a data: URI prefix would fail
# the strict decode — this is bare base64 — and the bytes are a real image
@@ -360,6 +364,9 @@ runs:
' --env-var "driver_password=${DRIVER_PASSWORD}" \' \
' --env-var "driver_phone=${DRIVER_PHONE}" \' \
' --env-var "device_token=ci-contract-device-token" \' \
+ ' --env-var "base64_file_data=iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAbElEQVR42hXNQRUAUQhCUaMYhShGeVGIQhSizB+XXA7ODDtouIHBQ4YOM8suWm5h8ZKl+0CskDiBsIioHhx76LiDw0eO3oN/4FVf+J8h0PduzBqZ8x/bxNQPwgaFy192SGgelC0q13/CJaXlA8Z7WAFXOTbyAAAAAElFTkSuQmCC" \' \
+ ' --env-var "from_datetime=2026-01-01T00:00:00Z" \' \
+ ' --env-var "to_datetime=2027-01-01T00:00:00Z" \' \
' --env-var "proof_photo_base64=iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAbElEQVR42hXNQRUAUQhCUaMYhShGeVGIQhSizB+XXA7ODDtouIHBQ4YOM8suWm5h8ZKl+0CskDiBsIioHhx76LiDw0eO3oN/4FVf+J8h0PduzBqZ8x/bxNQPwgaFy192SGgelC0q13/CJaXlA8Z7WAFXOTbyAAAAAElFTkSuQmCC" \' \
' --env-var "proof_signature_base64=iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAbElEQVR42hXNQRUAUQhCUaMYhShGeVGIQhSizB+XXA7ODDtouIHBQ4YOM8suWm5h8ZKl+0CskDiBsIioHhx76LiDw0eO3oN/4FVf+J8h0PduzBqZ8x/bxNQPwgaFy192SGgelC0q13/CJaXlA8Z7WAFXOTbyAAAAAElFTkSuQmCC" \' \
' --env-var "invoice_public_id=${INVOICE_PUBLIC_ID}" \' \
diff --git a/scripts/ci/find-unsourced-variables.py b/scripts/ci/find-unsourced-variables.py
new file mode 100755
index 00000000..ec7620ac
--- /dev/null
+++ b/scripts/ci/find-unsourced-variables.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+"""Report {{variables}} a collection references but nothing ever sets.
+
+An unresolved Postman variable does not error — the literal "{{name}}" is sent, and the
+API answers with whatever that garbage produces. Those failures read as API problems and
+are often diagnosed as such: {{cart_id}} was unset for the entire life of the Storefront
+collection, and because the product id in the same URL *did* resolve, the endpoint
+answered "Invalid product provided" — an error about the other half of the path.
+
+A variable is considered sourced if a script sets it (pm.environment.set / cv.set) or the
+contract action injects it with --env-var. Collection-level `variables:` declarations do
+NOT count: the CLI does not resolve them, only --env-var values.
+
+Usage: find-unsourced-variables.py <collections-root> [action.yml]
+Exit code is always 0 — this reports, it does not gate.
+"""
+import glob
+import os
+import re
+import sys
+
+root = sys.argv[1]
+action = sys.argv[2] if len(sys.argv) > 2 else '.github/actions/postman-contract/action.yml'
+
+injected = set()
+if os.path.isfile(action):
+ injected = set(re.findall(r'--env-var "([A-Za-z0-9_]+)=', open(action).read()))
+
+total = 0
+for coll in sorted(os.listdir(root)):
+ d = os.path.join(root, coll)
+ if not os.path.isdir(d):
+ continue
+
+ used, produced = {}, set(injected)
+ for p in glob.glob(os.path.join(d, '**', '*.request.yaml'), recursive=True):
+ s = open(p).read()
+ name = os.path.basename(p)[:-len('.request.yaml')]
+ for v in re.findall(r'\{\{([A-Za-z0-9_]+)\}\}', s):
+ used.setdefault(v, set()).add(name)
+ produced |= set(re.findall(r'\.set\(\s*[\'"]([A-Za-z0-9_]+)[\'"]', s))
+
+ # {{$randomEmail}} and friends are generated by Postman itself.
+ missing = {v: n for v, n in used.items() if v not in produced and not v.startswith('$')}
+ total += len(missing)
+
+ print(f'\n{coll} — {len(missing)} variable(s) with no source')
+ for v, names in sorted(missing.items()):
+ print(f' {{{{{v}}}}} <- {", ".join(sorted(names))}')
+
+print(f'\n{total} unsourced variable(s) in total.')
diff --git a/scripts/ci/order-collection-requests.py b/scripts/ci/order-collection-requests.py
index 77354be5..906e37b3 100755
--- a/scripts/ci/order-collection-requests.py
+++ b/scripts/ci/order-collection-requests.py
@@ -119,6 +119,10 @@ RUN_LATE = {
'Checkout/Capture checkout as order', # needs {{checkout_token}} from Before
'Checkout/Get Checkout Status', # ditto
'Checkout/Update Stripe Payment Intent', # needs the cart and the service quote
+ # {{order_id}} is captured by Capture checkout as order — the only request that
+ # creates a storefront order.
+ 'Orders/Complete Order Pickup',
+ 'Orders/Get Order Receipt',
'Cart/Remove item from cart', # LAST: it empties what the above depend on
],
}