Skip to content

Complete mail rule reorder rule ID requests#1656

Open
sysuljx wants to merge 2 commits into
larksuite:mainfrom
sysuljx:feat/7442359
Open

Complete mail rule reorder rule ID requests#1656
sysuljx wants to merge 2 commits into
larksuite:mainfrom
sysuljx:feat/7442359

Conversation

@sysuljx

@sysuljx sysuljx commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Adds request preparation for mail user mailbox rule reordering so callers can provide a partial rule_ids ordering while the CLI sends the full ordered list required by the API.

  • Fetches the current mailbox rules before reorder requests and appends omitted rules after the requested ordering.
  • Validates missing, duplicate, unknown, or malformed rule_ids before sending the reorder request.
  • Covers completion, dry-run, and validation behavior with service command tests.

Summary by CodeRabbit

  • New Features
    • Added support for reordering mailbox rules, automatically completing partial rule_ids using the current mailbox order.
    • Preserves the requested rule_ids order and appends any remaining rules.
  • Bug Fixes
    • Added validation to reject duplicate or unknown rule_ids before any reorder call.
    • Enhanced --dry-run output to display the completed rule_ids.
  • Refactor
    • Improved internal request handling by initializing the API client only when needed.
  • Tests
    • Added coverage for successful, partial, unknown/duplicate, and --dry-run scenarios.

@coderabbitai

coderabbitai Bot commented Jun 29, 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

Run ID: 7cdc72c9-575b-42ae-bb94-fa24df8d39f2

📥 Commits

Reviewing files that changed from the base of the PR and between 42837c1 and ce2f7ea.

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

📝 Walkthrough

Walkthrough

Adds pre-request preparation for the mail.user_mailbox.rules.reorder CLI command: the command now validates and completes rule_ids by fetching the current rule list, and serviceMethodRun lazily initializes the API client around that preparation flow. Tests cover partial, complete, unknown, duplicate, and dry-run cases.

Changes

Mail Rule Reorder Pre-request Preparation

Layer / File(s) Summary
Lazy API client and preparation dispatch in serviceMethodRun
cmd/service/service.go
ac is created only when request preparation is needed, and is lazily initialized later if still nil.
Reorder dispatch, validation, merging, and URL helpers
cmd/service/mail_rule_reorder.go
Adds the reorder schema dispatcher, validated rule_ids parsing, list-response extraction, ID merging, and list-URL derivation.
Tests for partial, complete, unknown, duplicate, and dry-run cases
cmd/service/mail_rule_reorder_test.go
Adds HTTP stubs, helpers, and test coverage for completed IDs, preserved order, validation failures, and dry-run output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hop through rules in a tidy line,
Fetch the list, and all the IDs align.
If one is missing, the command says no,
Dry-run still sings the completed show.
A mailbox twirl with ordered flair —
Hoppy little changes, neat and fair!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change, but it omits the required Summary/Changes/Test Plan/Related Issues template sections. Add the template sections with a brief summary, bullet list of changes, a test plan, and related issues status.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 is specific and matches the main change: completing mail rule reorder requests.
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 the size/L Large or sensitive change across domains or core paths label Jun 29, 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: 4

🤖 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_rule_reorder_test.go`:
- Around line 73-77: The test helper executeMailRuleReorder currently creates a
real cmdutil.TestFactory without isolating CLI config state, which can leak
between tests and make results order-dependent. Update this helper in
mail_rule_reorder_test.go to sandbox LARKSUITE_CLI_CONFIG_DIR by setting it with
t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) before calling
cmdutil.TestFactory, so each test runs with its own config directory.
- Around line 105-116: The helper in requireValidationError currently only
checks err.Error() text, which is too weak for these error-path tests. Update it
to assert typed validation metadata using errs.ProblemOf on the returned
*errs.ValidationError, and keep errors.As only to confirm the error is a
ValidationError when Param also needs to be verified. Replace the substring
match with explicit checks for the expected category, subtype, and param fields
so regressions in the typed error contract are caught.
- Around line 154-168: The dry-run assertion in
TestMailRuleReorderDryRunListsAndPrintsCompletedBody only checks that the
emitted payload contains the expected rule_ids values, not that their order is
preserved. Update the test to inspect the completed output from
executeMailRuleReorder and assert the exact sequence of IDs in order, using the
existing TestMailRuleReorderDryRunListsAndPrintsCompletedBody and
mailRuleListStub helpers so it fails if IDs are reordered or extra IDs are
appended.

In `@cmd/service/mail_rule_reorder.go`:
- Around line 49-62: The validation errors in mail_rule_reorder are tagging the
wrong parameter; update the .WithParam usage in the reorder validation branch so
it reports the nested input as --data.rule_ids instead of rule_ids. Make the
same metadata adjustment for the related error-path assertions in the mail rule
reorder tests, and use the existing mail rule reorder validation logic and error
construction in cmd/service/mail_rule_reorder.go as the reference points.
🪄 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: 2cd7b1a9-7626-4553-b8b8-6785dcbe69d8

📥 Commits

Reviewing files that changed from the base of the PR and between ebb0b6f and 42837c1.

📒 Files selected for processing (3)
  • cmd/service/mail_rule_reorder.go
  • cmd/service/mail_rule_reorder_test.go
  • cmd/service/service.go

Comment thread cmd/service/mail_rule_reorder_test.go
Comment thread cmd/service/mail_rule_reorder_test.go Outdated
Comment thread cmd/service/mail_rule_reorder_test.go Outdated
Comment thread cmd/service/mail_rule_reorder.go Outdated
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add sysuljx/cli#feat/7442359 -y -g

@sysuljx

sysuljx commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 AI Review | CR 汇总 | 可合入(未发现问题)

增量审查:基于已有 4 条行级评论(均已在最新提交中标记解决),本次重点复核 mail.user_mailbox.rules.reorder 的请求预处理、rule_ids 补齐顺序、重复/未知输入校验、dry-run 输出和结构化错误元数据,未发现新的 P0-P3 问题。

验证:go test ./cmd/service -run MailRuleReorder -count=1go test ./cmd/service -count=1 均通过。

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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