Skip to content

test: add coverage for HookRegistry.unregister#118

Merged
rolling-codes merged 1 commit into
mainfrom
fix/hooks-unregister-coverage
Jul 22, 2026
Merged

test: add coverage for HookRegistry.unregister#118
rolling-codes merged 1 commit into
mainfrom
fix/hooks-unregister-coverage

Conversation

@rolling-codes

@rolling-codes rolling-codes commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Fixes the codecov/patch failure from #117.

HookRegistry.unregister() was added in #117 but had no tests, dropping patch coverage to 12.50% (target 76%).

5 tests added covering:

  • Normal removal: callback no longer fires after unregister
  • Returns False when callback was never registered
  • Idempotent: second unregister on same callback returns False without raising
  • Invalid hook name raises ValueError
  • Only the targeted callback is removed when multiple are registered

Summary by Sourcery

Add missing tests for HookRegistry.unregister behavior to restore hook system coverage.

Tests:

  • Add tests verifying unregister removes callbacks and prevents them from firing.
  • Add tests asserting unregister returns False when the callback was never registered or when called repeatedly on the same callback.
  • Add a test confirming unregister raises ValueError for unsupported hook names.
  • Add a test ensuring unregister only removes the targeted callback when multiple callbacks are registered for the same hook.

Five tests covering the new method added in #117:
- removes callback and prevents it from firing
- returns False when callback was never registered
- idempotent on repeated unregister calls
- raises ValueError for unsupported hook names
- removes only the targeted callback, leaving others intact
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds focused async tests for HookRegistry.unregister to validate normal removal behavior, failure/false-return cases, idempotency, invalid hook name handling, and selective callback removal, in order to restore patch coverage for the newly added unregister method.

File-Level Changes

Change Details Files
Add async tests to fully cover HookRegistry.unregister behavior.
  • Add test verifying that a callback is no longer invoked after being unregistered and that unregister returns True when it removes a registered callback.
  • Add test asserting unregister returns False when attempting to remove a callback that was never registered.
  • Add test confirming unregister is idempotent by returning False on a second call for the same callback without raising.
  • Add test confirming unregister raises ValueError with an appropriate message when called with an unsupported hook name.
  • Add test ensuring only the specified callback is removed when multiple callbacks are registered for the same hook.
tests/test_hooks.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions github-actions Bot added the tests label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@rolling-codes, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8d56df47-003f-4e33-896c-f8629f9cb1e0

📥 Commits

Reviewing files that changed from the base of the PR and between 96677e2 and 913c2ac.

📒 Files selected for processing (1)
  • tests/test_hooks.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/hooks-unregister-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@rolling-codes
rolling-codes merged commit eb92bdf into main Jul 22, 2026
10 of 11 checks passed
@rolling-codes
rolling-codes deleted the fix/hooks-unregister-coverage branch July 22, 2026 22:21

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider defining small named helper functions instead of inline lambdas for the callbacks (e.g., def cb_a(**kw): ...) to improve readability and make debugging stack traces clearer across the new tests.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider defining small named helper functions instead of inline lambdas for the callbacks (e.g., `def cb_a(**kw): ...`) to improve readability and make debugging stack traces clearer across the new tests.

## Individual Comments

### Comment 1
<location path="tests/test_hooks.py" line_range="144-149" />
<code_context>
+    assert result is False
+
+
+async def test_unregister_idempotent_on_repeat():
+    registry = HookRegistry()
+    cb = lambda **kw: None
+    registry.register("after_command", cb)
+    assert registry.unregister("after_command", cb) is True
+    assert registry.unregister("after_command", cb) is False
+
+
</code_context>
<issue_to_address>
**issue (testing):** Add a test for unregistering a callback that is registered multiple times for the same hook to pin down the expected behavior.

We only test idempotency after a successful unregister, but not the case where the same callback is registered multiple times for the same hook (e.g., `register(..., cb)` twice, then `unregister` once). Please add a test that defines whether a single `unregister` removes one or all registrations, and checks that `fire` calls the callback the expected number of times. This will pin down the intended contract for future refactors.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/test_hooks.py
Comment on lines +144 to +149
async def test_unregister_idempotent_on_repeat():
registry = HookRegistry()
cb = lambda **kw: None
registry.register("after_command", cb)
assert registry.unregister("after_command", cb) is True
assert registry.unregister("after_command", cb) is False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (testing): Add a test for unregistering a callback that is registered multiple times for the same hook to pin down the expected behavior.

We only test idempotency after a successful unregister, but not the case where the same callback is registered multiple times for the same hook (e.g., register(..., cb) twice, then unregister once). Please add a test that defines whether a single unregister removes one or all registrations, and checks that fire calls the callback the expected number of times. This will pin down the intended contract for future refactors.

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@rolling-codes rolling-codes mentioned this pull request Jul 22, 2026
rolling-codes added a commit that referenced this pull request Jul 22, 2026
## v5.58.0 Release PR

Bumps version to 5.58.0 and updates CHANGELOG.

### What's in this release (since v5.57.0)

**Changed**
- Docs accuracy audit across 10 files — fixed plugin counts, stale
method names, wrong constructor params, wrong type names, wrong class
relationships, stale CI pins (#116, #117)
- `HookRegistry.unregister(hook, callback) -> bool` — new public method;
returns `False` instead of raising on already-removed callbacks (#117)

**Tests**
- Full coverage for `HookRegistry.unregister()` — removal, idempotency,
invalid hook name, selective removal (#118)

**Release metadata**: `easycord-5.58.0-py3-none-any.whl` and
`easycord-5.58.0.tar.gz`

---------

Co-authored-by: tee <Thomas_BIRRELL@proton.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants