Files
OmniRoute/tests/unit/cli/launch-command.test.ts
Diego Rodrigues de Sa e Souza 5c4b0e327d fix(cli): harden launch/launch-codex with free-claude-code patterns (#4278)
Applies proven patterns from the free-claude-code reference adapters:

launch (Claude Code):
- always set ANTHROPIC_AUTH_TOKEN — a no-auth sentinel when none is resolved —
  so newer Claude Code doesn't stop at its local login gate before contacting
  OmniRoute (an open backend ignores the value; ANTHROPIC_API_KEY stays stripped).

launch-codex:
- remote-aware: resolves the root base URL + auth from --remote/--api-key, the
  active context, then localhost (was localhost/--remote only).
- inject the `omniroute` provider via `-c` flags (model_provider + base_url +
  env_key + wire_api=responses + requires_openai_auth=false) so it works WITHOUT
  a pre-existing ~/.codex/config.toml.
- strip OPENAI_*/CODEX_* from the child env (defense-in-depth) and set
  OMNIROUTE_API_KEY to the token or a sentinel. (Honest note: this does NOT
  silence codex's refresh_token log noise — that comes from ~/.codex/auth.json,
  is cosmetic, and does not block requests.)
- replace a hard-coded Tailscale IP in --remote help with a placeholder.

Tests: buildCodexEnv (strip + sentinel + no-mutate), buildCodexProviderArgs
(inline provider def), resolveCodexTarget; updated buildClaudeEnv sentinel test.
Validated remotely vs VPS v3.8.30: `launch-codex --remote ... exec` → "OK".
19 unit tests pass; check:cli-i18n green.
2026-06-19 11:40:53 -03:00

26 lines
1.2 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { buildClaudeEnv } from "../../../bin/cli/commands/launch.mjs";
test("buildClaudeEnv strips ANTHROPIC_* and injects proxy vars", () => {
const env = buildClaudeEnv({ ANTHROPIC_API_KEY: "leak", ANTHROPIC_BASE_URL: "old", PATH: "/bin" }, 20128, "secret");
assert.equal(env.ANTHROPIC_API_KEY, undefined);
assert.equal(env.ANTHROPIC_BASE_URL, "http://localhost:20128");
assert.equal(env.ANTHROPIC_AUTH_TOKEN, "secret");
assert.equal(env.CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY, "1");
assert.equal(env.CLAUDE_CODE_AUTO_COMPACT_WINDOW, "190000");
assert.equal(env.PATH, "/bin", "non-ANTHROPIC vars are preserved");
});
test("buildClaudeEnv uses a no-auth sentinel when no token is provided (bypasses Claude's login gate)", () => {
const env = buildClaudeEnv({ PATH: "/bin" }, 20128, undefined);
assert.equal(env.ANTHROPIC_AUTH_TOKEN, "omniroute-no-auth");
assert.equal(env.ANTHROPIC_BASE_URL, "http://localhost:20128");
});
test("buildClaudeEnv does not mutate the input env object", () => {
const input = { ANTHROPIC_API_KEY: "leak", PATH: "/bin" };
buildClaudeEnv(input, 20128, "x");
assert.equal(input.ANTHROPIC_API_KEY, "leak");
});