Skip to content

Commit e430896

Browse files
vvillait88claude
andcommitted
test: Checkout gate-hook + capture_wallet + zero-settle paths reach 95% coverage
Adds tests covering the previously-uncovered Checkout flows: - gate run_gate escape hatch (allow / deny / invalid-shape branches) - gate per_request_policy returning None (skip-gate path) - gate on_denied callback reshaping the canonical denial body - gate happy path attaches ctx.capture_wallet closure; the closure itself is exercised end-to-end with AgentScoreCore.acapture_wallet mocked - Checkout.accepted_rails dedupes tempo + tempo_session to a single slug - Checkout.accepted_method_names emits each protocol method - zero-settle MPP carve-out at zero (compose_mppx skipped, signer lifted) Also tightens the _spec_rail_key / _spec_method_name return types from RailKey | None / str | None to non-nullable (every code path returns a value; the | None was dead and the key is None checks in the accepted_rails / accepted_method_names accessors were unreachable). Mirrors the same fix landed in node-commerce. Tests: 1156 passed, 4 skipped. Total coverage: 93.02 to 95.00 percent. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 79a8b84 commit e430896

2 files changed

Lines changed: 417 additions & 11 deletions

File tree

agentscore_commerce/checkout.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,34 +104,30 @@
104104
)
105105

106106

107-
def _spec_rail_key(spec: CheckoutRailSpec) -> RailKey | None:
107+
def _spec_rail_key(spec: CheckoutRailSpec) -> RailKey:
108108
"""Map a ``*RailSpec`` instance to its canonical :data:`RailKey` slug.
109109
110110
Tempo charge and Tempo session both speak MPP on Tempo, so they fold to
111-
``"tempo_mpp"``. Unknown types return ``None``.
111+
``"tempo_mpp"``.
112112
"""
113113
if isinstance(spec, (TempoRailSpec, TempoSessionRailSpec)):
114114
return "tempo_mpp"
115115
if isinstance(spec, X402BaseRailSpec):
116116
return "x402_base"
117117
if isinstance(spec, SolanaMppRailSpec):
118118
return "solana_mpp"
119-
if isinstance(spec, StripeRailSpec):
120-
return "stripe"
121-
return None
119+
return "stripe" # StripeRailSpec is the only remaining variant in CheckoutRailSpec.
122120

123121

124-
def _spec_method_name(spec: CheckoutRailSpec) -> str | None:
122+
def _spec_method_name(spec: CheckoutRailSpec) -> str:
125123
"""Protocol-shaped method name for the ``methods: [...]`` discovery array."""
126124
if isinstance(spec, (TempoRailSpec, TempoSessionRailSpec)):
127125
return "tempo/charge"
128126
if isinstance(spec, X402BaseRailSpec):
129127
return "x402/exact (base)"
130128
if isinstance(spec, SolanaMppRailSpec):
131129
return "solana/charge"
132-
if isinstance(spec, StripeRailSpec):
133-
return "stripe/spt"
134-
return None
130+
return "stripe/spt" # StripeRailSpec is the only remaining variant in CheckoutRailSpec.
135131

136132

137133
class CheckoutValidationError(Exception):
@@ -618,7 +614,7 @@ def accepted_rails(self) -> list[RailKey]:
618614
seen: set[str] = set()
619615
for spec in self.rails.values():
620616
key = _spec_rail_key(spec)
621-
if key is None or key in seen:
617+
if key in seen:
622618
continue
623619
seen.add(key)
624620
out.append(key)
@@ -635,7 +631,7 @@ def accepted_method_names(self) -> list[str]:
635631
seen: set[str] = set()
636632
for spec in self.rails.values():
637633
name = _spec_method_name(spec)
638-
if name is None or name in seen:
634+
if name in seen:
639635
continue
640636
seen.add(name)
641637
out.append(name)

0 commit comments

Comments
 (0)