Skip to content

Commit 16a0c9f

Browse files
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]>
1 parent 26f9271 commit 16a0c9f

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎docs/release-boundary.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ historical lockfile's HTTPS-only build instructions.
4949
The live `packages/diffci-cli/` directory is the separately reviewed,
5050
Core-native successor package. It is not a rewrite of the historical archive.
5151

52-
Rust support is experimental: it has not yet narrowed a published project's history, so treat its selections as advisory until it has. Rust selection uses Cargo workspace members, target roots, and dependency edges from offline, locked, all-features metadata. Only crates plain `cargo test` covers (the root package, `default-members`, or every member of a virtual workspace) are test targets. Locked registry and Git dependencies, including their build scripts and procedural macros, do not block: a `Cargo.lock` change requires full validation. Local path dependencies outside the workspace still do; Cargo manifests outside the workspace that no member depends on are confined to their own directories. Crate source and member-manifest changes select that crate and dependent crates; parent crates conservatively depend on nested package sources too. A workspace crate with a build script, code that runs Cargo or rustc, or code that climbs out of its crate directory in code depends on every workspace crate; a literal path in Rust code that reaches another crate is a dependency on it. Library and binary target roots are both production sources and unit-test identities. Statically resolved in-crate include inputs retain dependency ownership. Root Cargo.toml, any Cargo.lock, and every path outside the modeled source/include inventory require full validation, including deletions and rename origins; documentation follows the shared classification unless Rust code names it or a workspace build script exists. Cargo target build output is excluded. Symlinked directories or Rust files inside module trees, omitted Rust source, path attributes, computed or non-Rust code includes, build-changing Cargo configuration (repository, parent directories or `$CARGO_HOME`) or compiler environment, and mixed-language repositories require full validation. This is a conservative syntax and metadata model, not a proof that arbitrary Rust code is hermetic.
52+
Rust support is experimental: it has not yet narrowed a published project's history, so treat its selections as advisory until it has. Rust selection uses Cargo workspace members, target roots, and dependency edges from offline, locked, all-features metadata. Only crates plain `cargo test` covers (the root package, `default-members`, or every member of a virtual workspace) are test targets. Locked registry and Git dependencies, including their build scripts and procedural macros, do not block: a `Cargo.lock` change requires full validation. Local path dependencies outside the workspace still do; Cargo manifests outside the workspace that no member depends on are confined to their own directories. Crate source and member-manifest changes select that crate and dependent crates; parent crates conservatively depend on nested package sources too. A workspace crate with a build script, code that runs Cargo or rustc, or code that climbs out of its crate directory in code depends on every workspace crate; a literal path in Rust code that reaches another crate is a dependency on it. Library and binary target roots are both production sources and unit-test identities. Statically resolved in-crate include inputs retain dependency ownership. Root Cargo.toml, any Cargo.lock, and every path outside the modeled source/include inventory require full validation, including deletions and rename origins; documentation follows the shared classification unless Rust code names it (a Markdown file or extension, or a documentation directory anywhere in a path), climbs out of its crate directory, or a workspace build script exists. Cargo target build output is excluded. Symlinked directories or Rust files inside module trees, omitted Rust source, path attributes, computed or non-Rust code includes, build-changing Cargo configuration (repository, parent directories or `$CARGO_HOME`) or compiler environment, and mixed-language repositories require full validation. This is a conservative syntax and metadata model, not a proof that arbitrary Rust code is hermetic.
5353

5454
Feature-conditional source is modeled at crate level. A reduced package set can change Cargo feature unification, so when any declaration requests features, disables defaults or forwards features, Cargo itself (`cargo tree`, offline and locked) resolves features for the full invocation and for each tested crate alone and with its dependents. Every synthesized command must contain a set Cargo resolved with the full invocation's features for each package a selected crate would otherwise build differently; otherwise the plan is refused. Feature-required test targets keep the full original invocation. Supported unit-test packages share one command with repeated `-p` arguments; selecting a source root never drops its crate's doctests.
5555

‎src/repo/adapters/rust.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,14 @@ function rustInputs(source: string): { inputs: Array<{ path: string; code: boole
281281
tokens.forEach((token, index) => {
282282
if (token.literal === undefined || includeArguments.has(index)) return;
283283
if (pathLike(token.literal)) paths.push(token.literal);
284-
// A test that checks README or docs content at run time (version-sync and the like).
285-
if (/\.(?:md|mdx)$|^(?:\.\/)?(?:docs?|documentation)(?:\/|$)/i.test(token.literal)) documentation = true;
284+
// A test that checks README or docs content at run time (version-sync, link checks and the like):
285+
// a Markdown name or bare extension (`"md"` in an extension check), or a documentation directory
286+
// anywhere in the path (`../docs`, `concat!(env!("CARGO_MANIFEST_DIR"), "/../docs")`).
287+
if (/(?:^|\.)mdx?$|(?:^|[\\/])(?:docs?|documentation)(?:[\\/]|$)/i.test(token.literal)) documentation = true;
286288
});
287-
return { inputs, paths, compiles, navigates: navigatesUpward(tokens), documentation };
289+
const navigates = navigatesUpward(tokens);
290+
// Code that climbs out of its crate can walk to README or docs without naming them.
291+
return { inputs, paths, compiles, navigates, documentation: documentation || navigates };
288292
}
289293

290294
/** Code that climbs out of its crate directory in code (`.parent()`, `.ancestors()`, `PathBuf::pop`,

‎tests/repo/rust-integration.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ test("documentation stays full-suite when Rust code may read it, and excluded fi
197197
graph = await buildDependencyGraph({ repoPath: root });
198198
assert.deepEqual(graph.profile.rustDocumentationReaders, ["app/src/lib.rs"]);
199199
assert.equal(new ImpactAnalyzer().analyze(delta("README.md"), graph, graph.profile).fallbackRequired, true);
200+
// Paths that reach docs relative to the crate, or walk up and match the Markdown extension (review on #94).
201+
for (const body of ['let _ = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../docs");',
202+
'let _ = concat!(env!("CARGO_MANIFEST_DIR"), "/../docs");',
203+
'let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap(); for e in std::fs::read_dir(root).unwrap() { let p = e.unwrap().path(); if p.extension().map_or(false, |x| x == "md") { let _ = p; } }']) {
204+
writeFileSync(join(root, "app/src/lib.rs"), `#[test] fn docs() { ${body} }`);
205+
graph = await buildDependencyGraph({ repoPath: root });
206+
assert.deepEqual(graph.profile.rustDocumentationReaders, ["app/src/lib.rs"], body);
207+
assert.equal(new ImpactAnalyzer().analyze(delta("docs/guide.md"), graph, graph.profile).fallbackRequired, true, body);
208+
}
209+
// Ordinary strings that merely contain "doc" or "md" are not documentation paths.
210+
writeFileSync(join(root, "app/src/lib.rs"), '#[test] fn names() { assert_eq!("cmd", "cmd"); let _ = "doctor/visit"; }');
211+
graph = await buildDependencyGraph({ repoPath: root });
212+
assert.deepEqual(graph.profile.rustDocumentationReaders, []);
200213
// A member that path-depends on the fixture keeps the repository-wide fallback.
201214
output = metadata([{ id: "sample", name: "sample", manifest_path: join(root, "tests/fixtures/sample/Cargo.toml"), dependencies: [], features: {},
202215
targets: [{ name: "sample", kind: ["lib"], src_path: join(root, "tests/fixtures/sample/src/lib.rs"), test: true, doctest: true }] }]);

0 commit comments

Comments
 (0)