Repository navigation
Conversation
Validate the complete namespace before installation while retaining existing caller identities. Related to pytest-dev#761. AI-assisted with OpenAI Codex.
Cover normal and historic retry, namespace validation, duplicate specifications, and warnings treated as errors. Seven cases fail on the original base; all pass with the fix. AI-assisted with OpenAI Codex.
…nto fix-hookspec-validation-761
Remove only implementations and unused callers created by the failed registration. Track active registration ownership to preserve nested replacement registrations, including the same plugin object. Add regression coverage and update the existing issue 761 changelog.
Remove only implementations and unused callers created by the failed registration. Preserve nested registry changes, including re-registration of the same plugin object.
Cover replay and callback failures, original tracebacks, retries, existing state, unused new callers, nested registrations and late-spec validation. Full suite: 239 passed; all pre-commit hooks passed.
Update the existing changelog fragment for hookspec validation and historic registration rollback.
…nto fix-hookspec-validation-761
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.
Summary
Make failed hookspec validation and historic plugin registration recoverable.
Problem
add_hookspecs()installs specifications before validating existing implementations. A validation error leaves partially installed specifications and prevents a retry, even after the invalid plugin is removed.When historic replay raises during
register(), the plugin and implementations processed earlier remain registered. Replay may also add specifications or register other plugins, so restoring the entire manager would discard valid user changes.Solution
HookCaller, then install the prepared specification and historic state. Keep existing caller identities and implementations.BaseExceptionfor cleanup and use a bareraiseto preserve the original exception and traceback. Avoid plugin equality during rollback and retain replay side effects.761.bugfix.rstfragment.Regression Tests
Add 20 test cases (after parametrization) and strengthen the existing late-spec validation test. Coverage includes:
RuntimeErrorandKeyboardInterrupt, with exception identity and traceback checks.Validation
Tested on Windows with CPython 3.12.13:
uv run pytest -q --tb=short: 239 passed.uv run pre-commit run --all-files: all hooks passed, including Ruff, formatting and mypy.git diff origin/main --check: passed.6995073) produced 19 failures and 2 passing controls. The working checkout was unchanged._manager.pyhas no uncovered statements; combined statement/branch coverage is 99%.Other Python versions and platforms await CI after PR creation.
Related Issue
Fixes #761.
Related: #779 also addresses historic registration rollback.
Prepared with OpenAI Codex; local tests and self-review were performed before submission.