Repository navigation
Expand file tree
/
Copy pathagent_intelligence_test.go
More file actions
114 lines (99 loc) · 3.25 KB
/
Copy pathagent_intelligence_test.go
File metadata and controls
114 lines (99 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package engine
import (
"context"
"testing"
"github.com/GrayCodeAI/reflect/internal/engine/agent"
)
func TestAgentIntelligence_SelectMode(t *testing.T) {
ai := NewAgentIntelligence()
tests := []struct {
prompt string
want agent.SubAgentMode
}{
{"find all files using deprecated API", agent.SubAgentExplore},
{"search for authentication code", agent.SubAgentExplore},
{"analyze the dependency graph", agent.SubAgentExplore},
{"implement the new endpoint", agent.SubAgentGeneral},
{"refactor the auth module", agent.SubAgentGeneral},
{"fix the bug in parser.go", agent.SubAgentGeneral},
}
for _, tt := range tests {
got := ai.SelectMode(tt.prompt)
if got != tt.want {
t.Errorf("SelectMode(%q) = %v, want %v", tt.prompt, got, tt.want)
}
}
}
func TestAgentIntelligence_AnalyzeForParallelism_Simple(t *testing.T) {
ai := NewAgentIntelligence()
// Simple task — no parallelism
d := ai.AnalyzeForParallelism("fix the typo")
if d.ShouldParallelize {
t.Error("simple task should not parallelize")
}
}
func TestAgentIntelligence_AnalyzeForParallelism_Conjunction(t *testing.T) {
ai := NewAgentIntelligence()
// "X and Y" with major scale
d := ai.AnalyzeForParallelism("refactor the auth module and redesign the database schema")
if !d.ShouldParallelize {
t.Error("conjunction task should parallelize")
}
if len(d.SubTasks) < 2 {
t.Errorf("expected 2+ subtasks, got %d", len(d.SubTasks))
}
}
func TestAgentIntelligence_AnalyzeForParallelism_Pipeline(t *testing.T) {
ai := NewAgentIntelligence()
// "research" + "build" + major scale keyword
d := ai.AnalyzeForParallelism("research the architecture patterns then build a new authentication system from scratch")
if !d.ShouldParallelize {
t.Error("research+build should parallelize as pipeline")
}
if d.Strategy != StrategyPipeline {
t.Errorf("expected pipeline strategy, got %v", d.Strategy)
}
}
func TestAgentIntelligence_ExecuteWithIntelligence_Single(t *testing.T) {
ai := NewAgentIntelligence()
called := false
result, err := ai.ExecuteWithIntelligence(context.Background(), "fix typo", func(_ context.Context, prompt string, mode agent.SubAgentMode) (string, error) {
called = true
return "fixed", nil
})
if err != nil {
t.Fatal(err)
}
if !called {
t.Error("exec function should be called")
}
if result != "fixed" {
t.Errorf("result = %q, want 'fixed'", result)
}
}
func TestSelfAwareness_ShouldDelegate(t *testing.T) {
sa := &SelfAwareness{MaxComplexity: ScaleMinor, Specialties: []string{"code-review"}}
if sa.ShouldDelegate("fix typo", ScalePatch) {
t.Error("patch should not delegate")
}
if !sa.ShouldDelegate("build new service", ScaleEpic) {
t.Error("epic should delegate when max is minor")
}
}
func TestSynthesisPrompt(t *testing.T) {
subtasks := []SubTask{
{ID: "a", Prompt: "find files", Mode: agent.SubAgentExplore},
{ID: "b", Prompt: "fix them", Mode: agent.SubAgentGeneral},
}
results := map[string]string{"a": "found 3 files", "b": "fixed all"}
prompt := MergeSynthesisPrompt(subtasks, results)
if !hasSubstr(prompt, "found 3 files") {
t.Error("expected result a in synthesis")
}
if !hasSubstr(prompt, "fixed all") {
t.Error("expected result b in synthesis")
}
if !hasSubstr(prompt, "Synthesis") {
t.Error("expected synthesis section")
}
}