Repository navigation
Go CLI: fix list provider instance tasks - #16345
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughThe CLI now parses API-specific list, show, and use commands in admin and user modes, routes them through renamed command handlers, and updates several shared helper responses and error paths. ChangesCLI API command routing
Sequence Diagram(s)sequenceDiagram
participant CLIInput
participant parseAdminUseCommand
participant ExecuteAdminCommand
participant CommonUseAPIServerCommand
CLIInput->>parseAdminUseCommand: USE API "server_name"
parseAdminUseCommand->>ExecuteAdminCommand: admin_use_api_server
ExecuteAdminCommand->>CommonUseAPIServerCommand: dispatch admin_use_api_server
CommonUseAPIServerCommand-->>ExecuteAdminCommand: ResponseIf
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/cli/user_parser.go (1)
396-413: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winFix the double-consumption of
MODELS.
parseListProviderInstanceCommandscalls this helper whilecurTokenis alreadyTokenModels; after Line 408 advances, Lines 410-413 reject validLIST PROVIDER ... INSTANCE ... MODELScommands.Proposed fix
func (p *Parser) parseListProviderInstanceModels(providerName, instanceName string) (*Command, error) { p.nextToken() // consume MODELS - if p.curToken.Type != TokenModels { - return nil, fmt.Errorf("expected MODELS") - } - p.nextToken() - cmd := NewCommand("api_list_provider_instance_models") if p.curToken.Type == TokenSync { cmd = NewCommand("api_list_provider_instance_models_sync") + p.nextToken() // consume SYNC }🤖 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 `@internal/cli/user_parser.go` around lines 396 - 413, The LIST parser is consuming MODELS twice: parseListProviderInstanceCommands already dispatches to parseListProviderInstanceModels when curToken is TokenModels, so remove the extra token advance/check in parseListProviderInstanceModels and let it continue parsing from the current MODELS token. Update the helper to resume with the next expected token after MODELS, preserving valid LIST PROVIDER ... INSTANCE ... MODELS commands.
🤖 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 `@internal/cli/common_command.go`:
- Around line 1367-1376: The auth value is being derived from CurrentAPIServer
instead of the requested serverName, so SHOW API SERVER can report the wrong
credentials state. Update the auth population logic in common command handling
to look up the target server using serverName and then read its client entry
from APIServerClientMap, while keeping the existing "unknown"/"login"/"api
key"/"no auth" cases intact. Use the serverName and APIServerClientMap
references to locate the affected branch.
---
Outside diff comments:
In `@internal/cli/user_parser.go`:
- Around line 396-413: The LIST parser is consuming MODELS twice:
parseListProviderInstanceCommands already dispatches to
parseListProviderInstanceModels when curToken is TokenModels, so remove the
extra token advance/check in parseListProviderInstanceModels and let it continue
parsing from the current MODELS token. Update the helper to resume with the next
expected token after MODELS, preserving valid LIST PROVIDER ... INSTANCE ...
MODELS commands.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 96a171f7-b831-49e0-9e5a-4f7255592808
📒 Files selected for processing (6)
internal/cli/admin_parser.gointernal/cli/cli_http.gointernal/cli/common_command.gointernal/cli/parser.gointernal/cli/user_command.gointernal/cli/user_parser.go
| if c.Config.APIClientConfig.CurrentAPIServer == "" { | ||
| result.Data["auth"] = "unknown" | ||
| } else { | ||
| result.Data["auth"] = "no auth" | ||
| if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken != nil { | ||
| result.Data["auth"] = "login" | ||
| } else if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey != nil { | ||
| result.Data["auth"] = "api key" | ||
| } else { | ||
| result.Data["auth"] = "no auth" | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use serverName when populating auth.
Line 1367 derives auth from CurrentAPIServer, so SHOW API SERVER "<name>" can report the current server's credentials—or "unknown" in admin mode—instead of the server requested by serverName.
Suggested fix
- if c.Config.APIClientConfig.CurrentAPIServer == "" {
- result.Data["auth"] = "unknown"
- } else {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken != nil {
- result.Data["auth"] = "login"
- } else if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey != nil {
- result.Data["auth"] = "api key"
- } else {
- result.Data["auth"] = "no auth"
- }
- }
+ if httpClient, ok := c.APIServerClientMap[serverName]; !ok || httpClient == nil {
+ result.Data["auth"] = "unknown"
+ } else if httpClient.LoginToken != nil {
+ result.Data["auth"] = "login"
+ } else if httpClient.APIKey != nil {
+ result.Data["auth"] = "api key"
+ } else {
+ result.Data["auth"] = "no auth"
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if c.Config.APIClientConfig.CurrentAPIServer == "" { | |
| result.Data["auth"] = "unknown" | |
| } else { | |
| result.Data["auth"] = "no auth" | |
| if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken != nil { | |
| result.Data["auth"] = "login" | |
| } else if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey != nil { | |
| result.Data["auth"] = "api key" | |
| } else { | |
| result.Data["auth"] = "no auth" | |
| } | |
| if httpClient, ok := c.APIServerClientMap[serverName]; !ok || httpClient == nil { | |
| result.Data["auth"] = "unknown" | |
| } else if httpClient.LoginToken != nil { | |
| result.Data["auth"] = "login" | |
| } else if httpClient.APIKey != nil { | |
| result.Data["auth"] = "api key" | |
| } else { | |
| result.Data["auth"] = "no auth" | |
| } |
🤖 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 `@internal/cli/common_command.go` around lines 1367 - 1376, The auth value is
being derived from CurrentAPIServer instead of the requested serverName, so SHOW
API SERVER can report the wrong credentials state. Update the auth population
logic in common command handling to look up the target server using serverName
and then read its client entry from APIServerClientMap, while keeping the
existing "unknown"/"login"/"api key"/"no auth" cases intact. Use the serverName
and APIServerClientMap references to locate the affected branch.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16345 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Type of change