9b0520e020
补齐核心后端逻辑的自动化测试,全部纯函数级、不依赖 docker/NATS/LLM,毫秒级跑完, 把"手动起全栈 curl 验证"变成 `go test`: - dispatcher/internal/eino (graph_test.go) evalCondition(各运算符+refs/tools/answer/profile 关键字+兜底)、resolveOperand、 aggregate(拼接/去重合并/默认/全空)、branchNode(真假边标签精确选路 + 无标签退回边序 + 单边剪枝)、cstr/cbool/countLines/labelOf/targetsOf。 - dispatcher/internal/dsl (compile_test.go) Topo(线性序 + 有环不丢节点)、Compile(system/query/tools 抽取 + 无输入兜底 + 空图用原文)、 ToolBinding(tool/retriever/非工具)、Parse(合法/非法)。 - mcp-go/internal/office (unioffice_test.go) RenderReport 产物为合法 docx(zip 三部件 + 标题/章节文本 + XML 转义)、escapeXML。 - mcp-go/internal/mcp (report_test.go) reportMarkdown(标题+多章 / 无标题)。 - gateway/internal/dsl (parser_test.go) ParseAndAssemble(task_ 前缀 + Graph 透传 + Meta 初始化 + 空/非法报错)。 `go test ./...` 各模块全绿。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
34 lines
840 B
Go
34 lines
840 B
Go
package dsl
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseAndAssemble_OK(t *testing.T) {
|
|
raw := json.RawMessage(`{"version":"1","nodes":[{"id":"a","kind":"input"}],"edges":[]}`)
|
|
task, err := ParseAndAssemble(raw)
|
|
if err != nil {
|
|
t.Fatalf("合法 DSL 不应报错: %v", err)
|
|
}
|
|
if !strings.HasPrefix(task.ID, "task_") {
|
|
t.Errorf("任务 ID 应以 task_ 前缀, got %q", task.ID)
|
|
}
|
|
if string(task.Graph) != string(raw) {
|
|
t.Error("Graph 应原样透传 DSL")
|
|
}
|
|
if task.Meta == nil {
|
|
t.Error("Meta 应已初始化(供网关注入身份)")
|
|
}
|
|
}
|
|
|
|
func TestParseAndAssemble_Errors(t *testing.T) {
|
|
if _, err := ParseAndAssemble(json.RawMessage(``)); err == nil {
|
|
t.Error("空 DSL 应报错")
|
|
}
|
|
if _, err := ParseAndAssemble(json.RawMessage(`{bad`)); err == nil {
|
|
t.Error("非法 JSON 应报错")
|
|
}
|
|
}
|