diff --git a/internal/ai/runtime/internal/impl/factory/agent_handler_service_test.go b/internal/ai/runtime/internal/impl/factory/agent_handler_service_test.go new file mode 100644 index 0000000..e24b1d6 --- /dev/null +++ b/internal/ai/runtime/internal/impl/factory/agent_handler_service_test.go @@ -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)) + } +} diff --git a/internal/ai/runtime/internal/impl/factory/tool_helpers_test.go b/internal/ai/runtime/internal/impl/factory/tool_helpers_test.go new file mode 100644 index 0000000..0afa32f --- /dev/null +++ b/internal/ai/runtime/internal/impl/factory/tool_helpers_test.go @@ -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) + } +}