Skip to content

feat(auth): add --user option to oo auth switch#241

Merged
BlackHole1 merged 1 commit into
mainfrom
add-switch-use
May 27, 2026
Merged

feat(auth): add --user option to oo auth switch#241
BlackHole1 merged 1 commit into
mainfrom
add-switch-use

Conversation

@BlackHole1
Copy link
Copy Markdown
Member

Previously oo auth switch could only rotate to the next saved account, which made scripted workflows pick the right account by running the command multiple times. The new -u, --user <user> option resolves a target account by exact account.id first and then by exact unique account.name, exiting non-zero without rewriting auth.toml when the value is ambiguous or unmatched.

Telemetry records a low-cardinality has_user_filter boolean so adoption of the new flag can be measured without capturing any account identity. Docs and the i18n catalog are updated in lock step with the user-facing contract.

Previously `oo auth switch` could only rotate to the next saved
account, which made scripted workflows pick the right account by
running the command multiple times. The new `-u, --user <user>`
option resolves a target account by exact `account.id` first and
then by exact unique `account.name`, exiting non-zero without
rewriting `auth.toml` when the value is ambiguous or unmatched.

Telemetry records a low-cardinality `has_user_filter` boolean so
adoption of the new flag can be measured without capturing any
account identity. Docs and the i18n catalog are updated in lock
step with the user-facing contract.

Signed-off-by: Kevin Cui <bh@bugs.cc>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Added --user/-u flag to oo auth switch command to select a specific account by ID or name instead of rotating to the next account.
  • Documentation

    • Expanded oo auth switch command documentation with detailed behavior specifications, error cases, and security guarantees in English and Chinese.
  • Tests

    • Added comprehensive test coverage for user selection functionality and error scenarios.

Walkthrough

This PR extends the oo auth switch command from a rotation-only operation to a user-selectable switcher. The command now accepts an optional --user/-u argument to switch directly to a specific saved account. Account resolution follows a deterministic order: exact id match first, then unique name match. Ambiguous names and unmatched accounts trigger user-friendly errors without modifying the auth file. The implementation includes comprehensive test coverage for success paths, error cases, input validation, and idempotency, alongside parallel updates to English and Chinese documentation, i18n catalogs, and telemetry tracking.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required format and clearly describes the main feature addition: implementing the --user option for the oo auth switch command.
Description check ✅ Passed The description is directly relevant to the changeset, explaining the new --user option functionality, matching behavior, error handling, telemetry, and documentation updates.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch add-switch-use

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
src/application/commands/auth/switch.ts (1)

17-17: ⚡ Quick win

Consider narrowing the type to success-path values only.

The SwitchMatchKind type includes "ambiguous" and "not_found", but these values can never reach the success path (lines 52-60) because resolveAccountByUser throws for both cases (lines 90, 95). This makes the type broader than necessary and could mislead future maintainers about which values can appear in logs or telemetry.

♻️ Narrow the type to success values
-type SwitchMatchKind = "ambiguous" | "id" | "name" | "next" | "not_found";
+type SwitchMatchKind = "id" | "name" | "next";
🤖 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 `@src/application/commands/auth/switch.ts` at line 17, SwitchMatchKind is wider
than needed because resolveAccountByUser throws on "ambiguous" and "not_found";
narrow the union to only the success-path variants ("id" | "name" | "next") by
updating the type alias SwitchMatchKind and any related logging/telemetry that
consumes it (e.g., usages inside switchAccount or resolveAccountByUser) so
callers only expect the actual possible values on the success path.
🤖 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.

Nitpick comments:
In `@src/application/commands/auth/switch.ts`:
- Line 17: SwitchMatchKind is wider than needed because resolveAccountByUser
throws on "ambiguous" and "not_found"; narrow the union to only the success-path
variants ("id" | "name" | "next") by updating the type alias SwitchMatchKind and
any related logging/telemetry that consumes it (e.g., usages inside
switchAccount or resolveAccountByUser) so callers only expect the actual
possible values on the success path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ba539b7d-038b-4895-ab1c-2bc46429a51d

📥 Commits

Reviewing files that changed from the base of the PR and between 0c4f514 and 083a921.

📒 Files selected for processing (6)
  • docs/commands.md
  • docs/commands.zh-CN.md
  • src/application/commands/auth/index.cli.test.ts
  • src/application/commands/auth/switch.ts
  • src/application/commands/telemetry-decisions.test.ts
  • src/i18n/catalog.ts

@BlackHole1 BlackHole1 merged commit 61a75fb into main May 27, 2026
6 checks passed
@BlackHole1 BlackHole1 deleted the add-switch-use branch May 27, 2026 09:33
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.

1 participant