feat(mail): unknown-flag fuzzy-match for lark-cli mail domain#806
Conversation
|
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 (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughAdds mail-specific unknown-flag error detection and suggestion generation. A new ChangesMail Flag Suggestion Error Handler
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #806 +/- ##
==========================================
+ Coverage 65.46% 65.85% +0.39%
==========================================
Files 510 517 +7
Lines 47129 48761 +1632
==========================================
+ Hits 30851 32113 +1262
- Misses 13607 13885 +278
- Partials 2671 2763 +92 ☔ 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@4dbbe72a6e5d49960e4cca0203dc48053a64fdc2🧩 Skill updatenpx skills add xzcong0820/larksuite-cli#harness/01kr5edze944jyrxcn6m99jcd1 -y -g |
5ae9c2d to
d271bf3
Compare
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/register_test.go`:
- Around line 357-363: The test currently only checks that returned error isn't
an *output.ExitError; additionally assert that the FlagErrorFunc is identity by
verifying the exact pointer is returned: call baseCmd.FlagErrorFunc()(baseCmd,
in) (already assigned to got) and assert got == in (pointer equality) to ensure
pass-through; update the test around the variables got and in (and the
FlagErrorFunc invocation) to include this equality check so any
wrapper/regression will fail.
🪄 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: d918f259-9a3a-4b2d-ab83-caca250b3df7
📒 Files selected for processing (4)
shortcuts/mail/flag_suggest.goshortcuts/mail/flag_suggest_test.goshortcuts/register.goshortcuts/register_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- shortcuts/register.go
- shortcuts/mail/flag_suggest.go
d271bf3 to
35745b5
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/flag_suggest_test.go`:
- Around line 65-80: TestSuggest_TopNAndStableSort never exercises top-N or
tie-break because unknown == "zzz" yields distances > levThreshold so suggest
returns empty; change the test so the unknown token (or the test names) produce
Levenshtein distances <= levThreshold for all candidates and equal among them so
suggest("...", names) returns a non-empty slice and exercises the cap and
lexicographic tie-break; update the string passed to suggest in
TestSuggest_TopNAndStableSort (or adjust the flagName entries) to a value within
levThreshold so the assertions on maxCandidates and stable sorting actually run.
In `@shortcuts/mail/flag_suggest.go`:
- Around line 72-84: The detail map may set "candidates" to a nil slice when
collectFlags(c) returns no entries because suggest or suggestShorthand can
return nil; change the construction so that matches is always a non-nil empty
slice before building detail (e.g., after calling suggest/suggestShorthand, if
matches == nil then set matches = []Candidate{}), so the "candidates" field in
the detail map is always emitted as an array; update references around
collectFlags(c), suggestShorthand(token, names), suggest(token, names), and the
detail variable accordingly.
🪄 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: c6beea24-3251-4623-9a5a-dd63dee4d561
📒 Files selected for processing (4)
shortcuts/mail/flag_suggest.goshortcuts/mail/flag_suggest_test.goshortcuts/register.goshortcuts/register_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- shortcuts/register.go
- shortcuts/register_test.go
Adds shortcuts/mail/flag_suggest.go (~120 LOC) implementing a cobra
FlagErrorFunc hook for the mail subcommand tree. On 'unknown flag: --X'
or 'unknown shorthand flag: "X" in -X', it collects flags from the
current command via cmd.Flags().VisitAll, runs bidirectional prefix
match + Levenshtein DP (threshold=max(1,len/3+1), cap 4), and returns
top-5 candidates inside the existing ErrorEnvelope JSON:
error.type = "unknown_flag"
error.detail.{unknown, command_path, candidates}
error.detail.candidates[*] = {flag, shorthand, distance, reason}
Exit code stays 1 (ExitAPI), not ExitValidation - no breaking change for
CI/agent scripts that check non-zero exit. stderr switches from plain
'Error: unknown flag: --X' to JSON envelope, aligning with the existing
'errors = JSON envelope on stderr' convention; mail unknown-flag was the
last gap.
Scope is strictly the mail subcommand tree: shortcuts/register.go gains
a single 'if service == "mail" { mail.InstallOnMail(svc) }' branch
after the existing Mount loop. Other domains (calendar / im / api /
auth / ...) keep cobra's default FlagErrorFunc and unchanged plain-text
stderr behavior.
Covers:
- shortcuts/mail/flag_suggest.go (new, ~120 LOC)
- shortcuts/mail/flag_suggest_test.go (new, 12 table-driven tests)
- shortcuts/register.go (+3 lines after mail Mount loop)
No changes to cmd/root.go or internal/output/* - ErrDetail.Detail is
already interface{}, handleRootError already routes *ExitError via
WriteErrorEnvelope.
35745b5 to
4dbbe72
Compare
Adds a per-shortcut FlagHints map (common/types.go) that lets mail shortcuts declare known flag aliases (e.g. "recipient" → "to"). At mount time, runner.go serialises FlagHints into cmd.Annotations so the data is accessible at error-handling time without creating a circular import between common and mail. mail/flag_suggest.go's flagSuggestErrorFunc gains a Priority-0 path that reads the hint map from cmd.Annotations and inserts the exact-match target as candidates[0] with reason="hint" and distance=0, before the existing prefix + Levenshtein fallback. The hint target is deduplicated from the suggest() results so it never appears twice. FlagHints is configured on five mail shortcuts: - mail_draft_edit, mail_message, mail_send, mail_thread, mail_triage Output format (candidates[] array, error.type="unknown_flag") is unchanged from PR larksuite#806.
…rksuite#806) Adds shortcuts/mail/flag_suggest.go (~120 LOC) implementing a cobra FlagErrorFunc hook for the mail subcommand tree. On 'unknown flag: --X' or 'unknown shorthand flag: "X" in -X', it collects flags from the current command via cmd.Flags().VisitAll, runs bidirectional prefix match + Levenshtein DP (threshold=max(1,len/3+1), cap 4), and returns top-5 candidates inside the existing ErrorEnvelope JSON: error.type = "unknown_flag" error.detail.{unknown, command_path, candidates} error.detail.candidates[*] = {flag, shorthand, distance, reason} Exit code stays 1 (ExitAPI), not ExitValidation - no breaking change for CI/agent scripts that check non-zero exit. stderr switches from plain 'Error: unknown flag: --X' to JSON envelope, aligning with the existing 'errors = JSON envelope on stderr' convention; mail unknown-flag was the last gap. Scope is strictly the mail subcommand tree: shortcuts/register.go gains a single 'if service == "mail" { mail.InstallOnMail(svc) }' branch after the existing Mount loop. Other domains (calendar / im / api / auth / ...) keep cobra's default FlagErrorFunc and unchanged plain-text stderr behavior. Covers: - shortcuts/mail/flag_suggest.go (new, ~120 LOC) - shortcuts/mail/flag_suggest_test.go (new, 12 table-driven tests) - shortcuts/register.go (+3 lines after mail Mount loop) No changes to cmd/root.go or internal/output/* - ErrDetail.Detail is already interface{}, handleRootError already routes *ExitError via WriteErrorEnvelope.
Generated by the harness-coding skill.
Summary
Adds mail-domain unknown-flag fuzzy-match → JSON ErrorEnvelope with did-you-mean candidates for
lark-cli mail. Strictly scoped toshortcuts/mail/+ a 1-line branch inshortcuts/register.go; non-mail domains are untouched. Exit code is unchanged (still1viaExitAPI, notExitValidation) — no breaking change to callers parsing exit codes.3 files changed, 508 insertions:
shortcuts/mail/flag_suggest.go— implementation (InstallOnMail,parseUnknownToken,collectFlags,suggestw/ prefix + Levenshtein DP,suggestShorthand,buildHint).shortcuts/mail/flag_suggest_test.go— 12 table-driven tests covering prefix / Levenshtein / hidden-skipped / top-N stable sort / shorthand exact + prefix fallback / parse regex / errorFunc pass-through / exit-code regression.shortcuts/register.go— +3 lines:if service == "mail" { mail.InstallOnMail(svc) }after the mount loop.Sprints
Source specs
This MR was created autonomously. Quality gates were enforced by the repo's own pre-commit hooks.
Summary by CodeRabbit
New Features
Behavior
Tests