Skip to content

feat: add detect_rail_from_headers helper - #24

Merged
vvillait88 merged 1 commit into
mainfrom
tec-302-detect-rail
May 14, 2026
Merged

feat: add detect_rail_from_headers helper#24
vvillait88 merged 1 commit into
mainfrom
tec-302-detect-rail

Conversation

@vvillait88

Copy link
Copy Markdown
Contributor

Summary

  • Returns \"mpp\" when Authorization: Payment is present, \"x402\" when payment-signature/x-payment is present, None otherwise.
  • Case-insensitive header-name lookup (RFC 7230 §3.2); auth scheme matched case-insensitive per RFC 7235.
  • In practice a client uses exactly one protocol; MPP wins as a documented tiebreaker for the rare degenerate case (both headers).
  • Exported from agentscore_commerce.payment.detect_rail_from_headers.

Tests

  • 14-fixture corpus locked as the cross-language contract with @agent-score/commerce's detectRailFromHeaders.
  • Parametrized via pytest.mark.parametrize so multiple drifts surface independently.
  • Additional invariants: array headers, undefined values, immutability.

Test plan

  • uv run pytest tests/test_dispatch.py — 16 tests pass
  • uv run pytest — full suite 945 pass / 3 skip, coverage 95.05%
  • uv run ruff check, uv run ruff format --check, uv run ty check — green

🤖 Generated with Claude Code

Returns "mpp" when Authorization: Payment is present, "x402" when
payment-signature/x-payment is present, None otherwise. Case-insensitive
header lookup per RFC 7230 §3.2; auth scheme matched per RFC 7235.

In practice a client constructs a request with exactly one protocol's
headers; if somehow both arrive (client bug or misconfigured proxy),
MPP wins by checking it first. Documented as a tiebreaker, not a feature.

Tests lock 14 cross-language fixtures with the @agent-score/commerce
sibling. Parametrized so multiple drifts surface independently.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vvillait88
vvillait88 merged commit 27adbda into main May 14, 2026
7 checks passed
@vvillait88
vvillait88 deleted the tec-302-detect-rail branch May 14, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant