/** * Preloaded into every test process (see scripts/run-tests.mjs). * Tests must never see real keys or reach the network: ambient secrets from the developer's shell * used to switch some tests into live mode (real SERV calls, slow and intermittently failing). */ const SECRET = /(API_KEY|_TOKEN|SECRET|PASSWORD|PRIVATE_KEY|VERDICT_KEY|_PAYTO|_PAY_TO|SHA256)$|^(TURSO_|CDP_|KITE_SESSION|VERCEL)/ for (const k of Object.keys(process.env)) if (SECRET.test(k)) delete process.env[k] delete process.env.ALLOWLATCH_PUBLIC_RATING_HINTS const LOOPBACK = new Set(['localhost', '127.0.0.1', '::1', '[::1]']) const realFetch = globalThis.fetch if (realFetch) { globalThis.fetch = function guardedFetch(input, init) { const raw = typeof input === 'string' ? input : input instanceof URL ? input.href : input?.url let host = '' try { host = new URL(String(raw)).hostname } catch { /* relative or odd URL: let fetch raise its own error */ } if (host && !LOOPBACK.has(host)) return Promise.reject(new TypeError(`fetch to ${host} blocked: tests run without network`)) return realFetch.call(this, input, init) } }