Skip to content

Go CLI: admin model framework - #16252

Merged
JinHai-CN merged 7 commits into
infiniflow:mainfrom
JinHai-CN:fix479
Jun 23, 2026
Merged

JinHai-CN merged 7 commits into
infiniflow:mainfrom
JinHai-CN:fix479

Conversation

@JinHai-CN

@JinHai-CN JinHai-CN commented Jun 23, 2026 •

Copy link
Copy Markdown
Member

What problem does this PR solve?

RAGFlow(admin)> list provider 'provider_name' instances;
+----------------------+-------------------------------------------------------------+---------------+---------+
| command              | error                                                       | provider_id   | user_id |
+----------------------+-------------------------------------------------------------+---------------+---------+
| list_model_instances | 'list model instances' is implemented in enterprise edition | provider_name | admin   |
+----------------------+-------------------------------------------------------------+---------------+---------+

RAGFlow(admin)> list provider 'provider_name' instance 'instance_name' models;
+----------------------+-------------------------------------------------------------+---------------+---------------+---------+
| command              | error                                                       | instance_name | provider_id   | user_id |
+----------------------+-------------------------------------------------------------+---------------+---------------+---------+
| list_instance_models | 'list instance models' is implemented in enterprise edition | instance_name | provider_name | admin   |
+----------------------+-------------------------------------------------------------+---------------+---------------+---------+

RAGFlow(admin)> show provider 'provider_name' instance 'instance_name';
+---------------+---------------------------------------------------------------+
| field         | value                                                         |
+---------------+---------------------------------------------------------------+
| command       | show_provider_instance                                        |
| error         | 'show provider instance' is implemented in enterprise edition |
| instance_name | instance_name                                                 |
| provider_id   | provider_name                                                 |
| user_id       | admin                                                         |
+---------------+---------------------------------------------------------------+

RAGFlow(admin)> show provider 'provider_name' instance 'instance_name' balance;
+---------------+-----------------------------------------------------------------------+
| field         | value                                                                 |
+---------------+-----------------------------------------------------------------------+
| user_id       | admin                                                                 |
| command       | show_provider_instance_balance                                        |
| error         | 'show provider instance balance' is implemented in enterprise edition |
| instance_name | instance_name                                                         |
| provider_id   | provider_name                                                         |
+---------------+-----------------------------------------------------------------------+

RAGFlow(admin)> check provider 'provider_name' region 'global' key 'api-key';
+-------------+---------------------------+
| field       | value                     |
+-------------+---------------------------+
| api_key     | api-key                   |
| base_url    |                           |
| command     | check_provider_connection |
| provider_id | provider_name             |
| region      | global                    |
| user_id     | admin                     |
+-------------+---------------------------+

RAGFlow(admin)> check provider 'provider_name' instance 'instance_name';
+---------------+------------------------------------------------------------------+
| field         | value                                                            |
+---------------+------------------------------------------------------------------+
| command       | check_instance_connection                                        |
| error         | 'check instance connection' is implemented in enterprise edition |
| instance_name | instance_name                                                    |
| provider_id   | provider_name                                                    |
| user_id       | admin                                                            |
+---------------+------------------------------------------------------------------+

RAGFlow(admin)> alter provider 'provider-name' instance 'instance-name' key 'new_key' name 'new_name';
+-------------------+----------------------------------------------------------------+
| field             | value                                                          |
+-------------------+----------------------------------------------------------------+
| command           | alter_provider_instance                                        |
| error             | 'alter provider instance' is implemented in enterprise edition |
| instance_name     | instance-name                                                  |
| new_api_key       | new_key                                                        |
| new_instance_name | new_name                                                       |
| provider_id       | provider-name                                                  |
| user_id           | admin                                                          |
+-------------------+----------------------------------------------------------------+

RAGFlow(admin)> disable provider 'zhipu-ai' instance 'test' model 'glm4.5';
+---------------+----------------------------------------------------------------+
| field         | value                                                          |
+---------------+----------------------------------------------------------------+
| error         | 'enable or disable model' is implemented in enterprise edition |
| instance_name | test                                                           |
| model_id      |                                                                |
| model_name    | glm4.5                                                         |
| provider_id   | zhipu-ai                                                       |
| status        | disable                                                        |
| user_id       | admin                                                          |
| command       | enable_or_disable_model                                        |
+---------------+----------------------------------------------------------------+

Type of change

  • New Feature (non-breaking change which adds functionality)

@JinHai-CN
JinHai-CN marked this pull request as ready for review June 23, 2026 02:28
@coderabbitai

coderabbitai Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds four new admin REST endpoints for listing provider instances, showing instance details, showing instance balance, and listing models within an instance. Introduces six shared CLI handlers that route to correct endpoints by CLIMode. Extends the CLI parser to dispatch LIST PROVIDER, SHOW PROVIDER, and CHECK PROVIDER subcommands. Unifies HTTP command dispatch for both admin and user modes by routing to shared Common handlers instead of user-only implementations.

Changes

Admin provider instance management

Layer / File(s) Summary
Admin REST endpoints: handlers, services, and routes
internal/admin/enterprise_handler.go, internal/admin/enterprise_service.go, internal/admin/router.go
Enables four previously commented routes for listing instances by provider, showing instance details, showing instance balance, and listing models within an instance. Handlers validate URL parameters and read user_id from context. Service stubs return command descriptors with enterprise-edition not-implemented messages. Router registers all four endpoints in the /providers group.
Shared CLI handlers for provider instance and connection operations
internal/cli/common_command.go
Adds six shared CLI handlers (CommonShowProviderInstanceCommand, CommonShowProviderInstanceBalanceCommand, CommonListProviderInstances, CommonListInstanceModels, CommonCheckProviderWithKey, CommonCheckProviderConnection) that validate required parameters, select admin or user endpoint by CLIMode, perform GET requests, validate HTTP 200, unmarshal into CommonDataResponse or CommonResponse, and return result or error.
CLI parser for LIST PROVIDER, SHOW PROVIDER, and CHECK PROVIDER subcommands
internal/cli/admin_parser.go, internal/cli/user_parser.go
Introduces parseAdminListProviderCommands() to parse LIST PROVIDER 'provider_name' and dispatch to INSTANCES, INSTANCE...MODELS, or MODELS handlers. Updates parseAdminShowProvider() to branch on next token and delegate to instance/model/balance sub-parsers. Extends parseAdminCheck() to recognize CHECK PROVIDER with instance or key variants (REGION, KEY, URL). Fixes variable scoping in user_parser.go to enable correct INSTANCE...MODELS parsing.
CLI HTTP command dispatch for admin and user modes
internal/cli/cli_http.go
Adds admin command cases for admin_show_provider_instance, admin_show_provider_instance_balance, admin_list_provider_instance_models, admin_list_provider_instances, admin_check_provider_with_key, and admin_check_provider_instance in ExecuteAdminCommand. Updates user command cases to route list_instance_models, list_provider_instances, show_provider_instance, and provider connection checks to shared Common handlers instead of user-only methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Router
  participant Handler
  participant Service
  Client->>Router: GET /api/v1/admin/providers/:provider_name/instances
  Router->>Handler: ListModelInstances(c)
  Handler->>Service: ListModelInstances(userID, providerName)
  Service-->>Handler: []map[string]interface{}, error
  Handler-->>Client: success or 500 response
  Client->>Router: GET /api/v1/admin/providers/:provider_name/instances/:instance_name
  Router->>Handler: ShowProviderInstance(c)
  Handler->>Service: ShowProviderInstance(userID, providerName, instanceName)
  Service-->>Handler: map[string]interface{}, error
  Handler-->>Client: success or 500 response
  Client->>Router: GET /api/v1/admin/providers/:provider_name/instances/:instance_name/balance
  Router->>Handler: ShowProviderInstanceBalance(c)
  Handler->>Service: ShowProviderInstanceBalance(userID, providerName, instanceName)
  Service-->>Handler: map[string]interface{}, error
  Handler-->>Client: success or 500 response
  Client->>Router: GET /api/v1/admin/providers/:provider_name/instances/:instance_name/models
  Router->>Handler: ListInstanceModels(c)
  Handler->>Service: ListInstanceModels(userID, providerName, instanceName)
  Service-->>Handler: []map[string]interface{}, error
  Handler-->>Client: success or 500 response
Loading

Possibly related PRs

  • infiniflow/ragflow#16243: Extends the enterprise admin provider/instance/models API surface by adding complementary endpoint handlers for provider and instance management operations.

Suggested labels

☯️ refactor, ci

🐰 Four routes now shine so bright,
Instance balance joins the sight,
The parser dispatches with newfound grace,
Shared handlers clean the way,
Admin and user code unified today! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Go CLI: admin model framework' accurately reflects the main objective of introducing admin CLI commands for provider and instance management, covering the foundational framework being established.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description check ✅ Passed The PR description is mostly complete with problem statement and type of change, but lacks detail on implementation scope and affected files.

✏️ 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.

❤️ Share

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

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 340-343: The providerName variable is being inserted directly into
URL paths in the fmt.Sprintf calls without proper escaping, which can cause
issues if the name contains reserved URL characters. Add the import for net/url
at the top of the file, then modify both the AdminServerClient path at line 340
and the APIMode path at line 343 to use url.PathEscape(providerName) instead of
interpolating providerName directly into the path strings.
🪄 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: 6a83b78f-9630-4769-ac26-3fa501c0900f

📥 Commits

Reviewing files that changed from the base of the PR and between b661e9c and 6f9daf6.

📒 Files selected for processing (7)
  • internal/admin/enterprise_handler.go
  • internal/admin/enterprise_service.go
  • internal/admin/router.go
  • internal/cli/admin_parser.go
  • internal/cli/cli_http.go
  • internal/cli/common_command.go
  • internal/cli/user_command.go
💤 Files with no reviewable changes (1)
  • internal/cli/user_command.go

Comment on lines +340 to +343
endPoint = fmt.Sprintf("/admin/providers/%s/instances", providerName)
resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/instances", providerName)

Copy link
Copy Markdown
Contributor

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

Escape provider_name before interpolating it into URL paths.

At Line 340 and Line 343, providerName is inserted raw into the path. Names with reserved URL chars can hit the wrong endpoint or fail routing.

Suggested fix
 func (c *CLI) CommonListProviderInstances(cmd *Command) (ResponseIf, error) {
 
 	providerName, ok := cmd.Params["provider_name"].(string)
 	if !ok {
 		return nil, fmt.Errorf("provider_name not provided")
 	}
+	escapedProviderName := url.PathEscape(providerName)
 
 	var resp *Response
 	var err error
 	var endPoint string
 	switch c.Config.CLIMode {
 	case AdminMode:
-		endPoint = fmt.Sprintf("/admin/providers/%s/instances", providerName)
+		endPoint = fmt.Sprintf("/admin/providers/%s/instances", escapedProviderName)
 		resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
 	case APIMode:
-		endPoint = fmt.Sprintf("/providers/%s/instances", providerName)
+		endPoint = fmt.Sprintf("/providers/%s/instances", escapedProviderName)
 		resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
 	default:
 		return nil, fmt.Errorf("invalid server type")
 	}

Also add:

import "net/url"
🤖 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 340 - 343, The providerName
variable is being inserted directly into URL paths in the fmt.Sprintf calls
without proper escaping, which can cause issues if the name contains reserved
URL characters. Add the import for net/url at the top of the file, then modify
both the AdminServerClient path at line 340 and the APIMode path at line 343 to
use url.PathEscape(providerName) instead of interpolating providerName directly
into the path strings.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
internal/cli/common_command.go (1)

343-347: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Escape path parameters before building endpoint URLs.

At Line 343 and Line 346, providerName/instanceName are interpolated raw into path segments. Reserved characters can break routing or hit a different endpoint.

Suggested fix
+import "net/url"
...
 func (c *CLI) CommonShowProviderInstanceCommand(cmd *Command) (ResponseIf, error) {
   instanceName, ok := cmd.Params["instance_name"].(string)
   if !ok {
     return nil, fmt.Errorf("instance name not provided")
   }
@@
   providerName, ok := cmd.Params["provider_name"].(string)
   if !ok {
     return nil, fmt.Errorf("provider name not provided")
   }
+  escapedProviderName := url.PathEscape(providerName)
+  escapedInstanceName := url.PathEscape(instanceName)
@@
   switch c.Config.CLIMode {
   case AdminMode:
-    endPoint = fmt.Sprintf("/admin/providers/%s/instances/%s", providerName, instanceName)
+    endPoint = fmt.Sprintf("/admin/providers/%s/instances/%s", escapedProviderName, escapedInstanceName)
     resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
   case APIMode:
-    endPoint = fmt.Sprintf("/providers/%s/instances/%s", providerName, instanceName)
+    endPoint = fmt.Sprintf("/providers/%s/instances/%s", escapedProviderName, escapedInstanceName)
     resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
🤖 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 343 - 347, The path parameters
providerName and instanceName are being directly interpolated into endpoint URLs
in the AdminMode and APIMode cases without proper URL escaping, which can cause
routing issues or security vulnerabilities if these parameters contain reserved
characters. Escape both providerName and instanceName using url.PathEscape from
the net/url package before passing them to the fmt.Sprintf calls in both the
AdminMode case (the endPoint assignment at line 343) and the APIMode case (the
endPoint assignment at line 346). Ensure the net/url package is imported in this
file.
🤖 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/admin_parser.go`:
- Around line 709-720: The default case in the switch statement checking
p.curToken.Type (which handles TokenInstance and TokenModel cases) silently
consumes unexpected tokens by calling p.nextToken() and then continues to create
and return a valid admin_show_provider command. This accepts invalid syntax
instead of rejecting it. Replace the default case logic to properly reject
unexpected tokens by returning an error instead of silently consuming the token
and proceeding with command creation. The default case should indicate that an
unexpected token was encountered after the provider name, rather than allowing
the parse to succeed.

---

Duplicate comments:
In `@internal/cli/common_command.go`:
- Around line 343-347: The path parameters providerName and instanceName are
being directly interpolated into endpoint URLs in the AdminMode and APIMode
cases without proper URL escaping, which can cause routing issues or security
vulnerabilities if these parameters contain reserved characters. Escape both
providerName and instanceName using url.PathEscape from the net/url package
before passing them to the fmt.Sprintf calls in both the AdminMode case (the
endPoint assignment at line 343) and the APIMode case (the endPoint assignment
at line 346). Ensure the net/url package is imported in this file.
🪄 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: 883b4e82-95e3-4a07-9ab1-b784a00e6a2c

📥 Commits

Reviewing files that changed from the base of the PR and between 454b2de and cbe45d8.

📒 Files selected for processing (7)
  • internal/admin/enterprise_handler.go
  • internal/admin/enterprise_service.go
  • internal/admin/router.go
  • internal/cli/admin_parser.go
  • internal/cli/cli_http.go
  • internal/cli/common_command.go
  • internal/cli/user_command.go
💤 Files with no reviewable changes (1)
  • internal/cli/user_command.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/admin/enterprise_service.go
  • internal/cli/cli_http.go

Comment on lines +709 to +720
switch p.curToken.Type {
case TokenInstance:
return p.parseAdminShowProviderInstance(providerName)
case TokenModel:
return p.parseAdminShowProviderModel(providerName)
default:
p.nextToken()
}

cmd := NewCommand("admin_show_provider")
cmd.Params["provider_name"] = providerName
return cmd, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject unexpected tokens after provider name in SHOW PROVIDER parsing.

The default branch (Line 714–Line 716) silently consumes any token and still emits admin_show_provider. This accepts invalid syntax instead of failing fast.

Suggested fix
 switch p.curToken.Type {
 case TokenInstance:
 	return p.parseAdminShowProviderInstance(providerName)
 case TokenModel:
 	return p.parseAdminShowProviderModel(providerName)
 default:
-	p.nextToken()
+	if p.curToken.Type != TokenSemicolon && p.curToken.Type != TokenEOF {
+		return nil, fmt.Errorf("unexpected token after provider name: %s", p.curToken.Literal)
+	}
+	if p.curToken.Type == TokenSemicolon {
+		p.nextToken()
+	}
 }
🤖 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/admin_parser.go` around lines 709 - 720, The default case in the
switch statement checking p.curToken.Type (which handles TokenInstance and
TokenModel cases) silently consumes unexpected tokens by calling p.nextToken()
and then continues to create and return a valid admin_show_provider command.
This accepts invalid syntax instead of rejecting it. Replace the default case
logic to properly reject unexpected tokens by returning an error instead of
silently consuming the token and proceeding with command creation. The default
case should indicate that an unexpected token was encountered after the provider
name, rather than allowing the parse to succeed.

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 23, 2026
@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jun 23, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 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/admin/enterprise_handler.go`:
- Line 587: The success message in the connection check response is incorrectly
labeled as "Model instance connection checked successfully" when this is
actually a provider-level connection check. Locate the success function call
around line 587 in the enterprise_handler.go file and update the message string
to correctly indicate this is a provider connection check rather than a model
instance check, changing the terminology from "Model instance" to "Provider" to
avoid misleading output in CLI and API responses.

In `@internal/admin/enterprise_service.go`:
- Around line 251-252: Remove the "api_key" field from the response map that is
being returned by the enterprise service. The line containing "api_key": apiKey,
should be deleted entirely, leaving only non-sensitive fields like "base_url":
baseURL, in the response to prevent API key secrets from being exposed through
logs, telemetry, or client-side persistence.
- Around line 246-254: The `CheckProviderConnection` method in the return
statement is missing the enterprise "not implemented" marker that other sibling
enterprise stub methods include. Add the appropriate enterprise "not
implemented" marker to the return map or method to maintain consistency with
other stub methods and prevent false success reporting for this unimplemented
feature.

In `@internal/admin/router.go`:
- Line 189: The route registration at line 189 uses HTTP GET method for the
CheckProviderConnection handler, but GET requests do not reliably support
request bodies. Change the route from GET to POST for the
/:provider_name/connection endpoint (provider.GET should become provider.POST),
which matches the handler's expectation of receiving JSON body data via
ShouldBindJSON.

In `@internal/cli/admin_parser.go`:
- Around line 892-894: The parseAdminCheckProviderInstance function returns
early and bypasses the end-of-command validation checks (semicolon/EOF
validation) that are performed for the REGION and KEY variants of the CHECK
PROVIDER command. After the early return statement in the TokenInstance
condition, ensure that parseAdminCheckProviderInstance is followed by the same
end-of-command validation logic that occurs in the REGION and KEY parsing paths
to maintain consistent validation across all command variants.

In `@internal/cli/common_command.go`:
- Around line 677-679: In the APIMode case within the provider connection check
logic, the HTTP method used for the API request is incorrect. Change the Request
method call on c.APIServerClientMap to use "POST" instead of "GET" when calling
the /providers/{provider_name}/connection endpoint. This aligns the client code
with the actual API endpoint definition which expects a POST request for
provider key connection checks.
🪄 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: 8f880c80-2fc6-4275-a1aa-28ca91447641

📥 Commits

Reviewing files that changed from the base of the PR and between 89fc45e and 112274d.

📒 Files selected for processing (7)
  • internal/admin/enterprise_handler.go
  • internal/admin/enterprise_service.go
  • internal/admin/router.go
  • internal/cli/admin_parser.go
  • internal/cli/cli_http.go
  • internal/cli/common_command.go
  • internal/cli/user_command.go
💤 Files with no reviewable changes (1)
  • internal/cli/user_command.go

return
}

success(c, result, "Model instance connection checked successfully")

Copy link
Copy Markdown
Contributor

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

Fix provider check success message text.

Line 587 currently says model instance for a provider-level connection check, which is misleading in CLI/API output.

Proposed patch
-	success(c, result, "Model instance connection checked successfully")
+	success(c, result, "Provider connection checked successfully")
📝 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.

Suggested change
success(c, result, "Model instance connection checked successfully")
success(c, result, "Provider connection checked successfully")
🤖 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/admin/enterprise_handler.go` at line 587, The success message in the
connection check response is incorrectly labeled as "Model instance connection
checked successfully" when this is actually a provider-level connection check.
Locate the success function call around line 587 in the enterprise_handler.go
file and update the message string to correctly indicate this is a provider
connection check rather than a model instance check, changing the terminology
from "Model instance" to "Provider" to avoid misleading output in CLI and API
responses.

Comment on lines +246 to +254
return map[string]interface{}{
"command": "check_provider_connection",
"user_id": userID,
"provider_id": providerName,
"region": region,
"api_key": apiKey,
"base_url": baseURL,
}, nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep enterprise stub contract consistent for provider checks.

CheckProviderConnection is the only new enterprise stub that omits the enterprise “not implemented” marker, while sibling methods include it. This can report a false success path for an unimplemented feature.

Proposed patch
 func (s *Service) CheckProviderConnection(userID, providerName, region, apiKey, baseURL string) (map[string]interface{}, error) {
 	return map[string]interface{}{
 		"command":     "check_provider_connection",
 		"user_id":     userID,
 		"provider_id": providerName,
 		"region":      region,
 		"api_key":     apiKey,
 		"base_url":    baseURL,
+		"error":       "'check provider connection' is implemented in enterprise edition",
 	}, nil
 }
📝 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.

Suggested change
return map[string]interface{}{
"command": "check_provider_connection",
"user_id": userID,
"provider_id": providerName,
"region": region,
"api_key": apiKey,
"base_url": baseURL,
}, nil
}
func (s *Service) CheckProviderConnection(userID, providerName, region, apiKey, baseURL string) (map[string]interface{}, error) {
return map[string]interface{}{
"command": "check_provider_connection",
"user_id": userID,
"provider_id": providerName,
"region": region,
"api_key": apiKey,
"base_url": baseURL,
"error": "'check provider connection' is implemented in enterprise edition",
}, nil
}
🤖 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/admin/enterprise_service.go` around lines 246 - 254, The
`CheckProviderConnection` method in the return statement is missing the
enterprise "not implemented" marker that other sibling enterprise stub methods
include. Add the appropriate enterprise "not implemented" marker to the return
map or method to maintain consistency with other stub methods and prevent false
success reporting for this unimplemented feature.

Comment on lines +251 to +252
"api_key": apiKey,
"base_url": baseURL,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Do not return raw API keys in service responses.

Line 251 includes api_key in the response map. Even in stub mode, echoing secrets increases leakage risk via logs, telemetry, or client-side persistence.

Proposed patch
-		"api_key":     apiKey,
+		"api_key":     "",

(Or omit api_key entirely and return only non-sensitive fields.)

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

Suggested change
"api_key": apiKey,
"base_url": baseURL,
"api_key": "",
"base_url": baseURL,
🤖 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/admin/enterprise_service.go` around lines 251 - 252, Remove the
"api_key" field from the response map that is being returned by the enterprise
service. The line containing "api_key": apiKey, should be deleted entirely,
leaving only non-sensitive fields like "base_url": baseURL, in the response to
prevent API key secrets from being exposed through logs, telemetry, or
client-side persistence.

Comment thread internal/admin/router.go Resolved
Comment on lines +892 to +894
if p.curToken.Type == TokenInstance {
return p.parseAdminCheckProviderInstance(providerName)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

CHECK PROVIDER ... INSTANCE ... bypasses end-of-command validation.

At Line 893, the early return skips the semicolon/EOF checks at Lines 928-933, so the INSTANCE variant is not validated as strictly as the REGION/KEY variant.

Suggested fix
 	if p.curToken.Type == TokenInstance {
-		return p.parseAdminCheckProviderInstance(providerName)
+		cmd, err := p.parseAdminCheckProviderInstance(providerName)
+		if err != nil {
+			return nil, err
+		}
+		if p.curToken.Type == TokenSemicolon {
+			p.nextToken()
+		}
+		if p.curToken.Type != TokenEOF {
+			return nil, fmt.Errorf("unexpected token: %s", p.curToken.Value)
+		}
+		return cmd, nil
 	}

Also applies to: 928-933, 946-959

🤖 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/admin_parser.go` around lines 892 - 894, The
parseAdminCheckProviderInstance function returns early and bypasses the
end-of-command validation checks (semicolon/EOF validation) that are performed
for the REGION and KEY variants of the CHECK PROVIDER command. After the early
return statement in the TokenInstance condition, ensure that
parseAdminCheckProviderInstance is followed by the same end-of-command
validation logic that occurs in the REGION and KEY parsing paths to maintain
consistent validation across all command variants.

Comment thread internal/cli/common_command.go Resolved
@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 23, 2026
@codecov

codecov Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (06ededb) to head (e2d44f8).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16252      +/-   ##
==========================================
- Coverage   94.56%   93.16%   -1.40%     
==========================================
  Files          10       10              
  Lines         717      717              
  Branches      118      118              
==========================================
- Hits          678      668      -10     
- Misses         25       29       +4     
- Partials       14       20       +6     

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

@JinHai-CN
JinHai-CN merged commit dec2ce4 into infiniflow:main Jun 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant