Rust Reporter
Relevant source files
The following files were used as context for generating this wiki page:
The Rust Reporter is a specialized test result collector for the TDD Guard system, designed to capture and normalize output from Rust test runners. It supports both standard cargo test and cargo nextest, providing a unified interface for TDD validation by intercepting test events and compilation errors.
Within the TDD Guard ecosystem, this reporter acts as a bridge between the Rust toolchain and the AI-driven validation logic. It transforms raw JSON test streams and compiler diagnostics into a structured test.json format used to enforce Test-Driven Development principles such as the Red-Green-Refactor cycle.
Sources: reporters/rust/README.md:1-10, reporters/rust/src/main.rs:14-20, CLAUDE.md:66-70
Architecture and Data Flow
The Rust Reporter operates primarily as a command-line filter or a direct test wrapper. It parses incoming data from stdin (passthrough mode) or executes the Rust compiler and test runner directly to capture stdout and stderr.
Execution Modes
- Direct Execution: The reporter detects the available runner (preferring
nextest), builds the appropriatecargocommand with JSON formatting flags, and manages the child process. - Passthrough Mode: The reporter reads piped output from a command like
cargo nextest run 2>&1 | tdd-guard-rust. It echoes the original output to the terminal while simultaneously extracting data for TDD Guard.
The following diagram illustrates the data flow from the Rust toolchain through the reporter components:
The diagram shows how raw output is bifurcated into JSON event parsing and text-based error parsing before being unified by the transformer.
Sources: reporters/rust/src/main.rs:65-95, reporters/rust/README.md:27-45, reporters/rust/src/main.rs:188-215
Component Breakdown
Main Execution Logic (main.rs)
The entry point handles command-line argument parsing using clap and determines the project root validation. It coordinates the reading of output buffers and the subsequent saving of results to the .claude/tdd-guard/data/test.json path.
Key Functions:
run_and_process: Orchestrates the test command execution and output collection.build_test_command: Configurescargowith flags like--format jsonor--message-format libtest-json.save_results: Persists the transformed data to the file system.
Sources: reporters/rust/src/main.rs:22-54, reporters/rust/src/main.rs:101-131, reporters/rust/src/main.rs:218-232
Compilation Error Parsing (error_parser.rs)
This module uses regular expressions to extract structured information from rustc diagnostic messages. It identifies error codes, file paths, line numbers, and supplementary help or note text.
pub struct CompilationError {
pub code: Option<String>,
pub file: Option<String>,
pub line: Option<u32>,
pub column: Option<u32>,
pub message: String,
pub help: Option<String>,
pub note: Option<String>,
}
Sources: reporters/rust/src/error_parser.rs:7-17
The parser employs several regex patterns to handle ANSI-escaped terminal output:
ERROR_CODE_RE: Matches standard Rust error codes (e.g.,E0432).LOCATION_RE: Captures file paths and coordinates (e.g.,--> src/lib.rs:1:5).ANSI_ESCAPE_RE: Strips terminal colors to ensure clean string matching.
Sources: reporters/rust/src/error_parser.rs:20-28, reporters/rust/src/error_parser.rs:31-33
Configuration and Integration
The reporter is configured via CLI flags and environment variables. The --project-root is mandatory for determining the output directory.
CLI Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
--project-root | Path | (Required) | Absolute path to the project directory. |
--passthrough | Boolean | false | Read from stdin instead of running tests. |
--runner | String | auto | Choose between nextest, cargo, or auto. |
--no-auto-passthrough | Boolean | false | Disable automatic passthrough when stdin is piped. |
Sources: reporters/rust/src/main.rs:22-54, reporters/rust/README.md:65-72
Integration Flow
The following sequence diagram shows the interaction between the TDD Guard test factory and the Rust binary during integration testing:
This diagram illustrates how the reporter is tested and how it consumes the output of the Rust toolchain.
Sources: reporters/test/factories/rust.ts:25-50, reporters/test/factories/rust.ts:80-110
Testing and Verification
The Rust Reporter is verified using integration tests that check its ability to report module paths, test names, and failure states across different scenarios.
- Module Path Reporting: Verified to report
single_passingorcompilationdepending on the failure type. - Error Detail Extraction: Specifically tested for the inclusion of Rust error codes (e.g.,
E0432) and precise file locations intest.json. - Expected/Actual Capture: Successfully extracts detailed values from panic messages for assertion failures (e.g., "expected 6 but got 5").
Sources: reporters/test/reporters.integration.test.ts:77-105, reporters/test/reporters.integration.test.ts:290-310, reporters/test/reporters.integration.test.ts:445-465
Conclusion
The Rust Reporter is a critical component for enabling TDD Guard in Rust projects. By providing deep integration with cargo and sophisticated parsing of rustc errors, it ensures that AI agents receive accurate feedback regarding test failures and compilation issues, thereby maintaining the integrity of the TDD workflow.
Sources: reporters/rust/README.md:74-76, CLAUDE.md:7-15