Skip to content

MAINT: Initializer Registry update and deleting old scaffolding#2122

Merged
rlundeen2 merged 11 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-phase-5-initializers
Jul 3, 2026
Merged

MAINT: Initializer Registry update and deleting old scaffolding#2122
rlundeen2 merged 11 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-phase-5-initializers

Conversation

@rlundeen2

Copy link
Copy Markdown
Contributor

Problem

InitializerRegistry predated the unified Registry base and carried its own bespoke machinery, so initializers didn't behave like the other registry-backed components (scenarios, targets, scorers, converters). External initializer-script loading lived in setup/initialization.py rather than in the registry that owns building components, and a large amount of legacy registry scaffolding (class_registries/, object_registries/, base.py, dead discovery helpers) was left unused.

This is the Phase 5 (initializers) + cleanup slice of the unified-registry redesign. Design & rationale: https://gist.github.com/rlundeen2/f7960f7e8973fbb705b1b4bb48d8cdb2

What changed

Initializers onto the unified registry

  • InitializerRegistry now extends the unified Registry[PyRITInitializer, InitializerMetadata], so initializers are discovered, built, and configured the same way as scenarios.
  • The registry owns turning external .py scripts into initializer instances (create_from_script_paths); setup/initialization.py delegates instead of hand-rolling module loading.
  • create_and_configure(name, initializer_params=...) centralizes build → set-params → validate, paralleling ScenarioRegistry.create_and_initialize_async. initialize_async still runs later, in listed order, from the setup flow.
  • Added composable TagQuery filtering to instance registries.

Cleanup / deleted scaffolding

  • Deleted pyrit/registry/class_registries/, pyrit/registry/object_registries/, and pyrit/registry/base.py.
  • Renamed ClassRegistryEntryRegistryMetadata into its own module; removed the unused RegistryProtocol and the dead discovery helpers.

Net: +895 / −2679 across 39 files.

Testing

  • ruff and ty clean; full registry, setup, and backend-service unit suites pass.

rlundeen2 and others added 9 commits July 2, 2026 14:42
Move InitializerRegistry from the transitional BaseClassRegistry to the
unified Registry base, mirroring the ScenarioRegistry migration (PR microsoft#2115).
The registry now lives in pyrit/registry/components/ and uses the Registry
class catalog (register_class / create_instance / get_class_names /
get_all_registered_class_metadata) instead of the old ClassEntry storage.

- Add create_and_configure lifecycle method (parallel to scenario's
  create_and_initialize_async); route configuration_loader through it.
- Override _discover for the filesystem scan; _identifier_type returns None.
- Inline unregister_and_cleanup since Registry has no unregister.
- Update backend initializer_service and configuration_loader consumers.
- Migrate tests and the class-registry doc (.py + .ipynb) to the new API.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
_run_initializers_async fetched the class via get_class() and did the
instantiate + set_params_from_args dance inline, diverging from how the
same service builds scenarios (create_and_initialize_async). Route it
through the registry-owned create_and_configure lifecycle instead, which
also adds the parameter validation it was skipping.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move the external .py script-loading logic out of setup/initialization.py
and into InitializerRegistry.create_from_script_paths, so the registry is
the single owner of turning scripts into initializer instances. Share the
module-import and module-defined-subclass discovery helpers with
register_from_content.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Rename the create_and_configure argument from 'args' to 'initializer_params'
so it parallels ScenarioRegistry.create_and_initialize_async's
'scenario_params'. The method name intentionally stays create_and_configure
(it stops before initialize_async, which the PyRIT init flow runs in order).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Wire the existing registry-agnostic TagQuery into DefaultInstanceRegistry (and
the InstanceRegistry protocol) via query_by_tags, so callers can filter held
instances with arbitrary AND/OR/exclude tag predicates instead of only the
single-key get_by_tag. Matching is on tag keys, consistent with TagQuery.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Remove the now-unused BaseClassRegistry/ClassEntry and BaseInstanceRegistry
legacy stacks that the unified Registry migration made obsolete. RegistryEntry
is re-pointed to its canonical home in instance_registry, and the RegistryProtocol
docstring plus a test docstring are updated to drop references to the deleted
classes. test_base.py keeps its ClassRegistryEntry and _matches_filters coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Move the shared registry metadata base out of base.py into its own
registry_metadata.py module, renamed from ClassRegistryEntry to the clearer
RegistryMetadata. All six component metadata classes plus scenario/initializer
description helpers now extend/reference it from the new module.

With that moved, base.py held only dead weight: RegistryProtocol had no
production implementers after the legacy-registry deletion, and _matches_filters/
_get_metadata_value were byte-identical duplicates of the copies in registry.py.
instance_registry now uses registry.py's _matches_filters, RegistryProtocol is
dropped from the public API (and the registry doc updated), and base.py is deleted.

Also trim discovery.py: discover_in_directory is still used by the initializer
registry, but discover_in_package and discover_subclasses_in_loaded_modules were
unused exports and are removed.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ests

- Add public PyRITInitializer.validate_params() so the registry no longer
  reaches into the private _validate_params; validate() delegates to it.
- Collapse redundant _discovery_path None-guards in InitializerRegistry.__init__
  and drop the now-unnecessary assert in _discover.
- Rewrite _process_file to reuse _load_module_from_path +
  _module_defined_initializers, removing a duplicate module scan loop.
- Add direct unit tests for create_and_configure (build, param set,
  unknown param ValueError, unknown name KeyError).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- test_filename_extension_existing_pdf downloaded fake_CV.pdf from
  raw.githubusercontent.com, so it failed in CI without network. Read the
  PDF from the local datasets directory instead (no network in unit tests).
- Apply ruff format (collapse over-wrapped lines) to satisfy pre-commit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Comment thread pyrit/setup/initialization.py
rlundeen2 and others added 2 commits July 2, 2026 22:20
Add unit tests for discovery, registration, and metadata edge cases.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Type the discovery helper base_class/return as type[PyRITInitializer].

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@rlundeen2 rlundeen2 enabled auto-merge July 3, 2026 05:29
@rlundeen2 rlundeen2 disabled auto-merge July 3, 2026 05:37
@rlundeen2 rlundeen2 enabled auto-merge July 3, 2026 05:38
@rlundeen2 rlundeen2 added this pull request to the merge queue Jul 3, 2026
Merged via the queue into microsoft:main with commit b818290 Jul 3, 2026
53 checks passed
@rlundeen2 rlundeen2 deleted the rlundeen2-phase-5-initializers branch July 3, 2026 05:57
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.

2 participants