Skip to content

MAINT: Extract technique factory resolution from MatrixAtomicAttackBuilder (#2869) - #2879

Open
Vardhman Gupta (Kaap10) wants to merge 3 commits into
microsoft:mainfrom
Kaap10:feature/extract-technique-resolution-2869
Open

Vardhman Gupta (Kaap10) wants to merge 3 commits into
microsoft:mainfrom
Kaap10:feature/extract-technique-resolution-2869

Conversation

@Kaap10

@Kaap10 Vardhman Gupta (Kaap10) commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #2869

While exploring technique resolution across different scenario architectures, I noticed that pyrit/scenario/core/matrix_atomic_attack_builder.py combined both matrix combinatorial expansion and generic technique factory resolution/validation logic (resolve_technique_factories, resolve_technique_factories_for_techniques, and TechniqueResolutionError).

As highlighted in the builder's module docstring, scenarios of different shapes (such as adaptive scenarios, composite builders, or per-objective builders) also need technique resolution from AttackTechniqueRegistry and extra_factories, but they shouldn't need to import or couple with matrix_atomic_attack_builder.py.

This PR extracts the technique resolution and missing technique validation logic into a dedicated private helper module:

  1. Created pyrit/scenario/core/_technique_resolution.py containing TechniqueResolutionError, resolve_technique_factories, and resolve_technique_factories_for_techniques with complete Google/Sphinx style docstrings.
  2. Re-exported all resolution symbols in pyrit/scenario/core/matrix_atomic_attack_builder.py (with explicit __all__) and registered lazy exports in pyrit/scenario/core/__init__.py to ensure complete backward compatibility for external callers and legacy imports.
  3. Updated internal consumers in pyrit/scenario/core/scenario.py to import directly from _technique_resolution.

Tests and Documentation

  • Moved dedicated unit tests to tests/unit/scenario/core/test_technique_resolution.py covering context resolution, sequence resolution, error deduplication in first seen order, ValueError inheritance, and extra_factories overrides.
  • Added backward-compatibility re-export identity assertions in tests/unit/scenario/core/test_matrix_atomic_attack_builder.py.
  • Updated mock patch targets in tests/unit/scenario/test_default_run_size_estimates.py to point to _technique_resolution.
  • Ran the full scenario unit test suite (pytest tests/unit/scenario/), all 1,268 unit tests passed.
  • Verified linting and formatting with ruff check and ruff format, all checks passed with 0 errors.

@Kaap10

Copy link
Copy Markdown
Contributor Author

Hi Roman Lutz (@romanlutz), this PR extracts technique factory resolution into a dedicated module per #2869 with full test parity. Whenever you have some time, could you please take a look and approve the workflow run? Thanks!

Comment thread tests/unit/scenario/core/test_technique_resolution.py
Comment thread pyrit/scenario/core/_technique_resolution.py
@Kaap10

Vardhman Gupta (Kaap10) commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi Roman Lutz (@romanlutz),

Thanks for the review! I have addressed both points in the latest commit (b0417efa):

  1. Private Helper Module: Renamed technique_resolution.py to pyrit/scenario/core/_technique_resolution.py to keep the implementation private while maintaining all public re-exports from pyrit.scenario.core and matrix_atomic_attack_builder.
  2. Deduplicated Resolver Tests & Compatibility Checks: Moved the resolver test suite into test_technique_resolution.py and replaced the duplicates in test_matrix_atomic_attack_builder.py with TestLegacyReExports to verify identity (is) for all legacy re-exports.

All linting checks (ruff) and unit tests (pytest tests/unit/scenario/ - 1,268 tests) pass cleanly. Please let me know if anything else is needed!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MAINT: Extract technique factory resolution from MatrixAtomicAttackBuilder

2 participants