-
Notifications
You must be signed in to change notification settings - Fork 841
FIX: warn when selected attack techniques have no registered factory #2466
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| """Tests for skipped-technique diagnostics in ``ScenarioRunService`` run summaries.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from pyrit.backend.services.scenario_run_service import ScenarioRunService | ||
| from pyrit.models.identifiers.scenario_identifier import ScenarioIdentifier | ||
| from pyrit.models.results.scenario_result import ScenarioResult | ||
|
|
||
|
|
||
| def _service() -> ScenarioRunService: | ||
| from unittest.mock import MagicMock | ||
|
|
||
| service = object.__new__(ScenarioRunService) | ||
| service._active_tasks = {} | ||
| # The error fallback path queries persisted error results; none exist here. | ||
| service._memory = MagicMock() | ||
| service._memory.get_attack_results.return_value = [] | ||
| return service | ||
|
|
||
|
|
||
| def _result(*, techniques, display_groups) -> ScenarioResult: | ||
| return ScenarioResult( | ||
| scenario_identifier=ScenarioIdentifier(name="scenario", techniques=techniques), | ||
| attack_results={}, | ||
| display_group_map=display_groups, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("patch_central_database") | ||
| class TestBuildResponseSkippedTechniques: | ||
| """Selected techniques with no built attack cell surface as ``skipped_techniques``.""" | ||
|
Contributor
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. The new focused tests pass, but |
||
|
|
||
| def test_selected_without_built_label_is_reported_skipped(self): | ||
| result = _result(techniques=["alpha", "ghost"], display_groups={"alpha::ds": "alpha"}) | ||
|
|
||
| summary = _service()._build_response_from_db(scenario_result=result) | ||
|
|
||
| assert summary.skipped_techniques == ["ghost"] | ||
| assert summary.techniques_used is not None | ||
|
|
||
| def test_decorated_display_label_still_counts_as_built(self): | ||
| # Custom ``display_group_fn`` may decorate technique names; a label that | ||
| # contains the technique name must not be reported as skipped. | ||
| result = _result(techniques=["alpha"], display_groups={"cell-1": "alpha (hard mode)"}) | ||
|
|
||
| summary = _service()._build_response_from_db(scenario_result=result) | ||
|
|
||
| assert summary.skipped_techniques == [] | ||
|
|
||
| def test_no_selection_reports_no_skips(self): | ||
| result = _result(techniques=None, display_groups={}) | ||
|
|
||
| summary = _service()._build_response_from_db(scenario_result=result) | ||
|
|
||
| assert summary.skipped_techniques == [] | ||
|
|
||
| def test_skips_are_sorted_and_deduplicated(self): | ||
| result = _result( | ||
| techniques=["zeta", "alpha", "alpha"], | ||
| display_groups={"mid::ds": "mid"}, | ||
| ) | ||
|
|
||
| summary = _service()._build_response_from_db(scenario_result=result) | ||
|
|
||
| assert summary.skipped_techniques == ["alpha", "zeta"] | ||
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.
display_group_mapis presentation data and cannot reliably tell us which factories resolved. Rapid Response groups by dataset, Adversarial Benchmark by target, and Jailbreak by template, so their successfully built techniques will be reported as skipped here. Please persist the exact missing names fromresolve_technique_factories()and expose that authoritative list instead.