Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions src/skillspector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches the next scan only when every occurrence shares the representative's hashed fields. finding_fingerprint hashes confidence, context and code_snippet (suppression.py:236,247-248). deduplicate() intentionally leaves confidence and location-specific context out of the compaction key (deduplicate.py:84-86), and _expand_occurrences copies the representative's values onto every occurrence (report.py:255-275). For context-bearing static-pattern rules, such as AR2 with its ±3-line get_context window, the non-representative entries never match what partition_findings computes, so #633's repro still reports references/notes.md:3. RP1 in #630 only works because it carries no context. Please fingerprint the exact kept, pre-deduplication list the report node partitions, as #637 does with active_findings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The baseline now fingerprints active_findings retained before display deduplication, preserving each original context and confidence. A real CLI AR2 round trip across two files fails with the old call site and passes after repair; all423 adjacent CLI, suppression and report tests pass.

data = build_baseline_dict(
findings,
reason=reason,
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/test_suppression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the baseline and the partitioned findings here come from _expand_occurrences([folded]), so the test checks the expansion against itself rather than against the report node's real per-occurrence findings, which carry their own context. It also never calls the CLI, so it passes even if the cli.py change is reverted. Please add a CLI round trip (baseline, then scan --baseline --format json) with a context-bearing rule repeated across lines or files, for example #633's AR2 repro. Assert issues == [] and that every occurrence is in suppressed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the expansion-against-itself test with an actual baseline then scan --baseline --format json invocation. It checks issues are empty and both AR2 file occurrences have fingerprints; reverting the CLI call site makes it fail.

kept, suppressed = partition_findings(
per_line,
baseline,
file_cache=file_cache,
scanner_version=SCANNER_VERSION,
)
assert kept == []
assert len(suppressed) == 3
Loading