Skip to content

feat(rust): map Cargo packages and test targets - #91

Merged
adityankale190895 merged 3 commits into
DiffCI:mainfrom
FredApps:rust/58-cargo-package-mapping
Nov 15, 2026
Merged

adityankale190895 merged 3 commits into
DiffCI:mainfrom
FredApps:rust/58-cargo-package-mapping

Conversation

@FredApps

@FredApps FredApps commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Map Cargo workspace members and target roots with validated metadata, deepest-package ownership, and explicit test-to-package/target routing.
  • Add single-crate, multi-member and nested-package fixtures plus malformed metadata, excluded crates, symlink escape and duplicate-target regressions.
  • Run metadata offline and locked; no dependency downloads or lockfile writes. Cargo availability is checked in hosted CI so executable fixtures cannot silently skip there.

Fixes #58. First milestone of #62; dependency selection (#59), command synthesis (#60), registration and the public replay remain separate steps.

Safety boundary

This adapter is deliberately not registered yet. A global foundation blocker keeps direct callers on full validation until crate dependency edges are implemented. Missing Cargo, failed metadata, unsupported targets and incomplete ownership all produce blockers rather than an empty successful graph.

Validation

  • npm ci, typecheck, build and release-boundary audit passed in the cloud workspace.
  • Focused mapping/regression tests passed; three real-Cargo fixtures skip locally because Cargo is unavailable.
  • Full suite via Node's direct tsx loader passed all non-IPC checks after updating fallback documentation. Three existing runner-launch tests require an IPC socket disallowed in the cloud sandbox. The normal npm test wrapper has the same restriction.
  • Hosted Linux/Windows Node 22/24 CI passed for this exact head, including the Cargo prerequisite and complete test/build/audit/agent/benchmark matrix. CLI packaging, Observer Action smoke and CodeQL also passed.
  • Independent review identified an excluded nested-crate ownership gap; fixed with an explicit manifest boundary and regression coverage.

All commits are DCO signed off.

@FredApps

Copy link
Copy Markdown
Contributor Author

@adityankale190895 could you review this Cargo package/target mapping foundation for #62? It's ready for review and all checks are passing.

@adityankale190895 adityankale190895 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a careful foundation. The global foundation blocker, strict metadata validation, --no-deps --offline --locked, deepest-package ownership, the excluded-crate boundary and the symlink-escape checks all look right to me. One fix before merge, plus a few smaller notes.

Should fix

1. A symlinked checkout path makes every manifest look external (src/repo/adapters/rust.ts)

The workspace-root check compares realpathSync(metadata.workspace_root) with realpathSync(root), but everything after it goes through internalPath(root, …) with root = resolve(context.repoPath), which isn't resolved. Cargo takes its cwd from the OS, and getcwd usually returns the physical path. So when repoPath has a symlink in it, manifest_path and src_path come back under the real path. One example is macOS tmpdir(), where /var/… is really /private/var/…. Another is a symlinked checkout or CI workspace. relative() then starts with ../, and every package gets "has an unavailable or external manifest".

This fails closed, so it isn't a safety problem, but the adapter would always fall back for those users, and the reason would point them the wrong way. CI only covers Linux and Windows, so nothing would catch it. Suggested fix: compute realpathSync(root) once, resolve each metadata path with realpathSync before relative(), and add a fixture that reaches the repo through a symlinked directory. Computing it once also removes the repeated realpathSync(root) call per .rs file in repositoryPath.

Worth deciding before registration (#94)

2. Any Cargo.toml outside workspace membership blocks the whole repo. Fixture crates such as tests/fixtures/*/Cargo.toml are common in Rust repos. owner() already blocks .rs files under an unmodeled manifest boundary one at a time. Could the global blocker be limited to changes under those boundaries? Or is there a case you want the repo-wide fallback for?

Nits

  1. release-files.json: src/repo/adapters/rust.ts and tests/repo/rust-adapter.test.ts are out of alphabetical order.
  2. docs/using-diffci.md: 12 rows of the fallback-reasons table repeat the same Meaning text. Grouping them, or giving each row its own next step, would read better. The bare #62 won't link on the docs site.

@adityankale190895

Copy link
Copy Markdown
Member

Hi @FredApps, thank you for the five safety fixes (#32–#36) and the Cargo series (#91–#95), which is the groundwork for Rust support.

We have just added contributor tiers to DiffCI (CONTRIBUTING.md), and I would like to invite you to be the area maintainer for the Rust (Cargo) adapter. In practice that means:

  • your name as the Rust adapter maintainer in the README and the adapter docs
  • design decisions in the Rust adapter are yours to propose, and I review rather than decide
  • you are requested as a reviewer on PRs that touch it
  • co-authorship of the write-up when Rust support ships

No obligation and no fixed hours. If you would rather keep contributing as you are, that is completely fine. Either way, let me know if anything is blocking the #91 fix.

You are also on our new contributors page, diffci.com/contributors. Tell me if you would rather not be listed there, or would like a different name or link.

Compute the workspace root's real path once and realpath Cargo metadata
paths before relative() so a checkout reached through a symlink (macOS
tmpdir, linked workspaces) is not treated as external. Reuse that
resolved root in repositoryPath instead of calling realpathSync per
file.

Also sort the new adapter files in release-files.json and group the
repeated Rust fallback-reason rows, with a full link to DiffCI#62.

Signed-off-by: FredApps <[email protected]>
@FredApps

Copy link
Copy Markdown
Contributor Author

@adityankale190895 thanks for the review — the symlink checkout bug is fixed, along with the two nits. CI is green on the new head.

1. Symlinked checkout paths — 17024f1 computes realpathSync(root) once, realpaths each Cargo metadata path before relative(), and reuses that resolved root in repositoryPath (no per-file realpathSync(root)). A new fixture reaches the repo through a symlinked directory, with metadata paths under the physical tree the way Cargo reports them. It runs on Linux CI and skips gracefully if the symlink cannot be created (for example on an unprivileged Windows runner).

I also merged main into the branch in 913ce30.

3. release-files.json — same fix commit: src/repo/adapters/rust.ts now sits after python.ts, and tests/repo/rust-adapter.test.ts after runner-universe.test.ts.

4. docs/using-diffci.md — the 12 reasons that shared one Meaning are grouped into a single table row, and the two ownership-ambiguity reasons into another. The bare #62 is now a full link to the issue.

2. Global blocker for out-of-workspace Cargo.toml — left unchanged here, as you suggested we decide this before registration. I'd keep the repo-wide fallback in this foundation: without crate dependency edges we cannot tell whether a workspace member path-depends on an excluded fixture crate, so a change under tests/fixtures/*/Cargo.toml could be dropped silently if we only blocked files under that boundary.

For #94, once #92's dependency graph is available, I'd narrow it: treat unmodeled manifests as hard ownership boundaries (as owner() already does for .rs files), and require full validation only when the changed set or its dependents intersect those boundaries. If metadata still cannot say whether a workspace member depends on such a crate, keep the repo-wide fallback for that case.

Could you take another look?

@FredApps

Copy link
Copy Markdown
Contributor Author

@adityankale190895 thank you, I'd be glad to accept the invitation and take on the area-maintainer role for the Rust (Cargo) adapter. Listing me on the contributors page is fine too. Nothing is blocking the #91 fix any more: it's pushed and CI is green, so it's ready for another look whenever you have time. Once #91 lands, I'll bring #92 to #95 up to date on top of it.

@adityankale190895 adityankale190895 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this all looks good. Approving.

  • Symlinked checkout: resolving the root once and resolving each metadata path before relative() fixes it, and the new fixture (physical metadata paths, symlinked repoPath) tests exactly that case. Good that it ran on the Windows jobs too, where the junction gets created.
  • Nits 3 and 4: done, thanks.
  • Repo-wide blocker for out-of-workspace Cargo.toml: agreed, keep it for now. The foundation blocker already makes every Rust repo fall back, so nothing changes for users in this PR. Your plan for #94 makes sense: treat unmodeled manifests as ownership boundaries once #92 has dependency edges, and keep the repo-wide fallback only when the metadata can't rule out a dependency.

I'll squash-merge this. Welcome aboard as Rust adapter maintainer. I'll add you to the README and the adapter docs.

@adityankale190895
adityankale190895 merged commit 7033d98 into DiffCI:main Nov 15, 2026
13 checks passed
adityankale190895 added a commit that referenced this pull request Nov 15, 2026
Credit #91 in the README (below the credit bot's automated range) and name
the area maintainer in the roadmap and the Rust adapter docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FredApps added a commit to FredApps/core that referenced this pull request Nov 15, 2026
Resolve the DiffCI#91 squash merge: keep main's symlinked-checkout fix,
grouped fallback-reason rows and maintainer line, and reapply this
milestone's crate dependency analysis on top.

Signed-off-by: FredApps <[email protected]>
FredApps added a commit to FredApps/core that referenced this pull request Nov 15, 2026
Bring in main (including the DiffCI#91 squash merge) through the updated
dependency milestone; this milestone's changes are reapplied unchanged.

Signed-off-by: FredApps <[email protected]>
FredApps added a commit to FredApps/core that referenced this pull request Nov 15, 2026
Bring in main (including the DiffCI#91 squash merge) through the updated
command milestone. Bump the graph cache schema to 15 after main's 11-14,
and keep release-files.json alphabetical.

Signed-off-by: FredApps <[email protected]>
FredApps added a commit to FredApps/core that referenced this pull request Nov 15, 2026
Bring in main (including the DiffCI#91 squash merge) through the updated
registration milestone; the replay and execution evidence is reapplied
unchanged.

Signed-off-by: FredApps <[email protected]>
FredApps added a commit to FredApps/core that referenced this pull request Nov 15, 2026
…ixture fallbacks

Review on DiffCI#94:
1. Documentation changes follow the shared classification (no tests, no
   fallback) unless Rust code names a documentation path or a workspace
   build script exists; include_str!'d docs stay modelled assets.
   .github/** keeps the full suite: it is the invocation evidence.
2. Leave Maven, Python and Go behaviour as on main: the test matcher adds
   only Rust targets, goTestPackages only drops Rust contributions, and
   hydrated graphs only trust declared test identities for .rs nodes.
3. Accept ordinary CI around a plain `cargo test`: checkout, toolchain and
   cache actions, a matrix, output-only env, and build/clippy/fmt/doc/
   rustup steps or jobs. Test flags, other runners, compiler env,
   conditional or relocated test steps and unknown actions stay advisory.
4. Label Rust support experimental in the docs.

From DiffCI#91 (point 2): Cargo manifests outside the workspace no longer block
the repository when metadata shows no member depends on them; their files
stay unmodelled, so changing one keeps the full suite.

Also pass Cargo feature coverage and documentation readers to the profile.

Signed-off-by: FredApps <[email protected]>
adityankale190895 added a commit that referenced this pull request Nov 16, 2026
…#94)

* feat(rust): map Cargo packages and test targets (#58)

Signed-off-by: FredApps <[email protected]>

* feat(rust): select workspace tests by crate dependencies (#59)

Signed-off-by: FredApps <[email protected]>

* feat(rust): synthesize conservative Cargo test commands (#60)

Signed-off-by: FredApps <[email protected]>

* feat(rust): register conservative Cargo adapter and document boundaries

Signed-off-by: FredApps <[email protected]>

* fix(rust): narrow dependency, feature and runtime-input blockers

Review on #92: the checks were so broad that no real crate could select
fewer tests. Keep failing closed where a subset can actually differ.

- Locked registry/Git dependencies (including build scripts and proc
  macros) no longer block; Cargo.lock changes keep the full suite. Local
  path dependencies outside the workspace still block.
- A workspace crate with a build script depends on every workspace crate:
  it and its dependents run for any Rust change, other crates narrow.
- Feature requests no longer block. Cargo (`cargo tree`) resolves each
  tested crate alone and with its dependents; the coverage is recorded
  for the planner to check each selected set. Missing evidence blocks.
- Drop the fs/process/unsafe/extern keyword denylist. Literal paths that
  reach another crate, and code that runs Cargo/rustc, become crate
  dependencies instead of blockers.
- Check only module trees for symlinks and unlisted sources (no 50k
  cap; linked LICENSE/README files are fine).
- Read parent-directory and $CARGO_HOME Cargo config, block only
  build-changing keys, and include RUSTDOCFLAGS and CARGO_BUILD_TARGET.

Signed-off-by: FredApps <[email protected]>

* fix(rust): select only crates plain cargo test covers; check features per command

Review on #93: plain `cargo test` tests only the root package of a
non-virtual workspace, or `default-members`. Register test targets only
for `workspace_default_members`, so a selective run stays a subset of the
full one; other members remain sources that reach tested dependents.
Metadata without default members (Cargo < 1.71) falls back.

With #92's feature coverage, every synthesized Cargo invocation must
contain a unit Cargo resolved with the full run's features for each
package a selected crate would otherwise build differently; otherwise
the plan is refused. Profiles without coverage are refused.

Also keep release-files.json alphabetical.

Signed-off-by: FredApps <[email protected]>

* fix(rust): keep registration Rust-only; narrow docs, invocation and fixture fallbacks

Review on #94:
1. Documentation changes follow the shared classification (no tests, no
   fallback) unless Rust code names a documentation path or a workspace
   build script exists; include_str!'d docs stay modelled assets.
   .github/** keeps the full suite: it is the invocation evidence.
2. Leave Maven, Python and Go behaviour as on main: the test matcher adds
   only Rust targets, goTestPackages only drops Rust contributions, and
   hydrated graphs only trust declared test identities for .rs nodes.
3. Accept ordinary CI around a plain `cargo test`: checkout, toolchain and
   cache actions, a matrix, output-only env, and build/clippy/fmt/doc/
   rustup steps or jobs. Test flags, other runners, compiler env,
   conditional or relocated test steps and unknown actions stay advisory.
4. Label Rust support experimental in the docs.

From #91 (point 2): Cargo manifests outside the workspace no longer block
the repository when metadata shows no member depends on them; their files
stay unmodelled, so changing one keeps the full suite.

Also pass Cargo feature coverage and documentation readers to the profile.

Signed-off-by: FredApps <[email protected]>

* fix(rust): paths that climb out of a crate in code depend on every crate

Review on #92: a test that reads another crate's files only counted as
depending on it when the code held a literal path to that crate. Tests
that check every crate's files usually build the path instead, through
.parent(), .ancestors(), PathBuf::pop or a formatted '..' path, so a
change to the other crate skipped them.

Treat such code like code that runs Cargo: its crate depends on every
workspace crate. It only fires where the file also works with paths, so
tree parent() methods and Vec::pop keep narrowing. Crate-local paths
built from CARGO_MANIFEST_DIR stay narrow; the literal pass resolves them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: adityankale190895 <[email protected]>

* fix(rust): find documentation reads through relative and walked paths

Review on #94: a test that reached docs/ through "../docs",
concat!(env!("CARGO_MANIFEST_DIR"), "/../docs") or a directory walk that
matched the "md" extension was not recorded as reading documentation, so
a docs-only change ran no tests and kept no fallback.

Match a documentation directory anywhere in a path, a Markdown name or a
bare md/mdx extension, and count code that climbs out of its crate as a
documentation reader too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: adityankale190895 <[email protected]>

---------

Signed-off-by: FredApps <[email protected]>
Signed-off-by: adityankale190895 <[email protected]>
Co-authored-by: adityankale190895 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
adityankale190895 added a commit that referenced this pull request Nov 16, 2026
* feat(rust): map Cargo packages and test targets (#58)

Signed-off-by: FredApps <[email protected]>

* feat(rust): select workspace tests by crate dependencies (#59)

Signed-off-by: FredApps <[email protected]>

* feat(rust): synthesize conservative Cargo test commands (#60)

Signed-off-by: FredApps <[email protected]>

* feat(rust): register conservative Cargo adapter and document boundaries

Signed-off-by: FredApps <[email protected]>

* test(rust): add pinned public glob replay on hosted CI

Signed-off-by: FredApps <[email protected]>

* docs(rust): publish measured glob replay and fallback limits

Signed-off-by: FredApps <[email protected]>

* test(rust): execute selections from real Git changes

Signed-off-by: FredApps <[email protected]>

* docs(rust): publish Linux selective execution evidence

Signed-off-by: FredApps <[email protected]>

* fix(rust): narrow dependency, feature and runtime-input blockers

Review on #92: the checks were so broad that no real crate could select
fewer tests. Keep failing closed where a subset can actually differ.

- Locked registry/Git dependencies (including build scripts and proc
  macros) no longer block; Cargo.lock changes keep the full suite. Local
  path dependencies outside the workspace still block.
- A workspace crate with a build script depends on every workspace crate:
  it and its dependents run for any Rust change, other crates narrow.
- Feature requests no longer block. Cargo (`cargo tree`) resolves each
  tested crate alone and with its dependents; the coverage is recorded
  for the planner to check each selected set. Missing evidence blocks.
- Drop the fs/process/unsafe/extern keyword denylist. Literal paths that
  reach another crate, and code that runs Cargo/rustc, become crate
  dependencies instead of blockers.
- Check only module trees for symlinks and unlisted sources (no 50k
  cap; linked LICENSE/README files are fine).
- Read parent-directory and $CARGO_HOME Cargo config, block only
  build-changing keys, and include RUSTDOCFLAGS and CARGO_BUILD_TARGET.

Signed-off-by: FredApps <[email protected]>

* fix(rust): select only crates plain cargo test covers; check features per command

Review on #93: plain `cargo test` tests only the root package of a
non-virtual workspace, or `default-members`. Register test targets only
for `workspace_default_members`, so a selective run stays a subset of the
full one; other members remain sources that reach tested dependents.
Metadata without default members (Cargo < 1.71) falls back.

With #92's feature coverage, every synthesized Cargo invocation must
contain a unit Cargo resolved with the full run's features for each
package a selected crate would otherwise build differently; otherwise
the plan is refused. Profiles without coverage are refused.

Also keep release-files.json alphabetical.

Signed-off-by: FredApps <[email protected]>

* fix(rust): keep registration Rust-only; narrow docs, invocation and fixture fallbacks

Review on #94:
1. Documentation changes follow the shared classification (no tests, no
   fallback) unless Rust code names a documentation path or a workspace
   build script exists; include_str!'d docs stay modelled assets.
   .github/** keeps the full suite: it is the invocation evidence.
2. Leave Maven, Python and Go behaviour as on main: the test matcher adds
   only Rust targets, goTestPackages only drops Rust contributions, and
   hydrated graphs only trust declared test identities for .rs nodes.
3. Accept ordinary CI around a plain `cargo test`: checkout, toolchain and
   cache actions, a matrix, output-only env, and build/clippy/fmt/doc/
   rustup steps or jobs. Test flags, other runners, compiler env,
   conditional or relocated test steps and unknown actions stay advisory.
4. Label Rust support experimental in the docs.

From #91 (point 2): Cargo manifests outside the workspace no longer block
the repository when metadata shows no member depends on them; their files
stay unmodelled, so changing one keeps the full suite.

Also pass Cargo feature coverage and documentation readers to the profile.

Signed-off-by: FredApps <[email protected]>

* ci(rust): run glob replay on demand, execution proof in one Linux job

Signed-off-by: FredApps <[email protected]>

* fix(rust): paths that climb out of a crate in code depend on every crate

Review on #92: a test that reads another crate's files only counted as
depending on it when the code held a literal path to that crate. Tests
that check every crate's files usually build the path instead, through
.parent(), .ancestors(), PathBuf::pop or a formatted '..' path, so a
change to the other crate skipped them.

Treat such code like code that runs Cargo: its crate depends on every
workspace crate. It only fires where the file also works with paths, so
tree parent() methods and Vec::pop keep narrowing. Crate-local paths
built from CARGO_MANIFEST_DIR stay narrow; the literal pass resolves them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: adityankale190895 <[email protected]>

* fix(rust): find documentation reads through relative and walked paths

Review on #94: a test that reached docs/ through "../docs",
concat!(env!("CARGO_MANIFEST_DIR"), "/../docs") or a directory walk that
matched the "md" extension was not recorded as reading documentation, so
a docs-only change ran no tests and kept no fallback.

Match a documentation directory anywhere in a path, a Markdown name or a
bare md/mdx extension, and count code that climbs out of its crate as a
documentation reader too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: adityankale190895 <[email protected]>

---------

Signed-off-by: FredApps <[email protected]>
Signed-off-by: adityankale190895 <[email protected]>
Co-authored-by: adityankale190895 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
adityankale190895 pushed a commit that referenced this pull request Nov 18, 2026
…f blocking it (#256)

* feat(rust): treat in-repository local path packages as boundaries, not a repository-wide fallback

Part of #131 (external dependency inputs, out-of-workspace Cargo.toml). As agreed
in #91: a local path package that is not a workspace member but lives inside the
repository (an excluded or vendored crate, or a [patch] target) no longer blocks
every change. Its files stay unmodelled, so changing one keeps the full suite.

Dependency edges now follow non-member packages until they reach members, so
a -> vendor/bridge -> b still selects a when b changes. When such a package has
a build script, or code that could read other crates' files (path literals,
includes outside it, climbing out of its directory, running Cargo), the members
that reach it depend on every workspace crate.

Path packages outside the repository keep the repository-wide fallback, because
they can change without the diff showing it.

Signed-off-by: FredApps <[email protected]>

* fix(rust): record readers and program runs of in-repo local packages

A local path package inside the repository that is not a workspace
member was scanned only to decide whether it was opaque. Its build
scripts and documentation readers were never added to
rustDocumentationReaders, and its program runs never set
rustRunsPrograms, so a docs-only change could select no tests even
when member tests call bridge code that reads the docs.

Every such package is now scanned up front, reached or not. Unreadable
or unscannable files count as readers and program runs. #[path]
inputs resolve from the inline module base, as for members.

Signed-off-by: FredApps <[email protected]>

---------

Signed-off-by: FredApps <[email protected]>
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.

Rust adapter: map files to Cargo packages and test targets

2 participants