|
| 1 | +--- |
| 2 | +description: Rust development patterns and conventions for sentry-cli |
| 3 | +globs: *.rs,Cargo.*,.cargo/**/*,src/**/*,apple-catalog-parsing/**/* |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | + |
| 7 | +# Rust Development Guidelines |
| 8 | + |
| 9 | +## Code Organization |
| 10 | + |
| 11 | +- Follow existing module structure in `src/commands/` for new commands |
| 12 | +- Use `anyhow::Result` for error handling patterns |
| 13 | +- Consider cross-platform compatibility |
| 14 | +- Ensure backward compatibility for CLI interface |
| 15 | + |
| 16 | +## Common Patterns |
| 17 | + |
| 18 | +- Use existing error types and handling patterns |
| 19 | +- Follow established CLI argument parsing patterns using `clap` |
| 20 | +- Reuse utility functions from `src/utils/` |
| 21 | +- Match existing code style and naming conventions |
| 22 | +- Add appropriate logging using `log` crate patterns |
| 23 | + |
| 24 | +## Development Commands |
| 25 | + |
| 26 | +```bash |
| 27 | +# Essential Rust workflow - run against the whole workspace |
| 28 | +cargo build --workspace |
| 29 | +cargo test --workspace |
| 30 | +cargo clippy --workspace |
| 31 | +cargo fmt |
| 32 | + |
| 33 | +# Local testing |
| 34 | +./bin/sentry-cli --help |
| 35 | +``` |
| 36 | + |
| 37 | +## Testing Requirements |
| 38 | + |
| 39 | +- Update integration tests in `tests/integration/` with `.trycmd` files |
| 40 | +- Unit tests alongside source code |
| 41 | +- Cross-platform testing considerations |
| 42 | + |
| 43 | +## Error Handling Patterns |
| 44 | + |
| 45 | +- Use `anyhow::Result` for application-level errors |
| 46 | +- Use `thiserror` for library-level error types (see `src/utils/auth_token/error.rs`) |
| 47 | +- Chain errors with `.context()` for better error messages |
| 48 | +- Custom error types in `src/api/errors/` and `src/utils/dif_upload/error.rs` |
| 49 | + |
| 50 | +## Testing Patterns |
| 51 | + |
| 52 | +- Integration tests use `trycmd` crate for CLI testing (asserting output) |
| 53 | +- Use `assert_cmd` crate when asserting behavior rather than just output |
| 54 | +- Test fixtures in `tests/integration/_fixtures/` |
| 55 | +- Mock API responses in `tests/integration/_responses/` |
| 56 | +- Use `TestManager` for setting up test environments |
| 57 | +- Platform-specific tests with `#[cfg(target_os = "...")]` |
| 58 | + |
| 59 | +## Swift/Apple Integration |
| 60 | + |
| 61 | +- Swift code in `apple-catalog-parsing/` is used for parsing xarchive files |
| 62 | +- Used by the `mobile-app upload` command for iOS app processing |
| 63 | +- Built as a separate crate with FFI bindings to Rust |
| 64 | +- Only compiled on macOS targets |
| 65 | +- Tests run via `swift-test.yml` workflow in CI |
| 66 | + |
| 67 | +# Rust Testing Guidelines |
| 68 | + |
| 69 | +## Unit Tests |
| 70 | + |
| 71 | +- Colocate with source code |
| 72 | +- Use `#[cfg(test)]` modules |
| 73 | +- Mock external dependencies |
| 74 | + |
| 75 | +## Integration Tests |
| 76 | + |
| 77 | +- Use `trycmd` for CLI interface testing when asserting output |
| 78 | +- Use `assert_cmd` for testing behavior rather than just output |
| 79 | +- Structure: `tests/integration/_cases/<command>/<test>.trycmd` |
| 80 | +- Fixtures: `tests/integration/_fixtures/` |
| 81 | +- Expected outputs: `tests/integration/_expected_outputs/` |
| 82 | +- API mocks: `tests/integration/_responses/` |
| 83 | + |
| 84 | +## Snapshot Management |
| 85 | + |
| 86 | +```bash |
| 87 | +# Update snapshots |
| 88 | +TRYCMD=overwrite cargo test |
| 89 | + |
| 90 | +# Debug test output |
| 91 | +TRYCMD=dump cargo test |
| 92 | +``` |
| 93 | + |
| 94 | +## Test Utilities |
| 95 | + |
| 96 | +- `TestManager`: Sets up test environment with mock server |
| 97 | +- `MockEndpointBuilder`: Creates API endpoint mocks |
| 98 | +- `copy_recursively`: Helper for fixture setup |
| 99 | +- Environment setup via `test_utils::env` |
| 100 | + |
| 101 | +## Platform-Specific Testing |
| 102 | + |
| 103 | +- Use `#[cfg(windows)]` for Windows-specific tests |
| 104 | +- Separate `.trycmd` files when behavior differs |
| 105 | +- Test on CI matrix: Linux, macOS, Windows |
| 106 | + |
| 107 | +## Assert Command vs Trycmd |
| 108 | + |
| 109 | +- `trycmd`: Best for testing exact CLI output, supports snapshot testing |
| 110 | +- `assert_cmd`: Better for testing behavior, exit codes, and when you need programmatic assertions |
| 111 | +- Example of `assert_cmd` usage can be found in `TestManager::run_and_assert()`# Testing Guidelines |
| 112 | + |
| 113 | +## Unit Tests |
| 114 | + |
| 115 | +- Colocate with source code |
| 116 | +- Use `#[cfg(test)]` modules |
| 117 | +- Mock external dependencies |
| 118 | + |
| 119 | +## Integration Tests |
| 120 | + |
| 121 | +- Use `trycmd` for CLI interface testing when asserting output |
| 122 | +- Use `assert_cmd` for testing behavior rather than just output |
| 123 | +- Structure: `tests/integration/_cases/<command>/<test>.trycmd` |
| 124 | +- Fixtures: `tests/integration/_fixtures/` |
| 125 | +- Expected outputs: `tests/integration/_expected_outputs/` |
| 126 | +- API mocks: `tests/integration/_responses/` |
| 127 | + |
| 128 | +## Snapshot Management |
| 129 | + |
| 130 | +```bash |
| 131 | +# Update snapshots |
| 132 | +TRYCMD=overwrite cargo test |
| 133 | + |
| 134 | +# Debug test output |
| 135 | +TRYCMD=dump cargo test |
| 136 | +``` |
| 137 | + |
| 138 | +## Test Utilities |
| 139 | + |
| 140 | +- `TestManager`: Sets up test environment with mock server |
| 141 | +- `MockEndpointBuilder`: Creates API endpoint mocks |
| 142 | +- `copy_recursively`: Helper for fixture setup |
| 143 | +- Environment setup via `test_utils::env` |
| 144 | + |
| 145 | +## Platform-Specific Testing |
| 146 | + |
| 147 | +- Use `#[cfg(windows)]` for Windows-specific tests |
| 148 | +- Separate `.trycmd` files when behavior differs |
| 149 | +- Test on CI matrix: Linux, macOS, Windows |
| 150 | + |
| 151 | +## Assert Command vs Trycmd |
| 152 | + |
| 153 | +- `trycmd`: Best for testing exact CLI output, supports snapshot testing |
| 154 | +- `assert_cmd`: Better for testing behavior, exit codes, and when you need programmatic assertions |
| 155 | +- Example of `assert_cmd` usage can be found in `TestManager::run_and_assert()` |
0 commit comments