MAINT: Initializer Registry update and deleting old scaffolding#2122
Merged
rlundeen2 merged 11 commits intoJul 3, 2026
Conversation
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>
romanlutz
approved these changes
Jul 3, 2026
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>
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.
Problem
InitializerRegistrypredated the unifiedRegistrybase 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 insetup/initialization.pyrather than in the registry that owns building components, and a large amount of legacy registry scaffolding (class_registries/,object_registries/,base.py, deaddiscoveryhelpers) 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
InitializerRegistrynow extends the unifiedRegistry[PyRITInitializer, InitializerMetadata], so initializers are discovered, built, and configured the same way as scenarios..pyscripts into initializer instances (create_from_script_paths);setup/initialization.pydelegates instead of hand-rolling module loading.create_and_configure(name, initializer_params=...)centralizes build → set-params → validate, parallelingScenarioRegistry.create_and_initialize_async.initialize_asyncstill runs later, in listed order, from the setup flow.TagQueryfiltering to instance registries.Cleanup / deleted scaffolding
pyrit/registry/class_registries/,pyrit/registry/object_registries/, andpyrit/registry/base.py.ClassRegistryEntry→RegistryMetadatainto its own module; removed the unusedRegistryProtocoland the deaddiscoveryhelpers.Net: +895 / −2679 across 39 files.
Testing
ruffandtyclean; full registry, setup, and backend-service unit suites pass.