Repository navigation
Expand file tree
/
Copy pathcontrol_plane_test.go
More file actions
91 lines (84 loc) · 2.66 KB
/
Copy pathcontrol_plane_test.go
File metadata and controls
91 lines (84 loc) · 2.66 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
package engine
import (
"context"
"encoding/json"
"strings"
"testing"
"github.com/GrayCodeAI/reflect/internal/engine/safety"
"github.com/GrayCodeAI/reflect/internal/tool"
"github.com/GrayCodeAI/reflect/internal/types"
)
func TestWorkModePlanFiltersToolsAndBash(t *testing.T) {
reg := tool.NewRegistry(
tool.BashTool{}, tool.FileReadTool{}, tool.FileWriteTool{}, tool.GrepTool{},
tool.ToolSearchTool{},
)
reg.EnableLazyModelSurface([]string{"Bash", "Read", "Write", "Grep", "ToolSearch"})
sess := NewSession("test", "test", "sys", reg)
if err := sess.SetWorkMode(WorkModePlan); err != nil {
t.Fatal(err)
}
if !sess.Tools().ReadOnlyBash() {
t.Fatal("plan mode should set read-only bash")
}
names := reg.ModelVisibleNames()
for _, n := range names {
if n == "Write" {
t.Fatalf("Write should not be model-visible in plan mode: %v", names)
}
}
if !reg.IsModelVisible("Read") {
t.Fatal("Read should be visible in plan")
}
if sess.WorkMode() != WorkModePlan {
t.Fatalf("WorkMode = %s", sess.WorkMode())
}
if addon := sess.workModeSystemAddon(); !strings.Contains(addon, "PLAN") {
t.Fatalf("plan addon missing: %q", addon)
}
}
func TestLazyRelayToolsAndPromote(t *testing.T) {
reg := tool.NewRegistry(tool.FileReadTool{}, tool.ImpactTool{})
reg.EnableLazyModelSurface([]string{"Read"})
relay := reg.RelayTools()
if len(relay) != 1 || relay[0].Name != "Read" {
t.Fatalf("RelayTools = %#v, want only Read", relay)
}
if !reg.PromoteModelTool("Impact") {
t.Fatal("promote Impact failed")
}
relay = reg.RelayTools()
if len(relay) != 2 {
t.Fatalf("after promote RelayTools len = %d", len(relay))
}
}
func TestToolSearchSelectPromotes(t *testing.T) {
reg := tool.NewRegistry(tool.FileReadTool{}, tool.ImpactTool{}, tool.ToolSearchTool{})
reg.EnableLazyModelSurface([]string{"Read", "ToolSearch"})
sess := NewSession("test", "test", "sys", reg)
sess.PermSvc().SetAutonomy(safety.AutonomyYOLO)
ch := make(chan StreamEvent, 8)
input, _ := json.Marshal(map[string]interface{}{"query": "select:Impact"})
res := sess.executeSingleTool(context.Background(), types.ToolCall{
Name: "ToolSearch", ID: "ts1",
Arguments: map[string]interface{}{"query": "select:Impact"},
}, ch, 0, "")
_ = input
if res.isErr {
t.Fatalf("ToolSearch failed: %v", res.err)
}
if !reg.IsModelVisible("Impact") {
t.Fatalf("Impact should be promoted; visible=%v", reg.ModelVisibleNames())
}
}
func TestSpawnControllerStatus(t *testing.T) {
sess := NewSession("test", "test", "sys", tool.NewRegistry())
sess.WireAgentTool()
sc := sess.SpawnController()
if sc.Status() == "" {
t.Fatal("empty status")
}
if sc.Tasks() == nil {
t.Fatal("tasks registry nil after ensure")
}
}