summaryrefslogtreecommitdiff
path: root/internal/api/elaborate_test.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-03-10 09:33:55 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-03-10 09:33:55 +0000
commite392f99727aa2f399033896f2cda5b22e3277700 (patch)
tree4c4f445b90a5c1402aacf6d809984bb395255b4d /internal/api/elaborate_test.go
parent63ccc3380df10cab066e08b40ea41ee1b51bb651 (diff)
feat: append verbatim user input to docs/RAW_NARRATIVE.md
The elaborator now logs every user prompt to docs/RAW_NARRATIVE.md within the project directory. This is done in a background goroutine to ensure it doesn't delay the response.
Diffstat (limited to 'internal/api/elaborate_test.go')
-rw-r--r--internal/api/elaborate_test.go50
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))
+ }
+}