Repository navigation
test(sdk): make the x402Serve smoke test hermetic (#126) - #151
Open
fernando-mendoza wants to merge 1 commit into
Open
fernando-mendoza wants to merge 1 commit into
fernando-mendoza wants to merge 1 commit into
Conversation
The guard-integration cases reached preflight(), which fetched the default facilitator (channels.openzeppelin.com) three times per run. Stub that fetch with a 503 and assert on x402Serve's error path, so the result no longer depends on a third-party service. Add a jest setupFilesAfterEnv guard that refuses non-loopback sockets and fails the test that opened one, even when the code under test swallows the error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes the
x402Servesmoke test hermetic. The test no longer calls the real facilitator, and a jest guard keeps that from coming back. This changes test files only;x402Serve()runtime defaults are unchanged.What was leaking
In
src/x402serve-smoke.test.ts, the guard-integration cases that get past the guard reachpreflight(). That fetcheshttps://channels.openzeppelin.com/x402/testnet/supported, which is one call in the replay test and two in the no-guard test. These are the 3 outbound requests per run from the 2 Oct harness. The tests passed either way because the assertions tolerated any downstream result.How each "Done when" item is met
fetchwith a503(jest.spyOn(globalThis, 'fetch'), restored after each test). The tests assert on the exact error path: the preflight URL, a503status,error: 'x402 payments unavailable', anddetail: 'facilitator returned 503'. The results are deterministic, and the no-guard test is now a positive assertion rather than "not 409".jest.no-network.jsis wired assetupFilesAfterEnv. It refuses any non-loopbacknet.Socket#connect, which coversfetch/undici, http(s), tls and ws, and fails the test inafterEach. It fails the test even when the code under test swallows the error, asx402Servedoes by turning it into a 503. Loopback stays allowed for local stub servers. Without the stub, it fails the two tests withoutbound network blocked in tests: channels.openzeppelin.com:443.npm testpasses offline. I ran it inside a network namespace with no external interface (unshare -rn, loopback only).Test results (Node 22.23.3, after
npm run build)npm testonline: jest 3 suites, 56 passed; node:test 126 tests, 126 passed, 0 failednpm testoffline (unshare -rn): the same resultsnpx jest, 3 runs in a row: 56/56 each timefetchwhose error is swallowed still fails the testtsc --noEmit: OK;node scripts/clean-install-check.mjs: OK (jest.no-network.jsis not infiles, so it is not published)Closes #126