Files
ai-agent/internal/ai/runtime/reply_helpers_test.go
T
mlogclub 6122a1d881 refactor: remove AgentRunLog related code and components
- Deleted AgentRunLogResponse struct from skill_response.go.
- Removed agent_run_log_repository.go and agent_run_log_service.go files.
- Eliminated AgentRunLogDetailDialog component and its related logic from the dashboard.
- Removed agent run log fetching functions from admin API.
- Updated navigation and localization files to remove references to agent run logs.
2026-06-23 23:22:18 +08:00

91 lines
2.9 KiB
Go

package runtime
import (
"testing"
applicationruntime "agent-desk/internal/ai/application/runtime"
"agent-desk/internal/models"
"agent-desk/internal/pkg/toolx"
)
func TestRuntimeTraceFinalAction(t *testing.T) {
if got := runtimeTraceFinalAction(&applicationruntime.Summary{Status: "completed", ReplyText: "ok"}); got != "reply" {
t.Fatalf("expected reply final action, got %q", got)
}
if got := runtimeTraceFinalAction(&applicationruntime.Summary{Status: "completed"}); got != "completed" {
t.Fatalf("expected completed final action, got %q", got)
}
if got := runtimeTraceFinalAction(&applicationruntime.Summary{Status: "fallback"}); got != "fallback" {
t.Fatalf("expected fallback final action, got %q", got)
}
}
func TestExtractRuntimeToolTraces(t *testing.T) {
summary := &applicationruntime.Summary{
TraceData: `{
"toolSearch": {"items": [{"targetToolCode":"mcp/server/tool_a"}]},
"graphTools": {"items": [{"toolCode":"` + toolx.GraphAnalyzeConversation.Code + `"}]}
}`,
}
if got := extractToolSearchTrace(summary); got == "" {
t.Fatalf("expected tool search trace")
}
if got := extractGraphToolTrace(summary); got == "" {
t.Fatalf("expected graph tool trace")
}
if got := firstGraphToolCode(summary); got != toolx.GraphAnalyzeConversation.Code {
t.Fatalf("unexpected graph tool code: %q", got)
}
}
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 TestBuildConversationInterruptStoresWorkflowCheckpointData(t *testing.T) {
item := buildConversationInterrupt(testConversation(1), testMessage(2), testAIAgent(3), &applicationruntime.Summary{
CheckPointData: `{"confirmNodeId":"confirm_1"}`,
Interrupted: true,
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)
}
}
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}
}