Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ All notable changes to SkillEvaluator are documented in this file.

### Fixed

- SARIF reporting retains findings on cyclic symbolic links on Python 3.12, resolving
Comment thread
Afloat16 marked this conversation as resolved.
Resolved
artifact locations as far as possible instead of aborting the entire report.
- Direct Tier 1 validates the target, selected checks and LLM configuration before
preparing scanners, so configuration errors do not trigger downloads or stdout noise.
- Documentation-only CI follows imports through collected test modules and
Expand Down
21 changes: 15 additions & 6 deletions src/skillevaluator/reporting/sarif_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,23 @@ def _positive_start_line(line_number: Any) -> int | None:
return None


def _resolve_for_reporting(path: Path) -> Path:
"""Resolve accessible path components without failing on a cyclic link.

Python 3.12's non-strict ``Path.resolve()`` still raises for link loops.
A report must be able to identify those links as the finding's artifact.
"""
return Path(os.path.realpath(path))
Comment thread
chrisknvidia marked this conversation as resolved.
Resolved


def _resolve_artifact_path(file_path: str, scan_root: Path | None) -> Path:
"""Resolve a validator file path against the scanned skill directory."""
normalized = file_path.replace("\\", "/")
path = Path(normalized)
if scan_root is not None and not path.is_absolute():
return (scan_root / path).resolve()
return _resolve_for_reporting(scan_root / path)
if path.is_absolute():
return path.resolve()
return _resolve_for_reporting(path)
return path


Expand Down Expand Up @@ -147,7 +156,7 @@ def _unresolved_artifact_path(file_path: str, scan_root: Path | None) -> Path |
if not path.is_absolute():
if scan_root is None:
return None
path = scan_root.resolve() / path
path = _resolve_for_reporting(scan_root) / path
return Path(os.path.normpath(path))


Expand All @@ -163,8 +172,8 @@ def _workspace_relative_path(
target is outside it keeps the path of the link, which is what the
finding is about.
"""
root = workspace_root.resolve()
candidates = [path.resolve()]
root = _resolve_for_reporting(workspace_root)
candidates = [_resolve_for_reporting(path)]
unresolved = _unresolved_artifact_path(file_path, scan_root)
if unresolved is not None:
candidates.append(unresolved)
Expand Down Expand Up @@ -193,7 +202,7 @@ def _normalize_artifact_uri(
relative = _workspace_relative_path(path, file_path, workspace_root, scan_root)
if relative is not None:
return _relative_reference(relative.as_posix())
return _file_uri(path.resolve())
return _file_uri(_resolve_for_reporting(path))
if path.is_absolute():
return _file_uri(path)
return _relative_reference(path.as_posix())
Expand Down
47 changes: 47 additions & 0 deletions tests/reporting/test_sarif_symlink_loops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Findings about cyclic links must remain exportable to SARIF."""

import json
from pathlib import Path

import pytest

from skillevaluator.models import Finding, Severity, ValidationResult
from skillevaluator.reporting import SARIFReporter


@pytest.mark.parametrize("relative", [False, True])
@pytest.mark.parametrize("two_links", [False, True])
@pytest.mark.parametrize("with_workspace", [False, True])
def test_sarif_preserves_a_finding_on_a_symlink_loop(
tmp_path: Path, relative: bool, two_links: bool, with_workspace: bool
) -> None:
skill = tmp_path / "skills" / "demo"
skill.mkdir(parents=True)
link = skill / "loop.md"
try:
link.symlink_to("other.md" if two_links else "loop.md")
if two_links:
(skill / "other.md").symlink_to("loop.md")
except OSError:
pytest.skip("symlinks are not available")
result = ValidationResult(validator_name="security")
result.add_finding(
Finding(
category="SECURITY",
severity=Severity.HIGH,
check_name="unsafe-link",
message="The resource is a cyclic symbolic link",
file_path="loop.md" if relative else str(link),
)
)

output = SARIFReporter(workspace_root=tmp_path if with_workspace else None, scan_root=skill).render_all([result])

findings = json.loads(output)["runs"][0]["results"]
assert len(findings) == 1
expected = "skills/demo/loop.md" if with_workspace else link.as_uri()
assert findings[0]["locations"][0]["physicalLocation"]["artifactLocation"]["uri"] == expected
assert findings[0]["message"]["text"] == "The resource is a cyclic symbolic link"