Skip to content

test(x402): re-enable retry_with_x402 and direct request tests#1105

Open
yashhzd wants to merge 1 commit intocoinbase:mainfrom
yashhzd:fix/python-x402-retry-tests
Open

test(x402): re-enable retry_with_x402 and direct request tests#1105
yashhzd wants to merge 1 commit intocoinbase:mainfrom
yashhzd:fix/python-x402-retry-tests

Conversation

@yashhzd
Copy link
Copy Markdown

@yashhzd yashhzd commented Apr 14, 2026

Summary

Re-enables the Python x402 action provider tests for retry_with_x402 and make_http_request_with_x402 that were commented out in python/coinbase-agentkit/tests/action_providers/x402/test_x402_action_provider.py with the note:

These tests are temporarily disabled due to inconsistent mock patching behavior between local and CI/CD environments. The tests pass locally but fail in CI/CD with AttributeError.

Root cause

The disabled tests used:

@patch("coinbase_agentkit.action_providers.x402.x402_action_provider.decode_x_payment_response")

but decode_x_payment_response is not imported in x402_action_provider.py. The current provider inlines base64.b64decode + json.loads on the payment-response / x-payment-response header, so there is no decode_x_payment_response attribute to patch. mock.patch raised AttributeError wherever it evaluated the target, which is why the tests failed in CI.

The obsolete mock_x402_requests fixture in conftest.py also patched x402.clients.requests.x402_requests, but the provider imports x402_requests from x402.http.clients.requests — another reason those old tests would not affect the provider's bound reference.

What this PR does

  1. Deletes the three disabled test bodies and obsolete fixtures (mock_x402_requests, mock_decode_payment).
  2. Adds two robust fixtures in conftest.py:
    • mock_x402_session patches x402_requests at the provider module path — the location actually bound by the provider — so the patch is stable across environments.
    • patch_x402_client stubs x402ActionProvider._create_x402_client so tests don't need a real signable wallet.
  3. Adds coverage for the current provider API and response schema:
    • retry_with_x402: success with payment proof, success without proof, non-200 upstream response, unregistered service, non-USDC asset, payment above max_payment_usdc, network mismatch.
    • make_http_request_with_x402: success with proof, success without proof, non-200 upstream, unregistered service (with dynamic registration hint), unsupported wallet provider.

No production code is changed — this PR is scoped to test infrastructure only.

Verification

Run from python/coinbase-agentkit/:

uv sync
uv run pytest tests/action_providers/x402/ -v
uv run ruff format tests/action_providers/x402/ --check
uv run ruff check tests/action_providers/x402/
uv run pytest

Results on this branch:

  • tests/action_providers/x402/: 22 passed (was 10 passing + 3 commented-out).
  • Full python/coinbase-agentkit suite: 675 passed, 35 deselected.
  • ruff format --check and ruff check both pass.

Test plan

  • x402 action provider tests pass locally
  • Full python/coinbase-agentkit test suite passes locally
  • ruff format --check passes on touched files
  • ruff check passes on touched files
  • CI passes on this PR

… tests

The disabled tests patched decode_x_payment_response on the x402 action
provider module, but that symbol is no longer imported there — the provider
inlines base64+JSON decoding of the payment-response header. The missing
attribute made the patch fail inconsistently across environments, so the
tests were commented out.

Rewrite the tests against the current provider API:

- Patch x402_requests at the provider module path (where it is actually
  bound) and stub _create_x402_client so tests do not need a real signer.
- Drop the obsolete mock_x402_requests and mock_decode_payment fixtures
  from conftest, and add a mock_x402_session fixture + a pre-encoded
  payment-proof header constant.
- Add coverage for retry_with_x402 (success with/without payment proof,
  non-200 response, unregistered service, non-USDC asset, amount above
  max_payment_usdc, network mismatch) and make_http_request_with_x402
  (success with/without payment proof, non-200, unregistered service,
  unsupported wallet provider).

Full python/coinbase-agentkit test suite: 675 passed.
@yashhzd yashhzd requested a review from murrlincoln as a code owner April 14, 2026 18:47
@cb-heimdall
Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider python

Development

Successfully merging this pull request may close these issues.

2 participants