Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ All notable changes to `agent-readback`. Dates are UTC.
(`tabindex="0"`), is a labelled region named by its heading, and has a
visible focus outline, so keyboard users can scroll it in any browser.
Column headers carry `scope="col"` and each table is labelled by its heading.
- Stripe: a refund whose id is empty or only whitespace is now a malformed
read (`unverified`). It used to pass the id check, become a snapshot key, and
could return `verified` for an otherwise matching claim. FHIR already
rejected such Appointment ids; both now have end-to-end regression tests.

## 0.3.1 — 2026-11-22

Expand Down
3 changes: 2 additions & 1 deletion agent_readback/verifiers/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def _refunds(self, payment_intent: str) -> dict[str, dict[str, Any]]:
if not isinstance(items, list) or not isinstance(has_more, bool):
raise ValueError("malformed Stripe response: data is not a list or has_more is not a boolean")
for item in items:
if not isinstance(item, dict) or not isinstance(item.get("id"), str) or not item["id"]:
if not isinstance(item, dict) or not isinstance(item.get("id"), str) or not item["id"].strip():
# A blank id would become a snapshot key and let a malformed refund verify a claim.
raise ValueError("malformed Stripe response: refund without a string id")
found[item["id"]] = {name: item.get(name) for name in FIELDS}
if not has_more:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_fhir_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ def handle(request):
"bundle without resourceType": {"entry": []},
"matched entry is not an Appointment": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Patient", "id": "p1"}}]},
"appointment without an id": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment"}}]},
"appointment id is empty": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": ""}}]},
"appointment id is whitespace": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": " "}}]},
"actor is a list": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": "a1", "participant": [{"actor": []}]}}]},
"actor is an empty dict list": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": "a1", "participant": [{"actor": [{}]}]}}]},
"actor is an empty string": {"resourceType": "Bundle", "entry": [{"resource": {"resourceType": "Appointment", "id": "a1", "participant": [{"actor": ""}]}}]},
"entry search is a string": {"resourceType": "Bundle", "entry": [{"search": "match", "resource": {"resourceType": "Appointment", "id": "a1"}}]},
}
Expand Down
13 changes: 13 additions & 0 deletions tests/test_stripe_sql_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ def sync_auth_flow(self, request):
"page is a list": [],
"refund is a string": {"data": ["re_1"], "has_more": False},
"refund id is a number": {"data": [{"id": 7}], "has_more": False},
"refund id is empty": {"data": [{"id": ""}], "has_more": False},
"refund id is whitespace": {"data": [{"id": " "}], "has_more": False},
"has_more is a string": {"data": [], "has_more": "false"},
"data is an object": {"data": {"id": "re_1"}, "has_more": False},
"error body with 200": {"error": {"type": "api_error", "message": "x"}},
Expand Down Expand Up @@ -453,3 +455,14 @@ def test_has_more_with_an_empty_page_is_an_incomplete_read_not_verified():
before = verifier.snapshot(REFUND)
assert before == set()
assert verifier.check(REFUND, before).status is Status.UNVERIFIED


def test_blank_refund_id_never_verifies_an_otherwise_matching_refund():
# Stripe ids never contain whitespace; a blank one is a malformed read, not a new refund to verify against.
blank = {"id": " ", "amount": 2500, "currency": "usd", "status": "succeeded", "payment_intent": "pi_1"}
pages = [{"data": [], "has_more": False}, {"data": [blank], "has_more": False}]
transport = httpx.MockTransport(lambda request: httpx.Response(200, json=pages.pop(0) if len(pages) > 1 else pages[0]))
with httpx.Client(transport=transport, base_url="https://stripe.test") as client:
verifier = StripeRefundVerifier(client)
verdict = verifier.check(REFUND, verifier.snapshot(REFUND))
assert verdict.status is Status.UNVERIFIED and kinds(verdict) == [FindingKind.UNREACHABLE]
Loading