Skip to content

feat(mail): add message_ids validation in +messages before batch_get#1202

Open
xukuncx wants to merge 1 commit into
larksuite:mainfrom
xukuncx:feat/4f09079
Open

feat(mail): add message_ids validation in +messages before batch_get#1202
xukuncx wants to merge 1 commit into
larksuite:mainfrom
xukuncx:feat/4f09079

Conversation

@xukuncx
Copy link
Copy Markdown
Collaborator

@xukuncx xukuncx commented Jun 1, 2026

Generated by the harness-coding skill.

  • Branch: feat/4f09079
  • Target: main

Sprints

ID Title Status Commit
S1 Synthesize transport contract for cli passed 99e314f
S2 Add message_ids validation in mail +messages before batch_get API call passed 410dcfb

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

    • Multi-message fetch auto-chunks requests into batches of 20 while preserving the original ID order; help text updated.
  • Bug Fixes / Validation

    • Improved client-side validation for --message-ids: requires at least one ID, trims entries, rejects empty or numeric-only IDs and invalid formats.
  • Tests

    • Added unit tests for validation and batching (20, >20, trimming, invalid inputs).

@github-actions github-actions Bot added domain/mail PR touches the mail domain size/M Single-domain feat or fix with limited business impact labels Jun 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds CLI-side parsing and validation for comma-separated --message-ids (non-empty list, no blank entries, per-ID base64url format and non-numeric checks), integrates validation into MailMessages (help text, Validate, DryRun, Execute), and adds unit and integration tests including batching into 20-item backend chunks.

Changes

Message ID validation for mail shortcuts

Layer / File(s) Summary
Validation helpers
shortcuts/mail/helpers.go
Adds validateMessageIDs (list parsing: require non-blank input, reject empty entries, preserve order, delegate per-entry checks) and validateBatchGetMessageID (reject numeric-only IDs, require valid base64url-decoded non-empty payload; return validation errors with 1-based index).
MailMessages help and wiring
shortcuts/mail/mail_messages.go
Update +messages help to state backend auto-chunks into batches of 20; call validateMessageIDs(...) from MailMessages.Validate, use it in DryRun, and parse/validate in Execute (removed custom empty-input check and unused import).
MailMessages chunking test & helpers
shortcuts/mail/mail_messages_test.go
Adds TestMailMessagesExecuteChunksMoreThanTwentyIDs which constructs 21 base64url IDs, stubs two batch_get POSTs asserting first request has 20 IDs and second has 1, and asserts output contains one message per requested ID; includes request-body matcher and mock response builder helpers.
Validation unit tests
shortcuts/mail/mail_shortcut_validation_test.go
Adds validMessageIDForTest and multiple tests covering valid IDs, empty/whitespace input, empty-entry rejection, trimming, malformed inputs (JSON-like, colon-joined, numeric-only, invalid base64), and boundary checks for 20 vs 21 IDs (adds encoding/base64 import).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • chanthuang

Poem

🐇 I nibble IDs, one by one,
I trim the spaces 'til the job is done.
No pure digits, and base64 must be true—
Batches hop along, twenty then few.
A tidy list, ready for the queue.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete relative to the repository's template. It lacks a Summary section explaining motivation and scope, a Changes section listing main modifications, and a Test Plan section with verification steps. Add a Summary (1-3 sentences on motivation), a Changes section listing the key updates, and a Test Plan section documenting how the changes were verified.
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(mail): add message_ids validation in +messages before batch_get' directly and clearly summarizes the main change: adding validation for message IDs in the mail +messages shortcut before the batch_get API call.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
shortcuts/mail/mail_shortcut_validation_test.go (1)

187-246: ⚡ Quick win

Add one integration test through MailMessages.Validate to 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0bdd7de and 410dcfb.

📒 Files selected for processing (3)
  • shortcuts/mail/helpers.go
  • shortcuts/mail/mail_messages.go
  • shortcuts/mail/mail_shortcut_validation_test.go

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@bb30ede239f4d1b46c2caf3e8e08f39c49cc550d

🧩 Skill update

npx skills add xukuncx/cli#feat/4f09079 -y -g

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 410dcfb and f09ed8e.

📒 Files selected for processing (3)
  • shortcuts/mail/helpers.go
  • shortcuts/mail/mail_messages.go
  • shortcuts/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

Comment thread shortcuts/mail/helpers.go Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.26%. Comparing base (99e314f) to head (bb30ede).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/mail/mail_messages.go 62.50% 2 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xukuncx xukuncx force-pushed the feat/4f09079 branch 2 times, most recently from ed7f175 to 226fa09 Compare June 1, 2026 12:49
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed7f175 and 226fa09.

📒 Files selected for processing (4)
  • shortcuts/mail/helpers.go
  • shortcuts/mail/mail_messages.go
  • shortcuts/mail/mail_messages_test.go
  • shortcuts/mail/mail_shortcut_validation_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • shortcuts/mail/mail_messages_test.go

Comment thread shortcuts/mail/helpers.go
Comment thread shortcuts/mail/mail_shortcut_validation_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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/mail PR touches the mail domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant