Repository navigation
feat: filter non-findings and constrain comment verbosity #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b46808
feat: filter non-findings and constrain comment verbosity
aliasunder 7204628
fix: narrow non-finding filter to prefix-only matching
aliasunder 792cb8c
fix: address bot review findings — doc comments, test assertions, fix…
aliasunder 14bcf6c
fix: filter before cap, trim whitespace, guard empty suggestion
aliasunder 7d2fdfa
refactor: simplify suggestion null/empty guard to falsy check
aliasunder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| import { describe, expect, it } from "vitest" | ||
| import { filterNonFindings } from "../filter-non-findings.js" | ||
| import { makeFinding } from "./make-finding.js" | ||
|
|
||
| describe("filterNonFindings", () => { | ||
| // --- Prefix patterns that should be dropped --- | ||
|
|
||
| it("drops a finding whose failure_scenario starts with 'N/A'", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: "N/A — tests are valid.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [], droppedAsNonFinding: 1 }) | ||
| }) | ||
|
|
||
| it("drops a finding whose failure_scenario starts with 'n/a' (case-insensitive)", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: "n/a — Zod validation catches malformed responses.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [], droppedAsNonFinding: 1 }) | ||
| }) | ||
|
|
||
| it("drops a finding whose failure_scenario starts with 'NA' (no slash)", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: "NA — the code handles this edge case.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [], droppedAsNonFinding: 1 }) | ||
| }) | ||
|
|
||
| it("drops a finding whose failure_scenario starts with 'Not applicable'", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: "Not applicable — the code handles this edge case.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [], droppedAsNonFinding: 1 }) | ||
| }) | ||
|
|
||
| it("drops a finding whose failure_scenario starts with 'Placeholder'", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: "Placeholder — re-evaluating.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [], droppedAsNonFinding: 1 }) | ||
| }) | ||
|
|
||
| // --- Passthrough: real findings must not be dropped --- | ||
|
|
||
| it("keeps a finding with a concrete failure scenario", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: | ||
| "A CI step that gates deployment reads the env var, but the value is never set in the matrix.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [finding], droppedAsNonFinding: 0 }) | ||
| }) | ||
|
|
||
| it("keeps a finding that mentions 'by design' as a qualifier", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: | ||
| "The function returns null by design, but the caller never null-checks.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [finding], droppedAsNonFinding: 0 }) | ||
| }) | ||
|
|
||
| it("keeps a finding that mentions 'this is correct' as a qualifier", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: | ||
| "This is correct for ASCII but breaks on multi-byte UTF-8.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [finding], droppedAsNonFinding: 0 }) | ||
| }) | ||
|
|
||
| it("keeps a finding starting with 'None of'", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: "None of the guards catch this input.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [finding], droppedAsNonFinding: 0 }) | ||
| }) | ||
|
|
||
| it("keeps all findings when none are non-findings", () => { | ||
| const findings = [ | ||
| makeFinding({ | ||
| line: 1, | ||
| failure_scenario: | ||
| 'register(" ", "value") succeeds and the entry is orphaned.', | ||
| }), | ||
| makeFinding({ | ||
| line: 10, | ||
| failure_scenario: | ||
| "A user configures the threshold to 'extreme' and the action crashes.", | ||
| }), | ||
| ] | ||
|
|
||
| const result = filterNonFindings(findings) | ||
|
|
||
| expect(result).toEqual({ findings, droppedAsNonFinding: 0 }) | ||
| }) | ||
|
|
||
| // --- Mixed and edge cases --- | ||
|
|
||
| it("returns empty findings when all findings are non-findings", () => { | ||
| const findings = [ | ||
| makeFinding({ line: 1, failure_scenario: "N/A — tests are valid." }), | ||
| makeFinding({ | ||
| line: 2, | ||
| failure_scenario: "Not applicable — already handled.", | ||
| }), | ||
| ] | ||
|
|
||
| const result = filterNonFindings(findings) | ||
|
|
||
| expect(result).toEqual({ findings: [], droppedAsNonFinding: 2 }) | ||
| }) | ||
|
|
||
| it("filters selectively in a mixed set of findings", () => { | ||
| const realFinding = makeFinding({ | ||
| line: 1, | ||
| failure_scenario: | ||
| 'register(" ", "value") succeeds and the entry is orphaned.', | ||
| }) | ||
| const nonFinding = makeFinding({ | ||
| line: 2, | ||
| failure_scenario: "N/A — this is correct behavior.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([realFinding, nonFinding]) | ||
|
|
||
| expect(result).toEqual({ | ||
| findings: [realFinding], | ||
| droppedAsNonFinding: 1, | ||
| }) | ||
| }) | ||
|
|
||
| it("does not drop a finding that contains 'None' mid-sentence", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: | ||
| "Returns None instead of an empty list when the input is empty.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [finding], droppedAsNonFinding: 0 }) | ||
| }) | ||
|
|
||
| it("drops a finding with leading whitespace before the prefix", () => { | ||
| const finding = makeFinding({ | ||
| failure_scenario: " N/A — tests are valid.", | ||
| }) | ||
|
|
||
| const result = filterNonFindings([finding]) | ||
|
|
||
| expect(result).toEqual({ findings: [], droppedAsNonFinding: 1 }) | ||
| }) | ||
|
|
||
| it("handles an empty findings array", () => { | ||
| const result = filterNonFindings([]) | ||
|
|
||
| expect(result).toEqual({ findings: [], droppedAsNonFinding: 0 }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.