MCPcopy Index your code
hub / github.com/MiniCodeMonkey/chief / TestLoop_RunWithMockClaude

Function TestLoop_RunWithMockClaude

internal/loop/loop_test.go:168–264  ·  view source on GitHub ↗

TestLoop_RunWithMockClaude tests the loop with a mock Claude script. This is an integration test that requires a Unix-like shell.

(t *testing.T)

Source from the content-addressed store, hash-verified

166// TestLoop_RunWithMockClaude tests the loop with a mock Claude script.
167// This is an integration test that requires a Unix-like shell.
168func TestLoop_RunWithMockClaude(t *testing.T) {
169 if os.Getenv("CI") != "" {
170 t.Skip("Skipping integration test in CI")
171 }
172
173 tmpDir := t.TempDir()
174
175 // Create a mock Claude output
176 mockOutput := []string{
177 `{"type":"system","subtype":"init"}`,
178 `{"type":"assistant","message":{"content":[{"type":"text","text":"Starting work on story"}]}}`,
179 `{"type":"assistant","message":{"content":[{"type":"tool_use","id":"123","name":"Read","input":{"file_path":"test.go"}}]}}`,
180 `{"type":"user","message":{"content":[{"type":"tool_result","tool_use_id":"123","content":"file content"}]}}`,
181 `{"type":"assistant","message":{"content":[{"type":"text","text":"Work complete"}]}}`,
182 }
183
184 scriptPath := createMockClaudeScript(t, tmpDir, mockOutput)
185 prdPath := createTestPRD(t, tmpDir, true) // Already complete so loop stops after one iteration
186
187 // Create a prompt that invokes our mock script instead of real Claude
188 // For the actual test, we'll test the internal methods
189 l := NewLoop(prdPath, "test prompt", 1, testProvider)
190
191 // Override the command for testing - we'll test processOutput directly
192 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
193 defer cancel()
194
195 // Collect events in a goroutine
196 var events []Event
197 done := make(chan bool)
198 go func() {
199 for event := range l.Events() {
200 events = append(events, event)
201 }
202 done <- true
203 }()
204
205 // Test processOutput directly with mock data
206 r, w, _ := os.Pipe()
207 go func() {
208 for _, line := range mockOutput {
209 w.WriteString(line + "\n")
210 }
211 w.Close()
212 }()
213
214 l.iteration = 1
215 l.processOutput(r)
216
217 // Close events channel and wait for collection
218 close(l.events)
219 <-done
220
221 // Verify we got expected events
222 if len(events) == 0 {
223 t.Error("Expected at least one event")
224 }
225

Callers

nothing calls this directly

Calls 5

EventsMethod · 0.95
processOutputMethod · 0.95
createMockClaudeScriptFunction · 0.85
createTestPRDFunction · 0.85
NewLoopFunction · 0.85

Tested by

no test coverage detected