MCPcopy Create free account
hub / github.com/aurora-develop/aurora / TestHandlerStreamsPatchEvents

Function TestHandlerStreamsPatchEvents

internal/chatgpt/request_test.go:49–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

47}
48
49func TestHandlerStreamsPatchEvents(t *testing.T) {
50 gin.SetMode(gin.TestMode)
51
52 body := strings.Join([]string{
53 `data: {"p":"/conversation_id","o":"replace","v":"conv-test"}`,
54 `data: {"p":"/message/id","o":"replace","v":"msg-test"}`,
55 `data: {"p":"/message/content/parts/0","o":"append","v":"hello"}`,
56 `data: {"p":"/message/content/parts/0","o":"append","v":" world"}`,
57 `data: {"p":"/message/metadata/finish_details","o":"replace","v":{"type":"stop"}}`,
58 `data: {"p":"/message/end_turn","o":"replace","v":true}`,
59 `data: [DONE]`,
60 ``,
61 }, "\n")
62 response := &http.Response{Body: io.NopCloser(strings.NewReader(body))}
63 writer := httptest.NewRecorder()
64 c, _ := gin.CreateTestContext(writer)
65
66 full, continueInfo := Handler(c, response, nil, nil, "request-id", chatGPTRequestForTest(), true, "auto")
67
68 if continueInfo != nil {
69 t.Fatalf("continueInfo = %#v, want nil", continueInfo)
70 }
71 if full != "hello world" {
72 t.Fatalf("full response = %q, want %q", full, "hello world")
73 }
74 output := writer.Body.String()
75 if !strings.Contains(output, `"content":"hello"`) {
76 t.Fatalf("stream output does not contain first delta: %s", output)
77 }
78 if !strings.Contains(output, `"content":" world"`) {
79 t.Fatalf("stream output does not contain second delta: %s", output)
80 }
81 if !strings.Contains(output, `"finish_reason":"stop"`) {
82 t.Fatalf("stream output does not contain stop chunk: %s", output)
83 }
84}
85
86func TestHandlerStreamsOpenAIChunksAndSentinel(t *testing.T) {
87 gin.SetMode(gin.TestMode)

Callers

nothing calls this directly

Calls 3

chatGPTRequestForTestFunction · 0.85
StringMethod · 0.80
HandlerFunction · 0.70

Tested by

no test coverage detected