Skip to content

test#1658

Closed
maojinze7-prog wants to merge 0 commit into
mainfrom
feat/whoami-command
Closed

test#1658
maojinze7-prog wants to merge 0 commit into
mainfrom
feat/whoami-command

Conversation

@maojinze7-prog

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

Copy link
Copy Markdown
Collaborator

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new whoami CLI command is added in cmd/whoami/whoami.go with supporting tests. It resolves the effective identity (user, bot, or none) via identitydiag.Diagnose, supports --json and --verify flags, degrades gracefully when config is absent, and is registered on the root command.

Changes

whoami command

Layer / File(s) Summary
Identity resolution, result shape, and rendering
cmd/whoami/whoami.go
effectiveIdentity selects user over bot or falls back to "none"; whoamiResult/buildResult construct the JSON output shape; renderText, userLine, and botLine handle human-readable formatting with per-identity detail lines.
Cobra command wiring and whoamiRun
cmd/whoami/whoami.go
whoamiOptions and NewCmdWhoami define --json/--verify flags with auth check disabled; whoamiRun loads config (degrading to "none" on not-configured errors), calls identitydiag.Diagnose, and routes to JSON or text output.
Unit and integration tests
cmd/whoami/whoami_test.go
Table-driven tests cover effectiveIdentity, buildResult (nil config, verify on/off), renderText scenarios (user, none, bot-only, mixed), whoamiRun (not-configured degradation, error passthrough, JSON/text bot output), and NewCmdWhoami flag metadata.
Root command registration
cmd/build.go
Imports cmd/whoami and registers whoami.NewCmdWhoami(f, nil) on rootCmd.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, who goes there?
A whoami command fills the air,
User or bot, or "none" at best,
JSON or text — it passes the test!
The rabbit knows who's logged in today~ ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.46% 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 clearly names the new whoami command and its main purpose: showing the current effective identity.
Description check ✅ Passed The description covers Summary, Changes, Test Plan, and Related Issues with enough detail to match the template.
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-command

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.

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jun 29, 2026
@maojinze7-prog maojinze7-prog deleted the feat/whoami-command branch June 29, 2026 14:45
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.62921% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.73%. Comparing base (ebb0b6f) to head (8a3276f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
cmd/whoami/whoami.go 96.59% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1658      +/-   ##
==========================================
+ Coverage   74.71%   74.73%   +0.02%     
==========================================
  Files         810      811       +1     
  Lines       81839    81928      +89     
==========================================
+ Hits        61142    61228      +86     
- Misses      16131    16134       +3     
  Partials     4566     4566              

☔ 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

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

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

@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 186-195: The malformed-config test only checks for a non-nil
error, so it can miss regressions in the typed error contract. Update the
`whoamiRun` error-path assertion in `whoami_test.go` to inspect the returned
error with `errs.ProblemOf`, and verify the expected `category` and `subtype`
for the `SubtypeInvalidConfig` case. Keep the existing `whoamiRun` /
`whoamiOptions` setup, but make the test fail if the typed metadata is rewritten
or lost.

In `@cmd/whoami/whoami.go`:
- Around line 140-149: The whoami command currently ignores unexpected
positional arguments instead of rejecting them; update the cobra.Command setup
in whoamiRun/command construction to add Args validation that returns
errs.NewValidationError(errs.SubtypeInvalidArgument, ...) when extra args are
provided. Make sure the validation is wired through the whoami command path so
RunE still calls runF or whoamiRun only after args are checked, and add a test
in whoami_test.go that covers the invalid-argument failure case.
- Around line 143-147: Propagate the Cobra command context through the whoami
execution path instead of always creating a background context. Update the RunE
path and the whoamiRun function so it uses cmd.Context() (and passes it into
identitydiag.Diagnose) when running --verify, preserving cancellation and
deadlines from the parent command. Keep the existing runF override behavior
intact while ensuring the default whoamiRun flow receives the command context.
🪄 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: becffa63-4e53-4f56-93d0-49d177a88016

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd0758 and 8a3276f.

📒 Files selected for processing (3)
  • cmd/build.go
  • cmd/whoami/whoami.go
  • cmd/whoami/whoami_test.go

Comment thread cmd/whoami/whoami_test.go Outdated
Comment on lines +186 to +195
t.Run("malformed config passes through error", func(t *testing.T) {
f, _, _, _ := cmdutil.TestFactory(t, nil)
f.Config = func() (*core.CliConfig, error) {
return nil, errs.NewConfigError(errs.SubtypeInvalidConfig, "malformed")
}
err := whoamiRun(&whoamiOptions{Factory: f})
if err == nil {
t.Fatal("expected non-nil error for invalid config, got nil")
}
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert the typed config error contract here.

Line 191 only checks that an error is returned, so this test will miss regressions where whoamiRun rewrites SubtypeInvalidConfig into a different typed error. In *_test.go error-path cases, please assert the returned problem metadata with errs.ProblemOf (at least category and subtype). As per coding guidelines, "Error-path tests must assert typed metadata via errs.ProblemOf (category / subtype / param) and cause preservation, not message substrings alone".

🧪 Proposed assertion upgrade
 	t.Run("malformed config passes through error", func(t *testing.T) {
 		f, _, _, _ := cmdutil.TestFactory(t, nil)
 		f.Config = func() (*core.CliConfig, error) {
 			return nil, errs.NewConfigError(errs.SubtypeInvalidConfig, "malformed")
 		}
 		err := whoamiRun(&whoamiOptions{Factory: f})
 		if err == nil {
 			t.Fatal("expected non-nil error for invalid config, got nil")
 		}
+		p, ok := errs.ProblemOf(err)
+		if !ok {
+			t.Fatalf("expected typed error, got %T", err)
+		}
+		if p.Subtype != errs.SubtypeInvalidConfig {
+			t.Errorf("subtype = %q, want %q", p.Subtype, errs.SubtypeInvalidConfig)
+		}
 	})
🤖 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 `@cmd/whoami/whoami_test.go` around lines 186 - 195, The malformed-config test
only checks for a non-nil error, so it can miss regressions in the typed error
contract. Update the `whoamiRun` error-path assertion in `whoami_test.go` to
inspect the returned error with `errs.ProblemOf`, and verify the expected
`category` and `subtype` for the `SubtypeInvalidConfig` case. Keep the existing
`whoamiRun` / `whoamiOptions` setup, but make the test fail if the typed
metadata is rewritten or lost.

Sources: Coding guidelines, Learnings

Comment thread cmd/whoami/whoami.go Outdated
Comment on lines +140 to +149
cmd := &cobra.Command{
Use: "whoami",
Short: "Show the current effective identity (profile, app, bot/user, token status)",
RunE: func(cmd *cobra.Command, args []string) error {
if runF != nil {
return runF(opts)
}
return whoamiRun(opts)
},
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- whoami.go ---'
sed -n '1,240p' cmd/whoami/whoami.go

echo
echo '--- whoami_test.go ---'
sed -n '1,260p' cmd/whoami/whoami_test.go

echo
echo '--- search for Args validation in cmd ---'
rg -n 'Args:\s*func|NoArgs|ExactArgs|MinimumNArgs|MaximumNArgs' cmd --glob '*.go'

echo
echo '--- search for whoami tests referencing args ---'
rg -n 'args|positional|unexpected|validation|invalid argument' cmd/whoami --glob '*_test.go'

Repository: larksuite/cli

Length of output: 14324


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- whoami-related files ---'
git ls-files 'cmd/whoami/*'

echo
echo '--- search whoami command references ---'
rg -n 'whoami' cmd --glob '*.go'

echo
echo '--- search for cobra Args helpers in similar commands ---'
rg -n 'NoArgs|ExactArgs|MinimumNArgs|MaximumNArgs|Args:\s*func' cmd --glob '*.go'

Repository: larksuite/cli

Length of output: 3440


Reject unexpected positional arguments.
whoami currently accepts and ignores extra args; add Args validation with errs.NewValidationError(errs.SubtypeInvalidArgument, ...) and cover the failure in cmd/whoami/whoami_test.go.

🤖 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 `@cmd/whoami/whoami.go` around lines 140 - 149, The whoami command currently
ignores unexpected positional arguments instead of rejecting them; update the
cobra.Command setup in whoamiRun/command construction to add Args validation
that returns errs.NewValidationError(errs.SubtypeInvalidArgument, ...) when
extra args are provided. Make sure the validation is wired through the whoami
command path so RunE still calls runF or whoamiRun only after args are checked,
and add a test in whoami_test.go that covers the invalid-argument failure case.

Source: Coding guidelines

Comment thread cmd/whoami/whoami.go Outdated
Comment on lines +143 to +147
RunE: func(cmd *cobra.Command, args []string) error {
if runF != nil {
return runF(opts)
}
return whoamiRun(opts)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

git ls-files cmd/whoami/whoami.go internal | sed -n '1,120p'
echo '--- whoami.go ---'
cat -n cmd/whoami/whoami.go | sed -n '1,240p'
echo '--- Diagnose references ---'
rg -n "func Diagnose|identitydiag\.Diagnose|Diagnose\(" -S .

Repository: larksuite/cli

Length of output: 11753


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- internal/identitydiag/diagnostics.go ---'
cat -n internal/identitydiag/diagnostics.go | sed -n '1,260p'
echo '--- cmd/doctor/doctor.go ---'
cat -n cmd/doctor/doctor.go | sed -n '1,200p'
echo '--- cmd/auth/status.go ---'
cat -n cmd/auth/status.go | sed -n '1,140p'

Repository: larksuite/cli

Length of output: 21001


Propagate cmd.Context() into whoamiRun. identitydiag.Diagnose already accepts a context, but whoamiRun always uses context.Background(). That drops cancellation/deadlines for --verify, so Ctrl-C or parent cancellation can still leave the probe running until the internal timeout expires.

🤖 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 `@cmd/whoami/whoami.go` around lines 143 - 147, Propagate the Cobra command
context through the whoami execution path instead of always creating a
background context. Update the RunE path and the whoamiRun function so it uses
cmd.Context() (and passes it into identitydiag.Diagnose) when running --verify,
preserving cancellation and deadlines from the parent command. Keep the existing
runF override behavior intact while ensuring the default whoamiRun flow receives
the command context.

@maojinze7-prog maojinze7-prog restored the feat/whoami-command branch June 29, 2026 14:57
@maojinze7-prog maojinze7-prog deleted the feat/whoami-command branch June 29, 2026 14:58
@maojinze7-prog maojinze7-prog changed the title feat: add whoami command to show current effective identity test Jun 29, 2026
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.

1 participant