diff --git a/tests/test_cargo_introspect.py b/tests/test_cargo_introspect.py index 9abf82655..7b6779dda 100644 --- a/tests/test_cargo_introspect.py +++ b/tests/test_cargo_introspect.py @@ -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)