Files
ai-agent/internal/ai/runtime/reply_helpers_test.go
T
mlogclub 541e4c5874 refactor: replace skill code with skill ID across the application
- Updated skill handling to use skill IDs instead of skill codes in various components, services, and models.
- Modified tests to reflect changes in skill identification.
- Removed references to skill codes in favor of skill IDs for consistency and clarity.
- Updated localization files to remove skill code references and adjust error messages accordingly.
2026-06-20 20:42:07 +08:00

112 lines
2.9 KiB
Go

package runtime
import (
"strings"
"testing"
applicationruntime "agent-desk/internal/ai/application/runtime"
"agent-desk/internal/pkg/toolx"
)
func TestSummaryPrimaryToolCodePrefersToolSearchTarget(t *testing.T) {
summary := &applicationruntime.Summary{
InvokedToolCodes: []string{toolx.BuiltinToolSearch.Code},
TraceData: `{
"toolSearch": {
"items": [
{"targetToolCode":"mcp/server/tool_a"}
]
}
}`,
}
if got := summaryPrimaryToolCode(summary); got != "mcp/server/tool_a" {
t.Fatalf("unexpected primary tool code: %q", got)
}
}
func TestToRunLogFinalAction(t *testing.T) {
if got := toRunLogFinalAction(&applicationruntime.Summary{PlannedSkillID: 44, ReplyText: "ok"}); got != "skill" {
t.Fatalf("expected skill final action, got %q", got)
}
graphSummary := &applicationruntime.Summary{
ReplyText: "ok",
TraceData: `{
"graphTools": {
"items": [
{"toolCode":"` + toolx.GraphAnalyzeConversation.Code + `"}
]
}
}`,
}
if got := toRunLogFinalAction(graphSummary); got != "graph" {
t.Fatalf("expected graph final action, got %q", got)
}
if got := toRunLogFinalAction(&applicationruntime.Summary{Status: "fallback"}); got != "fallback" {
t.Fatalf("expected fallback final action, got %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 TestGraphPlanReason(t *testing.T) {
summary := &applicationruntime.Summary{
TraceData: `{
"graphTools": {
"items": [
{
"toolCode":"` + toolx.GraphTriageServiceRequest.Code + `",
"recommendedAction":"create_ticket",
"ticketDraftReady": true
}
]
}
}`,
}
got := graphPlanReason(summary)
if !strings.Contains(got, "create_ticket") || !strings.Contains(got, "ready ticket draft") {
t.Fatalf("unexpected graph plan reason: %q", got)
}
}
func TestExtractHandoffReason(t *testing.T) {
summary := &applicationruntime.Summary{
TraceData: `{
"graphTools": {
"items": [
{
"toolCode":"` + toolx.GraphHandoffConversation.Code + `",
"arguments":{"reason":" 用户明确要求人工处理 "}
}
]
}
}`,
}
if got := extractHandoffReason(summary); got != "用户明确要求人工处理" {
t.Fatalf("unexpected handoff reason: %q", got)
}
}
type fakeErr string
func (e fakeErr) Error() string {
return string(e)
}