Skip to content

MAINT: Migrate ScenarioRunState, ComponentType and ScorerInitializerTags to StrEnum (P311-17) - #4521

Merged
Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
DevShoaib78:fix/strenum-text-bugs
Nov 22, 2026
Merged

Roman Lutz (romanlutz) merged 3 commits into
microsoft:mainfrom
DevShoaib78:fix/strenum-text-bugs

Conversation

@DevShoaib78

Copy link
Copy Markdown
Contributor

Description

PR 1 of #4508: the three str, Enum classes whose members reach user-facing text as Class.MEMBER now inherit from StrEnum, so str() and f-strings give the value. Same pattern as #3850 (ConversationRetryReason) and #4126 (SeedOrigin).

  • ScenarioRunState: the 409 details from cancel_run_async and get_run_results_async now read Cannot cancel run in 'COMPLETED' state. and Current status: 'IN_PROGRESS'. instead of 'ScenarioRunState.COMPLETED'. The "Resuming scenario" info log changes the same way. The class docstring says why it is a StrEnum.
  • ComponentType: the "no registry is wired for component type ..." errors in registry.py and resolution.py now say 'scenario' instead of 'ComponentType.SCENARIO'.
  • ScorerInitializerTags: the two "tagged ... as ..." log lines now print best_objective.
  • Values, equality, hashing, JSON and DB writes are unchanged: members are still str, and stored or serialized paths already used .value. Downstream code that calls str() on a member sees the value now, as with the earlier two migrations.
  • Tests: each enum gets a string-contract test in its own test file. The cancel and results service tests now match the exact message instead of a prefix (which is how the old text slipped through), a route test runs the real service and checks the full 409 detail, and the ComponentType error and scorer log lines are asserted in full.

PRs 2 and 3 of the issue (AttackOutcome, the batch of 61 classes, re-enabling UP042) are not part of this PR, so #4508 stays open.

…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 AI balanced review requested due to automatic review settings November 21, 2026 11:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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, and ScorerInitializerTags while 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

@DevShoaib78

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 22, 2026
Merged via the queue into microsoft:main with commit 8175234 Nov 22, 2026
66 checks passed
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.

3 participants