feat(mail): bot+mailbox=me validation and dynamic --as help tests#895
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds tests for ChangesBot identity and mailbox validation
Sequence DiagramsequenceDiagram
participant CLI as CLI Command
participant Shortcut as Shortcut (e.g., MailMessage)
participant Validate as validateBotMailboxNotMe
participant Runtime as RuntimeContext
participant Output as ExitError
CLI->>Shortcut: invoke with flags (`--as`, `--mailbox`)
Shortcut->>Validate: call validateBotMailboxNotMe(runtime)
Validate->>Runtime: inspect runtime.IsBot() and resolved mailbox
alt mailbox == "me" and runtime.IsBot()
Validate->>Output: return ExitValidation error (message about explicit email)
Output->>CLI: validation error returned
else valid
Validate->>Shortcut: return nil
Shortcut->>CLI: continue to DryRun/Execute
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
internal/cmdutil/identity_flag_test.go (2)
71-89: 💤 Low valueConsider 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.Hiddenis 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 valueConsider adding visibility and default value checks for consistency.
The test properly validates the usage text, but existing tests (lines 63-68) also verify
flag.Hiddenis 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
📒 Files selected for processing (7)
internal/cmdutil/identity_flag_test.goshortcuts/mail/helpers.goshortcuts/mail/mail_message.goshortcuts/mail/mail_messages.goshortcuts/mail/mail_shortcut_validation_test.goshortcuts/mail/mail_thread.goshortcuts/mail/mail_triage.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #895 +/- ##
==========================================
+ Coverage 65.90% 67.19% +1.29%
==========================================
Files 520 569 +49
Lines 49274 53530 +4256
==========================================
+ Hits 32474 35970 +3496
- Misses 14026 14544 +518
- Partials 2774 3016 +242 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@677f79333a70e4aefeb064359bf10fe092bca3a9🧩 Skill updatenpx skills add xzcong0820/larksuite-cli#feat/831a0c0 -y -g |
There was a problem hiding this comment.
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/mail_template_update.go`:
- Around line 85-90: In the Validate function, skip mailbox validation when the
local-only flag is set by checking runtime.Bool("print-patch-template") before
calling validateBotMailboxNotMe; either move the existing if
runtime.Bool("print-patch-template") early or add a guard so
validateBotMailboxNotMe(runtime) is not invoked when
runtime.Bool("print-patch-template") is true, referencing the Validate function
and validateBotMailboxNotMe and the "print-patch-template" runtime flag.
🪄 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: e537865a-6870-4d3c-b358-cfdafbe4ca02
📒 Files selected for processing (2)
shortcuts/mail/mail_template_create.goshortcuts/mail/mail_template_update.go
…rksuite#895) * feat(mail): bot+mailbox=me validation and dynamic --as help tests 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 * test(cmdutil): add Hidden and DefValue assertions to identity flag tests * fix(mail): add bot+mailbox=me validation to +template-create and +template-update * fix(mail): add bot+mailbox=me validation to +template-update * fix(mail): gofmt mail_template_create.go * fix(mail): gofmt mail_template_update.go * fix(mail): skip bot+mailbox=me check for print-patch-template local path
Summary
Add cross-field validation that rejects the combination of
--as botwith the default--mailbox me, and add tests verifying the--asflag usage text reflects the supported identity types dynamically.Changes
shortcuts/mail/helpers.go: addvalidateBotMailboxNotMehelper — returns a structured validation error when bot identity is used withmailbox=me, which cannot be resolved under a tenant access tokenshortcuts/mail/mail_message.go,mail_messages.go,mail_thread.go,mail_triage.go: wirevalidateBotMailboxNotMeinto theValidatehook of each shortcutshortcuts/mail/mail_shortcut_validation_test.go: 9 unit tests covering bot+me rejection and explicit-mailbox / user-identity pass-through for all four shortcutsinternal/cmdutil/identity_flag_test.go: 2 unit tests verifying--asusage text rendersidentity type: useroridentity type: user | botaccording to the declaredAuthTypesTest Plan
go test ./shortcuts/mail/... ./internal/cmdutil/...)lark-cli mail +message --as bot(no explicit mailbox) exits 2 with validation errorlark-cli mail +message --as bot --mailbox alice@example.compasses validationlark-cli mail +watch --helpshowsidentity type: useronlylark-cli mail +message --helpshowsidentity type: user | botRelated Issues
Summary by CodeRabbit
Bug Fixes
Tests