Skip to content

refactor: type hook returns - #1106

Merged
linuxdaemon merged 10 commits into
mainfrom
hook-returns
Dec 2, 2026
Merged

linuxdaemon merged 10 commits into
mainfrom
hook-returns

Conversation

@linuxdaemon

Copy link
Copy Markdown
Member

Add hook return types, clean up other return type annotations, and update related code accordingly

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.81663% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.83%. Comparing base (8f3ee6a) to head (0406276).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
tests/core_tests/test_irc_client.py 87.93% 6 Missing and 1 partial ⚠️
plugins/core/core_out.py 57.14% 6 Missing ⚠️
cloudbot/clients/irc.py 73.33% 2 Missing and 2 partials ⚠️
cloudbot/reloader.py 88.23% 2 Missing and 2 partials ⚠️
plugins/quote.py 57.14% 3 Missing ⚠️
cloudbot/plugin.py 96.72% 1 Missing and 1 partial ⚠️
cloudbot/event.py 96.42% 1 Missing ⚠️
plugins/core/core_hooks.py 50.00% 1 Missing ⚠️
plugins/google_translate.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1106      +/-   ##
==========================================
+ Coverage   87.78%   87.83%   +0.04%     
==========================================
  Files         299      300       +1     
  Lines       22305    22452     +147     
  Branches     1846     1849       +3     
==========================================
+ Hits        19581    19721     +140     
- Misses       2321     2328       +7     
  Partials      403      403              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Copilot AI 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.

🟡 Changes recommended

Awaitable validation bypasses normal hook and sieve failure handling and can leave tasks tracked, while new return-type aliases reject supported post-hook and capability results.

4 open issues
What changed in this PR

This PR adds explicit return types throughout CloudBot’s hook system, carrying them from decorators through hook execution and updating related plugins and tests.

Changes:

  • Define per-hook return types and synchronous/asynchronous callable overloads.
  • Adjust hook execution, outgoing IRC filtering, reply handling, and plugin error returns.
  • Update supporting annotations, test fixtures, and hook-contract checks.
File Description
tests/​util/​mock_bot.py Pass a typed bot to the plugin manager.
tests/​plugin_tests/​test_chain.py Annotate test-hook returns.
tests/​core_tests/​test_reloader.py Pass typed bots to reloaders.
tests/​core_tests/​test_plugin_manager.py Update generic hook annotations.
tests/​core_tests/​test_plugin_hooks.py Check per-hook return and event types.
tests/​core_tests/​test_hook.py Update decorator tests for typed returns.
tests/​core_tests/​test_event.py Adapt outgoing-event parsing tests.
tests/​core_tests/​test_bot.py Update generic hook annotations.
plugins/​utility.py Simplify ROT13 encoding.
plugins/​quote.py Annotate returns and stringify quote errors.
plugins/​grab.py Annotate paginated grab results.
plugins/​google_translate.py Return translation errors as strings.
plugins/​core/​regex_chans.py Update sieve hook annotations.
plugins/​core/​core_sieve.py Update sieve hook annotations.
plugins/​core/​core_out.py Add byte-aware outgoing filters and annotations.
plugins/​core/​core_hooks.py Limit automatic replies to message-producing hooks.
cloudbot/​typedefs.py Add shared callable and exception aliases.
cloudbot/​reloader.py Type reloaders, handlers, and filesystem paths.
cloudbot/​plugin.py Type execution results and validate awaitable returns.
cloudbot/​plugin_hooks.py Parameterize hook classes by return type.
cloudbot/​permissions.py Annotate permission-query results.
cloudbot/​hook.py Export per-hook return aliases.
cloudbot/​event.py Type event helpers and outgoing line storage.
cloudbot/​clients/​irc.py Track typed outgoing-filter results.
cloudbot/​client.py Annotate client interface returns.
cloudbot/​_hooks/​sieve.py Type sieve returns and decorator overloads.
cloudbot/​_hooks/​regex.py Type regex reply returns and overloads.
cloudbot/​_hooks/​post_hook.py Define post-hook return typing.
cloudbot/​_hooks/​permission.py Define permission-hook return typing.
cloudbot/​_hooks/​periodic.py Type periodic hooks and overloads.
cloudbot/​_hooks/​on_stop.py Type shutdown hooks and overloads.
cloudbot/​_hooks/​on_start.py Type startup hooks and overloads.
cloudbot/​_hooks/​irc_raw.py Type raw IRC hooks and overloads.
cloudbot/​_hooks/​irc_out.py Define outgoing-filter return variants.
cloudbot/​_hooks/​event.py Type event reply returns and overloads.
cloudbot/​_hooks/​connect.py Type connection hooks and overloads.
cloudbot/​_hooks/​config.py Type configuration hooks and overloads.
cloudbot/​_hooks/​command.py Type command reply returns and overloads.
cloudbot/​_hooks/​cap.py Separate capability-availability and acknowledgment returns.
cloudbot/​_hooks/​base.py Add return-type generics to hook infrastructure.

Review effort: Balanced

Comment thread cloudbot/plugin.py Resolved
Comment thread cloudbot/plugin.py Resolved
Comment thread cloudbot/_hooks/cap.py Resolved
Comment thread cloudbot/_hooks/post_hook.py Resolved

Copilot AI 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.

🔵 Needs a closer look

Outgoing hook changes break empty-result suppression and leave irc_raw unset, allowing suppressed messages to send and existing hooks to receive None instead of the outgoing line.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Outgoing hooks receive None for irc_raw

cloudbot/​clients/​irc.py:504

Passing only line leaves the inherited Event.irc_raw at its default None; IrcOutEvent does not copy line into that field. Outgoing hooks requesting the existing irc_raw argument therefore receive None instead of the current outgoing line, breaking that event-field contract. Please populate irc_raw alongside the new line argument.

Medium severity Empty hook results no longer suppress outgoing messages

cloudbot/​clients/​irc.py:522

This changes the existing suppression behavior for outgoing hooks returning "" or b"": they previously stopped the send, but now subsequent filters run. For example, an empty result followed by truncate_line writes a bare CRLF instead of suppressing the message. Please retain the falsy-result check so empty results stop the chain as before.

4 resolved since last review

Review effort: Balanced

Copilot AI 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.

🟡 Changes recommended

The unconditional UTF-8 decode can raise UnicodeDecodeError for non-UTF-8 connections, aborting remaining outgoing hooks and the fallback send instead of respecting the connection’s configured encoding and error policy.

1 open issue

Review effort: Balanced

Comment thread cloudbot/clients/irc.py Resolved

Copilot AI 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.

🟡 Changes recommended

Invalid outgoing-hook bytes under strict decoding can abort sending before any write and bypass the existing error fallback, even when the next hook only needs line.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread cloudbot/clients/irc.py Resolved

Copilot AI 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.

🟡 Changes recommended

Event initialization shadows the irc_raw compatibility accessor with None, causing outgoing hooks that use it to receive the wrong value and potentially fail into the fallback send path.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread cloudbot/event.py Resolved

Copilot AI 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.

🟡 Changes recommended

Reading IrcOutEvent.irc_raw causes duplicate key enumeration, increasing len(event) and making it inconsistent with len(dict(event)).

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread cloudbot/event.py Resolved

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because the byte-filter chaining test passes through a UTF-8 fallback without exercising the later sieves.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@linuxdaemon
linuxdaemon merged commit c2ae62d into main Dec 2, 2026
25 of 26 checks passed
@linuxdaemon
linuxdaemon deleted the hook-returns branch December 2, 2026 04:36
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