File size: 2,599 Bytes
a9e27c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Codex's CLI catalog and external credential integration."""

import tomllib
from unittest.mock import patch

import pytest

from free_claude_code.cli.launchers import codex, runner
from tests.cli.conftest import LaunchCapture
from tests.cli.test_launcher_workflow import launch


def test_external_credential_command_needs_no_native_launch(
    launch_capture: LaunchCapture, capsys: pytest.CaptureFixture[str]
) -> None:
    with patch.object(
        runner, "launch_harness", side_effect=AssertionError("must not launch")
    ):
        codex.launch(["--print-proxy-auth-token"])
    assert capsys.readouterr() == ("launcher-test-token\n", "")
    assert not launch_capture.commands
    assert not launch_capture.probes
    assert not launch_capture.requests


def test_codex_selects_the_advertised_slug_from_opaque_catalog_data(
    launch_capture: LaunchCapture,
) -> None:
    launch_capture.catalog = {
        "default_model_id": "arbitrary-wire-id",
        "data": [
            {
                "id": "arbitrary-wire-id",
                "provider_model_ref": "nvidia_nim/catalog-model:variant",
                "supportsReasoning": False,
            }
        ],
    }
    launch("codex", ["exec", "--model", "native-choice", "hello"])
    command = launch_capture.commands[0]
    config = tomllib.loads(
        "\n".join(command[i + 1] for i, arg in enumerate(command) if arg == "-c")
    )
    assert config["model"] == "arbitrary-wire-id"
    assert config["model_providers"]["fcc"]["wire_api"] == "responses"
    assert config["model_providers"]["fcc"]["stream_idle_timeout_ms"] == 2147483647
    assert "request_max_retries" not in config["model_providers"]["fcc"]
    assert "stream_max_retries" not in config["model_providers"]["fcc"]
    assert config["model_providers"]["fcc"]["base_url"] == "http://127.0.0.1:8182/v1"
    assert config["model_providers"]["fcc"]["auth"] == {
        "command": "fcc-codex",
        "args": ["--print-proxy-auth-token"],
    }
    assert command[-4:] == ["exec", "--model", "native-choice", "hello"]


def test_codex_scrubs_parent_task_identity_and_preserves_native_home(
    launch_capture: LaunchCapture, monkeypatch: pytest.MonkeyPatch
) -> None:
    monkeypatch.setenv("CODEX_HOME", "native-codex-home")
    monkeypatch.setenv("CODEX_THREAD_ID", "parent-task")
    monkeypatch.setenv("OPENAI_SOMETHING", "old-route")
    launch("codex", [])
    env = launch_capture.environments[0]
    assert env["CODEX_HOME"] == "native-codex-home"
    assert "CODEX_THREAD_ID" not in env
    assert not any(key.startswith("OPENAI_") for key in env)