Skip to content

Add mail rule reorder shortcut - #2246

Open
yangr-happy wants to merge 3 commits into
larksuite:mainfrom
yangr-happy:feat/1759d14
Open

Add mail rule reorder shortcut#2246
yangr-happy wants to merge 3 commits into
larksuite:mainfrom
yangr-happy:feat/1759d14

Conversation

@yangr-happy

@yangr-happy yangr-happy commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Adds a mail rule reorder shortcut that accepts a partial ordered list of rule IDs and expands it to the complete mailbox rule order before submitting the reorder request.

Changes include:

  • fetch the current mailbox rules before reordering
  • validate empty, duplicate, and unknown rule IDs before calling reorder
  • preserve the relative order of rules omitted by the user
  • surface reorder failures with the submitted full ID list for diagnostics
  • add focused tests for validation, request shape, list failure, reorder failure, and full-list compatibility
  • document that partial rule ID input is supported by the shortcut

Summary by CodeRabbit

  • New Features

    • Added a mail rule reordering command that moves selected rules to the front while preserving all remaining rules in their existing order.
    • Supports input validation, dry-run previews, structured and human-readable output, and actionable error hints.
    • Requires confirmation before applying changes.
  • Documentation

    • Added guidance for identifying rule IDs and avoiding incomplete reorder requests.
  • Tests

    • Added coverage for successful reordering, validation errors, unknown rules, API failures, and partial ordering.

Fetch the current mail rule list before reorder so callers can provide a partial front segment while the API still receives the complete rule ID order.

Co-authored-by: TRAE CLI <noreply@bytedance.com>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 751e6b2c-9151-4306-9968-40be2e81bd8a

📥 Commits

Reviewing files that changed from the base of the PR and between c636d07 and 06f5769.

📒 Files selected for processing (1)
  • shortcuts/mail/mail_rule_reorder.go

📝 Walkthrough

Walkthrough

The PR adds and registers mail +rule-reorder. The shortcut validates input, fetches current rules, builds a complete order, submits it, and documents confirmation and usage requirements.

Changes

Mail rule reorder

Layer / File(s) Summary
Shortcut entry and operation wiring
shortcuts/mail/mail_rule_reorder.go, shortcuts/mail/shortcuts.go, skill-template/domains/mail.md, skills/lark-mail/...
Adds the shortcut, scopes, flags, validation, dry-run operations, registration, confirmation requirements, and usage guidance.
Rule retrieval and complete order construction
shortcuts/mail/mail_rule_reorder.go
Normalizes rule IDs, validates current rules, parses sequence values, preserves omitted rules, and rejects duplicate or unknown IDs.
Submission, output, and behavioral validation
shortcuts/mail/mail_rule_reorder.go, shortcuts/mail/mail_rule_reorder_test.go
Submits the complete rule ID list, formats results and API error hints, and tests success and failure paths.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant MailRuleReorder
  participant MailAPI
  Client->>MailRuleReorder: Provide front-segment rule IDs
  MailRuleReorder->>MailAPI: Fetch current rule list
  MailAPI-->>MailRuleReorder: Return rule IDs and sequences
  MailRuleReorder->>MailRuleReorder: Validate and build complete order
  MailRuleReorder->>MailAPI: Submit complete rule ID list
  MailAPI-->>MailRuleReorder: Return reorder result
  MailRuleReorder-->>Client: Return structured or human-readable output
Loading

Possibly related PRs

  • larksuite/cli#2166: Implements related mail rule reorder ID completion and validation logic.
  • larksuite/cli#2167: Implements related partial-ID completion and complete reorder submission behavior.
  • larksuite/cli#2175: Implements related partial mail-rule reorder behavior in the shortcut layer.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: adding a mail rule reorder shortcut.
Description check ✅ Passed The description clearly covers the scope, implementation changes, tests, and documentation updates, although it omits explicit template headings and issue status.
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.
✨ 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.

@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 Aug 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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/mail_rule_reorder_test.go`:
- Around line 245-260: Update shortcuts/mail/mail_rule_reorder_test.go:245-260
in requireMailRuleValidation to assert validation Category and Subtype via
errs.ProblemOf while retaining errors.As for ValidationError.Param; update
shortcuts/mail/mail_rule_reorder_test.go:142-148 to verify the list failure’s
API Category, populated Subtype, and preserved cause; update
shortcuts/mail/mail_rule_reorder_test.go:173-179 to retain the hint assertion
and add API metadata and cause-preservation checks for the wrapped reorder
failure.

In `@shortcuts/mail/mail_rule_reorder.go`:
- Line 33: Update the AuthTypes configuration used by executeMailRuleReorder to
include only "user", removing "bot" so this mail reorder write shortcut requires
user authentication.
- Around line 136-153: Update the rule-list parsing around the loop that builds
mailRuleOrderItem to validate the response shape before conversion: require
data["items"] to be an array, require each item to be an object with a string id
and a supported sequence representation, and return mailInvalidResponseError for
missing or unsupported values. Replace the mailRuleStringValue/int64PointerValue
coercion path with a typed boundary projection that rejects non-string IDs and
fractional or otherwise invalid sequence values while preserving valid ordering
behavior and sortMailRulesBySequenceWhenComplete.
🪄 Autofix

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 Plus

Run ID: 7c17d797-2ada-4d30-b404-d591760d6254

📥 Commits

Reviewing files that changed from the base of the PR and between 7be2476 and 740dfbb.

📒 Files selected for processing (6)
  • shortcuts/mail/mail_rule_reorder.go
  • shortcuts/mail/mail_rule_reorder_test.go
  • shortcuts/mail/shortcuts.go
  • skill-template/domains/mail.md
  • skills/lark-mail/SKILL.md
  • skills/lark-mail/references/lark-mail-rules.md

Comment thread shortcuts/mail/mail_rule_reorder_test.go
Comment thread shortcuts/mail/mail_rule_reorder.go Outdated
Comment thread shortcuts/mail/mail_rule_reorder.go Outdated
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add yangr-happy/cli#feat/1759d14 -y -g

yangr-happy and others added 2 commits August 8, 2026 17:57
Restrict the reorder shortcut to user auth, reject malformed rule list payloads, and assert typed error contracts in tests.

Change-Type: ci-fix

Co-authored-by: TRAE CLI <noreply@bytedance.com>
The sequence parser returns intermediate detail that fetchMailRulesForReorder wraps into the typed invalid_response error contract.

Change-Type: ci-fix

Co-authored-by: TRAE CLI <noreply@bytedance.com>
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