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

2.9 KB
Raw Blame
/**
 * Scope guard for the deliberate NVIDIA validation proxy bypass (#3226).
 *
 * Context: NVIDIA's API-key validation endpoint stalls when routed through the
 * global proxy/TLS-patched fetch (undici dispatcher → 504). As a documented
 * exception, `directHttpsRequest()` in `src/lib/providers/validation.ts` calls
 * `safeOutboundFetch({ bypassProxyPatch: true })`, which resolves the native
 * fetch reference via `getOriginalFetch()` and bypasses the patch for that one
 * validation call only.
 *
 * This test asserts that the bypass is CONFINED to the validation path and has
 * NOT silently spread to the chat hot path (chatHelpers / chatCore).
 *
 * See also: tests/unit/nvidia-validation-bypass-proxy-3226.test.ts (mechanism seam tests).
 */
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";

test("bypassProxyPatch is present in the NVIDIA validation path (#3226 documented exception)", () => {
  // After the validation.ts godfile split (#4921–#4930), bypassProxyPatch moved to the
  // extracted validation/headers.ts. Assert the bypass lives in the validation LAYER
  // (validation.ts + its extracted modules), not that it stayed in one file.
  const validationLayer =
    readFileSync("src/lib/providers/validation.ts", "utf8") +
    readFileSync("src/lib/providers/validation/headers.ts", "utf8");
  assert.ok(
    validationLayer.includes("bypassProxyPatch"),
    "expected bypassProxyPatch in the validation layer (validation/headers.ts) — the documented NVIDIA exception"
  );
  assert.ok(
    validationLayer.includes("directHttpsRequest"),
    "expected directHttpsRequest helper in the validation layer"
  );
});

test("bypassProxyPatch is absent from the chat hot path (scope guard — #3226)", () => {
  // The chat hot path must never bypass the proxy patch.
  // If either of these assertions starts failing, a code change has silently
  // extended the NVIDIA-only exception to the chat/usage egress path.
  const chatHelpers = readFileSync("src/sse/handlers/chatHelpers.ts", "utf8");
  // Anchor: without it, extracting the egress code into another module would make the
  // negative guard below pass against a file that no longer contains the hot path.
  assert.match(chatHelpers, /export async function executeChatWithBreaker\(/);
  assert.ok(
    !chatHelpers.includes("bypassProxyPatch"),
    "chatHelpers.ts must not bypass the proxy patch — only NVIDIA validation may do this (#3226)"
  );

  const chatCore = readFileSync("open-sse/handlers/chatCore.ts", "utf8");
  // Anchor: chatCore.ts is actively being split, so pin the entry point the route
  // imports — the negative guard is worthless if this read silently misses the file.
  assert.match(chatCore, /export async function handleChatCore\(/);
  assert.ok(
    !chatCore.includes("bypassProxyPatch"),
    "chatCore.ts must not bypass the proxy patch — only NVIDIA validation may do this (#3226)"
  );
});