Files
ai-agent/internal/ai/skills/log_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

88 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,
ManualSkillDefinitionID: 44,
UserMessage: "我要退款",
},
&ExecutionPlan{
AIAgent: models.AIAgent{ID: 22},
AIConfig: models.AIConfig{
ID: 33,
ModelName: "gpt-test",
Provider: enums.AIProviderOpenAI,
},
Skill: &models.SkillDefinition{ID: 44},
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.SkillDefinitionID != 44 {
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)
}