feat: 实现完整的本地配置管理与CLI重构

本次重构实现了标准化的本地配置系统,替换原有的硬编码环境变量读取逻辑:
1. 新增跨平台的原子化配置文件读写,支持Unix和Windows系统
2. 新增init命令用于安全初始化和更新本地凭据
3. 替换原有错误提示文案为更友好的中文提示
4. 更新文档说明新的配置流程和安全规范
5. 新增完整的配置相关测试用例
6. 添加必要的依赖包支持
This commit is contained in:
2026-08-01 02:39:49 +08:00
parent 3466e19d13
commit 340dd241c9
14 changed files with 793 additions and 20 deletions
+12 -3
View File
@@ -3,6 +3,9 @@ package command
import (
"bytes"
"errors"
"os"
"path/filepath"
"strings"
"testing"
dto "code.zhecent.com/open/shop-crm-agent/internal/api"
@@ -13,6 +16,7 @@ import (
func TestRootCommandExposesOnlyCrmOperations(t *testing.T) {
cmd := New("test-version")
want := map[string]bool{
"init": true,
"customer-list": true, "project": true,
"quotation": true, "catalog-search": true, "edit": true,
}
@@ -55,13 +59,18 @@ func TestProjectCommandsExcludeProgressAndTemplateFlag(t *testing.T) {
}
}
func TestRemoteCommandRequiresEnvironmentConfiguration(t *testing.T) {
func TestRemoteCommandRequiresCredentialConfiguration(t *testing.T) {
t.Setenv("LIGHTCORE_API_BASE_URL", "")
t.Setenv("LIGHTCORE_SHOP_CRM_AGENT_TOKEN", "")
repoRoot := t.TempDir()
if err := os.WriteFile(filepath.Join(repoRoot, "go.mod"), []byte("module code.zhecent.com/open/shop-crm-agent\n"), 0o600); err != nil {
t.Fatal(err)
}
t.Chdir(repoRoot)
cmd := New("test")
cmd.SetArgs([]string{"customer-list"})
if err := cmd.Execute(); err == nil {
t.Fatal("missing environment configuration was accepted")
if err := cmd.Execute(); err == nil || !strings.Contains(err.Error(), "shop-crm-agent init") {
t.Fatalf("error = %v", err)
}
}