]> git.giacomolli.uk - onechat/blobdiff - model_test.go
Bind external events to permanent agent IDs
[onechat] / model_test.go
index 90d0e93366d7226bf37e0bb795f48fbcd08ba749..4045e9deade3f5b2db80e8e68de2f1dcebf40626 100644 (file)
@@ -50,6 +50,7 @@ func TestClientSendsTheFixedRequestFields(t *testing.T) {
                        map[string]any{"type": "input_text", "text": "hello"},
                },
        }}, body["input"])
                        map[string]any{"type": "input_text", "text": "hello"},
                },
        }}, body["input"])
+
        require.Len(t, body["tools"], 1)
 }
 
        require.Len(t, body["tools"], 1)
 }
 
@@ -64,12 +65,12 @@ func TestClientSendsTheSessionHeaderToChatGPT(t *testing.T) {
                want string
        }{
                {
                want string
        }{
                {
-                       name: "ChatGPT backend",
+                       name: "sends the session header to ChatGPT",
                        auth: auth,
                        want: "agent-key",
                },
                {
                        auth: auth,
                        want: "agent-key",
                },
                {
-                       name: "OpenAI API",
+                       name: "omits the session header for the API",
                        auth: ModelAPIKey(modelTestKey),
                        want: "",
                },
                        auth: ModelAPIKey(modelTestKey),
                        want: "",
                },
@@ -149,7 +150,10 @@ func TestClientRecordsEachCall(t *testing.T) {
                if call.number == 1 {
                        w.WriteHeader(http.StatusTooManyRequests)
 
                if call.number == 1 {
                        w.WriteHeader(http.StatusTooManyRequests)
 
-                       _, _ = io.WriteString(w, `{"detail": "slow down"}`)
+                       _, err := io.WriteString(w, `{"detail": "slow down"}`)
+                       if err != nil {
+                               panic(err)
+                       }
 
                        return
                }
 
                        return
                }
@@ -236,22 +240,22 @@ func TestClientFailsWhenTheResponseFails(t *testing.T) {
                want   string
        }{
                {
                want   string
        }{
                {
-                       name:   "failed response",
+                       name:   "reports the response failure cause",
                        events: []any{map[string]any{"type": "response.failed", "response": map[string]any{"error": map[string]any{"code": "server_error", "message": "busy"}}}},
                        want:   "server_error: busy",
                },
                {
                        events: []any{map[string]any{"type": "response.failed", "response": map[string]any{"error": map[string]any{"code": "server_error", "message": "busy"}}}},
                        want:   "server_error: busy",
                },
                {
-                       name:   "incomplete response",
+                       name:   "reports why the response is incomplete",
                        events: []any{map[string]any{"type": "response.incomplete", "response": map[string]any{"incomplete_details": map[string]any{"reason": "content_filter"}}}},
                        want:   "content_filter",
                },
                {
                        events: []any{map[string]any{"type": "response.incomplete", "response": map[string]any{"incomplete_details": map[string]any{"reason": "content_filter"}}}},
                        want:   "content_filter",
                },
                {
-                       name:   "error event",
+                       name:   "reports the stream error cause",
                        events: []any{map[string]any{"type": "error", "code": "rate_limit", "message": "too many"}},
                        want:   "rate_limit: too many",
                },
                {
                        events: []any{map[string]any{"type": "error", "code": "rate_limit", "message": "too many"}},
                        want:   "rate_limit: too many",
                },
                {
-                       name:   "stream ends early",
+                       name:   "refuses an unfinished response stream",
                        events: []any{map[string]any{"type": "response.output_item.done", "item": modelMessageItem("cut")}},
                        want:   "ended before the response completed",
                },
                        events: []any{map[string]any{"type": "response.output_item.done", "item": modelMessageItem("cut")}},
                        want:   "ended before the response completed",
                },