]> git.giacomolli.uk - onechat/blobdiff - turn_test.go
Check the complete message before committing
[onechat] / turn_test.go
index 733c9a935d61c7f8ae9a7caca1012e6995ffd5a6..3c6bb06aa1d244328442c1d8b643d02c0db22976 100644 (file)
@@ -18,7 +18,7 @@ func TestTurnRunsToolsUntilTheFinalAnswer(t *testing.T) {
        server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
                if call.number == 0 {
                        modelWriteEvents(w, modelCompletedEvent([]any{
-                               modelReasoningItem("rs_1", "opaque thought"),
+                               turnReasoningItem("rs_1", "opaque thought"),
                                modelFunctionCallItem("fc_1", "call_1", "shell", `{"command":"echo hi"}`),
                        }, 100, 0, 5))
 
@@ -57,6 +57,7 @@ func TestTurnRunsToolsUntilTheFinalAnswer(t *testing.T) {
                "echo: hi\n",
                "reply: It said hi.",
        }, test.Log(t))
+
        require.Equal(t, []string{"user", "busy", "tool", "echo", "reply", "idle"}, test.events.Kinds())
 
        var turns []string
@@ -369,6 +370,13 @@ func (r *TurnEventRecorder) Last(kind string) string {
        return r.LastEvent(kind).Text
 }
 
+func (r *TurnEventRecorder) Add(event Event) {
+       r.mutex.Lock()
+       defer r.mutex.Unlock()
+
+       r.events = append(r.events, event)
+}
+
 // LastEvent returns the last event of kind.
 func (r *TurnEventRecorder) LastEvent(kind string) Event {
        r.mutex.Lock()
@@ -383,11 +391,13 @@ func (r *TurnEventRecorder) LastEvent(kind string) Event {
        return Event{}
 }
 
-func (r *TurnEventRecorder) Add(event Event) {
-       r.mutex.Lock()
-       defer r.mutex.Unlock()
-
-       r.events = append(r.events, event)
+func turnReasoningItem(id, encrypted string) map[string]any {
+       return map[string]any{
+               "type":              "reasoning",
+               "id":                id,
+               "encrypted_content": encrypted,
+               "summary":           []any{},
+       }
 }
 
 // turnInputTexts returns the text of each user message of the input of call.
@@ -423,12 +433,3 @@ func turnInputTexts(t *testing.T, call ModelFakeCall) []string {
 
        return texts
 }
-
-func modelReasoningItem(id, encrypted string) map[string]any {
-       return map[string]any{
-               "type":              "reasoning",
-               "id":                id,
-               "encrypted_content": encrypted,
-               "summary":           []any{},
-       }
-}