|
| 1 | +# Pathfinding Repository - Copilot Coding Agent Instructions |
| 2 | + |
| 3 | +## Repository Overview |
| 4 | + |
| 5 | +This is a Rust library crate that implements pathfinding, flow, and graph algorithms. It provides generic implementations of algorithms like A*, Dijkstra, BFS, DFS, Kruskal, Prim, and many others for directed graphs, undirected graphs, and matching problems. |
| 6 | + |
| 7 | +**Key Facts:** |
| 8 | +- **Language:** Rust (edition 2024) |
| 9 | +- **MSRV:** 1.86.0 (Minimum Supported Rust Version) |
| 10 | +- **Size:** ~6,000 lines of source code, ~4,400 lines of tests |
| 11 | +- **Type:** Library crate (no binary) |
| 12 | +- **Dependencies:** Minimal (num-traits, indexmap, rustc-hash, integer-sqrt, thiserror, deprecate-until) |
| 13 | +- **Repository:** https://github.com/evenfurther/pathfinding |
| 14 | + |
| 15 | +## Build and Validation Commands |
| 16 | + |
| 17 | +### Prerequisites |
| 18 | +All commands should be run from the repository root. The project requires Rust toolchain (stable, beta, nightly, or MSRV 1.86.0). |
| 19 | + |
| 20 | +### Essential Commands (In Order) |
| 21 | + |
| 22 | +**1. Check Code (Fast):** |
| 23 | +```bash |
| 24 | +cargo check --all-targets |
| 25 | +``` |
| 26 | +Time: ~35 seconds (first run), ~1 second (incremental) |
| 27 | + |
| 28 | +**2. Run Tests:** |
| 29 | +```bash |
| 30 | +# Unit and integration tests (ALWAYS run this) |
| 31 | +cargo test --tests --benches |
| 32 | + |
| 33 | +# Documentation tests (ALWAYS run this) |
| 34 | +cargo test --doc |
| 35 | +``` |
| 36 | +Time: ~25 seconds for compilation + ~1 second for test execution |
| 37 | + |
| 38 | +**3. Format Check:** |
| 39 | +```bash |
| 40 | +cargo +stable fmt --all -- --check |
| 41 | +``` |
| 42 | +Time: ~1 second. If this fails, run `cargo +stable fmt --all` to auto-fix. |
| 43 | + |
| 44 | +**4. Lint with Clippy:** |
| 45 | +```bash |
| 46 | +# First install nightly if needed |
| 47 | +rustup install --profile default nightly |
| 48 | + |
| 49 | +# Then run clippy |
| 50 | +cargo +nightly clippy --all-targets -- -D warnings |
| 51 | +``` |
| 52 | +Time: ~15 seconds. Clippy MUST run with nightly and MUST pass with no warnings. |
| 53 | + |
| 54 | +**5. Pre-commit Checks (Optional but Recommended):** |
| 55 | +Pre-commit is a Python program that runs various checks. Install with: |
| 56 | +```bash |
| 57 | +pip install pre-commit |
| 58 | +pre-commit install --hook-type commit-msg |
| 59 | +``` |
| 60 | +Then run manually with: |
| 61 | +```bash |
| 62 | +pre-commit run --all-files |
| 63 | +``` |
| 64 | +Note: Pre-commit may timeout on slow networks when installing hooks. The checks include: trailing whitespace, TOML/YAML validation, codespell, and conventional commit message format. |
| 65 | + |
| 66 | +**6. MSRV Consistency Check:** |
| 67 | +```bash |
| 68 | +sh tests/check-msrv-consistency.sh |
| 69 | +``` |
| 70 | +This verifies that the MSRV in Cargo.toml matches the documentation in src/lib.rs. |
| 71 | + |
| 72 | +**7. Cargo Deny (License and Security Checks):** |
| 73 | +```bash |
| 74 | +# Install once |
| 75 | +cargo install cargo-deny |
| 76 | + |
| 77 | +# Run checks |
| 78 | +cargo deny check |
| 79 | +``` |
| 80 | +Note: May fail with network errors when fetching advisory database. |
| 81 | + |
| 82 | +### Release Build |
| 83 | +```bash |
| 84 | +cargo build --release |
| 85 | +``` |
| 86 | +Time: ~3 seconds (incremental) |
| 87 | + |
| 88 | +### Run Examples |
| 89 | +```bash |
| 90 | +cargo run --example sliding-puzzle |
| 91 | +cargo run --example bfs_bidirectional |
| 92 | +``` |
| 93 | + |
| 94 | +### Benchmarks |
| 95 | +```bash |
| 96 | +# Build benchmarks (don't run them, they take a long time) |
| 97 | +cargo bench --no-run |
| 98 | +``` |
| 99 | +Time: ~50 seconds |
| 100 | + |
| 101 | +## Project Structure |
| 102 | + |
| 103 | +### Root Directory Files |
| 104 | +- `Cargo.toml` - Project manifest with dependencies, MSRV (rust-version = "1.86.0"), and linting configuration |
| 105 | +- `Cargo.lock` - Locked dependency versions |
| 106 | +- `README.md` - User-facing documentation |
| 107 | +- `CHANGELOG.md` - Version history |
| 108 | +- `.gitignore` - Ignores: target/, mutants.out*, flamegraph.svg, perf.data* |
| 109 | +- `deny.toml` - Configuration for cargo-deny (license and security checks) |
| 110 | +- `.pre-commit-config.yaml` - Pre-commit hooks configuration |
| 111 | +- `.gitlab-ci.yml` - GitLab CI configuration (legacy) |
| 112 | +- `release.sh` - Release script (requires git-extras and gh CLI) |
| 113 | + |
| 114 | +### Source Code Structure |
| 115 | +``` |
| 116 | +src/ |
| 117 | +├── lib.rs # Main library entry point with module exports |
| 118 | +├── directed/ # Directed graph algorithms |
| 119 | +│ ├── mod.rs |
| 120 | +│ ├── astar.rs # A* pathfinding |
| 121 | +│ ├── bfs.rs # Breadth-first search |
| 122 | +│ ├── dfs.rs # Depth-first search |
| 123 | +│ ├── dijkstra.rs # Dijkstra's algorithm |
| 124 | +│ ├── edmonds_karp.rs # Maximum flow |
| 125 | +│ ├── fringe.rs # Fringe search |
| 126 | +│ ├── idastar.rs # Iterative deepening A* |
| 127 | +│ ├── iddfs.rs # Iterative deepening DFS |
| 128 | +│ ├── count_paths.rs # Path counting in DAGs |
| 129 | +│ ├── cycle_detection.rs # Floyd and Brent algorithms |
| 130 | +│ ├── strongly_connected_components.rs |
| 131 | +│ ├── topological_sort.rs |
| 132 | +│ └── yen.rs # K-shortest paths |
| 133 | +├── undirected/ # Undirected graph algorithms |
| 134 | +│ ├── mod.rs |
| 135 | +│ ├── cliques.rs # Bron-Kerbosch algorithm |
| 136 | +│ ├── connected_components.rs |
| 137 | +│ ├── kruskal.rs # Minimum spanning tree |
| 138 | +│ └── prim.rs # Minimum spanning tree |
| 139 | +├── grid.rs # Grid data structure |
| 140 | +├── matrix.rs # Matrix data structure |
| 141 | +├── kuhn_munkres.rs # Hungarian algorithm for matching |
| 142 | +├── noderefs.rs # Node reference utilities |
| 143 | +└── utils.rs # Utility functions |
| 144 | +``` |
| 145 | + |
| 146 | +### Tests and Examples |
| 147 | +``` |
| 148 | +tests/ # Integration tests (35+ test files) |
| 149 | +examples/ # Example programs (bfs_bidirectional.rs, sliding-puzzle.rs) |
| 150 | +benches/ # Benchmark suites (algos.rs, edmondskarp.rs, matrices.rs, etc.) |
| 151 | +``` |
| 152 | + |
| 153 | +### GitHub Actions Workflows |
| 154 | +Located in `.github/workflows/`: |
| 155 | + |
| 156 | +1. **tests.yml** (Runs on PRs and merge groups): |
| 157 | + - `check` job: Runs MSRV check and `cargo check --all-targets` with nightly |
| 158 | + - `cargo-deny` job: Runs license and security checks |
| 159 | + - `test` job: Runs tests on stable, beta, nightly, and MSRV toolchains |
| 160 | + - `test-release` job: Runs tests in release mode with nightly |
| 161 | + - `test-minimal-versions` job: Tests with minimal dependency versions |
| 162 | + - `fmt` job: Checks formatting with stable rustfmt |
| 163 | + - `clippy` job: Runs clippy with nightly, treating warnings as errors |
| 164 | + |
| 165 | +2. **pre-commit.yaml** (Runs on PRs and merge groups): |
| 166 | + - Runs pre-commit hooks (trailing whitespace, TOML/YAML validation, codespell, conventional commits) |
| 167 | + |
| 168 | +3. **codspeed.yml** (Runs on main branch pushes and PRs): |
| 169 | + - Runs performance benchmarks |
| 170 | + |
| 171 | +## Critical Validation Rules |
| 172 | + |
| 173 | +### Before Committing |
| 174 | +1. **ALWAYS run tests first:** `cargo test --tests --benches && cargo test --doc` |
| 175 | +2. **ALWAYS run formatting:** `cargo +stable fmt --all -- --check` (auto-fix with `cargo +stable fmt --all`) |
| 176 | +3. **ALWAYS run clippy with nightly:** `cargo +nightly clippy --all-targets -- -D warnings` |
| 177 | +4. **Check MSRV consistency:** `sh tests/check-msrv-consistency.sh` if you modify Cargo.toml or src/lib.rs |
| 178 | + |
| 179 | +### Commit Message Format |
| 180 | +This repository uses **conventional commits**. Every commit message must follow this format: |
| 181 | +``` |
| 182 | +<type>(<scope>): <description> |
| 183 | +
|
| 184 | +Examples: |
| 185 | +- feat(matrix): add Matrix::transpose() |
| 186 | +- fix(tests): remove unused imports |
| 187 | +- chore(changelog): prepare for next release |
| 188 | +``` |
| 189 | +Valid types: `feat`, `fix`, `chore`, `test` |
| 190 | + |
| 191 | +### Common Pitfalls |
| 192 | +1. **Clippy must run with nightly**, not stable. The CI will fail if you only test with stable clippy. |
| 193 | +2. **Formatting must use stable rustfmt**, not nightly. Use `cargo +stable fmt`. |
| 194 | +3. **All warnings are errors in clippy**. The build will fail if clippy reports any warnings. |
| 195 | +4. **Tests must pass in both debug and release modes** on multiple toolchains (stable, beta, nightly, MSRV). |
| 196 | +5. **Documentation tests are separate** from regular tests. Always run both `cargo test --tests` and `cargo test --doc`. |
| 197 | +6. **Benchmarks are tests too**. Use `--benches` flag when running tests to include benchmark tests. |
| 198 | + |
| 199 | +## Development Workflow |
| 200 | + |
| 201 | +### Typical Change Process |
| 202 | +1. Make your code changes in the appropriate module (src/directed/, src/undirected/, etc.) |
| 203 | +2. If you modify public APIs, update documentation with examples |
| 204 | +3. Run `cargo test --tests --benches && cargo test --doc` to verify functionality |
| 205 | +4. Run `cargo +stable fmt --all` to format code |
| 206 | +5. Run `cargo +nightly clippy --all-targets -- -D warnings` to check for issues |
| 207 | +6. If you changed Cargo.toml or src/lib.rs MSRV documentation, run `sh tests/check-msrv-consistency.sh` |
| 208 | +7. Commit with a conventional commit message |
| 209 | + |
| 210 | +### Where to Make Changes |
| 211 | +- **Adding a new algorithm:** Create a new file in src/directed/ or src/undirected/, add module to mod.rs, export from lib.rs |
| 212 | +- **Modifying existing algorithm:** Edit the corresponding file in src/directed/ or src/undirected/ |
| 213 | +- **Adding utility functions:** Add to src/utils.rs |
| 214 | +- **Adding data structures:** Create a new file in src/ (like grid.rs or matrix.rs) |
| 215 | +- **Adding tests:** Create a new file in tests/ directory |
| 216 | +- **Adding examples:** Create a new .rs file in examples/ directory |
| 217 | + |
| 218 | +### Linting Configuration |
| 219 | +Clippy lints are configured in Cargo.toml under `[lints.clippy]`: |
| 220 | +- `pedantic = "deny"` - All pedantic lints are errors |
| 221 | +- `missing_const_for_fn = "deny"` - Functions that could be const must be const |
| 222 | +- `redundant_clone = "deny"` - Redundant clones are errors |
| 223 | +- `module_name_repetitions = "allow"` - Exception for module name repetitions |
| 224 | +- `too_long_first_doc_paragraph = "allow"` - Temporary exception for long doc paragraphs |
| 225 | + |
| 226 | +## Quick Reference |
| 227 | + |
| 228 | +**Test everything:** `cargo test --tests --benches && cargo test --doc` |
| 229 | +**Format code:** `cargo +stable fmt --all` |
| 230 | +**Lint code:** `cargo +nightly clippy --all-targets -- -D warnings` |
| 231 | +**Check quickly:** `cargo check --all-targets` |
| 232 | +**Build release:** `cargo build --release` |
| 233 | +**Run example:** `cargo run --example <name>` |
| 234 | + |
| 235 | +## Trust These Instructions |
| 236 | + |
| 237 | +These instructions have been validated by running all commands and observing their behavior. If you encounter discrepancies, verify first before searching extensively. The most common issues are: |
| 238 | +1. Using wrong Rust toolchain (stable vs nightly) for clippy or fmt |
| 239 | +2. Forgetting to run both `--tests` and `--doc` test suites |
| 240 | +3. Not including `--benches` flag when running tests |
| 241 | +4. Network timeouts with pre-commit or cargo-deny (not your fault, skip and continue) |
0 commit comments