From 8e19a91f0795294ae1fb3869fcc37fac8ee30bfa Mon Sep 17 00:00:00 2001 From: Deepak Jain Date: Thu, 24 Sep 2026 16:29:21 +0000 Subject: [PATCH 1/2] fix(baseline): fingerprint every occurrence so repeated findings stay suppressed The baseline command fingerprinted effective_findings(), the deduplicated list where repeats are folded into one finding carrying occurrences. The report node applies baseline suppression to the per-line list it partitions, and fingerprints bind to start_line, so only the representative line of a repeated finding was suppressed on the next scan. Expand occurrences before building the baseline dict so each repeated line gets its own fingerprint. Adds a regression test mirroring both call sites. Fixes #630 Signed-off-by: Deepak Jain --- src/skillspector/cli.py | 10 +++++-- tests/unit/test_suppression.py | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/skillspector/cli.py b/src/skillspector/cli.py index 3a4d1b5204..a8a5c680aa 100644 --- a/src/skillspector/cli.py +++ b/src/skillspector/cli.py @@ -60,7 +60,7 @@ from skillspector.models import Finding from skillspector.multi_skill import MultiSkillDetectionResult, SkillDirectory, detect_skills from skillspector.nodes.analyzers import ANALYZER_MODULES, ANALYZER_NODE_IDS -from skillspector.nodes.report import report +from skillspector.nodes.report import _expand_occurrences, report from skillspector.sarif_models import SARIF_SCHEMA_URI, validate_sarif_report from skillspector.semantic_runtime import ( has_semantic_runtime_event, @@ -3181,7 +3181,13 @@ def baseline( state = _scan_state(input_path, FormatChoice.json, no_llm) state["baseline_path"] = os.path.abspath(output.expanduser()) result = graph.invoke(state) - findings = effective_findings(result) + # Fingerprints bind to a finding's location, but effective_findings() + # returns the deduplicated list where repeats are folded into one + # finding with occurrences. The report node applies baseline + # suppression to the per-line list it partitions, so expand here to + # fingerprint every occurrence: each repeated line is then suppressed + # instead of only the representative line. + findings = _expand_occurrences(effective_findings(result)) data = build_baseline_dict( findings, reason=reason, diff --git a/tests/unit/test_suppression.py b/tests/unit/test_suppression.py index fede5eb22a..e05b9e8d6a 100644 --- a/tests/unit/test_suppression.py +++ b/tests/unit/test_suppression.py @@ -1051,3 +1051,56 @@ def test_effective_findings_skips_a_suppressed_entry_with_no_finding() -> None: } assert effective_findings(result) == [kept] + + +def test_baseline_expands_occurrences_before_fingerprinting() -> None: + """A baseline must suppress every repeated line, not only the folded + finding's representative occurrence (issue #630). + + The `baseline` command fingerprints `effective_findings()`, which is the + deduplicated list where repeats are folded into one finding carrying + `occurrences`. The report node partitions the per-line list, so the + command expands occurrences first; otherwise only the first line of a + repeated finding is suppressed on the next scan. + """ + from skillspector.nodes.report import _expand_occurrences + + content = ( + "---\nname: demo\ndescription: demo\n---\n\n" + "Start it with `npx @modelcontextprotocol/server-filesystem ./docs`.\n\n" + "If it stops, run `npx @modelcontextprotocol/server-filesystem ./docs` again.\n\n" + "On a fresh machine, `npx @modelcontextprotocol/server-filesystem ./docs` also installs it.\n" + ) + folded = replace( + _finding( + rule_id="RP1", + file="demo/SKILL.md", + message="remote package execution", + matched_text="npx @modelcontextprotocol/server-filesystem ./docs", + start_line=6, + ), + occurrences=[ + {"file": "demo/SKILL.md", "start_line": 6, "end_line": 6}, + {"file": "demo/SKILL.md", "start_line": 8, "end_line": 8}, + {"file": "demo/SKILL.md", "start_line": 10, "end_line": 10}, + ], + ) + file_cache = {"demo/SKILL.md": content} + # Mirror the `baseline` command: expand before fingerprinting. + data = build_baseline_dict( + _expand_occurrences([folded]), + file_cache=file_cache, + scanner_version=SCANNER_VERSION, + ) + assert len(data["fingerprints"]) == 3 + baseline = baseline_from_dict(data) + # Mirror the report node: partition the per-line findings. + per_line = _expand_occurrences([folded]) + kept, suppressed = partition_findings( + per_line, + baseline, + file_cache=file_cache, + scanner_version=SCANNER_VERSION, + ) + assert kept == [] + assert len(suppressed) == 3 From d1536da1037ea4c35c22d9d4310e6abdbb89f282 Mon Sep 17 00:00:00 2001 From: Deepak Jain Date: Mon, 28 Sep 2026 14:47:49 -0700 Subject: [PATCH 2/2] fix(baseline): retain exact occurrence fingerprints Signed-off-by: Deepak Jain --- src/skillspector/cli.py | 16 +++++----- src/skillspector/nodes/report.py | 1 + src/skillspector/state.py | 2 ++ tests/unit/test_cli.py | 39 +++++++++++++++++++++++ tests/unit/test_suppression.py | 53 -------------------------------- 5 files changed, 50 insertions(+), 61 deletions(-) diff --git a/src/skillspector/cli.py b/src/skillspector/cli.py index a8a5c680aa..8308fadf92 100644 --- a/src/skillspector/cli.py +++ b/src/skillspector/cli.py @@ -60,7 +60,7 @@ from skillspector.models import Finding from skillspector.multi_skill import MultiSkillDetectionResult, SkillDirectory, detect_skills from skillspector.nodes.analyzers import ANALYZER_MODULES, ANALYZER_NODE_IDS -from skillspector.nodes.report import _expand_occurrences, report +from skillspector.nodes.report import report from skillspector.sarif_models import SARIF_SCHEMA_URI, validate_sarif_report from skillspector.semantic_runtime import ( has_semantic_runtime_event, @@ -3181,13 +3181,13 @@ def baseline( state = _scan_state(input_path, FormatChoice.json, no_llm) state["baseline_path"] = os.path.abspath(output.expanduser()) result = graph.invoke(state) - # Fingerprints bind to a finding's location, but effective_findings() - # returns the deduplicated list where repeats are folded into one - # finding with occurrences. The report node applies baseline - # suppression to the per-line list it partitions, so expand here to - # fingerprint every occurrence: each repeated line is then suppressed - # instead of only the representative line. - findings = _expand_occurrences(effective_findings(result)) + # Keep each occurrence's original context and confidence; display + # deduplication cannot reconstruct those fingerprint inputs. + findings = ( + _coerce_findings_list(result["active_findings"]) + if "active_findings" in result + else effective_findings(result) + ) data = build_baseline_dict( findings, reason=reason, diff --git a/src/skillspector/nodes/report.py b/src/skillspector/nodes/report.py index d2e5ae9bdf..e0b2f11996 100644 --- a/src/skillspector/nodes/report.py +++ b/src/skillspector/nodes/report.py @@ -1837,6 +1837,7 @@ def report(state: SkillspectorState) -> dict[str, object]: "risk_recommendation": risk_recommendation, "report_body": report_body, "filtered_findings": reported_findings, + "active_findings": active_findings, "suppressed_findings": suppressed, "execution_successful": execution_successful, "analysis_completeness": dict(analysis_completeness), diff --git a/src/skillspector/state.py b/src/skillspector/state.py index ba39b5621b..eafb8eeefd 100644 --- a/src/skillspector/state.py +++ b/src/skillspector/state.py @@ -280,6 +280,8 @@ class SkillspectorState(TypedDict, total=False): # Compatibility projection emitted only by the report after effective-ID # selection. Meta analysis never stores a second filtered collection. filtered_findings: list[Finding] + # Exact kept occurrences before display deduplication, for baseline generation. + active_findings: list[Finding] # LLM runtime telemetry: each LLM-backed node appends one record (built with # ``llm_call_record``) so the report can detect a *silent degradation* — the diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 96dd9203ac..796f4df102 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -6078,3 +6078,42 @@ def test_cli_baseline_uses_local_cache_for_provider_excluded_findings(tmp_path: written = yaml.safe_load(out.read_text(encoding="utf-8")) assert [entry["file"] for entry in written["fingerprints"]] == [".hidden.md"] assert len(written["fingerprints"][0]["hash"]) == len("sha256:") + 64 + + +def test_baseline_preserves_distinct_context_for_repeated_findings(tmp_path: Path) -> None: + skill = tmp_path / "skill" + skill.mkdir() + (skill / "references").mkdir() + (skill / "SKILL.md").write_text( + "---\nname: demo\ndescription: demo\n---\n\n# Service\n\n" + "The upstream service deletes unused files, and the link dies with no warning.\n", + encoding="utf-8", + ) + (skill / "references" / "notes.md").write_text( + "# Mirror\n\nThe mirror drops stale entries with no warning.\n", encoding="utf-8" + ) + baseline = tmp_path / "baseline.yaml" + generated = runner.invoke(app, ["baseline", str(skill), "--no-llm", "-o", str(baseline)]) + assert generated.exit_code == 0, generated.output + result = runner.invoke( + app, + [ + "scan", + str(skill), + "--no-llm", + "--baseline", + str(baseline), + "--format", + "json", + "--show-suppressed", + ], + ) + assert result.exit_code == 0, result.output + data = json.loads(result.stdout) + assert data["issues"] == [] + entries = yaml.safe_load(baseline.read_text())["fingerprints"] + assert {entry["file"] for entry in entries if entry["rule_id"] == "AR2"} == { + "SKILL.md", + "references/notes.md", + } + assert data["suppressed_count"] >= 2 diff --git a/tests/unit/test_suppression.py b/tests/unit/test_suppression.py index e05b9e8d6a..fede5eb22a 100644 --- a/tests/unit/test_suppression.py +++ b/tests/unit/test_suppression.py @@ -1051,56 +1051,3 @@ def test_effective_findings_skips_a_suppressed_entry_with_no_finding() -> None: } assert effective_findings(result) == [kept] - - -def test_baseline_expands_occurrences_before_fingerprinting() -> None: - """A baseline must suppress every repeated line, not only the folded - finding's representative occurrence (issue #630). - - The `baseline` command fingerprints `effective_findings()`, which is the - deduplicated list where repeats are folded into one finding carrying - `occurrences`. The report node partitions the per-line list, so the - command expands occurrences first; otherwise only the first line of a - repeated finding is suppressed on the next scan. - """ - from skillspector.nodes.report import _expand_occurrences - - content = ( - "---\nname: demo\ndescription: demo\n---\n\n" - "Start it with `npx @modelcontextprotocol/server-filesystem ./docs`.\n\n" - "If it stops, run `npx @modelcontextprotocol/server-filesystem ./docs` again.\n\n" - "On a fresh machine, `npx @modelcontextprotocol/server-filesystem ./docs` also installs it.\n" - ) - folded = replace( - _finding( - rule_id="RP1", - file="demo/SKILL.md", - message="remote package execution", - matched_text="npx @modelcontextprotocol/server-filesystem ./docs", - start_line=6, - ), - occurrences=[ - {"file": "demo/SKILL.md", "start_line": 6, "end_line": 6}, - {"file": "demo/SKILL.md", "start_line": 8, "end_line": 8}, - {"file": "demo/SKILL.md", "start_line": 10, "end_line": 10}, - ], - ) - file_cache = {"demo/SKILL.md": content} - # Mirror the `baseline` command: expand before fingerprinting. - data = build_baseline_dict( - _expand_occurrences([folded]), - file_cache=file_cache, - scanner_version=SCANNER_VERSION, - ) - assert len(data["fingerprints"]) == 3 - baseline = baseline_from_dict(data) - # Mirror the report node: partition the per-line findings. - per_line = _expand_occurrences([folded]) - kept, suppressed = partition_findings( - per_line, - baseline, - file_cache=file_cache, - scanner_version=SCANNER_VERSION, - ) - assert kept == [] - assert len(suppressed) == 3