Repository navigation
fix(resolve): keep the Cargo manifests resolution reads inside the project root - #349
Merged
Merged
Conversation
…oject root rust_manifest_inputs names the Cargo.toml files load_rust_crates reads and the watcher's Rust control row digests. It replaced `\` with `/` and then skipped only a path that started with `/` or held a `..` segment, so a drive-absolute or drive-relative path (`C:\x\a.rs`, `C:/x/a.rs`, `C:x\a.rs`) and one whose normalized form starts with a drive (`./C:/x/a.rs`) got through. On Windows `Path::join` lets a right side with a drive prefix replace the root, so such a probe reads a manifest outside the project (hard invariant 5; OD-B15). It now follows go_module_inputs: a `.rs` path is normalized by pathutil::lexical_relative, which refuses a rooted, UNC, drive-letter or `..`-above-the-root path, and the walk up runs over the normalized path. load_rust_crates also joins each input to the root through pathutil::lexical_path_within_root, a second check at the read itself. Every input already passes it, so the file it reads is unchanged. Why the extraction version does not move: resolution reads the paths the scan produced, which are project-relative, and for those the inputs are unchanged. Windows allows no `:` in a file name, so no indexed path there has a drive's shape and an existing index's Rust manifest inputs stay the same. On Unix only a root directory literally named `<letter>:...` (such as `C:outside`) changes: its Cargo.toml is no longer read, an intentional over-rejection that matches go_module_inputs. An existing index of such a tree keeps its old result, which read a file inside the root, until its next sync re-resolves the Rust files for the moved control row. No existing index serves an edge from outside the root. Tests, each red at 8166929 with only the tests applied: - rust_manifest_inputs_skip_paths_that_could_leave_the_root runs the 14 inputs of the go_module_inputs test with `.go` read as `.rs` and checks that each output is a fixed point of lexical_relative. At 8166929 it gave six extra inputs (./Cargo.toml, ./C:/Cargo.toml, ./C:/outside/Cargo.toml, C:/Cargo.toml, C:/outside/Cargo.toml, C:outside/Cargo.toml) and no b/Cargo.toml. - load_rust_crates_over_rejects_a_unix_directory_named_like_a_drive (Unix) pins the over-rejection at the read; at 8166929 the project crates were [app, escaped]. - The Unix-only sync convergence cases rust_cargo_drive_letter_directory_source_appears and _leaves add, then remove, a .rs file under a C:outside directory whose manifest depends on futures. Each sync, through the CLI and the watcher path, equals a fresh init, control-input rows included. At 8166929 the fresh, respectively the before, index lacked `drain references Stream`. The probe harness's fixture-path guard now allows `:` on Unix only, where it is an ordinary byte of a name; Windows still refuses it. Verified with cargo test -p codegraph-resolve (all targets), codegraph-watch's control_inputs tests, the sync_convergence rust_cargo and rust_ cases, the probes rust family, cargo fmt --check, clippy -D warnings on codegraph-resolve and codegraph-rs (Linux, and Windows msvc through cargo-xwin), docs-check, and scripts/regen-goldens.sh --check with explicit release binaries: all 32 corpora identical. UPSTREAM.md's current alignment drops the rust_manifest_inputs half of the OD-B15 entry; its other two differences stay.
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #349 +/- ##
=======================================
Coverage 96.40% 96.40%
=======================================
Files 368 368
Lines 254382 254439 +57
=======================================
+ Hits 245229 245284 +55
- Misses 9153 9155 +2
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rust_manifest_inputslists theCargo.tomlpaths that Rust resolution reads and that the watcher's Rust control row digests. It now normalizes each.rspath withpathutil::lexical_relativeand skips any path that could leave the project root lexically: rooted, UNC, drive-absolute, drive-relative, or..above the root.go_module_inputsalready applies this rule. Both callers are covered:load_rust_cratesand theControlKind::Rustbranch ofcontrol_inputs::digests_of.load_rust_cratesalso joins each input to the root throughpathutil::lexical_path_within_root, a second check at the read. Every input already passes it, so the file read does not change.docs/upstream-sync/UPSTREAM.md: the OD-B15 entry under Current alignment drops itsrust_manifest_inputshalf and keeps the other two differences.Why
The old filter replaced
\with/and skipped only paths that started with/or held a..segment.C:\x\a.rs,C:/x/a.rs,C:x\a.rsand./C:/x/a.rsall got through. On Windows,Path::joinlets a right side with a drive prefix replace the root, so the probe could read a manifest outside the project (hard invariant 5; X08 / OD-B15).The extraction version stays at 23:
:in a file name, so no indexed path there has a drive's shape.<letter>:...(for exampleC:outside) changes: itsCargo.tomlis no longer read. This is an intentional over-rejection that matchesgo_module_inputs. An existing index of such a tree keeps its old result, which came from a file inside the root, until a sync re-reads the Rust control inputs. A CLI sync always re-reads them; the watcher re-reads them when a Rust file comes, goes or changes language, or when a recorded input changes. No existing index serves an edge read from outside the root.Verification
Red at
8166929with only the new tests applied (production code unchanged):rust_manifest_inputs_skip_paths_that_could_leave_the_rootruns the 14 inputs of the Go test with.goread as.rs, and checks that each output is a fixed point oflexical_relative. It returned six extra inputs (./Cargo.toml,./C:/Cargo.toml,./C:/outside/Cargo.toml,C:/Cargo.toml,C:/outside/Cargo.toml,C:outside/Cargo.toml) and nob/Cargo.toml.load_rust_crates_over_rejects_a_unix_directory_named_like_a_drive(Unix): the project crates were["app", "escaped"]instead of["app"].rust_cargo_drive_letter_directory_source_appearsand_leaves(Unix) add, then remove, a.rsfile under aC:outsidedirectory whose manifest depends onfutures. The fresh index (appears) and the before index (leaves) lackedfunction drain -[references]-> trait Stream, because the dependency inC:outside/Cargo.tomlwas read.Green at
725b8cc(all cargo commands useenv -u RUSTUP_TOOLCHAIN, Rust 1.98.0):cargo test -p codegraph-resolve --locked: the whole crate, 2374 passed. This run used the same production code just before the commit.--lib -- rust_scope::tests pathutil::tests go_module: 36 passed at the commit.cargo test -p codegraph-watch --locked control_inputs: 11 passed.cargo test -p codegraph-rs --locked --test sync_convergence rust_cargo: 4 passed. Both drivers equal a fresh init, control-input rows included. Therust_filter: 44 passed.cargo test -p codegraph-rs --locked --test probes -- rust: 52 passed.cargo fmt --all --check;cargo clippy -p codegraph-resolve -p codegraph-rs --all-targets --locked -- -D warningson Linux, and onx86_64-pc-windows-msvcthrough cargo-xwin.python3 scripts/docs-check.py;make fmt-oxfmt-checkwith oxfmt 0.64.0.scripts/regen-goldens.sh --checkwith explicit releaseCODEGRAPH_BINandBENCH_BINbuilt at725b8cc: all 32 corpora identical.Notes
checked_relativeincrates/codegraph-cli/tests/probes/support.rsnow accepts:in a fixture path on Unix only, where it is an ordinary byte of a name. Windows still refuses it.#[cfg(unix)]tests next tomatrix!, because the macro has nocfgsupport. The coverage gates do not count them; other matrix cases still cover Rust and both change kinds.rust_manifest_inputs_skip_paths_that_could_leave_the_root(0.00 s locally).d2facd72), which moves with B's extraction-version bump, and the other readers without full containment (C# project files, pubspec, the digest side of app markers and manifest candidates,package_manifestsimporting_dir,path_aliasesnearest_alias_walk), planned for C's early batch.