Repository navigation
Expand file tree
/
Copy pathauto_commit_wire_test.go
More file actions
59 lines (52 loc) · 1.72 KB
/
Copy pathauto_commit_wire_test.go
File metadata and controls
59 lines (52 loc) · 1.72 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
package engine
import (
"context"
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/GrayCodeAI/reflect/internal/engine/safety"
"github.com/GrayCodeAI/reflect/internal/tool"
"github.com/GrayCodeAI/reflect/internal/types"
)
// autoCommitCaptureTool records ToolContext.AutoCommit for the wire path.
type autoCommitCaptureTool struct {
saw bool
}
func (t *autoCommitCaptureTool) Name() string { return "Read" }
func (t *autoCommitCaptureTool) Description() string { return "capture" }
func (t *autoCommitCaptureTool) Parameters() map[string]interface{} {
return map[string]interface{}{"type": "object", "properties": map[string]interface{}{}}
}
func (t *autoCommitCaptureTool) Execute(ctx context.Context, _ json.RawMessage) (string, error) {
tc := tool.GetToolContext(ctx)
t.saw = tc != nil && tc.AutoCommit
return "ok", nil
}
func TestSetAutoCommit_PropagatesToToolContext(t *testing.T) {
cap := &autoCommitCaptureTool{}
sess := NewSession("test", "test", "sys", tool.NewRegistry(cap))
sess.PermSvc().SetAutonomy(safety.AutonomyYOLO)
if sess.AutoCommit() {
t.Fatal("default auto-commit should be off")
}
sess.SetAutoCommit(true)
if !sess.AutoCommit() {
t.Fatal("AutoCommit() false after SetAutoCommit(true)")
}
ch := make(chan StreamEvent, 4)
res := sess.executeSingleTool(context.Background(), types.ToolCall{Name: "Read", ID: "ac"}, ch, 0, "")
if res.isErr {
t.Fatalf("tool failed: %#v", res)
}
if !cap.saw {
t.Fatal("ToolContext.AutoCommit not set during ExecuteOne")
}
// Write path still honors git AutoCommit when enabled (smoke: tool runs).
dir := t.TempDir()
path := filepath.Join(dir, "f.txt")
if err := os.WriteFile(path, []byte("x"), 0o600); err != nil {
t.Fatal(err)
}
_ = path
}