8
8
. "github.com/onsi/gomega"
9
9
"github.com/sclevine/spec"
10
10
"github.com/sclevine/spec/report"
11
+ "os"
11
12
"testing"
12
13
)
13
14
@@ -39,7 +40,10 @@ func testHistory(t *testing.T, when spec.G, it spec.S) {
39
40
const threadName = "threadName"
40
41
41
42
it ("returns an error when store fails" , func () {
42
- mockHistoryStore .EXPECT ().ReadThread (threadName ).Return (nil , errors .New ("store error" )).Times (1 )
43
+ mockHistoryStore .EXPECT ().
44
+ ReadThread (threadName ).
45
+ Return (nil , errors .New ("store error" )).
46
+ Times (1 )
43
47
44
48
_ , err := subject .ParseUserHistory (threadName )
45
49
Expect (err ).To (MatchError ("store error" ))
@@ -53,7 +57,10 @@ func testHistory(t *testing.T, when spec.G, it spec.S) {
53
57
{Message : api.Message {Role : "system" , Content : "ignore this" }},
54
58
}
55
59
56
- mockHistoryStore .EXPECT ().ReadThread (threadName ).Return (historyEntries , nil ).Times (1 )
60
+ mockHistoryStore .EXPECT ().
61
+ ReadThread (threadName ).
62
+ Return (historyEntries , nil ).
63
+ Times (1 )
57
64
58
65
result , err := subject .ParseUserHistory (threadName )
59
66
Expect (err ).NotTo (HaveOccurred ())
@@ -66,7 +73,22 @@ func testHistory(t *testing.T, when spec.G, it spec.S) {
66
73
{Message : api.Message {Role : "system" , Content : "setup" }},
67
74
}
68
75
69
- mockHistoryStore .EXPECT ().ReadThread (threadName ).Return (historyEntries , nil ).Times (1 )
76
+ mockHistoryStore .EXPECT ().
77
+ ReadThread (threadName ).
78
+ Return (historyEntries , nil ).
79
+ Times (1 )
80
+
81
+ result , err := subject .ParseUserHistory (threadName )
82
+ Expect (err ).NotTo (HaveOccurred ())
83
+ Expect (result ).To (BeEmpty ())
84
+ })
85
+
86
+ it ("returns an empty list when the thread does not exist" , func () {
87
+ // Simulate store returning a file-not-found error
88
+ mockHistoryStore .EXPECT ().
89
+ ReadThread (threadName ).
90
+ Return (nil , os .ErrNotExist ).
91
+ Times (1 )
70
92
71
93
result , err := subject .ParseUserHistory (threadName )
72
94
Expect (err ).NotTo (HaveOccurred ())
0 commit comments