Skip to content

Complete mail rule reorder IDs - #2312

Open
yangr-happy wants to merge 3 commits into
larksuite:mainfrom
yangr-happy:feat/58b8374
Open

Complete mail rule reorder IDs#2312
yangr-happy wants to merge 3 commits into
larksuite:mainfrom
yangr-happy:feat/58b8374

Conversation

@yangr-happy

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

Copy link
Copy Markdown
Collaborator

Complete mail rule reorder IDs

Fetch the current mailbox rule list before running the generated reorder command, complete partial rule_id input locally, and reject invalid inputs before making the write call.

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

Summary by CodeRabbit

  • New Features

    • Mail rules can now be reordered by specifying rule IDs; remaining rules are completed automatically.
    • Supports rule lists spanning multiple pages, with safeguards against excessive or repeated pagination.
    • Invalid, empty, duplicate, unknown, or incomplete rule IDs are rejected before submission.
    • Failed reorder requests now include a retry hint.
  • Documentation

    • Added examples and guidance for reordering mail rules, including partial rule ID handling.

Fetch the current mailbox rule list before running the generated reorder command, complete partial rule_id input locally, and reject invalid inputs before making the write call.

Co-authored-by: TRAE CLI <noreply@bytedance.com>
@github-actions github-actions Bot added domain/mail PR touches the mail domain size/L Large or sensitive change across domains or core paths labels Aug 12, 2026
@coderabbitai

coderabbitai Bot commented Aug 12, 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: 5cec73b1-8e2a-4046-9b07-2d03bdde13fd

📥 Commits

Reviewing files that changed from the base of the PR and between 76744e5 and 0cd80b0.

📒 Files selected for processing (2)
  • cmd/service/mail_rules_reorder_test.go
  • cmd/service/service.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/service/service.go

📝 Walkthrough

Walkthrough

The mail rule reorder command now fetches all rule IDs, validates requested IDs, completes partial orders, submits the full order, handles pagination, and adds retry guidance for reorder failures. Tests and documentation cover the new behavior.

Changes

Mail rule reorder flow

Layer / File(s) Summary
Fetch and validate current rules
cmd/service/service.go, cmd/service/mail_rules_reorder_test.go
The service validates request bodies and retrieves all current rule IDs through paginated list responses. Tests cover malformed input, list failures, and invalid pagination.
Complete reorder request
cmd/service/service.go, cmd/service/mail_rules_reorder_test.go
The service rejects invalid IDs, preserves requested order, appends omitted rules, and adds a retry hint to reorder failures. Tests verify submission ordering and failure handling.
Verify command flow and documentation
cmd/service/mail_rules_reorder_test.go, skills/lark-mail/references/lark-mail-rules.md
Tests cover command setup, ID completion, empty lists, validation, pagination, and error classification. Documentation describes partial rule ordering.

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

Sequence Diagram(s)

sequenceDiagram
  participant MailRuleCommand
  participant MailRuleListAPI
  participant MailRuleReorderAPI
  MailRuleCommand->>MailRuleListAPI: Fetch all current rule IDs
  MailRuleListAPI-->>MailRuleCommand: Return paginated rule IDs
  MailRuleCommand->>MailRuleCommand: Validate and complete requested order
  MailRuleCommand->>MailRuleReorderAPI: Submit completed rule IDs
  MailRuleReorderAPI-->>MailRuleCommand: Return response or retry error
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the main change but omits the required Changes, Test Plan, and Related Issues sections. Add the required sections and document the changes, test results, manual verification, and related issues.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: completing mail rule reorder IDs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@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: 5

🤖 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 `@cmd/service/mail_rules_reorder_test.go`:
- Around line 48-50: Before the cmdutil.TestFactory call in the shared
command-test setup, set LARKSUITE_CLI_CONFIG_DIR to t.TempDir() using t.Setenv
so every test in the file uses an isolated CLI configuration directory.
- Around line 121-125: Update the error assertions in the reorder tests,
including the cases around the shown and additionally referenced blocks, to
inspect errs.ProblemOf(err) metadata instead of matching error strings; for
validation failures, also assert *errs.ValidationError.Param. Track reorder
invocations with an explicit counter rather than relying on “no stub” text, and
verify wrapped causes using errors.Is or errors.As.

In `@cmd/service/service.go`:
- Around line 517-520: Remove the page_token entry from the params map before
the initial list request in the reorder flow, while preserving other
caller-supplied parameters. Add a regression test covering reorder parameters
that include page_token and verify the first CallAPI list request is sent
without that token.
- Around line 469-479: Add command-level regression tests for the local body
validation around serviceStringSlice and rule_ids, covering missing rule_ids, an
empty array, an empty ID, and a non-string ID. Assert each returns the expected
typed validation metadata, and verify neither list nor reorder is invoked for
invalid input.
- Around line 557-565: Update the pagination loop around nextPageToken to track
previously seen non-empty continuation tokens, and return
errs.NewInternalError(errs.SubtypeInvalidResponse, ...) when nextToken has
already been encountered. Preserve the existing missing-token validation and
normal page_token assignment for new tokens.
🪄 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: bdce4a15-26b6-4aaf-90d4-52b005049881

📥 Commits

Reviewing files that changed from the base of the PR and between fd97039 and fef57ab.

📒 Files selected for processing (3)
  • cmd/service/mail_rules_reorder_test.go
  • cmd/service/service.go
  • skills/lark-mail/references/lark-mail-rules.md

Comment thread cmd/service/mail_rules_reorder_test.go
Comment thread cmd/service/mail_rules_reorder_test.go
Comment thread cmd/service/service.go
Comment thread cmd/service/service.go
Comment thread cmd/service/service.go
@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add yangr-happy/cli#feat/58b8374 -y -g

Reset list pagination before completing reorder IDs, reject repeated list page tokens, and cover local validation with typed error assertions.

Change-Type: ci-fix

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

@yangr-happy yangr-happy left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

提交已有草稿回复,释放后续审查评论。

Comment thread cmd/service/service.go
Comment thread cmd/service/mail_rules_reorder_test.go
Comment thread cmd/service/service.go
Comment thread cmd/service/service.go Outdated
Comment thread cmd/service/service.go
Limit internal mail rules pagination before reorder and treat an empty current rule list as rule_ids validation failure.

Change-Type: ci-fix
Co-authored-by: TRAE CLI <noreply@bytedance.com>

@yangr-happy yangr-happy left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 AI Review | CR 汇总 | 有风险(2 个 P2)

增量审查:基于既有已解决评论,本次新增 2 条正确性问题。请优先修复内部 list 参数透传问题,并让 dry-run 不再展示与真实执行不一致的 reorder 请求。

Comment thread cmd/service/service.go
for k, v := range reorderRequest.Params {
params[k] = v
}
delete(params, "page_token")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 AI Review | [P2 正确性] 内部 list 仍会继承外部 page_size

fetchAllMailRuleIDs 只删除了透传进 reorder 的 page_token,但 page_size 仍会从 --params 原样带到内部 list 请求。生成式 service 命令会保留 undeclared params,所以用户如果传入 {"user_mailbox_id":"me","page_size":1},补齐前的 list 会按 1 条/页拉取;当邮箱规则数超过 100 条时会撞上新增的硬上限并返回 invalid_response,无法完成“拉全并补齐 rule_ids”的目标。

修复建议: 构造内部 list 参数时同时移除外部 page_size,或显式设置一个受控的较大 page size;补充带 page_size:1 的回归测试,验证首个 list 请求不携带该值并仍按返回 token 拉全。

如有疑问或认为判断不准确,欢迎直接回复讨论。

Comment thread cmd/service/service.go
return err
}

if err := prepareMailRuleReorder(opts.Ctx, ac, opts, &request); err != nil {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 AI Review | [P2 正确性] dry-run 展示的请求与真实执行不一致

--dry-run 分支在这里之前已经返回,因此 mail rules reorder 的预览仍只显示用户输入的 partial rule_ids,例如 ["C"];真实执行同一命令会先 GET list,并把 POST body 改写成完整顺序,例如 ["C","A","B"]。这个仓库把 dry-run 作为写操作请求结构验证手段,当前输出会误导用户或自动化审计,以为真实写请求仍是不完整列表。

修复建议: 为该 schema 定制 dry-run:至少在预览中声明真实执行会先 list 并动态补齐 rule_ids,或输出两步计划(GET rules + POST reorder,POST body 标注为运行时补齐)。同时补一个 dry-run 用例,防止预览继续宣称会直接提交 partial body。

如有疑问或认为判断不准确,欢迎直接回复讨论。

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/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant