Fixes#877 (catpaw half). Test-only; no version bump.
Change: catpaw's index.test.mjs saves the fetch it found and puts it back in afterAll (in a finally, so a failed server stop still restores it). Its URL-rewriting wrapper now builds `new Request(patched, input)` when handed a Request, so the method, headers and body survive the rewrite; init still applies on top. fake.mjs records each model-types request's method, an x-test-marker header and body, and a new test sends a POST Request through the wrapper and checks all three reach the fake.
Kiro: its test files (usage, builderid, accounts, apikey, ...) already save and restore globalThis.fetch on main, unchanged since f379bf90; the per-file sweep below finds no kiro file leaving fetch changed.
Ran (WSL magpie-desktop, Bun 1.4.2, HOME=$(mktemp -d)), at edecd806 and at edecd806 merged onto origin/main 80c9b495:
- bun test packages/catpaw: 74 pass (main: 73).
- bun test packages/catpaw packages/inkstone/api.test.mjs: 89 pass; bun test packages/kiro packages/inkstone/api.test.mjs: 198 pass. Both also pass on main, because inkstone now passes headers and body through init (#847), so this order no longer shows the leak.
- #877 reproduced on main with a probe file run after catpaw (packages/zzprobe, not committed): globalThis.fetch is catpaw's wrapper, and fetch(new Request(url, {method: "POST"}), {body}) throws "fetch() request with GET/HEAD method cannot have body". At the PR head, and merged, the probe passes (native fetch, POST kept).
- bun scripts/check.mjs: pass.
- Root bun test on the merge: 8207 pass, 19 skip, 0 fail, 581 files. origin/main has since gained c00c4b9f (agy-cli test timing only, no fetch), not rerun with it.
- Per-file sweep on main (each of 579 test files alone, with a preload that compares fetch, setTimeout, Date.now, Math.random and WebSocket at the end): catpaw is the only file that leaves a rewriting wrapper. The other 88 that leave fetch changed are the deliberate loopback-only guards (cursor, trae, minimax, inkstone, sensenova, mclaw nonet.mjs; gcp-ai test/network.mjs), which hand input and init through unchanged.
Broken by hand:
- Restore removed: catpaw's own suite stays green (74 pass); the probe after it goes red (fetch is the wrapper). Nothing inside the package guards the restore; only a later file sees it.
- Request-preserving rewrite reverted to realFetch(patched, init): the new test goes red (401, the cookie header is lost along with the method).
Not tried: init overriding a Request's fields through the wrapper (the PR says it does; no test sends both); macOS (mote), where #877 was seen.
Co-authored-by: zhou.han <18181754+yetihan@users.noreply.github.com>