mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-27 11:15:59 +08:00
## What Fixes #12409. Implements admin CLI support for: - `list vars;` - `show var <name-or-prefix>;` - `set var <name> <value>;` ## Changes - Wire Go CLI variable commands to the admin API. - Support integer and quoted string values in `SET VAR`. - Return variable rows as `data_type`, `name`, `setting_type`, and `value`. - Add exact-name lookup with prefix fallback for `SHOW VAR`. - Validate values by stored data type: `string`, `integer`, `bool`, and `json`. - Keep the legacy Python admin CLI/server behavior aligned. - Update admin CLI docs and add focused tests. ## Verification - `go test -count=1 ./internal/cli` - `python3.12 -m py_compile admin/server/services.py admin/server/routes.py api/db/services/system_settings_service.py admin/client/parser.py admin/client/ragflow_client.py` - Python admin CLI parser smoke test for `SET VAR`, quoted values, `SHOW VAR`, and `LIST VARS`. - Attempted `./run_go_tests.sh`; local environment is missing native tokenizer/linker artifacts: - `internal/cpp/cmake-build-release/librag_tokenizer_c_api.a` - `-lstdc++` Co-authored-by: Jin Hai <haijin.chn@gmail.com>
66 lines
2.2 KiB
Go
66 lines
2.2 KiB
Go
//
|
|
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//
|
|
|
|
package admin
|
|
|
|
import (
|
|
"ragflow/internal/entity"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateSystemSettingValue(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dataType string
|
|
value string
|
|
wantError bool
|
|
}{
|
|
{name: "string accepts arbitrary text", dataType: "string", value: "local host"},
|
|
{name: "integer accepts digits", dataType: "integer", value: "15"},
|
|
{name: "integer rejects text", dataType: "integer", value: "localhost", wantError: true},
|
|
{name: "bool accepts true", dataType: "bool", value: "true"},
|
|
{name: "bool accepts false", dataType: "bool", value: "false"},
|
|
{name: "bool rejects non bool", dataType: "bool", value: "yes", wantError: true},
|
|
{name: "json accepts object", dataType: "json", value: `{"endpoint":"http://localhost:9385"}`},
|
|
{name: "json rejects invalid", dataType: "json", value: "{", wantError: true},
|
|
{name: "unknown type rejects", dataType: "float", value: "1.2", wantError: true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
setting := entity.SystemSettings{Name: "test.setting", DataType: tt.dataType}
|
|
err := validateSystemSettingValue(setting, tt.value)
|
|
if (err != nil) != tt.wantError {
|
|
t.Fatalf("validateSystemSettingValue() error = %v, wantError %v", err, tt.wantError)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestInferSystemSettingDataType(t *testing.T) {
|
|
tests := map[string]string{
|
|
"sandbox.self_managed": "json",
|
|
"mail.enabled": "bool",
|
|
"mail.server": "string",
|
|
}
|
|
|
|
for name, want := range tests {
|
|
if got := inferSystemSettingDataType(name); got != want {
|
|
t.Fatalf("inferSystemSettingDataType(%q) = %q, want %q", name, got, want)
|
|
}
|
|
}
|
|
}
|