Skip to content

feat: add whoami command showing effective identity#1666

Merged
liangshuo-1 merged 5 commits into
mainfrom
feat/whoami
Jun 30, 2026
Merged

feat: add whoami command showing effective identity#1666
liangshuo-1 merged 5 commits into
mainfrom
feat/whoami

Conversation

@maojinze7-prog

@maojinze7-prog maojinze7-prog commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a top-level lark-cli whoami command that shows, in one glance, the
identity 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 first
available one), whoami reports the effective identity resolved through the
same 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 status
shows user while whoami correctly shows bot. Output is human-readable by
default, with --json for scripts and agents.

The command is local-only: it makes no network calls.

Changes

  • New cmd/whoami package with the whoami command (Risk: read).
  • Flags: --as user|bot (preview a specific identity) and --json.
  • Reuses Factory.ResolveAs and identitydiag.Diagnose (local, verify=false),
    and validates the resolved identity via CheckIdentity, consistent with the
    api/service/shortcut commands — an unsupported --as value now returns a clear
    validation error instead of being echoed back.
  • Register the command in cmd/build.go.
  • Document whoami in the lark-shared identity guide.

Test Plan

  • Unit tests in cmd/whoami/whoami_test.go: pure mapping functions, Factory
    integration (bot identity), and rejection of invalid --as values.
  • make build, go vet ./..., and the full unit + integration suite pass.
  • Manual checks: human-readable and --json output for bot identity; empty
    config reports not_configured; not-logged-in user shows an actionable hint;
    invalid --as returns a validation error.

Related Issues

N/A

Summary by CodeRabbit

  • New Features

    • Added lark-cli whoami to display the effective identity used for the next API call, including active profile, app/brand info, and token availability/status.
    • Supports human-readable output and --json (including user/bot-specific details, and omits user fields for bot identity).
  • Documentation

    • Updated the authentication quick-reference to include the new whoami command and notes for using --json.

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bce5139a-54ed-4093-a567-b3a69a027426

📥 Commits

Reviewing files that changed from the base of the PR and between 8db7d31 and ac6b810.

📒 Files selected for processing (1)
  • cmd/whoami/whoami_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/whoami/whoami_test.go

📝 Walkthrough

Walkthrough

Adds a new lark-cli whoami subcommand that reports the effective CLI identity, token status, and local profile/app/brand context. It resolves identity from --as and local config, and can print either human-readable text or JSON.

Changes

whoami command implementation

Layer / File(s) Summary
Data structs, command wiring, and registration
cmd/whoami/whoami.go, cmd/build.go
whoamiResult and Options are defined; the Cobra command is wired with --as/--json flags and added to the root command tree.
Run logic, source resolution, and result building
cmd/whoami/whoami.go
whoamiRun loads config and resolves identity; resolveSource applies the precedence rules; buildResult maps bot/user diagnostics into the output; formatPretty renders the text form.
Unit and integration tests
cmd/whoami/whoami_test.go
Tests cover source precedence, result mapping for user and bot states, pretty output formatting, JSON execution, invalid --as handling, and config error propagation.
SKILL.md usage guidance
skills/lark-shared/SKILL.md
A quick-reference row is added for lark-cli whoami, including --json usage and contrast with auth status --json --verify.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size/M

Suggested reviewers

  • albertnusouo
  • liangshuo-1

Poem

🐰 Hop hop, a name appears,
Who am I? The rabbit cheers.
Bot or user, JSON bright,
Token status in plain sight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.41% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding a whoami command for effective identity.
Description check ✅ Passed The description matches the required template and includes summary, changes, test plan, and related issues.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/whoami

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 22108c3 and f9bb148.

📒 Files selected for processing (4)
  • cmd/build.go
  • cmd/whoami/whoami.go
  • cmd/whoami/whoami_test.go
  • skills/lark-shared/SKILL.md

Comment thread cmd/whoami/whoami_test.go
Comment thread cmd/whoami/whoami_test.go
Comment thread cmd/whoami/whoami.go
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.23810% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.73%. Comparing base (ebb0b6f) to head (ac6b810).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
cmd/whoami/whoami.go 95.18% 3 Missing and 1 partial ⚠️
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.
📢 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

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/whoami -y -g

@liangshuo-1
liangshuo-1 merged commit fb04275 into main Jun 30, 2026
53 of 55 checks passed
@liangshuo-1
liangshuo-1 deleted the feat/whoami branch June 30, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants