fix(service): advertise only supported identities in --as help - #2257
fix(service): advertise only supported identities in --as help#2257Pr1p wants to merge 2 commits into
Conversation
API method commands now derive --as help text and shell completion from their declared identities, matching the CheckIdentity runtime check. Restricted methods no longer advertise unsupported identities. Fixes larksuite#2206.
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesIdentity restrictions
Estimated code review effort: 2 (Simple) | ~15 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/cmdutil/identity_flag_test.go (1)
19-34: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winTest completion and the non-nil empty restriction.
These tests assert only flag usage text.
AddAPIIdentityFlagalso changesascompletion values and distinguishesnilfrom a non-nil empty list. A regression in either behavior will pass this suite.Invoke the registered
ascompletion callback. Assert unrestricted, user-only, bot-only, and empty-list results directly.As per coding guidelines, “Every behavior change must have an accompanying test, and contract tests must assert the changed field or behavior directly.”
Also applies to: 57-102
🤖 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 19 - 34, Expand the tests for AddAPIIdentityFlag to invoke the registered as completion callback and directly assert its results for nil (unrestricted), user-only, bot-only, and non-nil empty restrictions. Verify that nil and an empty list produce distinct completion behavior, while retaining the existing visibility, default-value, and usage assertions.Source: Coding guidelines
🤖 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.
Outside diff comments:
In `@internal/cmdutil/identity_flag_test.go`:
- Around line 19-34: Expand the tests for AddAPIIdentityFlag to invoke the
registered as completion callback and directly assert its results for nil
(unrestricted), user-only, bot-only, and non-nil empty restrictions. Verify that
nil and an empty list produce distinct completion behavior, while retaining the
existing visibility, default-value, and usage assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f0a57659-09ad-4c38-8a47-1d15c49e0a2b
📒 Files selected for processing (6)
cmd/api/api.gocmd/service/service.gocmd/service/service_test.gocmd/whoami/whoami.gointernal/cmdutil/identity_flag.gointernal/cmdutil/identity_flag_test.go
Addresses the CodeRabbit review on larksuite#2257: invoke the registered --as completion callback and assert unrestricted (user | bot), user-only, bot-only, and non-nil empty restriction results, including the nil vs empty distinction.
Summary
API method commands registered the
--asflag with a hardcoded "identity type: user | bot" help string even when the method metadata restricts identity (e.g.mail user_mailbox.drafts createonly supports user). The--ashelp and shell completion are now derived from the method's declared identities, keeping--helpin sync with the runtimeCheckIdentityvalidation.Changes
internal/cmdutil:AddAPIIdentityFlagaccepts a supported-identity list; nil keeps the unrestricted default (user | bot), a non-nil slice is rendered verbatim in help and completion.cmd/service: restricted API method commands pass their declared identities when registering--as; unrestricted methods keep the default.cmd/api,cmd/whoami: explicitly keep the unrestricteduser | botshape.Test Plan
go test ./internal/cmdutil ./cmd/service ./cmd/api ./cmd/whoamigo vetpasses on the affected packagesgofmtcleangolangci-lint run --new-from-rev=origin/mainreports 0 issueslark-cli mail user_mailbox.drafts create --helpflow showsidentity type: useronlyRelated Issues
--as botbut the command rejects it #2206Summary by CodeRabbit
New Features
Bug Fixes
Tests