-
Notifications
You must be signed in to change notification settings - Fork 61
Add unit tests for web x402 client request and receipt helpers #263
Copy link
Copy link
Open
Labels
TypeScriptTypeScript codeTypeScript codeenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersgssoc:approvedApproved for GSSoC contributionApproved for GSSoC contributionlevel:beginnerSmall, well-scoped work suitable for newer contributors.Small, well-scoped work suitable for newer contributors.type:testingTests, coverage, fixtures, or validation-only work.Tests, coverage, fixtures, or validation-only work.
Description
Metadata
Metadata
Assignees
Labels
TypeScriptTypeScript codeTypeScript codeenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersgssoc:approvedApproved for GSSoC contributionApproved for GSSoC contributionlevel:beginnerSmall, well-scoped work suitable for newer contributors.Small, well-scoped work suitable for newer contributors.type:testingTests, coverage, fixtures, or validation-only work.Tests, coverage, fixtures, or validation-only work.
Summary
The web x402 client module owns the browser-side HTTP request shape, payment-challenge parsing, signed retry headers, and receipt-header decoding, but it has no direct unit tests. These helpers are used by the paid summarize flow and can be tested without a wallet or running service.
Current behavior
The module currently:
paymentContextfrom a 402 response;X-402-*retry headers;Those contracts are only exercised indirectly by higher-level code.
Desired behavior
Add deterministic Bun tests that lock down the existing request, challenge, header, and response behavior. Production behavior should remain unchanged.
Key interfaces
getGatewayUrl()— configured URL and localhost fallback.postSummarize()— request URL, method, JSON body, content type, and caller-supplied headers.readPaymentChallenge()— valid challenge extraction and missing-context rejection.buildSignedHeaders()— exact signature, nonce, and numeric timestamp header values.readSummarizeSuccess()andsafeDecodeReceiptHeader()— valid, absent, malformed, and wrong-shape receipt headers.Acceptance criteria
paymentContextis missing.cd web && bun run test:unit && bun run typecheckpasses.Out of scope
Blocked by
None — can start immediately.