test(imbot/feishu): wire-level tests against a fake Feishu server#1136
Open
0x0079 wants to merge 1 commit into
Open
test(imbot/feishu): wire-level tests against a fake Feishu server#11360x0079 wants to merge 1 commit into
0x0079 wants to merge 1 commit into
Conversation
Point the Lark SDK HTTP client at a local httptest server (via WithOpenBaseUrl + WithHttpClient) and assert the exact outgoing request for each send path — no real credentials, no manual interaction, runs in CI deterministically. Coverage: - SendMessage plain text: msg_type=text, receive_id_type=open_id for ou_. - SendMessage with an inline keyboard: receive_id_type=chat_id for oc_, msg_type=interactive, and the button actually renders in the card body (guards the two bugs that bit us: open_id cross app, and the keyboard silently vanishing). - SendMessage with card_json: sent verbatim as an interactive message. - sendMedia image/file: uploads to /im/v1/images|files first, then sends a create with the returned key plumbed into the body. - EditMessage: PATCH /im/v1/messages/:id. DeleteMessage: DELETE same. React: POST .../reactions with the emoji. - Inbound replay: convertLarkMessageToCore on an image message yields a media attachment (feishu://<key>) and a chat-id reply target. This makes "is this change correct?" answerable by `go test ./imbot/platform/feishu/...`, leaving live Feishu only for a per-release render/delivery smoke check rather than per-change verification. https://claude.ai/code/session_014ThTKs7Ft4zptY2pQJDpjZ
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.
Stacked on #1109. Adds a verification layer so Feishu correctness can be checked by
go testinstead of by clicking buttons in a real Feishu client.Why
Manual Feishu interaction is expensive and shouldn't be the primary way to verify changes. The previous PRs covered the decode half (event →
core.Message) with pure unit tests, but the encode half — the exact HTTP request we send — was only verifiable by hand. That's precisely where the regressions hit: a wrongreceive_id_type(open_id cross app), a keyboard that silently vanished, media sent to the wrong endpoint.How
The Lark SDK lets you inject the base URL and HTTP client (
WithOpenBaseUrl+WithHttpClient, whereHttpClientis a one-method interface — the SDK's own tests do this). So we pointb.clientat a localhttptest.Server, call each send path, and assert the recorded request. No credentials, no network, deterministic in CI.Coverage
SendMessageplain text —msg_type=text,receive_id_type=open_idforou_.SendMessage+ inline keyboard —receive_id_type=chat_idforoc_,msg_type=interactive, and the button actually renders in the card body (guards both theopen_id cross appbug and the vanishing-keyboard bug).SendMessage+card_json— sent verbatim as an interactive message.sendMediaimage / file — uploads to/im/v1/images|filesfirst, then a create with the returned key plumbed into the body.EditMessage→PATCH /im/v1/messages/:id;DeleteMessage→DELETE;React→POST .../reactionswith the emoji.convertLarkMessageToCoreon an image message yields afeishu://<key>media attachment and a chat-id reply target.Proof the tests have teeth
Reverting
getReceiveIdTypeto the old buggy mapping (oc_ → open_id) makes the wire test fail withwire_test.go: receive_id_type = "open_id", want chat_id— i.e. it catches the exactopen_id cross appregression locally, before any real Feishu call. Restoring the fix turns it green.Net effect on verification
"Is this change correct?" becomes answerable by
go test ./imbot/platform/feishu/.... A real Feishu bot is then only needed for a per-release smoke check that the card actually renders and the WebSocket delivers events — not per change. The existingfeishu_e2e_test.go(behind thee2ebuild tag) already covers that.https://claude.ai/code/session_014ThTKs7Ft4zptY2pQJDpjZ
Generated by Claude Code