]> git.giacomolli.uk - onechat/blobdiff - subagent_run_test.go
Correct the remaining review style findings
[onechat] / subagent_run_test.go
index efd387cccde2270fab18a6459758c3e8d112c446..708b515745074ff889391970eda186b32cf6ed71 100644 (file)
@@ -182,7 +182,10 @@ func TestFullContextGivesAFailedReport(t *testing.T) {
                if subagentTestCall(call) {
                        w.WriteHeader(http.StatusBadRequest)
 
                if subagentTestCall(call) {
                        w.WriteHeader(http.StatusBadRequest)
 
-                       _, _ = io.WriteString(w, subagentTestFullContext)
+                       _, err := io.WriteString(w, subagentTestFullContext)
+                       if err != nil {
+                               panic(err)
+                       }
 
                        return
                }
 
                        return
                }
@@ -531,9 +534,38 @@ func TestRestartReportsASubagentThatCannotGoOn(t *testing.T) {
        require.JSONEq(t, `{"running": []}`, string(data))
 }
 
        require.JSONEq(t, `{"running": []}`, string(data))
 }
 
+// subagentTestLastItem returns the last input item of call.
+func subagentTestLastItem(call ModelFakeCall) map[string]any {
+       input := call.body["input"].([]any)
+
+       return input[len(input)-1].(map[string]any)
+}
+
+// subagentTestCall tells if call is a call of a subagent.
+func subagentTestCall(call ModelFakeCall) bool {
+       instructions, _ := call.body["instructions"].(string)
+
+       return strings.HasPrefix(instructions, "You are a subagent")
+}
+
+// subagentTestText returns the text of the user message item, or "" for another
+// item.
+func subagentTestText(item map[string]any) string {
+       content, _ := item["content"].([]any)
+
+       var text strings.Builder
+
+       for _, part := range content {
+               value, _ := part.(map[string]any)["text"].(string)
+               text.WriteString(value)
+       }
+
+       return text.String()
+}
+
 // subagentTestStart runs a loop of agent with its memory and subagents in the
 // subagentTestStart runs a loop of agent with its memory and subagents in the
-// agent directory, as the daemon does. The returned function stops the loop
-// and closes the files.
+// agent directory, as the daemon does. The returned function stops the loop and
+// closes the files.
 func subagentTestStart(t *testing.T, agent *Agent, server *ModelFake, events *TurnEventRecorder, logger *slog.Logger) (*TurnLoop, *Memory, func()) {
        t.Helper()
 
 func subagentTestStart(t *testing.T, agent *Agent, server *ModelFake, events *TurnEventRecorder, logger *slog.Logger) (*TurnLoop, *Memory, func()) {
        t.Helper()
 
@@ -562,8 +594,7 @@ func subagentTestStart(t *testing.T, agent *Agent, server *ModelFake, events *Tu
        }
 }
 
        }
 }
 
-// subagentTestChat returns each message of the chat in memory as
-// "kind: text".
+// subagentTestChat returns each message of the chat in memory as "kind: text".
 func subagentTestChat(t *testing.T, memory *Memory) []string {
        t.Helper()
 
 func subagentTestChat(t *testing.T, memory *Memory) []string {
        t.Helper()
 
@@ -578,32 +609,3 @@ func subagentTestChat(t *testing.T, memory *Memory) []string {
 
        return lines
 }
 
        return lines
 }
-
-// subagentTestCall tells if call is a call of a subagent.
-func subagentTestCall(call ModelFakeCall) bool {
-       instructions, _ := call.body["instructions"].(string)
-
-       return strings.HasPrefix(instructions, "You are a subagent")
-}
-
-// subagentTestLastItem returns the last input item of call.
-func subagentTestLastItem(call ModelFakeCall) map[string]any {
-       input := call.body["input"].([]any)
-
-       return input[len(input)-1].(map[string]any)
-}
-
-// subagentTestText returns the text of the user message item, or "" for
-// another item.
-func subagentTestText(item map[string]any) string {
-       content, _ := item["content"].([]any)
-
-       var text strings.Builder
-
-       for _, part := range content {
-               value, _ := part.(map[string]any)["text"].(string)
-               text.WriteString(value)
-       }
-
-       return text.String()
-}