Files
sundynix-agentix/sundynix-gateway/internal/handler/voice_task_test.go
T
Blizzard 302e1ebaff feat(voice): 上行接线——最终转写→组DSL→提交任务(Phase 1 打通)
ASR 最终转写触发一次任务提交,复用 HTTP SubmitTask 那条共用关卡
(preflightCore/launchCore),语音只是"嘴替键盘",编排/工具/计费一行不新造。

- task_handler.go: preflight/launch 抽出无 gin 内核 preflightCore/launchCore
  (preflightBlock 承载拦截态),gin 版做薄封装;语音会话无 gin.Context 也走同一关卡
- voice_task.go: buildVoiceGraph(转写→input→agent 单图) + submitVoiceTask(校验/关卡/落库发射)
- voice.go: 会话升级时抓租户/会话;结果 goroutine 见 Final→onFinalTranscript 提交、
  回 ServerTask{task_id};去重连发的重复 final;画布图一次性消费
- voice_task_test.go: 组图合法性 + 带转写 + input→agent 连边

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-22 09:16:29 +08:00

73 lines
2.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)
}
}