feat: add unit tests for AgentHandlerService and buildInstructionTraceSummary

This commit is contained in:
mlogclub
2026-04-14 10:51:10 +08:00
parent 7bdd462ed5
commit c12e75b6a1
2 changed files with 72 additions and 0 deletions
@@ -0,0 +1,46 @@
package factory
import (
"context"
"testing"
einocallbacks "cs-agent/internal/ai/runtime/internal/impl/callbacks"
)
func TestAgentHandlerServiceBuildWithCollectorOnly(t *testing.T) {
collector := einocallbacks.NewRuntimeTraceCollector()
service := NewAgentHandlerService(nil)
handlers, err := service.Build(context.Background(), BuildAgentHandlersInput{
Collector: collector,
InstructionSummary: einocallbacks.InstructionTraceSummary{
SectionTitles: []string{"项目级规则", "系统治理规则"},
HasProjectRule: true,
HasGovernanceRule: true,
},
})
if err != nil {
t.Fatalf("Build returned error: %v", err)
}
if len(handlers) != 1 {
t.Fatalf("expected 1 handler, got %d", len(handlers))
}
if !collector.Data.Instruction.HasProjectRule || !collector.Data.Instruction.HasGovernanceRule {
t.Fatalf("instruction summary was not written to collector: %#v", collector.Data.Instruction)
}
if len(collector.Data.Instruction.SectionTitles) != 2 {
t.Fatalf("unexpected section titles: %#v", collector.Data.Instruction.SectionTitles)
}
}
func TestAgentHandlerServiceBuildWithEmptyInput(t *testing.T) {
service := NewAgentHandlerService(nil)
handlers, err := service.Build(context.Background(), BuildAgentHandlersInput{})
if err != nil {
t.Fatalf("Build returned error: %v", err)
}
if len(handlers) != 0 {
t.Fatalf("expected no handlers, got %d", len(handlers))
}
}
@@ -0,0 +1,26 @@
package factory
import (
"testing"
)
func TestBuildInstructionTraceSummary(t *testing.T) {
got := buildInstructionTraceSummary(InstructionAssemblySummary{
SectionTitles: []string{"项目级规则", "当前技能上下文"},
HasProjectRule: true,
HasGovernanceRule: true,
HasAgentRule: true,
HasSkillRule: true,
HasToolRule: false,
})
if len(got.SectionTitles) != 2 {
t.Fatalf("unexpected section titles: %#v", got.SectionTitles)
}
if !got.HasProjectRule || !got.HasGovernanceRule || !got.HasAgentRule || !got.HasSkillRule {
t.Fatalf("unexpected summary flags: %#v", got)
}
if got.HasToolRule {
t.Fatalf("expected HasToolRule false, got %#v", got)
}
}