refactor(chat_gpt): decompose the two large handlers#607
Merged
Conversation
Splits the ~80-line handle_chat_gpt_question and ~60-line handle_reply
into small, single-purpose helpers (§4):
- `bot_configuration_for_message` / `bot_configuration_for_profile`:
pure profile-selection functions, now covered by unit tests.
- `build_question_context`: the summary-vs-rolling context routing.
- `send_gpt_reply`: thread-aware reply send (used by the question path).
handle_reply is additionally flattened from `if let Ok { .. }` to a
`let Ok(..) else { return Ok(()) }` guard. Its send stays non-threaded
to preserve exact current behavior.
Pure refactor — no happy-path behavior change (chat_gpt_e2e is the
backstop). 3 new unit tests; local gate green (fmt, clippy -D warnings,
11 unit tests, integration tests compile).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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.
Iteration 6/8 of the hardening plan (§4 refactors).
Splits the ~80-line
handle_chat_gpt_questionand ~60-linehandle_replyinto small, single-purpose helpers:bot_configuration_for_messagebot_configuration_for_profilebuild_question_contextsend_gpt_replyhandle_replyis also flattened fromif let Ok { … }to alet Ok(..) else { return Ok(()) }guard; its send stays non-threaded to preserve exact current behavior.Pure refactor — no happy-path behavior change (
chat_gpt_e2eexercises the question path end-to-end). 3 new unit tests for the pure selectors (8 → 11). Local gate green: fmt, clippy-D warnings, unit tests, integration tests compile.🤖 Generated with Claude Code