Repository navigation
MAINT: Migrate ScenarioRunState, ComponentType and ScorerInitializerTags to StrEnum (P311-17) - #4521
Merged
Roman Lutz (romanlutz) merged 3 commits intoNov 22, 2026
Conversation
…ags to StrEnum (P311-17) These three str, Enum classes reach user-facing text through str() and f-strings, which print 'ScenarioRunState.COMPLETED' instead of 'COMPLETED': the 409 details from cancel_run_async and get_run_results_async, the "no registry is wired for component type" errors, and the scorer initializer's best_objective log lines. As StrEnum they format as their value; values, equality, hashing and serialization are unchanged. Tests pin the exact message and log text, and check that every member formats as its value.
Copilot started reviewing on behalf of
Mohammed Shoaib Choudry (DevShoaib78)
November 21, 2026 11:22
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the StrEnum migration.
No open issues 🎉
What changed in this PR
Implements the first part of #4508 by migrating three enums to StrEnum, making user-facing errors and logs display their values rather than class-qualified names.
Changes:
- Migrate
ScenarioRunState,ComponentType, andScorerInitializerTagswhile preserving enum values and serialization behavior. - Add string-contract tests covering formatting, equality, hashing, value lookup, and JSON serialization.
- Strengthen regression checks for service errors, HTTP 409 details, registry errors, and scorer logs.
| File | Description |
|---|---|
| tests/unit/setup/test_scorer_initializer.py | Verify tag string behavior and value-based log messages. |
| tests/unit/registry/test_resolution.py | Assert registry errors name component types by value. |
| tests/unit/models/test_scenario_result.py | Add string-contract tests for scenario run states. |
| tests/unit/models/test_parameter.py | Add string-contract tests for component types. |
| tests/unit/backend/test_scenario_run_service.py | Tighten assertions for cancellation and results errors. |
| tests/unit/backend/test_scenario_run_routes.py | Verify real-service HTTP 409 detail and update mocked messages. |
| pyrit/setup/initializers/scorers.py | Migrate scorer initializer tags to StrEnum. |
| pyrit/models/results/scenario_result.py | Migrate scenario run states and document value-based formatting. |
| pyrit/models/parameter.py | Migrate component types to StrEnum. |
Review effort: Balanced
Contributor
Author
|
@microsoft-github-policy-service agree |
Roman Lutz (romanlutz)
approved these changes
Nov 22, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
PR 1 of #4508: the three
str, Enumclasses whose members reach user-facing text asClass.MEMBERnow inherit fromStrEnum, sostr()and f-strings give the value. Same pattern as #3850 (ConversationRetryReason) and #4126 (SeedOrigin).ScenarioRunState: the 409 details fromcancel_run_asyncandget_run_results_asyncnow readCannot cancel run in 'COMPLETED' state.andCurrent status: 'IN_PROGRESS'.instead of'ScenarioRunState.COMPLETED'. The "Resuming scenario" info log changes the same way. The class docstring says why it is aStrEnum.ComponentType: the "no registry is wired for component type ..." errors inregistry.pyandresolution.pynow say'scenario'instead of'ComponentType.SCENARIO'.ScorerInitializerTags: the two "tagged ... as ..." log lines now printbest_objective.str, and stored or serialized paths already used.value. Downstream code that callsstr()on a member sees the value now, as with the earlier two migrations.detail, and theComponentTypeerror and scorer log lines are asserted in full.PRs 2 and 3 of the issue (
AttackOutcome, the batch of 61 classes, re-enablingUP042) are not part of this PR, so #4508 stays open.