|
26 | 26 | from pyrit.scenario.core.matrix_atomic_attack_builder import ( |
27 | 27 | MatrixAtomicAttackBuilder, |
28 | 28 | MatrixCombo, |
29 | | - TechniqueResolutionError, |
30 | 29 | build_baseline_atomic_attack, |
31 | 30 | build_matrix_atomic_attacks, |
32 | | - resolve_technique_factories, |
33 | 31 | ) |
34 | 32 | from pyrit.scenario.core.scenario_context import ScenarioContext |
35 | 33 | from pyrit.score import TrueFalseScorer |
@@ -388,69 +386,6 @@ def _patch_registry(factories: dict): |
388 | 386 |
|
389 | 387 |
|
390 | 388 | @pytest.mark.usefixtures("patch_central_database") |
391 | | -class TestResolveTechniqueFactories: |
392 | | - """``resolve_technique_factories`` filters the registry to the selected techniques.""" |
393 | | - |
394 | | - def test_keeps_only_selected_in_order(self): |
395 | | - factories = { |
396 | | - "alpha": _mock_factory(name="alpha"), |
397 | | - "beta": _mock_factory(name="beta"), |
398 | | - "gamma": _mock_factory(name="gamma"), |
399 | | - } |
400 | | - context = _context(techniques=[_technique("beta"), _technique("alpha")]) |
401 | | - with _patch_registry(factories): |
402 | | - resolved = resolve_technique_factories(context=context) |
403 | | - assert list(resolved.keys()) == ["beta", "alpha"] |
404 | | - |
405 | | - def test_raises_when_any_selected_technique_is_missing(self): |
406 | | - factories = {"alpha": _mock_factory(name="alpha")} |
407 | | - context = _context(techniques=[_technique("alpha"), _technique("missing")]) |
408 | | - with _patch_registry(factories), pytest.raises(TechniqueResolutionError, match="missing"): |
409 | | - resolve_technique_factories(context=context) |
410 | | - |
411 | | - def test_raises_when_all_selected_techniques_missing(self): |
412 | | - """A nonempty selection resolving to nothing must fail loudly, not run baseline-only.""" |
413 | | - factories = {"alpha": _mock_factory(name="alpha")} |
414 | | - context = _context(techniques=[_technique("missing_a"), _technique("missing_b")]) |
415 | | - with _patch_registry(factories), pytest.raises(TechniqueResolutionError, match="missing_a"): |
416 | | - resolve_technique_factories(context=context) |
417 | | - |
418 | | - def test_empty_selection_resolves_without_error(self): |
419 | | - context = _context(techniques=[]) |
420 | | - with _patch_registry({}): |
421 | | - assert resolve_technique_factories(context=context) == {} |
422 | | - |
423 | | - def test_error_lists_each_missing_technique_once_in_selection_order(self): |
424 | | - factories = {"alpha": _mock_factory(name="alpha")} |
425 | | - context = _context( |
426 | | - techniques=[ |
427 | | - _technique("missing_a"), |
428 | | - _technique("alpha"), |
429 | | - _technique("missing_b"), |
430 | | - _technique("missing_a"), |
431 | | - ] |
432 | | - ) |
433 | | - with _patch_registry(factories), pytest.raises(TechniqueResolutionError) as exc_info: |
434 | | - resolve_technique_factories(context=context) |
435 | | - message = str(exc_info.value) |
436 | | - assert message.index("missing_a") < message.index("missing_b") |
437 | | - assert message.count("missing_a") == 1 |
438 | | - |
439 | | - def test_extra_factories_merged_and_override_registry(self): |
440 | | - registry_factories = {"alpha": _mock_factory(name="alpha")} |
441 | | - local_alpha = _mock_factory(name="alpha") |
442 | | - local_only = _mock_factory(name="local") |
443 | | - context = _context(techniques=[_technique("alpha"), _technique("local")]) |
444 | | - with _patch_registry(registry_factories): |
445 | | - resolved = resolve_technique_factories( |
446 | | - context=context, |
447 | | - extra_factories={"alpha": local_alpha, "local": local_only}, |
448 | | - ) |
449 | | - assert list(resolved.keys()) == ["alpha", "local"] |
450 | | - assert resolved["alpha"] is local_alpha # extra overrides the registry factory of the same name |
451 | | - assert resolved["local"] is local_only # local-only factory is selectable without global registration |
452 | | - |
453 | | - |
454 | 389 | @pytest.mark.usefixtures("patch_central_database") |
455 | 390 | class TestBuildMatrixAtomicAttacks: |
456 | 391 | """``build_matrix_atomic_attacks`` wires the context into the builder in one call.""" |
|
0 commit comments