Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.1 KB
Raw Blame
import { MockAgent, setGlobalDispatcher } from "undici";
import { Socket } from "node:net";

// Test-only network guard: no application imports, credentials, sockets or DNS.
// The global fetch seam catches catalog refreshes; MockAgent also blocks the
// native fetch captured by other modules before they install their wrappers.
const networkGuard = new MockAgent();
networkGuard.disableNetConnect();
setGlobalDispatcher(networkGuard);

export const unexpectedCatalogNetworkRequests: string[] = [];

// These handler-level regressions need no sockets, including loopback. This also
// catches transports with an explicit dispatcher that bypass MockAgent.
Socket.prototype.connect = function () {
  unexpectedCatalogNetworkRequests.push("node:net socket connection");
  throw new Error("#13389 regression forbids socket connections");
};

globalThis.fetch = async (input) => {
  const url = new URL(input instanceof Request ? input.url : String(input));
  unexpectedCatalogNetworkRequests.push(`${url.origin}${url.pathname}`);
  throw new Error("#13389 regression forbids external network requests");
};