Add regression tests for cargo subdirectory manifest discovery

Cover a Tauri style layout where the manifest lives one level down and
must still be found, a discovered workspace manifest whose own
members resolve relative to its own directory rather than the outer
scan root, a decoy manifest inside a dependency install folder that
must never be searched into, and a manifest nested past the discovery
depth cap that is correctly left unfound.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017qfdzgbA5KedGEjD1AayNh
This commit is contained in:
ayushcodes10andClaude Sonnet 5 committed 2026-09-22 14:50:13 +05:30
1 parent 577e51749a
commit 6d2ef5455f
1 file changed
+110
+110
View File
@@ -455,3 +455,113 @@ tokio_rt = { version = "1", package = "tokio" }
assert {node["id"] for node in result["nodes"]} == {"crate:app"}
assert result["edges"] == []
def test_cargo_introspect_discovers_a_manifest_in_a_subdirectory(tmp_path):
"""#3678: a Tauri-style layout keeps Cargo.toml in src-tauri/, not at the
scan root. introspect_cargo must find it rather than erroring as if no
crate existed at all."""
tauri = tmp_path / "src-tauri"
tauri.mkdir()
_write_manifest(
tauri / "Cargo.toml",
"""
[package]
name = "app"
version = "0.1.0"
edition = "2021"
""",
)
result = introspect_cargo(tmp_path)
assert {node["id"] for node in result["nodes"]} == {"crate:app"}
node = next(n for n in result["nodes"] if n["id"] == "crate:app")
assert node["source_file"] == "src-tauri/Cargo.toml", (
f"the discovered manifest's source_file should stay relative to the "
f"scan root, not the crate subdirectory; got {node['source_file']!r}"
)
def test_cargo_introspect_discovery_resolves_workspace_members_from_the_manifest(tmp_path):
"""A discovered workspace manifest's own members are still resolved
relative to ITS directory, not the outer scan root (#3678)."""
tauri = tmp_path / "src-tauri"
tauri.mkdir()
_write_manifest(
tauri / "Cargo.toml",
"""
[workspace]
members = ["core"]
""",
)
core = tauri / "core"
core.mkdir()
_write_manifest(
core / "Cargo.toml",
"""
[package]
name = "core"
version = "0.1.0"
edition = "2021"
""",
)
result = introspect_cargo(tmp_path)
assert {node["id"] for node in result["nodes"]} == {"crate:core"}
node = next(n for n in result["nodes"] if n["id"] == "crate:core")
assert node["source_file"] == "src-tauri/core/Cargo.toml"
def test_cargo_introspect_discovery_skips_noise_directories(tmp_path):
"""A Cargo.toml sitting inside node_modules/ (a vendored or example crate
pulled in by an npm dependency) must never win over a real, non-noise
subdirectory (#3678)."""
noise = tmp_path / "node_modules" / "some-pkg"
noise.mkdir(parents=True)
_write_manifest(
noise / "Cargo.toml",
"""
[package]
name = "decoy"
version = "0.1.0"
edition = "2021"
""",
)
real = tmp_path / "src-tauri"
real.mkdir()
_write_manifest(
real / "Cargo.toml",
"""
[package]
name = "app"
version = "0.1.0"
edition = "2021"
""",
)
result = introspect_cargo(tmp_path)
assert {node["id"] for node in result["nodes"]} == {"crate:app"}, (
"discovery must never search into node_modules/"
)
def test_cargo_introspect_discovery_does_not_search_past_the_depth_cap(tmp_path):
"""A manifest nested deeper than the discovery cap is left unfound rather
than searched for indefinitely (#3678)."""
deep = tmp_path / "a" / "b" / "c" / "d"
deep.mkdir(parents=True)
_write_manifest(
deep / "Cargo.toml",
"""
[package]
name = "too_deep"
version = "0.1.0"
edition = "2021"
""",
)
with pytest.raises(FileNotFoundError):
introspect_cargo(tmp_path)