|
| 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 | + Pre-commit 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 | + ### Release Build |
| 81 | + ```bash |
| 82 | + cargo build --release |
| 83 | + ``` |
| 84 | + Time: ~3 seconds (incremental) |
| 85 | + |
| 86 | + ### Run Examples |
| 87 | + ```bash |
| 88 | + cargo run --example sliding-puzzle |
| 89 | + cargo run --example bfs_bidirectional |
| 90 | + ``` |
| 91 | + |
| 92 | + ### Benchmarks |
| 93 | + ```bash |
| 94 | + # Build benchmarks (don't run them, they take a long time) |
| 95 | + cargo bench --no-run |
| 96 | + ``` |
| 97 | + Time: ~50 seconds |
| 98 | + |
| 99 | + ## Project Structure |
| 100 | + |
| 101 | + ### Root Directory Files |
| 102 | + - `Cargo.toml` - Project manifest with dependencies, MSRV (rust-version = "1.86.0"), and linting configuration |
| 103 | + - `Cargo.lock` - Locked dependency versions |
| 104 | + - `README.md` - User-facing documentation |
| 105 | + - `CHANGELOG.md` - Version history |
| 106 | + - `.gitignore` - Ignores: target/, mutants.out*, flamegraph.svg, perf.data* |
| 107 | + - `deny.toml` - Configuration for cargo-deny (license and security checks) |
| 108 | + - `.pre-commit-config.yaml` - Pre-commit hooks configuration |
| 109 | + - `.gitlab-ci.yml` - GitLab CI configuration (legacy) |
| 110 | + - `release.sh` - Release script (requires git-extras and gh CLI) |
| 111 | + |
| 112 | + ### Source Code Structure |
| 113 | + ``` |
| 114 | + src/ |
| 115 | + ├── lib.rs # Main library entry point with module exports |
| 116 | + ├── directed/ # Directed graph algorithms |
| 117 | + │ ├── mod.rs |
| 118 | + │ ├── astar.rs # A* pathfinding |
| 119 | + │ ├── bfs.rs # Breadth-first search |
| 120 | + │ ├── dfs.rs # Depth-first search |
| 121 | + │ ├── dijkstra.rs # Dijkstra's algorithm |
| 122 | + │ ├── edmonds_karp.rs # Maximum flow |
| 123 | + │ ├── fringe.rs # Fringe search |
| 124 | + │ ├── idastar.rs # Iterative deepening A* |
| 125 | + │ ├── iddfs.rs # Iterative deepening DFS |
| 126 | + │ ├── count_paths.rs # Path counting in DAGs |
| 127 | + │ ├── cycle_detection.rs # Floyd and Brent algorithms |
| 128 | + │ ├── strongly_connected_components.rs |
| 129 | + │ ├── topological_sort.rs |
| 130 | + │ └── yen.rs # K-shortest paths |
| 131 | + ├── undirected/ # Undirected graph algorithms |
| 132 | + │ ├── mod.rs |
| 133 | + │ ├── cliques.rs # Bron-Kerbosch algorithm |
| 134 | + │ ├── connected_components.rs |
| 135 | + │ ├── kruskal.rs # Minimum spanning tree |
| 136 | + │ └── prim.rs # Minimum spanning tree |
| 137 | + ├── grid.rs # Grid data structure |
| 138 | + ├── matrix.rs # Matrix data structure |
| 139 | + ├── kuhn_munkres.rs # Hungarian algorithm for matching |
| 140 | + ├── noderefs.rs # Node reference utilities |
| 141 | + └── utils.rs # Utility functions |
| 142 | + ``` |
| 143 | + |
| 144 | + ### Tests and Examples |
| 145 | + ``` |
| 146 | + tests/ # Integration tests (35+ test files) |
| 147 | + examples/ # Example programs (bfs_bidirectional.rs, sliding-puzzle.rs) |
| 148 | + benches/ # Benchmark suites (algos.rs, edmondskarp.rs, matrices.rs, etc.) |
| 149 | + ``` |
| 150 | + |
| 151 | + ### GitHub Actions Workflows |
| 152 | + Located in `.github/workflows/`: |
| 153 | + |
| 154 | + 1. **tests.yml** (Runs on PRs and merge groups): |
| 155 | + - `check` job: Runs MSRV check and `cargo check --all-targets` with nightly |
| 156 | + - `cargo-deny` job: Runs license and security checks |
| 157 | + - `test` job: Runs tests on stable, beta, nightly, and MSRV toolchains |
| 158 | + - `test-release` job: Runs tests in release mode with nightly |
| 159 | + - `test-minimal-versions` job: Tests with minimal dependency versions |
| 160 | + - `fmt` job: Checks formatting with stable rustfmt |
| 161 | + - `clippy` job: Runs clippy with nightly, treating warnings as errors |
| 162 | + |
| 163 | + 2. **pre-commit.yaml** (Runs on PRs and merge groups): |
| 164 | + - Runs pre-commit hooks (trailing whitespace, TOML/YAML validation, codespell, conventional commits) |
| 165 | + |
| 166 | + 3. **codspeed.yml** (Runs on main branch pushes and PRs): |
| 167 | + - Runs performance benchmarks |
| 168 | + |
| 169 | + ## Critical Validation Rules |
| 170 | + |
| 171 | + ### Before Committing |
| 172 | + 1. **ALWAYS run tests first:** `cargo test --tests --benches && cargo test --doc` |
| 173 | + 2. **ALWAYS run formatting:** `cargo +stable fmt --all -- --check` (auto-fix with `cargo +stable fmt --all`) |
| 174 | + 3. **ALWAYS run clippy with nightly:** `cargo +nightly clippy --all-targets -- -D warnings` |
| 175 | + 4. **Check MSRV consistency:** `sh tests/check-msrv-consistency.sh` if you modify Cargo.toml or src/lib.rs |
| 176 | + 5. **Remove trailing spaces:** All files must have trailing whitespace removed (pre-commit checks enforce this) |
| 177 | + 6. **Unix line terminators:** Unix regular \n terminators must be used |
| 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 | ++**Test everything:** `cargo test --tests --benches && cargo test --doc` |
| 234 | ++**Format code:** `cargo +stable fmt --all` |
| 235 | ++**Lint code:** `cargo +nightly clippy --all-targets -- -D warnings` |
| 236 | ++**Check quickly:** `cargo check --all-targets` |
| 237 | ++**Build release:** `cargo build --release` |
| 238 | + **Run example:** `cargo run --example <name>` |
| 239 | + |
| 240 | + ## Trust These Instructions |
| 241 | + |
| 242 | + 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: |
| 243 | + 1. Using wrong Rust toolchain (stable vs nightly) for clippy or fmt |
| 244 | + 2. Forgetting to run both `--tests` and `--doc` test suites |
| 245 | + 3. Not including `--benches` flag when running tests |
0 commit comments