// Patches globalThis.fetch at module init — the interception/polyfill // pattern (undici interceptors, msw-style mocks, dotenv-ordered setup). // USER-code fetch must read the LIVE global at call time, so calls made // after this module evaluates go through the wrapper: it logs each URL and // rewrites the fake origin to the harness server (argv[2]). const FAKE = "https://gateway.invalid"; const base = process.argv[2]; const orig = globalThis.fetch; globalThis.fetch = function fetch(input, init) { let url = typeof input === "string" ? input : input && typeof input.url === "string" ? input.url : String(input); console.log(`tap ${url}`); if (url.startsWith(FAKE)) url = base + url.slice(FAKE.length); return orig(url, init); }; export function tappedFetchName() { return globalThis.fetch.name; }