feat: add whoami command showing effective identity#1666
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new Changeswhoami command implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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.
Actionable comments posted: 3
🤖 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/whoami/whoami_test.go`:
- Around line 210-223: Strengthen TestWhoami_RejectsInvalidAs to assert the
typed validation contract instead of only checking for a non-nil error. After
cmd.Execute() fails, verify errs.ProblemOf(err) returns the expected validation
category/subtype for the --as path, and use errors.As(err, &ve) to assert
ve.Param equals "--as" since ProblemOf does not expose Param. Keep the test
anchored on NewCmdWhoami and cmd.Execute so it only passes for the intended
validation failure, not unrelated errors.
- Around line 225-236: The config error test only checks that cmd.Execute()
returns some error, so it does not prove the f.Config() failure is preserved.
Update TestWhoami_ConfigErrorPropagates in whoami_test.go to assert the returned
error matches wantErr using errors.Is or direct equality, and keep the check
centered on NewCmdWhoami and cmd.Execute() so later command failures cannot
satisfy it. If this path wraps structured errors, also verify the preserved
cause/metadata with errs.ProblemOf as required by the test guidelines.
In `@cmd/whoami/whoami.go`:
- Around line 126-138: The bot branch in whoami is mapping the wrong diagnostic
field for token state: update the core.AsBot handling in whoami so
res.TokenStatus comes from diag.Bot.TokenStatus instead of diag.Bot.Status,
matching the user branch’s use of TokenStatus and keeping both JSON and pretty
output correct for bot identity. Keep the existing availability/hint logic in
place and only change the token-status source in the bot result mapping.
🪄 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: 407c0ba5-9d53-4b2f-bc61-9c52592adcc1
📒 Files selected for processing (4)
cmd/build.gocmd/whoami/whoami.gocmd/whoami/whoami_test.goskills/lark-shared/SKILL.md
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1666 +/- ##
==========================================
+ Coverage 74.71% 74.73% +0.02%
==========================================
Files 810 811 +1
Lines 81839 81965 +126
==========================================
+ Hits 61142 61260 +118
- Misses 16131 16137 +6
- Partials 4566 4568 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@ac6b8103831cf1a5a3168b7a82e3010d0c67efcd🧩 Skill updatenpx skills add larksuite/cli#feat/whoami -y -g |
Summary
Add a top-level
lark-cli whoamicommand that shows, in one glance, theidentity the next API call will actually use, together with the active profile,
app, and local token status.
Unlike
auth status(which emits JSON for both identities and reports the firstavailable one),
whoamireports the effective identity resolved through thesame logic real API calls use (
--as, default-as, strict-mode, auto-detect).For example, when a user is logged in but default-as is
bot,auth statusshows
userwhilewhoamicorrectly showsbot. Output is human-readable bydefault, with
--jsonfor scripts and agents.The command is local-only: it makes no network calls.
Changes
cmd/whoamipackage with thewhoamicommand (Risk:read).--as user|bot(preview a specific identity) and--json.Factory.ResolveAsandidentitydiag.Diagnose(local,verify=false),and validates the resolved identity via
CheckIdentity, consistent with theapi/service/shortcut commands — an unsupported
--asvalue now returns a clearvalidation error instead of being echoed back.
cmd/build.go.whoamiin the lark-shared identity guide.Test Plan
cmd/whoami/whoami_test.go: pure mapping functions, Factoryintegration (bot identity), and rejection of invalid
--asvalues.make build,go vet ./..., and the full unit + integration suite pass.--jsonoutput for bot identity; emptyconfig reports
not_configured; not-logged-in user shows an actionable hint;invalid
--asreturns a validation error.Related Issues
N/A
Summary by CodeRabbit
New Features
lark-cli whoamito display the effective identity used for the next API call, including active profile, app/brand info, and token availability/status.--json(including user/bot-specific details, and omits user fields for bot identity).Documentation
whoamicommand and notes for using--json.