Files
chenhg5-cc-connect/platform
cg33 ca779955e0 fix(dingtalk): handle msgtype=file inbound (route to FileAttachment) — closes #981 file half (#1357)
* fix(dingtalk): handle msgtype=file inbound (route to FileAttachment)

DingTalk delivers user-uploaded files (PDF / txt / docx / …) via
msgtype="file" callbacks that carry a downloadCode + fileName in
the content payload. cc-connect previously had no branch for this
in onRawMessage's dispatcher: the message fell through to the
default text handler with an empty Content and no Files attached,
so the engine silently dropped the user message and the agent later
replied "I did not receive a file" — extremely confusing UX.

This is the file half of the same #981 family that PR #1128 already
fixed for image/picture msgtypes.

Fix mirrors handleImageMessage:

  - Route msgtype="file" to new handleFileMessage
  - Parse downloadCode + fileName from content map
  - Reuse the existing getDownloadURL / HTTP download path
  - Cap at 50 MiB (DingTalk's per-file limit is 100 MiB; 50 is
    plenty for agent inputs without OOM risk)
  - Build core.Message with Files: []core.FileAttachment{...}
    preserving FileName so the agent sees the original name

Tests
  - TestOnRawMessage_FileMsgTypeNotDroppedAsEmptyText (negative
    regression: handler must never see empty file inbound)
  - TestHandleFileMessage_BuildsFileAttachmentWithName (positive:
    mocks accessToken + download URL + file body, asserts the
    dispatched Message carries a FileAttachment with the correct
    name, bytes, and mime)
  - TestOnRawMessage_PictureMsgTypeNotDroppedAsEmptyText still
    passes (no regression on the image branch)

Verified manually
  - Sent .txt + "read this file" to DingTalk private chat with
    release-test cc-connect binary built from this branch
  - Before: msg silently dropped, agent had nothing to read
  - After:  "dingtalk: file downloaded successfully size=N
    file_name=xxx.txt" + agent correctly described file contents

Discovered by qa-cursor while running release-gate UI-P0-19
(designed as a known-gap case that was expected to fail).

* test(dingtalk): silence errcheck on recover() in file test

---------

Co-authored-by: qa-cursor <qa-cursor@spaceship.local>
2026-06-15 08:38:51 +08:00
..