Running Tests
Unit Tests
Run the full test suite:Test Output
Show output from passing tests:Coverage
Generate Coverage Report
Use the provided script to generate an HTML coverage report:- Installs
cargo-llvm-covif not already installed - Runs tests with coverage instrumentation
- Generates an HTML report at
target/llvm-cov/html/index.html - Prints a text summary
- Opens the report in your browser (macOS only)
Manual Coverage
Generate coverage without the script:Coverage Requirements
When adding new code:- Extract testable functions: Don’t embed complex logic in
mainorrunwhere it’s hard to unit-test - Write tests for new code: Ensure all new branches and paths are exercised
- Run coverage locally: Use
cargo testand verify coverage before pushing - Check CI results: The codecov check will fail if coverage drops
Best Practices
- Break complex functions into smaller, testable units
- Move business logic out of CLI entrypoints
- Test both happy paths and error conditions
- Write tests that can run in isolation
Writing Tests
Basic Test Structure
Tests are written using Rust’s built-in test framework:Testing with Tempfiles
Use thetempfile crate for tests that need file I/O:
Tempdir paths should be canonicalized before use to handle macOS
/var → /private/var symlinks.Serial Tests
Tests that modify process state (like changing the current directory) must use#[serial]:
Input Validation Tests
When testing input validation:Path Safety Tests
URL Encoding Tests
Resource Name Tests
Testing Checklist
When adding a new feature or fixing a bug:- Write tests for the happy path
- Write tests for error cases
- Test input validation (if applicable)
- Path traversal rejection (
../../.ssh) - Control character rejection
- Resource name validation
- URL encoding correctness
- Path traversal rejection (
- Use
#[serial]for tests that modify process state - Canonicalize temp paths for cross-platform compatibility
- Run
cargo testlocally - Run
cargo clippy -- -D warnings - Check coverage with
./scripts/coverage.sh
CI Requirements
The CI pipeline runs:- Unit tests:
cargo test - Linting:
cargo clippy -- -D warnings - Coverage check: codecov/patch validates new code is tested
- Changeset check: Ensures PR includes a changeset file
Integration Testing
The project includes smoke tests that run against live APIs:Next Steps
- Learn about contribution requirements: Contributing
- Understand the architecture: Architecture
- Set up your build environment: Building