Skip to main content
This guide covers the testing workflows for Codex CLI, including unit tests, integration tests, and snapshot tests.

Rust Testing

The Rust implementation uses standard cargo test along with specialized tools.

Running Tests

1

Run Tests for a Specific Crate

Always start by testing the specific crate you modified:
This is the fastest way to get feedback on your changes.
2

Run Full Test Suite (If Needed)

If you changed common, core, or protocol crates, run the complete test suite:
Avoid --all-features for routine local runs. It expands the build matrix and significantly increases build time and disk usage. Only use it when you specifically need full feature coverage.
3

Check Results

Review test output for any failures or warnings.

Snapshot Tests

Codex uses snapshot tests via insta to validate rendered output, especially in codex-tui.
Requirement: Any change that affects user-visible UI must include corresponding insta snapshot coverage.
1

Run Tests to Generate Snapshots

2

Check Pending Snapshots

3

Review Changes

Review the generated *.snap.new files directly, or preview a specific file:
4

Accept Snapshots (If Correct)

Only accept if you’ve verified the changes are correct:
If you don’t have the tool installed:

Test Assertions Best Practices

Integration Tests

When writing end-to-end Codex tests, use the utilities in core_test_support::responses.
Best practices for integration tests:
  • Prefer wait_for_event over wait_for_event_with_timeout
  • Prefer mount_sse_once over mount_sse_once_match or mount_sse_sequence
  • Avoid mutating process environment in tests

Spawning Workspace Binaries in Tests

Use codex_utils_cargo_bin::cargo_bin("...") instead of assert_cmd::Command::cargo_bin(...) when tests need to spawn first-party binaries.
This ensures paths resolve correctly under both Cargo and Bazel runfiles.

TypeScript Testing

The TypeScript implementation is legacy. This section is for reference only.
The TypeScript CLI uses Vitest for unit tests.

Running TypeScript Tests

Git Hooks

The TypeScript project uses Husky to enforce code quality:
  • Pre-commit hook: Runs lint-staged to format and lint files
  • Pre-push hook: Runs tests and type checking
These hooks help maintain code quality and prevent pushing code with failing tests.

App-Server Protocol Testing

After changing API shapes in app-server-protocol:
1

Regenerate Schema Fixtures

2

Validate Changes

Sandbox Testing

Test commands under the Codex sandbox using dedicated subcommands:
Use --log-denials on macOS to see what file accesses are being blocked by Seatbelt.

Before Submitting a PR

Before marking your PR as ready for review, run all checks locally:
CI failures that could have been caught locally slow down the review process. Always run checks before pushing.

Next Steps

Guidelines

Review contribution guidelines

Building

Learn how to build the project