Skip to content

Commit 2930672

Browse files
committed
fix(engine): resolve explicit advisory and policy files with the root
The --advisories and --policy paths reached the source manager as given, so their syntax-error notes were still located relative to the working directory. Cover them and a root reached through a symbolic link. Refs #206
1 parent b00d1f0 commit 2930672

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

‎src/coretrace_python/engine.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,12 @@ def analyze_project(
384384

385385
if jobs < 1:
386386
raise ValueError("jobs must be at least 1")
387-
# Module sources are loaded by their resolved path; every other file under the root
388-
# (manifests, configuration, advisories, policy) must be named the same way, or the
389-
# reports and baselines would see it relative to the working directory (#206).
387+
# Module sources are loaded by their resolved path; every other file the project is
388+
# read from (manifests, configuration, advisories, policy) must be named the same way,
389+
# or the reports and baselines would see it relative to the working directory (#206).
390390
root = root.resolve()
391+
advisory_files = [path.resolve() for path in advisory_files]
392+
policy_file = None if policy_file is None else policy_file.resolve()
391393
sources = SourceManager()
392394
findings: list[Finding] = []
393395
dependencies = resolve_dependencies(root, sources)

‎tests/test_relative_root.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,35 @@ def test_configuration_findings_are_located_relative_to_the_root(
7171
assert located(capsys, "hardcoded-credential") == ["settings.json"]
7272

7373

74+
@pytest.mark.parametrize(
75+
("option", "name", "text"),
76+
[
77+
("--policy", "bad-policy.toml", "[dependencies\n"),
78+
("--advisories", "bad-advisories.json", "{\n"),
79+
],
80+
)
81+
def test_explicit_files_are_located_relative_to_the_root(
82+
project: Path, option: str, name: str, text: str, capsys: pytest.CaptureFixture[str]
83+
) -> None:
84+
(project / name).write_text(text, encoding="utf-8")
85+
86+
main(["--check", "proj", option, f"proj/{name}", "--format", "json"])
87+
88+
assert located(capsys, "syntax-error") == [name]
89+
90+
91+
@pytest.mark.parametrize("form", ["relative", "absolute"])
92+
def test_a_root_reached_through_a_symbolic_link_keeps_root_relative_paths(
93+
project: Path, tmp_path: Path, form: str, capsys: pytest.CaptureFixture[str]
94+
) -> None:
95+
(tmp_path / "link").symlink_to(project, target_is_directory=True)
96+
root = "link" if form == "relative" else str(tmp_path / "link")
97+
98+
main(["--check", root, "--format", "json"])
99+
100+
assert located(capsys, "vulnerable-dependency") == ["uv.lock"]
101+
102+
74103
def test_a_baseline_recorded_with_a_relative_root_matches_an_absolute_one(
75104
project: Path, tmp_path: Path, capsys: pytest.CaptureFixture[str]
76105
) -> None:

0 commit comments

Comments
 (0)