diff options
Diffstat (limited to 'internal/api/elaborate_test.go')
| -rw-r--r-- | internal/api/elaborate_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/api/elaborate_test.go b/internal/api/elaborate_test.go index 114e75e..330c111 100644 --- a/internal/api/elaborate_test.go +++ b/internal/api/elaborate_test.go @@ -10,6 +10,7 @@ import ( "path/filepath" "strings" "testing" + "time" ) // createFakeClaude writes a shell script to a temp dir that prints output and exits with the @@ -260,3 +261,52 @@ func TestElaborateTask_WithProjectContext(t *testing.T) { t.Errorf("expected arguments to contain SESSION_STATE.md content, got %s", argsStr) } } + +func TestElaborateTask_AppendsRawNarrative(t *testing.T) { + srv, _ := testServer(t) + + workDir := t.TempDir() + prompt := "this is my raw request" + + task := elaboratedTask{ + Name: "Task", + Agent: elaboratedAgent{ + Instructions: "Instructions", + }, + } + taskJSON, _ := json.Marshal(task) + wrapper := map[string]string{"result": string(taskJSON)} + wrapperJSON, _ := json.Marshal(wrapper) + + srv.elaborateCmdPath = createFakeClaude(t, string(wrapperJSON), 0) + + body := fmt.Sprintf(`{"prompt":"%s", "project_dir":"%s"}`, prompt, workDir) + req := httptest.NewRequest("POST", "/api/tasks/elaborate", bytes.NewBufferString(body)) + req.Header.Set("Content-Type", "application/json") + w := httptest.NewRecorder() + + srv.Handler().ServeHTTP(w, req) + + if w.Code != http.StatusOK { + t.Fatalf("status: want 200, got %d; body: %s", w.Code, w.Body.String()) + } + + // It runs in a goroutine, so wait a bit + path := filepath.Join(workDir, "docs", "RAW_NARRATIVE.md") + var data []byte + var err error + for i := 0; i < 10; i++ { + data, err = os.ReadFile(path) + if err == nil { + break + } + time.Sleep(10 * time.Millisecond) + } + + if err != nil { + t.Fatalf("failed to read RAW_NARRATIVE.md: %v", err) + } + if !strings.Contains(string(data), prompt) { + t.Errorf("expected RAW_NARRATIVE.md to contain prompt, got %s", string(data)) + } +} |
