Files
ai-agent/internal/ai/skills/log_test.go
T
mlogclub 101577f163 Refactor internal services to use agent-desk package structure
- Updated import paths in multiple service files to reflect the new agent-desk module.
- Added a new configuration file for agent-desk in the Docker setup.
2026-05-31 18:43:48 +08:00

92 lines
2.1 KiB
Go

package skills
import (
"strings"
"testing"
"agent-desk/internal/models"
"agent-desk/internal/pkg/enums"
)
func TestBuildRunLogMatchedPlan(t *testing.T) {
log := BuildRunLog(
RuntimeContext{
AIAgent: models.AIAgent{ID: 22},
AIConfig: models.AIConfig{ID: 33},
ConversationID: 11,
ManualSkillCode: "manual_refund",
IntentCode: "refund",
UserMessage: "我要退款",
},
&ExecutionPlan{
AIAgent: models.AIAgent{ID: 22},
AIConfig: models.AIConfig{
ID: 33,
ModelName: "gpt-test",
Provider: enums.AIProviderOpenAI,
},
Skill: &models.SkillDefinition{
ID: 44,
Code: "refund_skill",
},
MatchReason: "llm_route",
},
&ExecutionTrace{Status: "ok"},
nil,
)
if log == nil {
t.Fatalf("expected run log")
}
if log.ConversationID != 11 || log.AIAgentID != 22 || log.AIConfigID != 33 {
t.Fatalf("unexpected ids in run log: %#v", log)
}
if !log.Matched || !log.FinalSelected || log.SkillCode != "refund_skill" {
t.Fatalf("expected matched skill log, got %#v", log)
}
if log.MatchReason != "llm_route" {
t.Fatalf("unexpected match reason: %q", log.MatchReason)
}
if !strings.Contains(log.TraceData, `"status":"ok"`) {
t.Fatalf("expected trace data to contain status, got %q", log.TraceData)
}
}
func TestBuildRunLogNotMatchedAndError(t *testing.T) {
log := BuildRunLog(
RuntimeContext{
AIAgent: models.AIAgent{ID: 22},
UserMessage: "随便问问",
},
nil,
&ExecutionTrace{Status: "route_error"},
assertErr("route failed"),
)
if log == nil {
t.Fatalf("expected run log")
}
if log.Matched {
t.Fatalf("expected unmatched log")
}
if log.ErrorMessage != "route failed" {
t.Fatalf("unexpected error message: %q", log.ErrorMessage)
}
noMatchLog := BuildRunLog(
RuntimeContext{AIAgent: models.AIAgent{ID: 22}, UserMessage: "随便问问"},
&ExecutionPlan{MatchReason: ""},
&ExecutionTrace{Status: "not_matched"},
nil,
)
if noMatchLog.MatchReason != "not_matched" {
t.Fatalf("expected default not_matched reason, got %q", noMatchLog.MatchReason)
}
}
type assertErr string
func (e assertErr) Error() string {
return string(e)
}