feat(mail): add message_ids validation in +messages before batch_get#1202
feat(mail): add message_ids validation in +messages before batch_get#1202xukuncx wants to merge 1 commit into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds CLI-side parsing and validation for comma-separated ChangesMessage ID validation for mail shortcuts
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/mail/mail_shortcut_validation_test.go (1)
187-246: ⚡ Quick winAdd one integration test through
MailMessages.Validateto lock CLI parsing + validation behavior.These tests validate the helper well, but they don’t verify the
splitByComma(runtime.Str("message-ids"))path. A single shortcut-level test (e.g.,"msg1,,msg2"and" msg1") would prevent regressions where parsing normalizes away invalid input before validation.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/mail/mail_shortcut_validation_test.go` around lines 187 - 246, Add an integration test that exercises the CLI parsing path by calling MailMessages.Validate with message-ids provided via runtime.Str so splitByComma(runtime.Str("message-ids")) is used; specifically construct a MailMessages instance whose MessageIDs string contains cases like "msg1,,msg2" (to ensure empty entries survive parsing) and " msg1" (to ensure leading/trailing whitespace is preserved) and assert MailMessages.Validate returns the same validation errors as validateMessageIDs (e.g., "entry 2 is empty" and "whitespace"); place the test alongside the existing tests and reference MailMessages.Validate and splitByComma/runtime.Str("message-ids") in the test to lock CLI parsing+validation behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@shortcuts/mail/mail_shortcut_validation_test.go`:
- Around line 187-246: Add an integration test that exercises the CLI parsing
path by calling MailMessages.Validate with message-ids provided via runtime.Str
so splitByComma(runtime.Str("message-ids")) is used; specifically construct a
MailMessages instance whose MessageIDs string contains cases like "msg1,,msg2"
(to ensure empty entries survive parsing) and " msg1" (to ensure
leading/trailing whitespace is preserved) and assert MailMessages.Validate
returns the same validation errors as validateMessageIDs (e.g., "entry 2 is
empty" and "whitespace"); place the test alongside the existing tests and
reference MailMessages.Validate and splitByComma/runtime.Str("message-ids") in
the test to lock CLI parsing+validation behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9263d4b2-7152-4e1d-b476-f6a499636c85
📒 Files selected for processing (3)
shortcuts/mail/helpers.goshortcuts/mail/mail_messages.goshortcuts/mail/mail_shortcut_validation_test.go
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@bb30ede239f4d1b46c2caf3e8e08f39c49cc550d🧩 Skill updatenpx skills add xukuncx/cli#feat/4f09079 -y -g |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@shortcuts/mail/helpers.go`:
- Around line 2666-2670: The validateMessageID routine currently only rejects
ASCII whitespace (`' '`, `'\t'`, `'\n'`, `'\r'`) but must reject all Unicode
whitespace; in the switch in validateMessageID (the branch inspecting rune
variable r) replace the case that checks specific ASCII whitespace with a
unicode.IsSpace(r) check so any Unicode whitespace rune is rejected, and ensure
the unicode package is imported if missing; keep the existing control-character
check (r < 0x20 || r == 0x7f) intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 58fe9122-2772-44bd-af4b-e6e7103cc9e7
📒 Files selected for processing (3)
shortcuts/mail/helpers.goshortcuts/mail/mail_messages.goshortcuts/mail/mail_shortcut_validation_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- shortcuts/mail/mail_messages.go
- shortcuts/mail/mail_shortcut_validation_test.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1202 +/- ##
==========================================
+ Coverage 69.14% 69.26% +0.12%
==========================================
Files 630 633 +3
Lines 59304 59591 +287
==========================================
+ Hits 41005 41278 +273
- Misses 14988 14990 +2
- Partials 3311 3323 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ed7f175 to
226fa09
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@shortcuts/mail/helpers.go`:
- Around line 2634-2643: The loop currently trims entries and allows duplicates;
update the parsing in the parts loop so entries are validated exactly as
provided (do not call strings.TrimSpace) and reject any entry that contains
leading/trailing whitespace by comparing part to strings.TrimSpace(part) and
returning output.ErrValidation for raw-entry violations; continue to call
validateBatchGetMessageID(part, i) on the original part for content validation,
and maintain a seen map (e.g., map[string]bool) to detect and return an error
for duplicate IDs before appending to ids to prevent repeated message rows.
In `@shortcuts/mail/mail_shortcut_validation_test.go`:
- Around line 189-266: The validator currently accepts duplicate IDs; add a unit
test in shortcuts/mail/mail_shortcut_validation_test.go (use
validMessageIDForTest to create two identical encoded IDs and assert a
validation error for duplicates) and update validateMessageIDs in
shortcuts/mail/helpers.go to detect duplicates by tracking seen entries (e.g.,
map[string]struct{}), treating equal trimmed entries as duplicates and returning
a validation error (consistent with other errors, e.g., "duplicate entry X" or
similar) instead of appending them.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1fe5a54b-8232-4680-b280-7281da4f8bef
📒 Files selected for processing (4)
shortcuts/mail/helpers.goshortcuts/mail/mail_messages.goshortcuts/mail/mail_messages_test.goshortcuts/mail/mail_shortcut_validation_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- shortcuts/mail/mail_messages_test.go
Add CLI-side validation for --message-ids in the mail +messages shortcut to catch obviously invalid inputs before making any API call. The batch_get endpoint would otherwise only reject malformed IDs server-side, returning unclear errors. Validation rules: - Reject empty message-ids list - Reject entries exceeding the server-mirrored batch limit of 20 IDs - Reject entries with leading/trailing whitespace - Reject entries containing control characters, whitespace, or path separators - Reject duplicate message IDs sprint: S2
Generated by the harness-coding skill.
Sprints
Source specs
(none)
This MR was created autonomously. Quality gates were enforced by the repo's own pre-commit hooks.
Summary by CodeRabbit
New Features
Bug Fixes / Validation
Tests