Skip to content

feat(mail): bot+mailbox=me validation and dynamic --as help tests#895

Open
xzcong0820 wants to merge 1 commit into
larksuite:mainfrom
xzcong0820:feat/831a0c0
Open

feat(mail): bot+mailbox=me validation and dynamic --as help tests#895
xzcong0820 wants to merge 1 commit into
larksuite:mainfrom
xzcong0820:feat/831a0c0

Conversation

@xzcong0820
Copy link
Copy Markdown
Collaborator

@xzcong0820 xzcong0820 commented May 14, 2026

Generated by the harness-coding skill.

  • Branch: feat/831a0c0
  • Target: main

Sprints

ID Title Status Commit
S1 Synthesize transport contract for larksuite/cli passed
S2 --as help text dynamic + bot+me cross-field validation passed 74234de

Source specs

  • tech-design.md

This MR was created autonomously. Quality gates were enforced by the repo's own pre-commit hooks.

Summary by CodeRabbit

Release Notes

  • Improvements

    • Mail commands now include validation requiring bots to specify an explicit mailbox instead of using the default option.
  • Tests

    • Added validation tests for mail commands to verify mailbox requirements across different identity types.

Review Change Stack

Add validateBotMailboxNotMe helper to shortcuts/mail/helpers.go and
wire it as a Validate callback into +message, +messages, +thread and
+triage, so bot identity combined with the default --mailbox me is
rejected early with a clear fixup hint instead of a late opaque API
error.

The --as help text was already dynamic via AddShortcutIdentityFlag;
add TC-10/TC-11 tests in internal/cmdutil/identity_flag_test.go to
pin that behaviour, and TC-1 through TC-9 in
shortcuts/mail/mail_shortcut_validation_test.go to cover the new
Validate callbacks.

+watch is excluded: its AuthTypes is ["user"], so bot is never valid.

sprint: S2
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

📝 Walkthrough

Walkthrough

This PR improves bot identity handling in the CLI. It adds identity flag usage formatting tests for the --as flag, implements a validation helper to prevent bots from using the default me mailbox, wires that validation into four mail shortcuts, and covers the feature with comprehensive tests.

Changes

Bot identity and mailbox validation

Layer / File(s) Summary
Identity flag usage formatting
internal/cmdutil/identity_flag_test.go
Tests verify the --as flag Usage text correctly formats allowed identity types: identity type: user for single type or identity type: user | bot for multiple types.
Bot mailbox validation helper
shortcuts/mail/helpers.go
validateBotMailboxNotMe checks if the runtime is a bot and the mailbox equals "me", returning a structured validation error instructing explicit email address use.
Mailbox validation in mail shortcuts
shortcuts/mail/mail_message.go, shortcuts/mail/mail_messages.go, shortcuts/mail/mail_thread.go, shortcuts/mail/mail_triage.go
Four mail shortcuts (MailMessage, MailMessages, MailThread, MailTriage) each add a Validate hook that invokes the bot mailbox validation helper before execution.
Validation test coverage
shortcuts/mail/mail_shortcut_validation_test.go
Helper assertions assertValidationError and assertValidatePasses plus nine test functions verify each mail shortcut correctly rejects --as bot with default me mailbox and accepts explicit mailbox values or --as user with me.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

domain/mail, size/M

Suggested reviewers

  • chanthuang
  • infeng

Poem

🐰 A bot's mailbox must be explicit,
No "me" for bots—that's too implicit,
Four shortcuts now validate with care,
Flag formatting shows types fair,
Identity and safety everywhere! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provided is auto-generated by a harness tool and lacks the required template sections (Summary, Changes list, Test Plan checklist, Related Issues) specified in the repository template. Rewrite the description following the repository template: add a brief Summary, list main Changes, document the Test Plan with checklist items, and include a Related Issues section.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the two main changes: bot+mailbox=me validation logic and dynamic --as help text tests with TestAddShortcutIdentityFlag additions.
Docstring Coverage ✅ Passed Docstring coverage is 93.75% which is sufficient. The required threshold is 80.00%.
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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@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 May 14, 2026
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 (2)
internal/cmdutil/identity_flag_test.go (2)

71-89: 💤 Low value

Consider adding visibility check for consistency.

The test properly validates the usage text, but existing tests in this file (lines 63-65) also verify that flag.Hidden is false. Adding this check would improve consistency with the established test pattern.

🔍 Optional consistency enhancement
 	if flag == nil {
 		t.Fatal("expected --as flag to be registered")
 	}
+	if flag.Hidden {
+		t.Fatal("expected --as flag to be visible")
+	}
 	wantUsage := "identity type: user"
🤖 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 `@internal/cmdutil/identity_flag_test.go` around lines 71 - 89, The test
TestAddShortcutIdentityFlag_UserOnlyAuthTypes should also assert the flag's
visibility like the other tests: after retrieving the flag via
cmd.Flags().Lookup("as") add a check that flag.Hidden is false (or call
t.Fatalf/t.Errorf with a clear message if it is true) to ensure the --as flag is
not hidden; update this in the test alongside the existing Usage assertions and
reference AddShortcutIdentityFlag and the flag variable for locating the change.

91-106: 💤 Low value

Consider adding visibility and default value checks for consistency.

The test properly validates the usage text, but existing tests (lines 63-68) also verify flag.Hidden is false and the default value is empty. Adding these checks would improve completeness and consistency with the established test pattern.

🔍 Optional consistency enhancement
 	if flag == nil {
 		t.Fatal("expected --as flag to be registered")
 	}
+	if flag.Hidden {
+		t.Fatal("expected --as flag to be visible")
+	}
+	if got := flag.DefValue; got != "" {
+		t.Fatalf("default value = %q, want empty string", got)
+	}
 	wantUsage := "identity type: user | bot"
🤖 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 `@internal/cmdutil/identity_flag_test.go` around lines 91 - 106, The test
TestAddShortcutIdentityFlag_UserBotAuthTypes currently only checks the --as flag
Usage; update it to also assert the flag's visibility and default value by
verifying flag.Hidden is false and flag.Value.String() is empty. Locate the test
function TestAddShortcutIdentityFlag_UserBotAuthTypes and after retrieving flag
:= cmd.Flags().Lookup("as"), add assertions similar to the existing pattern (as
in the other tests around lines 63-68) to check flag.Hidden == false and
flag.Value.String() == "" to ensure consistent coverage for
AddShortcutIdentityFlag.
🤖 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 `@internal/cmdutil/identity_flag_test.go`:
- Around line 71-89: The test TestAddShortcutIdentityFlag_UserOnlyAuthTypes
should also assert the flag's visibility like the other tests: after retrieving
the flag via cmd.Flags().Lookup("as") add a check that flag.Hidden is false (or
call t.Fatalf/t.Errorf with a clear message if it is true) to ensure the --as
flag is not hidden; update this in the test alongside the existing Usage
assertions and reference AddShortcutIdentityFlag and the flag variable for
locating the change.
- Around line 91-106: The test TestAddShortcutIdentityFlag_UserBotAuthTypes
currently only checks the --as flag Usage; update it to also assert the flag's
visibility and default value by verifying flag.Hidden is false and
flag.Value.String() is empty. Locate the test function
TestAddShortcutIdentityFlag_UserBotAuthTypes and after retrieving flag :=
cmd.Flags().Lookup("as"), add assertions similar to the existing pattern (as in
the other tests around lines 63-68) to check flag.Hidden == false and
flag.Value.String() == "" to ensure consistent coverage for
AddShortcutIdentityFlag.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 34c46c79-140e-4b19-89de-318bc743ed12

📥 Commits

Reviewing files that changed from the base of the PR and between 7acf64c and 74234de.

📒 Files selected for processing (7)
  • internal/cmdutil/identity_flag_test.go
  • shortcuts/mail/helpers.go
  • shortcuts/mail/mail_message.go
  • shortcuts/mail/mail_messages.go
  • shortcuts/mail/mail_shortcut_validation_test.go
  • shortcuts/mail/mail_thread.go
  • shortcuts/mail/mail_triage.go

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.09%. Comparing base (7acf64c) to head (74234de).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #895      +/-   ##
==========================================
+ Coverage   65.90%   66.09%   +0.19%     
==========================================
  Files         520      520              
  Lines       49274    49292      +18     
==========================================
+ Hits        32474    32580     +106     
+ Misses      14026    13919     -107     
- Partials     2774     2793      +19     

☔ 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.

@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add xzcong0820/larksuite-cli#feat/831a0c0 -y -g

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