Skip to content

Conversation

hongkongkiwi
Copy link

@hongkongkiwi hongkongkiwi commented Sep 23, 2025

Summary

Fixes an issue where the CLI --profile option was displaying the wrong profile name in command output.

Fixes #2542

Problem

When using --profile myprofile, the CLI would still display "profile: personal" or "profile: default" in the command output instead of showing the actual profile being used. This created confusion as users couldn't tell if their specified profile was actually being used.

Solution

  • Added profileToUse variable that correctly resolves the profile name at the start of the whoAmI function
  • Uses readAuthConfigCurrentProfileName() for proper default profile resolution when no --profile is specified
  • Ensures all messages (intro, error, and output) display the same profile consistently throughout execution

Changes

Modified packages/cli-v3/src/commands/whoami.ts:

  • Added import for readAuthConfigCurrentProfileName from configFiles.js
  • Introduced profileToUse variable that resolves to either the specified profile or the current default
  • Updated all profile references throughout the function to use profileToUse consistently

Testing

The fix ensures correct profile display in all scenarios:

  • trigger.dev whoami - correctly shows the current profile from config
  • trigger.dev whoami --profile myprofile - correctly shows "myprofile"
  • Error messages now accurately reference the profile being used

Related Issues

Fixes #2542 - CLI displays incorrect profile name when using --profile option

The CLI was displaying "default" or the first profile instead of the actual
profile being used when the --profile option was specified. This fix ensures
consistent profile resolution and display throughout the whoami command.

- Added profileToUse variable that correctly resolves the profile name
- Use readAuthConfigCurrentProfileName() for default profile resolution
- Ensure all messages display the same profile name consistently

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

changeset-bot bot commented Sep 23, 2025

⚠️ No Changeset found

Latest commit: 7ea6c37

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

The command now computes a single profileToUse from options?.profile?.trim() or readAuthConfigCurrentProfileName() and uses it consistently for authentication checks and all user-facing messages. Calls that previously passed options?.profile or showed a hard-coded "default" now use profileToUse. Error, login, and logout guidance text were updated to reference profileToUse. No exported/public APIs were added, removed, or changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change: fixing the CLI's display of the --profile option in the whoami command and uses the conventional prefix (fix(cli):), so it clearly reflects the main change in the diff.
Linked Issues Check ✅ Passed The changes to packages/cli-v3/src/commands/whoami.ts add readAuthConfigCurrentProfileName, compute a single profileToUse, replace all profile references with that value, and pass it to isLoggedIn, which directly implements the linked issue #2542 objectives to resolve and consistently display the actual profile used.
Out of Scope Changes Check ✅ Passed Only whoami.ts was modified to compute and use profileToUse and update related messages, and there are no unrelated file edits or feature changes detected, so no out-of-scope changes are present.
Description Check ✅ Passed The PR description provides a clear summary, problem statement, solution, file-level changes, testing scenarios, and references Fixes #2542, covering the core information required by the template for reviewers to assess the change; however it omits the repository checklist, the exact "Closes #" phrasing from the template, and the changelog/screenshots sections.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 449ee2d and 7ea6c37.

📒 Files selected for processing (1)
  • packages/cli-v3/src/commands/whoami.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/cli-v3/src/commands/whoami.ts

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/cli-v3/src/commands/whoami.ts (2)

77-79: Harden profile resolution with safe fallback and trim

readAuthConfigCurrentProfileName may throw if the config file is missing/corrupt (e.g., first‑run, not logged in). Also trim CLI input. Suggest a safe, explicit fallback to "default".

-  const profileToUse = options?.profile ?? readAuthConfigCurrentProfileName();
+  // Resolve the effective profile once. Fall back safely if config is missing.
+  let profileToUse: string = options?.profile?.trim() ?? "";
+  if (!profileToUse) {
+    try {
+      profileToUse = readAuthConfigCurrentProfileName();
+    } catch {
+      profileToUse = "default";
+    }
+  }

Please verify whether getConfig/readAuthConfigCurrentProfileName can throw on a fresh install or missing config and that "default" is an acceptable fallback for your UX.


150-151: Optional: prefer authenticated profile if available

Minor: after a successful auth, consider showing authentication.profile (canonicalized) if provided.

-      `Account details [${profileToUse}]`
+      `Account details [${(authentication as any).profile ?? profileToUse}]`

If LoginResult already narrows post early-return, you can type it without the cast.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49728b5 and 0ca1598.

📒 Files selected for processing (1)
  • packages/cli-v3/src/commands/whoami.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations

Files:

  • packages/cli-v3/src/commands/whoami.ts
🧬 Code graph analysis (1)
packages/cli-v3/src/commands/whoami.ts (2)
packages/cli-v3/src/utilities/configFiles.ts (1)
  • readAuthConfigCurrentProfileName (79-82)
packages/cli-v3/src/utilities/session.ts (1)
  • isLoggedIn (32-73)
🔇 Additional comments (4)
packages/cli-v3/src/commands/whoami.ts (4)

19-19: LGTM: correct import

Importing readAuthConfigCurrentProfileName here is appropriate and aligns with the PR goal.


80-80: LGTM: consistent intro messaging

Intro now reflects the resolved profile consistently.


107-107: LGTM: auth check uses the resolved profile

Passing profileToUse to isLoggedIn aligns behavior and messaging.


116-121: LGTM: error hints reference the actual profile

Logout/login guidance now correctly includes the resolved profile.

hongkongkiwi and others added 3 commits September 23, 2025 17:17
Address CodeRabbit review feedback:
- Use logical OR (||) instead of nullish coalescing (??) to handle empty strings
- Trim profile input to handle accidental whitespace from CLI

This ensures more robust profile resolution when users provide input with
accidental leading/trailing spaces.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Explains how profile resolution works:
- No --profile: uses Zod default (readAuthConfigCurrentProfileName)
- With --profile: trims whitespace, falls back to current if empty
- Current profile defaults to 'default' when no config exists
- Rely on Zod schema default (readAuthConfigCurrentProfileName) for --profile fallback
- Use consistent 'default' fallback pattern like other commands
- Remove redundant readAuthConfigCurrentProfileName call
- Maintain whitespace trimming for user input robustness
Copy link
Collaborator

@nicktrn nicktrn left a comment

Choose a reason for hiding this comment

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

Thanks for this @hongkongkiwi - sadly this tries to "fix" the output of the whoami command which was working fine before with --profile <name>. What we need to do is fix the header instead that is used for all commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: CLI displays incorrect profile name when using --profile option
2 participants