test(gateway): add coverage for hybrid LINE reply/push dispatch#623
Merged
test(gateway): add coverage for hybrid LINE reply/push dispatch#623
Conversation
Extract dispatch_line_reply() into a testable function and add 6 tests covering the full decision matrix: - cache hit → Reply API only - cache miss → Push API fallback - expired token → Push API fallback - Reply 400 invalid token → Push API fallback - Reply 5xx → no fallback (duplicate risk) - network error → no fallback (duplicate risk) Uses wiremock for HTTP mocking with scoped expectations. Closes #620
3 tasks
|
All PRs must reference a prior Discord discussion to ensure community alignment before implementation. Please edit the PR description to include a link like: This PR will be automatically closed in 3 days if the link is not added. |
added 2 commits
April 28, 2026 19:39
Address review feedback from 擺渡法師: wiremock mocks now verify Authorization bearer token and request body (replyToken, to, messages) in addition to method/path/count. - cache_hit: verifies replyToken + bearer token + message payload - cache_miss: verifies 'to' field + bearer token + message payload - expired_token: verifies push body + bearer token - 400 invalid token: verifies bearer token on both reply and push - 5xx: verifies bearer token on reply - network error: unchanged (no server to verify against)
thepagent
approved these changes
Apr 28, 2026
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.
What problem does this solve?
Issue #620 — the hybrid LINE reply/push strategy from PR #608 lacks focused test coverage for the dispatch decision logic. This is correctness-sensitive because it decides when to use the free Reply API, when to fall back to Push API, and when not to fall back to avoid duplicate delivery.
Closes #620
Proposed Solution
Extract
dispatch_line_reply()— pulled the LINE dispatch branch out of the WebSocket recv_task closure into a standalone async function with anapi_baseparameter for testability.6 test cases using
wiremockfor HTTP mocking with scoped expectations (expect(N)auto-verified on drop):cache_hit_uses_reply_apicache_miss_uses_push_apiexpired_token_uses_push_apireply_400_invalid_token_falls_back_to_pushreply_5xx_does_not_fallbackreply_network_error_does_not_fallbackWhy this approach?
api_baseparameter is the minimal refactor needed to make the logic testable without changing behavior.wiremockscoped mocks verify both positive (was called) and negative (was NOT called) expectations, which is critical for the "no fallback on 5xx/network error" safety invariant.Test Plan
cargo buildpassescargo testpasses — all 6 tests greenSupersedes #622 (which had unrelated diff noise from the base branch).