68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
import tomllib
|
|
from pathlib import Path
|
|
|
|
from agentci.adapters.codex import CodexClient, _session_id
|
|
|
|
|
|
def test_enables_codegraph_in_shared_codex_config() -> None:
|
|
root = Path(__file__).parents[1]
|
|
config = tomllib.loads((root / "codex" / "config.toml").read_text())
|
|
|
|
codegraph = config["mcp_servers"]["codegraph"]
|
|
assert codegraph["command"] == "codegraph"
|
|
assert codegraph["args"] == ["serve", "--mcp"]
|
|
assert codegraph["env"]["CODEGRAPH_TELEMETRY"] == "0"
|
|
|
|
|
|
def test_extracts_thread_id_from_jsonl() -> None:
|
|
output = '\n'.join(
|
|
[
|
|
'{"type":"turn.started"}',
|
|
'{"type":"thread.started","thread_id":"abc-123"}',
|
|
"not json",
|
|
]
|
|
)
|
|
assert _session_id(output) == "abc-123"
|
|
|
|
|
|
def test_missing_thread_id_returns_none() -> None:
|
|
assert _session_id('{"type":"turn.completed"}') is None
|
|
|
|
|
|
def test_turns_skip_interactive_git_trust_check(tmp_path) -> None:
|
|
client = CodexClient(
|
|
codex_home=tmp_path / "codex",
|
|
schemas_dir=tmp_path / "schemas",
|
|
timeout_seconds=60,
|
|
research_model="gpt-5.6-luna",
|
|
research_reasoning="high",
|
|
context7_api_key=None,
|
|
)
|
|
|
|
args = client._turn_args("model", "medium", "agentci-read", "plan.json")
|
|
|
|
assert "--skip-git-repo-check" in args
|
|
|
|
|
|
def test_configures_research_agent_and_optional_context7_key(tmp_path) -> None:
|
|
client = CodexClient(
|
|
codex_home=tmp_path / "codex",
|
|
schemas_dir=tmp_path / "schemas",
|
|
timeout_seconds=60,
|
|
research_model="research-model",
|
|
research_reasoning="high",
|
|
context7_api_key="ctx7-secret",
|
|
)
|
|
|
|
agent = (tmp_path / "codex" / "agents" / "research.toml").read_text()
|
|
parsed = tomllib.loads(agent)
|
|
assert 'name = "research"' in agent
|
|
assert parsed["model"] == "research-model"
|
|
assert parsed["model_reasoning_effort"] == "high"
|
|
assert parsed["web_search"] == "live"
|
|
assert parsed["mcp_servers"]["codegraph"]["enabled"] is False
|
|
assert 'url = "https://mcp.context7.com/mcp"' in agent
|
|
assert 'url = "https://mcp.grep.app"' in agent
|
|
assert "ctx7-secret" not in agent
|
|
assert client._environment()["CONTEXT7_API_KEY"] == "ctx7-secret"
|