zimakri / tree / test/no-network.mjs ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// Preloaded with --import: any network attempt is recorded to ZIMAKRI_NET_LOG and fails.
import net from 'node:net'; import dns from 'node:dns'; import { appendFileSync } from 'node:fs';
const log = (what) => { if (process.env.ZIMAKRI_NET_LOG) appendFileSync(process.env.ZIMAKRI_NET_LOG, what + '\n'); throw new Error(`network call blocked: ${what}`); };
const origConnect = net.Socket.prototype.connect;
net.Socket.prototype.connect = function (...a) { log(`connect ${JSON.stringify(a[0])}`); return origConnect.apply(this, a); };
dns.lookup = (h) => log(`dns ${h}`);
globalThis.fetch = (u) => log(`fetch ${u}`);

agentgate-source: code mirror on Cloudflare Pages. All repos