@@ -2652,6 +2652,48 @@ func TestSubscriptionsListen_NoHandlersNoListen(t *testing.T) {
26522652 }
26532653}
26542654
2655+ // TestSubscriptionsListen_MissingNotifications verifies that a
2656+ // subscriptions/listen request without the required "notifications" field
2657+ // is rejected with an invalid params error.
2658+ func TestSubscriptionsListen_MissingNotifications (t * testing.T ) {
2659+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
2660+ defer cancel ()
2661+
2662+ server := newSubListenServer ()
2663+ _ , st := NewInMemoryTransports ()
2664+ ss , err := server .Connect (ctx , st , nil )
2665+ if err != nil {
2666+ t .Fatalf ("server connect: %v" , err )
2667+ }
2668+ defer ss .Close ()
2669+
2670+ // Invoke the server handler directly with a nil Notifications field,
2671+ // simulating a request whose params omit the required field on the wire.
2672+ // The client-side subscriptionsListen does not await the RPC response
2673+ // (the call's lifetime is the notification stream), so we assert the
2674+ // server-side behavior at the handler level.
2675+ id , err := jsonrpc .MakeID ("test-1" )
2676+ if err != nil {
2677+ t .Fatalf ("MakeID: %v" , err )
2678+ }
2679+ reqCtx := context .WithValue (ctx , idContextKey {}, id )
2680+ req := & SubscriptionsListenRequest {
2681+ Session : ss ,
2682+ Params : & SubscriptionsListenParams {}, // Notifications is nil
2683+ }
2684+ _ , err = server .subscriptionsListen (reqCtx , req )
2685+ if err == nil {
2686+ t .Fatal ("expected error for missing notifications field, got nil" )
2687+ }
2688+ var jerr * jsonrpc.Error
2689+ if ! errors .As (err , & jerr ) {
2690+ t .Fatalf ("expected *jsonrpc.Error, got %T: %v" , err , err )
2691+ }
2692+ if jerr .Code != jsonrpc .CodeInvalidParams {
2693+ t .Errorf ("error code = %d, want %d" , jerr .Code , jsonrpc .CodeInvalidParams )
2694+ }
2695+ }
2696+
26552697// resourceSubServer builds a server that advertises resource subscriptions
26562698// and records every Subscribe/Unsubscribe handler invocation through chans.
26572699func resourceSubServer (t * testing.T , subCh , unsubCh chan string ) * Server {
0 commit comments