18c9354095
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package runtime
|
|
|
|
import (
|
|
"testing"
|
|
|
|
applicationruntime "code.tczkiot.com/wlw/ai-agent/internal/ai/application/runtime"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
|
)
|
|
|
|
func TestExtractInterruptMessageAndCheckpointError(t *testing.T) {
|
|
if got := extractInterruptMessage(`{"message":"请补充订单号"}`); got != "请补充订单号" {
|
|
t.Fatalf("unexpected interrupt message: %q", got)
|
|
}
|
|
if got := extractInterruptMessage("not-json"); got != "" {
|
|
t.Fatalf("expected empty message for invalid json, got %q", got)
|
|
}
|
|
|
|
err := fakeErr("Failed to load from checkpoint: record does not exist")
|
|
if !isCheckpointMissingError(err) {
|
|
t.Fatalf("expected checkpoint missing error to be detected")
|
|
}
|
|
if isCheckpointMissingError(fakeErr("other error")) {
|
|
t.Fatalf("expected unrelated error to be ignored")
|
|
}
|
|
}
|
|
|
|
func TestBuildConversationInterruptStoresCheckpointData(t *testing.T) {
|
|
item := buildConversationInterrupt(testConversation(1), testMessage(2), testAIAgent(3), &applicationruntime.RunResult{
|
|
CheckPointData: `{"confirmNodeId":"confirm_1"}`,
|
|
Interrupted: true,
|
|
AgentRunID: 88,
|
|
Interrupts: []applicationruntime.InterruptContextSummary{
|
|
{Type: "human_confirm", ID: "confirm_1", InfoPreview: `{"message":"请确认"}`},
|
|
},
|
|
})
|
|
if item == nil {
|
|
t.Fatalf("expected interrupt item")
|
|
}
|
|
if item.RequestData != `{"confirmNodeId":"confirm_1"}` {
|
|
t.Fatalf("unexpected request data: %q", item.RequestData)
|
|
}
|
|
if item.AgentRunID != 88 || item.InterruptID != "confirm_1" {
|
|
t.Fatalf("unexpected interrupt identity: run=%d interrupt=%q", item.AgentRunID, item.InterruptID)
|
|
}
|
|
}
|
|
|
|
type fakeErr string
|
|
|
|
func (e fakeErr) Error() string {
|
|
return string(e)
|
|
}
|
|
|
|
func testConversation(id int64) models.Conversation {
|
|
return models.Conversation{ID: id}
|
|
}
|
|
|
|
func testMessage(id int64) models.Message {
|
|
return models.Message{ID: id}
|
|
}
|
|
|
|
func testAIAgent(id int64) models.AIAgent {
|
|
return models.AIAgent{ID: id}
|
|
}
|