-
Notifications
You must be signed in to change notification settings - Fork 282
feat: add --severity-threshold to filter reported workloads #549
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
Open
ChrisJr404
wants to merge
1
commit into
robusta-dev:main
Choose a base branch
from
ChrisJr404:severity-threshold-filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
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,38 @@ | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
|
|
||
| from robusta_krr.core.models.result import filter_scans_by_severity | ||
| from robusta_krr.core.models.severity import Severity | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "severity, threshold, expected", | ||
| [ | ||
| (Severity.CRITICAL, Severity.WARNING, True), | ||
| (Severity.WARNING, Severity.WARNING, True), | ||
| (Severity.OK, Severity.WARNING, False), | ||
| (Severity.GOOD, Severity.WARNING, False), | ||
| (Severity.GOOD, Severity.GOOD, True), | ||
| # UNKNOWN cannot be measured, so it is never dropped | ||
| (Severity.UNKNOWN, Severity.CRITICAL, True), | ||
| # an UNKNOWN threshold keeps everything | ||
| (Severity.GOOD, Severity.UNKNOWN, True), | ||
| ], | ||
| ) | ||
| def test_is_at_least(severity: Severity, threshold: Severity, expected: bool) -> None: | ||
| assert severity.is_at_least(threshold) is expected | ||
|
|
||
|
|
||
| def test_filter_scans_by_severity_no_threshold() -> None: | ||
| scans = [SimpleNamespace(severity=s) for s in Severity] | ||
| assert filter_scans_by_severity(scans, None) == scans | ||
|
|
||
|
|
||
| def test_filter_scans_by_severity_warning() -> None: | ||
| scans = [ | ||
| SimpleNamespace(severity=s) for s in [Severity.GOOD, Severity.WARNING, Severity.CRITICAL, Severity.UNKNOWN] | ||
| ] | ||
| kept = [scan.severity for scan in filter_scans_by_severity(scans, Severity.WARNING)] | ||
| # GOOD is dropped, order is otherwise preserved, UNKNOWN is always kept | ||
| assert kept == [Severity.WARNING, Severity.CRITICAL, Severity.UNKNOWN] |
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
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: robusta-dev/krr
Length of output: 37511
🏁 Script executed:
Repository: robusta-dev/krr
Length of output: 14135
🏁 Script executed:
Repository: robusta-dev/krr
Length of output: 14135
🌐 Web query:
Typer 0.7.0 typer main.py get_click_param Enum click.Choice case_sensitive source💡 Result:
In Typer, the
case_sensitiveparameter is used to configure whetherEnum-based CLI parameters (choices) are case-sensitive [1][2]. When defining a CLI parameter using anEnum, you can control matching behavior by passingcase_sensitive=Falsetotyper.Optionortyper.Argument[1][2][3]. Whencase_sensitiveis set toFalse, the input provided by the user will be matched case-insensitively against the availableEnummembers [1][2][3]. By default, this parameter is set toTrue, meaning choices are case-sensitive [1][2][3]. Under the hood, Typer processes these parameters intyper.main.pyviaget_click_param, which transforms Typer-specific parameter definitions into Click parameters [4][5]. ForEnumtypes, Typer leverages Click'sclick.Choiceclass [1][2]. Thecase_sensitiveargument passed in Typer is mapped to the correspondingcase_sensitiveparameter inclick.Choice[6][7]. Click handles the normalization of these choices (e.g., usingcasefoldwhencase_sensitive=False) to ensure the input matches the expected enumeration member [7]. While Typer 0.7.0 was a significant release, it focused primarily on infrastructure and dependency management (such as adding support for newer Python versions and internal CI improvements) rather than changing the fundamental implementation ofcase_sensitiveforEnumchoices [8][9]. Note that in much more recent versions of Typer, the dependency on Click was changed to a vendored version, but thecase_sensitiveAPI and its reliance on the underlyingclick.Choicelogic have remained a consistent feature of the framework [10].Citations:
Enforce the documented
--severity-thresholdchoices.Typer 0.7.0 exposes every
Severitymember, includingUNKNOWN, andcase_sensitive=Falseacceptsunknown.Severity.is_at_least(Severity.UNKNOWN)returnsTruefor every scan. RejectSeverity.UNKNOWNat this CLI boundary, or document it as an intentional no-filter value, and add a test forunknown.🧰 Tools
🪛 Ruff (0.16.2)
[warning] 267-273: Do not perform function call
typer.Optionin argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable(B008)
🤖 Prompt for AI Agents
Source: MCP tools