The claw-code test suite ensures the integrity of the Rust implementation by validating CLI functionality, runtime state machines, and behavioral parity with the original agent harness. The suite spans from low-level unit tests to complex integration scenarios involving a deterministic mock LLM service.
The testing architecture is divided into three primary layers: standard Rust workspace tests, a specialized mock parity harness for E2E validation, and a Python-based audit workspace.
| Category | Description | Key Code Entities |
|---|---|---|
| Rust Workspace | Unit and integration tests for crates like runtime, api, and tools. | cargo test --workspace |
| Mock Parity Harness | E2E CLI tests against a scripted Anthropic-compatible mock service. | mock_parity_harness.rs, MockAnthropicService |
| State Machine Tests | Validation of worker boot, trust gates, and prompt delivery. | worker_boot.rs, WorkerRegistry |
| Contract Tests | Ensuring output formats (JSON/Compact) meet expectations. | output_format_contract.rs, compact_output.rs |
| Python Audit | Companion suite for tracking porting progress and manifest integrity. | run_parity_audit(), PortRuntime |
The following diagram illustrates how the test suite bridges the natural language requirements (testing "parity" and "safety") to the underlying code entities.
Test Execution to Code Entity Mapping
Sources: rust/crates/rusty-claude-cli/tests/mock_parity_harness.rs17-151 rust/crates/runtime/src/worker_boot.rs145-200 rust/crates/runtime/tests/integration_tests.rs20-44
The harness executes scripted scenarios (e.g., read_file_roundtrip, bash_stdout_roundtrip) against a clean-environment CLI instance rust/crates/rusty-claude-cli/tests/mock_parity_harness.rs30-151 It uses MockAnthropicService rust/crates/mock-anthropic-service/src/lib.rs26-31 to provide deterministic LLM responses, allowing the test to verify that the CLI correctly handles multi-tool turns and streaming text rust/mock_parity_scenarios.json2-55
Integration tests in the runtime crate verify that complex logic—like branch freshness detection—correctly flows into the PolicyEngine to generate actions like MergeForward rust/crates/runtime/tests/integration_tests.rs20-44 The WorkerRegistry is tested to ensure the WorkerStatus state machine correctly transitions through TrustRequired and ReadyForPrompt during boot rust/crates/runtime/src/worker_boot.rs30-37
Specific tests ensure that the --compact flag suppresses tool call IDs and spinner output, emitting only the final assistant text rust/crates/rusty-claude-cli/tests/compact_output.rs12-76 This maintains the contract for programmatic consumption of the CLI output.
Harness Execution Architecture
Sources: rust/crates/rusty-claude-cli/tests/mock_parity_harness.rs24-28 rust/MOCK_PARITY_HARNESS.md1-24 rust/mock_parity_scenarios.json1-109
The suite can be executed via standard Cargo commands or convenience scripts:
For details on CI pipelines and specific test categories, see Rust Test Suite & CI. For details on the Python companion and audit tools, see Python Companion Workspace & Audit.
Sources: PARITY.md13-25 rust/MOCK_PARITY_HARNESS.md26-38 rust/scripts/run_mock_parity_diff.py53-77