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.7 KB
Raw Blame
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import test from "node:test";

const REPO_ROOT = fileURLToPath(new URL("../..", import.meta.url));
const FIXTURE = fileURLToPath(
  new URL("../fixtures/codex-response-failed-boundary.fixture.ts", import.meta.url)
);

const CHILD_RUNTIME_ENV_KEYS = [
  "PATH",
  "TMPDIR",
  "TMP",
  "TEMP",
  "SystemRoot",
  "ComSpec",
  "PATHEXT",
  "LANG",
  "LC_ALL",
  "TZ",
] as const;

function buildFixtureEnv(): NodeJS.ProcessEnv {
  const env: NodeJS.ProcessEnv = {
    NODE_ENV: "test",
    APP_LOG_TO_FILE: "false",
    API_KEY_SECRET: "codex-boundary-fixture-api-key-secret-20260902",
    DISABLE_SQLITE_AUTO_BACKUP: "true",
  };

  for (const key of CHILD_RUNTIME_ENV_KEYS) {
    const value = process.env[key];
    if (value !== undefined) env[key] = value;
  }

  // A nested test runner must receive its own context instead of inheriting the parent's.
  delete env.NODE_TEST_CONTEXT;
  return env;
}

test("Codex public failure boundaries pass in an isolated process", () => {
  const result = spawnSync(
    process.execPath,
    [
      "--import",
      "tsx/esm",
      "--import",
      "./open-sse/utils/setupPolyfill.ts",
      "--test",
      "--test-force-exit",
      FIXTURE,
    ],
    {
      cwd: REPO_ROOT,
      encoding: "utf8",
      env: buildFixtureEnv(),
      timeout: 60_000,
    }
  );

  assert.ifError(result.error);
  assert.equal(
    result.signal,
    null,
    `isolated Codex boundary fixture terminated by ${result.signal}\n${result.stdout}\n${result.stderr}`
  );
  assert.equal(
    result.status,
    0,
    `isolated Codex boundary fixture failed\n${result.stdout}\n${result.stderr}`
  );
});