99ce07c1b0
把 JARVIS 做成每用户独立:名字(你叫JARVIS别人叫星期五)、人设(与主偏好记忆分开)、 可自带豆包配置(齐全则用用户的,否则回落系统)。 - store/user_jarvis.go: sundynix_user_jarvis(user_id唯一;name/persona/火山creds,APIKey密文) + Get/Save(upsert) + AutoMigrate 注册 - voice_config.go resolveJarvis(uid): 火山配置用户优先系统兜底 + 取名字/人设 - voice_task.go: voiceSystemPrompt(name,persona)——简短是硬基线,名字/语气由用户定; buildVoiceGraph 带 name+persona;voice.go 会话升级时按用户解析 - dispatcher compose_compiler: 语音任务(useVoice)不拉主偏好记忆,改用用户 persona(保留短期历史) - jarvis.go + 路由: GET/PUT /api/v1/me/jarvis(用户级,api_key 脱敏/留空沿用) 真机验证:设 name=星期五+干净人设→语音答"我是星期五…"(自称新名、无糙话、4.4s), has_own_voice=false 用系统豆包。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/sundynix/sundynix-gateway/internal/dsl"
|
|
)
|
|
|
|
// buildVoiceGraph 的产物必须是 dsl.ParseAndAssemble 能吃下的合法图,且带上转写文本。
|
|
func TestBuildVoiceGraph_Valid(t *testing.T) {
|
|
const q = "帮我查一下明天上海的天气"
|
|
raw := buildVoiceGraph(q, "", "")
|
|
|
|
// 1) 能通过 DSL 解析与拓扑校验(与 HTTP SubmitTask 同一条解析)。
|
|
task, err := dsl.ParseAndAssemble(raw)
|
|
if err != nil {
|
|
t.Fatalf("语音图未通过 DSL 校验: %v", err)
|
|
}
|
|
if task.ID == "" {
|
|
t.Fatal("task.ID 为空")
|
|
}
|
|
|
|
// 2) 图里带着转写文本(input 节点)与 JARVIS 系统提示(agent 节点)。
|
|
var g struct {
|
|
Nodes []struct {
|
|
ID string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
Config map[string]any `json:"config"`
|
|
} `json:"nodes"`
|
|
Edges []struct {
|
|
Source, Target string
|
|
} `json:"edges"`
|
|
}
|
|
if err := json.Unmarshal(raw, &g); err != nil {
|
|
t.Fatalf("反解语音图失败: %v", err)
|
|
}
|
|
if len(g.Nodes) != 2 || len(g.Edges) != 1 {
|
|
t.Fatalf("期望 2 节点 1 边,得 %d 节点 %d 边", len(g.Nodes), len(g.Edges))
|
|
}
|
|
var gotInput, gotAgent bool
|
|
for _, n := range g.Nodes {
|
|
switch n.Kind {
|
|
case "input":
|
|
gotInput = true
|
|
if text, _ := n.Config["text"].(string); text != q {
|
|
t.Errorf("input.text=%q,期望 %q", text, q)
|
|
}
|
|
case "agent":
|
|
gotAgent = true
|
|
if sys, _ := n.Config["system"].(string); !strings.Contains(sys, "JARVIS") {
|
|
t.Errorf("agent.system 未含 JARVIS 提示: %q", sys)
|
|
}
|
|
}
|
|
}
|
|
if !gotInput || !gotAgent {
|
|
t.Fatalf("缺 input(%v)/agent(%v) 节点", gotInput, gotAgent)
|
|
}
|
|
// 边必须连 input→agent(否则 compose 编译后 agent 收不到输入)。
|
|
if g.Edges[0].Source != "voice_in" || g.Edges[0].Target != "voice_agent" {
|
|
t.Errorf("边应为 voice_in→voice_agent,得 %s→%s", g.Edges[0].Source, g.Edges[0].Target)
|
|
}
|
|
}
|
|
|
|
// 空转写不该组图触发(提交侧兜底:submitVoiceTask 空转写返错)——这里只校验组图函数对空串仍产出结构。
|
|
func TestBuildVoiceGraph_EmptyStillStructured(t *testing.T) {
|
|
raw := buildVoiceGraph("", "", "")
|
|
if _, err := dsl.ParseAndAssemble(raw); err != nil {
|
|
t.Fatalf("空转写图仍应结构合法: %v", err)
|
|
}
|
|
}
|
|
|
|
// 用户自定义名字 + 人设应注入到 agent 节点的 system 里(名字替 JARVIS、人设附上)。
|
|
func TestBuildVoiceGraph_NamePersonaInjected(t *testing.T) {
|
|
raw := buildVoiceGraph("你好", "星期五", "简洁专业不说脏话")
|
|
var g struct {
|
|
Nodes []struct {
|
|
Kind string `json:"kind"`
|
|
Config map[string]any `json:"config"`
|
|
} `json:"nodes"`
|
|
}
|
|
if err := json.Unmarshal(raw, &g); err != nil {
|
|
t.Fatalf("反解失败: %v", err)
|
|
}
|
|
for _, n := range g.Nodes {
|
|
if n.Kind != "agent" {
|
|
continue
|
|
}
|
|
sys, _ := n.Config["system"].(string)
|
|
if !strings.Contains(sys, "星期五") {
|
|
t.Errorf("system 未含自定义名字「星期五」: %q", sys)
|
|
}
|
|
if strings.Contains(sys, "JARVIS") {
|
|
t.Errorf("有自定义名字时不应再出现 JARVIS: %q", sys)
|
|
}
|
|
if !strings.Contains(sys, "简洁专业不说脏话") {
|
|
t.Errorf("system 未含用户人设: %q", sys)
|
|
}
|
|
return
|
|
}
|
|
t.Fatal("没找到 agent 节点")
|
|
}
|