-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembed_test.go
More file actions
239 lines (214 loc) · 6.66 KB
/
embed_test.go
File metadata and controls
239 lines (214 loc) · 6.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package thtsfiles
import (
"strings"
"testing"
"github.com/scottames/thts/internal/agents"
)
func TestGetInstructions_DefaultCategories(t *testing.T) {
data := InstructionsData{
User: "testuser",
Categories: []CategoryRow{
{
Name: "decisions",
Description: "Architecture decisions",
Location: "`thoughts/shared/decisions/`",
Template: "decision.md",
},
{
Name: "notes",
Description: "Quick notes",
Location: "`thoughts/shared/notes/` or `thoughts/{user}/notes/`",
Trigger: "Gotchas discovered",
Template: "note.md",
},
{
Name: "plans",
Description: "Implementation plans",
Location: "`thoughts/shared/plans/`",
Trigger: "After plan approval",
Template: "plan.md",
},
{
Name: "research",
Description: "Research findings",
Location: "`thoughts/shared/research/`",
Trigger: "Research completes",
Template: "research.md",
},
},
}
result, err := GetInstructions(data)
if err != nil {
t.Fatalf("GetInstructions failed: %v", err)
}
// Verify static content preserved
if !strings.Contains(result, "# thts Integration Instructions") {
t.Error("missing header")
}
if !strings.Contains(result, "## Before Starting Work") {
t.Error("missing static section")
}
if !strings.Contains(result, "Before starting, do a quick triage") {
t.Error("missing triage guidance")
}
if !strings.Contains(result, "Ask question tool if available") {
t.Error("missing Ask question tool guidance")
}
// Verify Auto-Save Triggers table populated
if !strings.Contains(result, "**Gotchas discovered**") {
t.Error("missing trigger in Auto-Save table")
}
if !strings.Contains(result, "**After plan approval**") {
t.Error("missing plans trigger")
}
// Verify Where to Write table populated
if !strings.Contains(result, "| Architecture decisions |") {
t.Error("missing category in Where to Write table")
}
if !strings.Contains(result, "`thoughts/shared/decisions/`") {
t.Error("missing location in Where to Write table")
}
// Verify Templates table populated
if !strings.Contains(result, "`thoughts/.templates/decision.md`") {
t.Error("missing template path")
}
// Verify categories without triggers don't appear in trigger table
// decisions has no trigger, so shouldn't be in Auto-Save section
// But we need to check context - it should be in Where to Write but not Auto-Save triggers
autoSaveSection := extractSection(result, "## Auto-Save Triggers", "## Before Starting Work")
if strings.Contains(autoSaveSection, "Architecture decisions") {
t.Error("category without trigger appeared in Auto-Save table")
}
}
func TestGetInstructions_CustomCategories(t *testing.T) {
data := InstructionsData{
User: "testuser",
Categories: []CategoryRow{
{
Name: "tickets",
Description: "Ticket documentation",
Location: "`thoughts/{user}/tickets/`",
},
},
}
result, err := GetInstructions(data)
if err != nil {
t.Fatalf("GetInstructions failed: %v", err)
}
// Verify custom category appears
if !strings.Contains(result, "Ticket documentation") {
t.Error("missing custom category description")
}
if !strings.Contains(result, "`thoughts/{user}/tickets/`") {
t.Error("missing custom category location")
}
}
func TestGetInstructions_SubCategories(t *testing.T) {
data := InstructionsData{
User: "testuser",
Categories: []CategoryRow{
{
Name: "plans",
Description: "Implementation plans",
Location: "`thoughts/shared/plans/`",
Template: "plan.md",
},
{
Name: "plans/active",
Description: "Active plans",
Location: "`thoughts/shared/plans/active/`",
},
{
Name: "plans/complete",
Description: "Completed plans",
Location: "`thoughts/shared/plans/complete/`",
Trigger: "Implementation verified complete",
},
},
}
result, err := GetInstructions(data)
if err != nil {
t.Fatalf("GetInstructions failed: %v", err)
}
// Verify sub-categories appear
if !strings.Contains(result, "Active plans") {
t.Error("missing sub-category: plans/active")
}
if !strings.Contains(result, "Completed plans") {
t.Error("missing sub-category: plans/complete")
}
if !strings.Contains(result, "`thoughts/shared/plans/complete/`") {
t.Error("missing sub-category location")
}
}
func TestGetInstructions_EmptyCategories(t *testing.T) {
data := InstructionsData{
User: "testuser",
Categories: []CategoryRow{},
}
result, err := GetInstructions(data)
if err != nil {
t.Fatalf("GetInstructions failed: %v", err)
}
// Should still render static content
if !strings.Contains(result, "# thts Integration Instructions") {
t.Error("missing header with empty categories")
}
// Tables should be empty but headers present
if !strings.Contains(result, "## Where to Write") {
t.Error("missing Where to Write section")
}
}
func TestGetInstructions_BothScope(t *testing.T) {
data := InstructionsData{
User: "testuser",
Categories: []CategoryRow{
{
Name: "notes",
Description: "Quick notes",
Location: "`thoughts/shared/notes/` or `thoughts/{user}/notes/`",
},
},
}
result, err := GetInstructions(data)
if err != nil {
t.Fatalf("GetInstructions failed: %v", err)
}
if !strings.Contains(result, "`thoughts/shared/notes/` or `thoughts/{user}/notes/`") {
t.Error("missing 'both' scope location format")
}
}
// extractSection extracts content between two headers.
func extractSection(content, startHeader, endHeader string) string {
startIdx := strings.Index(content, startHeader)
if startIdx == -1 {
return ""
}
endIdx := strings.Index(content[startIdx+len(startHeader):], endHeader)
if endIdx == -1 {
return content[startIdx:]
}
return content[startIdx : startIdx+len(startHeader)+endIdx]
}
func TestRenderHook_ClaudePlanDirectiveByAgent(t *testing.T) {
claudeHook, err := RenderHook(agents.AgentClaude, "thts-session-start")
if err != nil {
t.Fatalf("RenderHook(claude) failed: %v", err)
}
if !strings.Contains(claudeHook, "Plan Mode Directive") {
t.Error("expected Claude session-start hook to include plan mode directive")
}
if !strings.Contains(claudeHook, "claudePlanDirective") {
t.Error("expected Claude session-start hook to check hooks.claudePlanDirective")
}
geminiHook, err := RenderHook(agents.AgentGemini, "thts-session-start")
if err != nil {
t.Fatalf("RenderHook(gemini) failed: %v", err)
}
if strings.Contains(geminiHook, "Plan Mode Directive") {
t.Error("expected Gemini session-start hook to exclude plan mode directive")
}
if strings.Contains(geminiHook, "claudePlanDirective") {
t.Error("expected Gemini session-start hook to exclude claudePlanDirective checks")
}
}