ef6f525a74
compose 已默认数天、HITL/多智能体/评测全在其上真实跑过,soak 充分。删掉自研拓扑 解释器这第二套引擎,消灭"双实现 drift"税: - 删 runGraph(graph.go 的自研解释器)+ composeEnabled/EINO_COMPOSE 逃生舱开关 + runConversation(仅 runGraph 用的死代码)。 - executeGraph 直接走 runComposeGraph;compose 编译失败兜底改单轮对话(不再回退 graph.go);清掉仅 runGraph 用的 import(otel attribute/trace/otelx)。 - 保留 board / 各节点执行器(retriever/tool/agent/branch/approval/map/render/aggregate) / 工具函数 —— 它们是 compose 各节点 lambda 复用的,非 graph.go 专属。 - 测试:8 处 runGraph→runComposeGraph;等价测试(对照两引擎)转为 compose 正确性测试; runConversation 的开关测试转为「无 ChatModel 降级 runAgent」。 go test ./... 全绿 + vet 干净;冒烟 简单 agent/分支图 跑通。此后每个编排改动不再两边 对齐,成本减半。DEPTH_ROADMAP T1.1 ✅。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
87 lines
3.0 KiB
Go
87 lines
3.0 KiB
Go
package eino
|
||
|
||
import (
|
||
"context"
|
||
"strings"
|
||
"testing"
|
||
|
||
"github.com/cloudwego/eino/components/model"
|
||
"github.com/cloudwego/eino/compose"
|
||
"github.com/cloudwego/eino/schema"
|
||
|
||
"github.com/sundynix/sundynix-dispatcher/internal/harness"
|
||
"github.com/sundynix/sundynix-dispatcher/internal/llm"
|
||
)
|
||
|
||
// stubModel 是实现 Eino model.BaseChatModel 的测试桩,固定回一段文本(确定性)。
|
||
type stubModel struct{ reply string }
|
||
|
||
func (s *stubModel) Generate(_ context.Context, _ []*schema.Message, _ ...model.Option) (*schema.Message, error) {
|
||
return schema.AssistantMessage(s.reply, nil), nil
|
||
}
|
||
|
||
func (s *stubModel) Stream(_ context.Context, _ []*schema.Message, _ ...model.Option) (*schema.StreamReader[*schema.Message], error) {
|
||
sr, sw := schema.Pipe[*schema.Message](1)
|
||
go func() {
|
||
sw.Send(schema.AssistantMessage(s.reply, nil), nil)
|
||
sw.Close()
|
||
}()
|
||
return sr, nil
|
||
}
|
||
|
||
// TestComposeGraphRuns 直接验证 compose.Graph(START→ChatModel→END)能编译并流式产出。
|
||
func TestComposeGraphRuns(t *testing.T) {
|
||
g := compose.NewGraph[[]*schema.Message, *schema.Message]()
|
||
if err := g.AddChatModelNode("model", &stubModel{reply: "你好世界"}); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
_ = g.AddEdge(compose.START, "model")
|
||
_ = g.AddEdge("model", compose.END)
|
||
r, err := g.Compile(context.Background())
|
||
if err != nil {
|
||
t.Fatalf("compile: %v", err)
|
||
}
|
||
out, err := r.Invoke(context.Background(), []*schema.Message{schema.UserMessage("hi")})
|
||
if err != nil {
|
||
t.Fatalf("invoke: %v", err)
|
||
}
|
||
if out.Content != "你好世界" {
|
||
t.Fatalf("got %q", out.Content)
|
||
}
|
||
}
|
||
|
||
// TestComposeConversation 验证对话主流程走 compose 路径:模型输出流式回流到 sink 并累计成稿。
|
||
func TestComposeConversation(t *testing.T) {
|
||
fs := &fakeSink{}
|
||
o := &Orchestrator{
|
||
pool: &fakeLLM{ready: true, cm: &stubModel{reply: "我是 compose 路径的回答"}},
|
||
breaker: harness.NewCircuitBreaker(),
|
||
sink: fs,
|
||
}
|
||
b := &board{query: "你好"}
|
||
o.runComposeConversation(context.Background(), "task_compose", b, "", &execTracer{}, "agent")
|
||
|
||
if !strings.Contains(b.answer, "compose 路径") {
|
||
t.Fatalf("成稿未含模型输出: %q", b.answer)
|
||
}
|
||
if !strings.Contains(fs.text(), "compose 路径") {
|
||
t.Fatalf("sink 未收到流式 token: %q", fs.text())
|
||
}
|
||
}
|
||
|
||
// TestComposeConversationDegradesToRunAgent 验证无 Eino ChatModel 时降级回 runAgent(流式回流不丢)。
|
||
func TestComposeConversationDegradesToRunAgent(t *testing.T) {
|
||
fs := &fakeSink{}
|
||
o := &Orchestrator{
|
||
// cm 为 nil → ChatModel() 返回 nil → runComposeConversation 降级 runAgent(走 stream 桩)。
|
||
pool: &fakeLLM{ready: true, stream: func([]llm.ChatMessage) string { return "降级路径回答" }},
|
||
breaker: harness.NewCircuitBreaker(),
|
||
sink: fs,
|
||
}
|
||
b := &board{query: "你好"}
|
||
o.runComposeConversation(context.Background(), "task_degrade", b, "", &execTracer{}, "agent")
|
||
if !strings.Contains(b.answer, "降级路径") {
|
||
t.Fatalf("无 ChatModel 应降级 runAgent 出稿: %q", b.answer)
|
||
}
|
||
}
|