-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatcher_test.go
More file actions
92 lines (84 loc) · 2.94 KB
/
watcher_test.go
File metadata and controls
92 lines (84 loc) · 2.94 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
package main
import (
"strings"
"testing"
)
func TestBuildTrendHumanReadable(t *testing.T) {
tests := []struct {
name string
history []int
buildOK bool
want string
}{
{name: "clean build", history: []int{1, 0}, buildOK: true, want: ""},
{name: "first failing cycle has no trend", history: []int{2}, want: ""},
{name: "new breakage", history: []int{0, 1}, want: "new breakage"},
{name: "fewer errors", history: []int{4, 2}, want: "fewer errors than last cycle"},
{name: "more errors", history: []int{1, 3}, want: "more errors than last cycle"},
{name: "stalled failing build", history: []int{2, 2, 2}, want: "3 cycles"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := buildTrend(tt.history, tt.buildOK); got != tt.want {
t.Fatalf("buildTrend(%v, %v) = %q, want %q", tt.history, tt.buildOK, got, tt.want)
}
})
}
}
func TestAbsorbJSONLEntriesSeedsExtraDirsAndRecentEdits(t *testing.T) {
extraDirs := make(map[string]bool)
var recentEditedFiles []string
var recentEntries []JSONLEntry
reason := absorbJSONLEntries("/home/yuxuan/work/trupal", []JSONLEntry{
{
Type: "user",
Role: "user",
HasText: true,
TextSnip: "Edit /tmp/testproject/server.go",
},
{
Type: "assistant",
Role: "assistant",
HasTool: true,
ToolNames: []string{"Edit"},
ToolFiles: []string{"/tmp/testproject/server.go"},
ToolDetails: []string{"server.go"},
},
}, extraDirs, &recentEditedFiles, &recentEntries)
if reason == "" {
t.Fatal("expected non-empty summary reason")
}
if !extraDirs["/tmp/testproject"] {
t.Fatalf("expected extraDirs to include /tmp/testproject, got %v", extraDirs)
}
if len(recentEditedFiles) != 1 || recentEditedFiles[0] != "/tmp/testproject/server.go" {
t.Fatalf("expected seeded recent edit, got %v", recentEditedFiles)
}
if len(recentEntries) != 2 {
t.Fatalf("expected recent entries cache to be populated, got %d", len(recentEntries))
}
}
func TestBuildBrainNotificationIncludesRecentSessionActivity(t *testing.T) {
notification := buildBrainNotification(
"/home/yuxuan/work/trupal",
"CC session updated",
[]JSONLEntry{
{Type: "user", Role: "user", HasText: true, TextSnip: "Run tests"},
{Type: "assistant", Role: "assistant", HasTool: true, ToolNames: []string{"Bash"}, ToolDetails: []string{"Verify"}},
},
[]string{"server.go"},
"M\tserver.go",
"diff --git a/server.go b/server.go\n--- a/server.go\n+++ b/server.go\n+new line\n",
nil,
&BuildDisplay{OK: true},
)
if !strings.Contains(notification, "RECENT SESSION ACTIVITY") {
t.Fatalf("expected notification to include recent session activity, got:\n%s", notification)
}
if !strings.Contains(notification, `- user: "Run tests"`) {
t.Fatalf("expected notification to include user snippet, got:\n%s", notification)
}
if !strings.Contains(notification, "- tool: Bash (Verify)") {
t.Fatalf("expected notification to include tool summary, got:\n%s", notification)
}
}