具体问题与边界
怎样证明 Mini Codex 的架构合同,而不是只证明一次 happy path 能输出答案?
验证分五层:领域单元、跨模块 Turn、故障注入、mypy strict、无阈值本机性能观测。当前基线 27 pass、1 opt-in skip、46 source files。 下面同时给出状态所有者、顺序、伪代码、故障残留和不可外推边界。
状态所有权
| 对象 | 所有者 | 生命周期 | 持久化 |
|---|---|---|---|
| pytest tests | 测试套件 | 每次验证运行 | 源码 |
| fault doubles | 测试用 Fake transport/sink/hook | 单测试 | 否 |
| mypy configuration | pyproject.toml | 项目生命周期 | 源码 |
| benchmark samples | runtime_baseline.py | 一次本机运行 | 只打印 |
| release claim | 研究 README/正文 | 更新时人工核对 | 文档 |
正常路径
- 单元测试验证 SSE chunk、Patch grammar、ExecPolicy longest prefix、Agent capacity 等局部合同。
- 跨模块测试通过 RuntimeManager→Session→Model→Tool→Rollout 检查 Call/Result、WorldState refresh、终态和 Resume。
- 故障注入让 Responses stream failed、Writer partial prefix、timeout、Interrupt、Approval deny、catalog refresh 等分支留下可断言状态。
- mypy strict 检查 46 个源文件,约束 Protocol、union 和 Optional 处理;它不替代运行时 Schema 校验。
- benchmark 连续运行 20 个离线单 Turn,报告 median/P95/max,不设跨机器阈值。当前观测中位约 14.46 ms、P95 约 19.06 ms,只是本机 2026-08-03 样本。
Python 风格伪代码
def verify_release():
run("uv run pytest -q")
assert summary == "27 passed, 1 skipped"
run("uv run mypy src")
assert checked_source_files == 46
metrics = run("uv run python benchmarks/runtime_baseline.py")
record_observation(metrics) # no universal SLA
FAULT_MATRIX = [
("SSE invalid/failed", "no ModelCompleted"),
("tool denied", "paired error Result"),
("process timeout", "killed and reaped"),
("interrupt", "exactly one Aborted"),
("writer partial prefix", "retry only suffix"),
("resume incomplete call", "prompt-only aborted"),
("mailbox full", "producer backpressure"),
]
for fault, expected_contract in FAULT_MATRIX:
inject(fault)
assert_contract(expected_contract)
伪代码没有复制 Rust 语法;它保留了状态修改、await、取消、外部副作用和结果反馈的实际顺序。
失败、取消与恢复
| 故障点 | 残留/风险 | 处理 |
|---|---|---|
| 只测最终字符串 | 中间配对/持久化可能错误 | 断言事件序列与第二次请求 |
| 测试没有 timeout | 死锁会挂 CI | 并发等待使用短 timeout/显式 cancel |
| 性能设绝对阈值 | 不同机器产生噪声失败 | 先记录分位数,趋势系统另建 |
| mypy 通过 | 不代表 wire JSON 合法 | 仍需 Adapter runtime validation |
| live test 默认联网 | CI 不可重复且可能计费 | 双环境变量 opt-in |
| 故障测试只断言抛异常 | 不知道留下什么 | 同时断言 Registry、文件、pending、history、终态 |
不变量
每个发布结论必须能落到可运行断言或明确的源码证据;性能数字必须标注环境与样本,故障测试必须说明残留状态。
设计取舍与不能外推的结论
27 项测试仍不是生产验证:没有平台沙箱、真实 MCP server matrix、长时间压力、crash subprocess、filesystem fault emulator 或多 Agent Session。矩阵的价值在于标出未证明区域,而不是制造完成感。
测试与复现
cd examples/mini-codex
uv run pytest -q -k 'test_interrupt_produces_one_aborted_terminal_event or test_writer_retries_only_unconfirmed_suffix or test_bounded_mailbox_applies_backpressure or test_process_manager_timeout_kills_and_reaps'
uv run mypy src
uv run python benchmarks/runtime_baseline.py
test_interrupt_produces_one_aborted_terminal_eventtest_writer_retries_only_unconfirmed_suffixtest_bounded_mailbox_applies_backpressuretest_process_manager_timeout_kills_and_reaps
官方源码导航
- codex-rs/core/src/client_tests.rs:流取消和 backpressure 故障测试
- codex-rs/core/src/unified_exec/process_manager_tests.rs:持续进程并发与清理
- codex-rs/apply-patch/tests/suite/tool.rs:Patch 成功/失败矩阵
- codex-rs/rollout/src/recorder_tests.rs:部分写与坏尾
- codex-rs/core/src/agent/registry_tests.rs:容量、reservation 与状态
- codex-rs/core/tests/suite:端到端 fixture 套件
Mini Codex 对照
tests:27 个离线行为测试与 1 个 opt-in live testpyproject.toml:mypy strict/pytest 配置benchmarks/runtime_baseline.py:20 Turn 本机观测src/mini_codex:46 个 Python 源文件
本节结论
每个发布结论必须能落到可运行断言或明确的源码证据;性能数字必须标注环境与样本,故障测试必须说明残留状态。
评论
登录后即可评论