Skip to content

fix(resolve): keep the Cargo manifests resolution reads inside the project root - #349

Merged
sunerpy merged 1 commit into
mainfrom
fix/rust-manifest-containment
Nov 27, 2026
Merged

sunerpy merged 1 commit into
mainfrom
fix/rust-manifest-containment

Conversation

@sunerpy

@sunerpy sunerpy commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • rust_manifest_inputs lists the Cargo.toml paths that Rust resolution reads and that the watcher's Rust control row digests. It now normalizes each .rs path with pathutil::lexical_relative and skips any path that could leave the project root lexically: rooted, UNC, drive-absolute, drive-relative, or .. above the root. go_module_inputs already applies this rule. Both callers are covered: load_rust_crates and the ControlKind::Rust branch of control_inputs::digests_of.
  • load_rust_crates also joins each input to the root through pathutil::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 its rust_manifest_inputs half 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.rs and ./C:/x/a.rs all got through. On Windows, Path::join lets 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:

  • Resolution reads paths the scan produced, which are project-relative. For those paths the inputs are unchanged.
  • Windows allows no : in a file name, so no indexed path there has a drive's shape.
  • On Unix, only a root directory literally named <letter>:... (for example C:outside) changes: its Cargo.toml is no longer read. This is an intentional over-rejection that matches go_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 8166929 with only the new tests applied (production code unchanged):

  • rust_manifest_inputs_skip_paths_that_could_leave_the_root runs the 14 inputs of the Go test with .go read as .rs, and checks that each output is a fixed point of lexical_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 no b/Cargo.toml.
  • load_rust_crates_over_rejects_a_unix_directory_named_like_a_drive (Unix): the project crates were ["app", "escaped"] instead of ["app"].
  • Sync convergence rust_cargo_drive_letter_directory_source_appears and _leaves (Unix) add, then remove, a .rs file under a C:outside directory whose manifest depends on futures. The fresh index (appears) and the before index (leaves) lacked function drain -[references]-> trait Stream, because the dependency in C:outside/Cargo.toml was read.

Green at 725b8cc (all cargo commands use env -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. The rust_ 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 warnings on Linux, and on x86_64-pc-windows-msvc through cargo-xwin.
  • python3 scripts/docs-check.py; make fmt-oxfmt-check with oxfmt 0.64.0.
  • scripts/regen-goldens.sh --check with explicit release CODEGRAPH_BIN and BENCH_BIN built at 725b8cc: all 32 corpora identical.

Notes

  • Test harness: checked_relative in crates/codegraph-cli/tests/probes/support.rs now accepts : in a fixture path on Unix only, where it is an ordinary byte of a name. Windows still refuses it.
  • The two sync cases are standalone #[cfg(unix)] tests next to matrix!, because the macro has no cfg support. The coverage gates do not count them; other matrix cases still cover Rust and both change kinds.
  • The only new test that runs on Windows is the pure-string rust_manifest_inputs_skip_paths_that_could_leave_the_root (0.00 s locally).
  • Out of scope, per the program plan: workspace-glob containment (upstream 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_manifests importing_dir, path_aliases nearest_alias_walk), planned for C's early batch.

…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

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.38710% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/codegraph-resolve/src/rust_scope.rs 98.38% 1 Missing ⚠️

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #349   +/-   ##
=======================================
  Coverage   96.40%   96.40%           
=======================================
  Files         368      368           
  Lines      254382   254439   +57     
=======================================
+ Hits       245229   245284   +55     
- Misses       9153     9155    +2     
Files with missing lines Coverage Δ
crates/codegraph-resolve/src/rust_scope.rs 98.43% <98.38%> (-0.02%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sunerpy
sunerpy merged commit 1c579c0 into main Nov 27, 2026
18 of 20 checks passed
@sunerpy
sunerpy deleted the fix/rust-manifest-containment branch November 27, 2026 08:55
@github-actions github-actions Bot mentioned this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant