Repository navigation
fix(baseline): fingerprint every occurrence so repeated findings stay suppressed #631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both the baseline and the partitioned findings here come from
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
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_fingerprinthashesconfidence,contextandcode_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_occurrencescopies the representative's values onto every occurrence (report.py:255-275). For context-bearing static-pattern rules, such as AR2 with its ±3-lineget_contextwindow, the non-representative entries never match whatpartition_findingscomputes, so #633's repro still reportsreferences/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 withactive_findings.There was a problem hiding this comment.
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.