Skip to content

Commit 34d794e

Browse files
committed
test(analyzer): validate canonical license fixtures independently
Signed-off-by: Rod Boev <[email protected]>
1 parent c77cadc commit 34d794e

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎src/skillspector/nodes/analyzers/static_runner.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def _normalize_license_line(line: str) -> str:
127127
),
128128
(
129129
(
130-
'this software is provided by the copyright holders and contributors "as is" and',
131-
"any express or implied warranties, including, but not limited to, the implied",
132-
"warranties of merchantability and fitness for a particular purpose are",
130+
'this software is provided by the copyright holders and contributors "as is"',
131+
"and any express or implied warranties, including, but not limited to, the",
132+
"implied warranties of merchantability and fitness for a particular purpose are",
133133
),
134134
1,
135135
),

‎tests/nodes/analyzers/test_static_patterns.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from __future__ import annotations
1919

20+
from pathlib import Path
2021
from unittest.mock import MagicMock
2122

2223
import pytest
@@ -1131,6 +1132,12 @@ def test_trigger_analysis_uses_distinct_work_after_static_skip(self):
11311132

11321133

11331134
class TestLicenseFiles:
1135+
@staticmethod
1136+
def _third_party_notice_range(start_line: int, end_line: int) -> str:
1137+
notice_path = Path(__file__).resolve().parents[3] / "THIRD_PARTY_NOTICES.md"
1138+
lines = notice_path.read_text(encoding="utf-8").splitlines()
1139+
return "\n".join(lines[start_line - 1 : end_line]) + "\n"
1140+
11341141
@staticmethod
11351142
def _range_content(range_index: int) -> tuple[str, int]:
11361143
canonical_lines, match_offset = static_runner._LICENSE_CANONICAL_RANGES[range_index]
@@ -1146,6 +1153,23 @@ def test_each_canonical_range_suppresses_only_ea3(self, range_index: int) -> Non
11461153

11471154
assert not any(f.rule_id == "EA3" and f.start_line == match_line for f in findings)
11481155

1156+
@pytest.mark.parametrize(
1157+
"start_line,match_line",
1158+
[(92, 2), (118, 2)],
1159+
ids=["mit_notice", "bsd_notice"],
1160+
)
1161+
def test_independent_third_party_ranges_suppress_ea3(
1162+
self, start_line: int, match_line: int
1163+
) -> None:
1164+
content = self._third_party_notice_range(start_line, start_line + 2)
1165+
findings = static_runner.run_static_patterns(
1166+
{"components": ["LICENSE"], "file_cache": {"LICENSE": content}},
1167+
[excessive_agency_module],
1168+
)
1169+
1170+
assert static_runner._is_license_boilerplate_line(content, match_line)
1171+
assert not any(f.rule_id == "EA3" and f.start_line == match_line for f in findings)
1172+
11491173
def test_review_payload_reports_ea3(self) -> None:
11501174
content = (
11511175
"Apache License\nVersion 2.0, January 2004\n"

0 commit comments

Comments
 (0)