package executor import ( "os" "path/filepath" "testing" ) func TestExtractSummary_WithSummarySection(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "stdout.log") content := streamLine(`{"type":"assistant","message":{"content":[{"type":"text","text":"## Summary\nThe task was completed successfully."}]}}`) if err := os.WriteFile(path, []byte(content), 0600); err != nil { t.Fatal(err) } got := extractSummary(path) want := "The task was completed successfully." if got != want { t.Errorf("got %q, want %q", got, want) } } func TestExtractSummary_NoSummary(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "stdout.log") content := streamLine(`{"type":"assistant","message":{"content":[{"type":"text","text":"All done, no summary heading."}]}}`) if err := os.WriteFile(path, []byte(content), 0600); err != nil { t.Fatal(err) } got := extractSummary(path) if got != "" { t.Errorf("expected empty string, got %q", got) } } func TestExtractSummary_MultipleSections_PicksLast(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "stdout.log") content := streamLine(`{"type":"assistant","message":{"content":[{"type":"text","text":"## Summary\nFirst summary."}]}}`) + streamLine(`{"type":"assistant","message":{"content":[{"type":"text","text":"## Summary\nFinal summary."}]}}`) if err := os.WriteFile(path, []byte(content), 0600); err != nil { t.Fatal(err) } got := extractSummary(path) want := "Final summary." if got != want { t.Errorf("got %q, want %q", got, want) } }