|
| 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 | +## Error Handling Patterns |
| 38 | + |
| 39 | +- Use `anyhow::Result` for application-level errors |
| 40 | +- Use `thiserror` for library-level error types (see `src/utils/auth_token/error.rs`) |
| 41 | +- Chain errors with `.context()` for better error messages |
| 42 | +- Custom error types in `src/api/errors/` and `src/utils/dif_upload/error.rs` |
| 43 | + |
| 44 | +## Swift/Apple Integration |
| 45 | + |
| 46 | +- Swift code in `apple-catalog-parsing/` is used for parsing xarchive files |
| 47 | +- Used by the `mobile-app upload` command for iOS app processing |
| 48 | +- Built as a separate crate with FFI bindings to Rust |
| 49 | +- Only compiled on macOS targets |
| 50 | +- Tests run via `swift-test.yml` workflow in CI |
| 51 | + |
| 52 | +# Rust Testing Guidelines |
| 53 | + |
| 54 | +## Unit Tests |
| 55 | + |
| 56 | +- Colocate with source code |
| 57 | +- Use `#[cfg(test)]` modules |
| 58 | +- Mock external dependencies |
| 59 | + |
| 60 | +## Integration Tests |
| 61 | + |
| 62 | +- Use `trycmd` for CLI interface testing when asserting output |
| 63 | +- Use `assert_cmd` for testing behavior rather than just output |
| 64 | +- Structure: `tests/integration/_cases/<command>/<test>.trycmd` |
| 65 | +- Fixtures: `tests/integration/_fixtures/` |
| 66 | +- Expected outputs: `tests/integration/_expected_outputs/` |
| 67 | +- API mocks: `tests/integration/_responses/` |
| 68 | + |
| 69 | +## Snapshot Management |
| 70 | + |
| 71 | +```bash |
| 72 | +# Update snapshots |
| 73 | +TRYCMD=overwrite cargo test |
| 74 | + |
| 75 | +# Debug test output |
| 76 | +TRYCMD=dump cargo test |
| 77 | +``` |
| 78 | + |
| 79 | +## Test Utilities |
| 80 | + |
| 81 | +- `TestManager`: Sets up test environment with mock server |
| 82 | +- `MockEndpointBuilder`: Creates API endpoint mocks |
| 83 | +- `copy_recursively`: Helper for fixture setup |
| 84 | +- Environment setup via `test_utils::env` |
| 85 | + |
| 86 | +## Platform-Specific Testing |
| 87 | + |
| 88 | +- Use `#[cfg(windows)]` for Windows-specific tests |
| 89 | +- Separate `.trycmd` files when behavior differs |
| 90 | +- Test on CI matrix: Linux, macOS, Windows |
| 91 | + |
| 92 | +## Assert Command vs Trycmd |
| 93 | + |
| 94 | +- `trycmd`: Best for testing exact CLI output, supports snapshot testing |
| 95 | +- `assert_cmd`: Better for testing behavior, exit codes, and when you need programmatic assertions |
| 96 | +- Example of `assert_cmd` usage can be found in `TestManager::run_and_assert()` |
0 commit comments