@@ -2218,6 +2218,56 @@ collectLoop:
22182218 }
22192219}
22202220
2221+ // TestProcessStreamPrimingEvent verifies that the streamable client correctly ignores
2222+ // SSE events with empty data buffers, which are used as priming events (e.g. SEP-1699).
2223+ func TestProcessStreamPrimingEvent (t * testing.T ) {
2224+ // We create a mock response with a priming event (empty data, with an ID),
2225+ // followed by a normal event.
2226+ sseData := `id: 123
2227+
2228+ id: 124
2229+ data: {"jsonrpc":"2.0","id":1,"result":{}}
2230+
2231+ `
2232+
2233+ ctx := t .Context ()
2234+ resp := & http.Response {
2235+ StatusCode : http .StatusOK ,
2236+ Header : http.Header {"Content-Type" : []string {"text/event-stream" }},
2237+ Body : io .NopCloser (strings .NewReader (sseData )),
2238+ }
2239+
2240+ incoming := make (chan jsonrpc.Message , 10 )
2241+ done := make (chan struct {})
2242+
2243+ conn := & streamableClientConn {
2244+ ctx : ctx ,
2245+ done : done ,
2246+ incoming : incoming ,
2247+ failed : make (chan struct {}),
2248+ logger : ensureLogger (nil ),
2249+ }
2250+
2251+ lastID , _ , clientClosed := conn .processStream (ctx , "test" , resp , nil )
2252+
2253+ if clientClosed {
2254+ t .Fatalf ("processStream was unexpectedly closed by client" )
2255+ }
2256+
2257+ if lastID != "124" {
2258+ t .Errorf ("lastEventID = %q, want %q" , lastID , "124" )
2259+ }
2260+
2261+ select {
2262+ case msg := <- incoming :
2263+ if res , ok := msg .(* jsonrpc.Response ); ! (ok && res .ID == jsonrpc2 .Int64ID (1 )) {
2264+ t .Errorf ("got unexpected message: %v" , msg )
2265+ }
2266+ default :
2267+ t .Errorf ("expected a JSON-RPC message to be produced" )
2268+ }
2269+ }
2270+
22212271// TestScanEventsPingFiltering is a unit test for the low-level event scanning
22222272// with ping events to verify scanEvents properly parses all event types.
22232273func TestScanEventsPingFiltering (t * testing.T ) {
0 commit comments