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
|
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)
}
}
|