refactor: 将客服后端重构为宿主可嵌入模块
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
This commit is contained in:
@@ -41,23 +41,18 @@ func TestLoadOverridesValuesFromEnvironment(t *testing.T) {
|
||||
content := []byte(`server:
|
||||
port: 8083
|
||||
db:
|
||||
type: sqlite
|
||||
dsn: file:./data/app.db?_busy_timeout=5000
|
||||
type: postgres
|
||||
dsn: postgres-dsn
|
||||
storage:
|
||||
local:
|
||||
baseUrl: /storage
|
||||
mcp:
|
||||
servers:
|
||||
system:
|
||||
endpoint: http://127.0.0.1:8083/api/mcp
|
||||
`)
|
||||
if err := os.WriteFile(path, content, 0600); err != nil {
|
||||
t.Fatalf("WriteFile() error = %v", err)
|
||||
}
|
||||
t.Setenv("AGENT_DESK_SERVER_PORT", "8090")
|
||||
t.Setenv("AGENT_DESK_DB_DSN", "mysql-dsn")
|
||||
t.Setenv("AGENT_DESK_DB_DSN", "postgres-override-dsn")
|
||||
t.Setenv("AGENT_DESK_STORAGE_LOCAL_BASEURL", "/files")
|
||||
t.Setenv("AGENT_DESK_MCP_SERVERS_SYSTEM_ENDPOINT", "http://127.0.0.1:8090/api/mcp")
|
||||
|
||||
cfg, err := Load(path)
|
||||
if err != nil {
|
||||
@@ -67,16 +62,48 @@ mcp:
|
||||
if cfg.Server.Port != 8090 {
|
||||
t.Fatalf("Server.Port=%d want 8090", cfg.Server.Port)
|
||||
}
|
||||
if cfg.DB.Type != "sqlite" {
|
||||
t.Fatalf("DB.Type=%q want sqlite", cfg.DB.Type)
|
||||
if cfg.DB.Type != "postgres" {
|
||||
t.Fatalf("DB.Type=%q want postgres", cfg.DB.Type)
|
||||
}
|
||||
if cfg.DB.DSN != "mysql-dsn" {
|
||||
t.Fatalf("DB.DSN=%q want mysql-dsn", cfg.DB.DSN)
|
||||
if cfg.DB.DSN != "postgres-override-dsn" {
|
||||
t.Fatalf("DB.DSN=%q want postgres-override-dsn", cfg.DB.DSN)
|
||||
}
|
||||
if cfg.Storage.Local.BaseURL != "/files" {
|
||||
t.Fatalf("Storage.Local.BaseURL=%q want /files", cfg.Storage.Local.BaseURL)
|
||||
}
|
||||
if cfg.MCP.Servers["system"].Endpoint != "http://127.0.0.1:8090/api/mcp" {
|
||||
t.Fatalf("MCP system endpoint=%q", cfg.MCP.Servers["system"].Endpoint)
|
||||
}
|
||||
|
||||
func TestFromSettingsBuildsRuntimeConfig(t *testing.T) {
|
||||
cfg, err := FromSettings(map[string]string{
|
||||
"ai_agent_language": "en-US",
|
||||
"ai_agent_storage_default": "oss",
|
||||
"ai_agent_storage_max_upload_size_mb": "64",
|
||||
"ai_agent_storage_oss_private": "true",
|
||||
"ai_vector_path": "/var/lib/agent-desk/vectors.db",
|
||||
"ai_agent_wxwork_notify_to_users": `[1,2,3]`,
|
||||
"ai_agent_wxwork_notify_dedupe_interval": "900",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("FromSettings() error = %v", err)
|
||||
}
|
||||
if cfg.Language != "en-US" || cfg.Storage.Default != "oss" {
|
||||
t.Fatalf("unexpected basic config: %+v", cfg)
|
||||
}
|
||||
if cfg.Storage.MaxUploadSizeMB != 64 || !cfg.Storage.OSS.Private {
|
||||
t.Fatalf("unexpected storage config: %+v", cfg.Storage)
|
||||
}
|
||||
if cfg.VectorDB.Path != "/var/lib/agent-desk/vectors.db" {
|
||||
t.Fatalf("VectorDB.Path=%q", cfg.VectorDB.Path)
|
||||
}
|
||||
if len(cfg.WxWork.Notify.ToUsers) != 3 || cfg.WxWork.Notify.DuplicateCheckInterval != 900 {
|
||||
t.Fatalf("unexpected WeCom notify config: %+v", cfg.WxWork.Notify)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromSettingsRejectsInvalidValues(t *testing.T) {
|
||||
if _, err := FromSettings(map[string]string{
|
||||
"ai_agent_wxwork_notify_dedupe_interval": "not-a-number",
|
||||
}); err == nil {
|
||||
t.Fatal("FromSettings() error = nil, want invalid setting error")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user