EasydictTests/Service/CodexCLI/codex-cli-overview.md
该目录覆盖 Codex CLI 翻译服务的关键单元测试,重点是 CLI 参数构建、
JSONL 事件解析和服务注册。本目录不覆盖 UI 或子进程实际执行,
真实子进程行为依赖 codex 二进制和登录态,由开发者本地手工验证。
CodexCLIRunnerTests.swift 是核心测试套件,覆盖多类逻辑:
buildArguments 必含 exec --json --skip-git-repo-check --ephemeral --sandbox read-only -C <tmp> 和翻译场景禁用的 Codex feature flags,
且通过 -- - 固定从 stdin 读取 prompt,避免长文本进入 argv。writePromptToStandardInput 验证 Unicode、前后空白和长文本会原样写入
stdin pipe。processCodexStdoutLine / terminalAgentMessage 验证多条
agent_message 只缓存最后一条,且失败或取消时不会输出缓存文本。parseCodexError 同时验证 stderr 兜底(not signed in、
rate limit、未知错误)和 stdout JSONL 路径(turn.failed.error
既可能是字符串也可能是 {message:...} 对象)。terminalError 验证用户取消优先于 CLI 退出错误,并保留正常
成功/失败退出的原有分类。parseCodexTokenUsage 验证 turn.completed.usage 的扁平字段读取、
多次 turn.completed 取最后一次、空 usage 返回 nil。buildProcessEnvironment 验证父进程优先、登录 shell allowlist 补齐、
PATH 合并去重、zsh/bash rc source,以及非 allowlist 变量不会进入子进程环境。runWhich、resolveLoginShellPath、extractLoginShellEnvironment、
extractCodexText 覆盖二进制探测、shell 路径回退、最终消息缓存和
env sentinel 解析。CodexCLIServiceTests.swift 验证服务的元信息:serviceType()、
apiKeyRequirement() == .agentCLI、isStream() == true,以及
QueryServiceFactory.shared.service(withTypeId:) 能正确返回
CodexCLIService 实例;同时覆盖推理等级选项不包含 Codex 不支持的
none,并确认官方 model_reasoning_effort 值会原样传给 CLI。buildArguments* 用例。CODEX_HOME、custom CA 或代理 → 先看
buildProcessEnvironment* 和 extractLoginShellEnvironment* 用例。notLoggedIn / quotaExceeded → 给
parseCodexError* 加新的 stdout 或 stderr 用例后再修
isCodexAuthenticationMessage / isCodexQuotaMessage 关键字列表。parseCodexTokenUsage 是否读到了
turn.completed.usage,必要时增加多 turn 场景。factoryRegistration;推理等级选项异常 → 看 service tests 的
reasoningEffortOptionsExcludeUnsupportedNoneValue 和相关 cliValue 用例。