feat(drive): pre-flight per-text-element byte limit for +add-comment#605
feat(drive): pre-flight per-text-element byte limit for +add-comment#605herbertliu wants to merge 1 commit intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughReplaced rune-count validation with UTF-8 byte-length validation (max 300 bytes) for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #605 +/- ##
==========================================
+ Coverage 59.82% 59.83% +0.01%
==========================================
Files 404 404
Lines 42527 42534 +7
==========================================
+ Hits 25440 25450 +10
+ Misses 15082 15080 -2
+ Partials 2005 2004 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@1216876519db467216e97b617a70f5f9bc4bfbc0🧩 Skill updatenpx skills add larksuite/cli#feat/add-comment-length-precheck -y -g |
The open-platform comment API returns an opaque [1069302] Invalid or missing parameters whenever a single reply_elements[i] text exceeds its implicit byte budget. The error does not name which element failed or that length is the cause, so callers resort to binary-search debugging. Empirically: Chinese text up to ~80 chars (~240 bytes) lands; ~130 chars (~390 bytes) fails. Set the pre-flight limit to 300 bytes which sits safely inside the known-good zone. - parseCommentReplyElements now rejects any text element whose UTF-8 byte length exceeds 300, with an ExitError naming the element index (#N, 1-based) and both the rune and byte counts, plus an ErrWithHint recommending the correct remediation (split into multiple text elements — the comment UI renders them as one contiguous comment). - The previous 1000-rune check is removed: it was too lenient (a Chinese text under that cap would still fail server-side). - skills/lark-drive/references/lark-drive-add-comment.md documents the per-element limit and the correct split pattern so agents avoid constructing oversized single elements upstream. Addresses Case 12 in the 踩坑列表 doc.
4740361 to
1216876
Compare
Summary
The open-platform comment API returns an opaque
[1069302] Invalid or missing parameterswhenever a singlereply_elements[i].textexceeds its implicit byte budget. The error does not name which element failed or that length is the cause, forcing callers to binary-search the content to locate the offender.This PR moves that detection into the CLI as a pre-flight check so agents / users see a clear, actionable error before hitting the server.
Changes
shortcuts/drive/drive_add_comment.go—parseCommentReplyElementsnow rejects any text element whose UTF-8 byte length exceeds 300 bytes (≈100 Chinese characters / 300 ASCII characters). The error:--content element #N)ErrWithHintrecommends the correct remediation: split into multiple{"type":"text","text":"..."}elements — the comment UI still renders them as one contiguous commentshortcuts/drive/drive_add_comment_test.go— 6 table-driven cases covering: ASCII at / over the boundary, Chinese at / over the boundary (exactly 100 chars = 300 bytes must fit), a 130-Chinese-char reproducer (390 bytes, reliably fails server-side), and correct index reporting when the second element is the offender. Hint text inspected viaExitError.Detail.Hint.skills/lark-drive/references/lark-drive-add-comment.md— new bullet documenting the per-element limit + the correct split pattern, so agents avoid constructing oversized single elements upstream in the first place.Empirical basis
[1069302]300 bytes sits comfortably inside the known-good zone: it rejects the 390-byte failure case pre-flight while leaving headroom for typical ~100-character comments.
Test Plan
go test ./shortcuts/drive/...passes (newTestParseCommentReplyElementsTextLengthwith 6 cases)go vet ./shortcuts/...cleangofmt -l shortcuts/cleangolangci-lint run --new-from-rev=origin/main— 0 issues🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Documentation