github-copilot-sdk 1.0.29-preview.4

Rust SDK for programmatic control of the GitHub Copilot CLI via JSON-RPC.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *--------------------------------------------------------------------------------------------*/

#![cfg(test)]

use super::*;

#[test]
fn listener_negotiation_logs_do_not_echo_remote_errors() {
    let message = "request rejected: token=listener-secret-sentinel";
    for method in ["host.getConfiguration", "host.ready"] {
        assert_eq!(
            remote_error_log_message(method, message),
            "listener negotiation request rejected"
        );
    }
    assert_eq!(remote_error_log_message("ping", message), message);
}

#[test]
fn deserialize_notification() {
    let json = r#"{"jsonrpc":"2.0","method":"session.event","params":{"id":"e1"}}"#;
    let msg: JsonRpcMessage = serde_json::from_str(json).unwrap();
    assert!(matches!(msg, JsonRpcMessage::Notification(n) if n.method == "session.event"));
}

#[test]
fn deserialize_request() {
    let json =
        r#"{"jsonrpc":"2.0","id":5,"method":"permission.request","params":{"kind":"shell"}}"#;
    let msg: JsonRpcMessage = serde_json::from_str(json).unwrap();
    assert!(
        matches!(msg, JsonRpcMessage::Request(r) if r.id == 5 && r.method == "permission.request")
    );
}

#[test]
fn deserialize_response_with_result() {
    let json = r#"{"jsonrpc":"2.0","id":3,"result":{"ok":true}}"#;
    let msg: JsonRpcMessage = serde_json::from_str(json).unwrap();
    assert!(matches!(msg, JsonRpcMessage::Response(r) if r.id == 3 && !r.is_error()));
}

#[test]
fn deserialize_error_response() {
    let json = r#"{"jsonrpc":"2.0","id":7,"error":{"code":-32600,"message":"Invalid Request","data":{"nested":[1,{"reason":"invalid"}]}}}"#;
    let msg: JsonRpcMessage = serde_json::from_str(json).unwrap();
    match msg {
        JsonRpcMessage::Response(r) => {
            assert!(r.is_error());
            let err = r.error.unwrap();
            assert_eq!(err.code, -32600);
            assert_eq!(err.message, "Invalid Request");
            assert_eq!(
                err.data,
                Some(serde_json::json!({"nested": [1, {"reason": "invalid"}]}))
            );
        }
        other => panic!("expected Response, got {other:?}"),
    }
}

#[test]
fn null_id_error_decodes_as_an_uncorrelated_error() {
    let json = r#"{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"recursion limit exceeded at line 1 column 513"}}"#;
    match serde_json::from_str::<JsonRpcMessage>(json).unwrap() {
        JsonRpcMessage::UncorrelatedError(error) => {
            assert_eq!(error.code, -32700);
            assert_eq!(
                error.message,
                "recursion limit exceeded at line 1 column 513"
            );
        }
        other => panic!("expected UncorrelatedError, got {other:?}"),
    }
    // A numeric id is still a response, and a null id must carry an error.
    let json = r#"{"jsonrpc":"2.0","id":3,"error":{"code":-32700,"message":"m"}}"#;
    assert!(matches!(
        serde_json::from_str::<JsonRpcMessage>(json).unwrap(),
        JsonRpcMessage::Response(response) if response.id == 3
    ));
    let json = r#"{"jsonrpc":"2.0","id":null,"result":{}}"#;
    assert!(serde_json::from_str::<JsonRpcMessage>(json).is_err());
}

#[test]
fn an_error_code_wider_than_i32_is_kept() {
    let json = r#"{"jsonrpc":"2.0","id":3,"error":{"code":4294967296,"message":"wide"}}"#;
    let JsonRpcMessage::Response(response) = serde_json::from_str::<JsonRpcMessage>(json).unwrap()
    else {
        panic!("expected a response");
    };
    let error = response.error.unwrap();
    assert_eq!(error.code, 4_294_967_296);
    // The public code is an `i32`: a wider one saturates, and the message keeps it.
    let error = Error::from_rpc(error.code, error.message, None);
    assert_eq!(error.rpc_code(), Some(i32::MAX));
    assert!(
        error
            .message()
            .is_some_and(|message| message.contains("4294967296")),
        "{error}"
    );
}

#[test]
fn a_peer_message_is_repeated_without_its_quoted_values() {
    let message = r#"invalid type: string "ghp_secret\"token", expected u64 at line 1 column 40"#;
    assert_eq!(
        sanitized_peer_message(message),
        "invalid type: string \"…\", expected u64 at line 1 column 40"
    );
    assert_eq!(
        sanitized_peer_message("unknown variant `ghp_secret`, expected one of `a`"),
        "unknown variant `…`, expected one of `…`"
    );
    let long = "x".repeat(500);
    assert_eq!(
        sanitized_peer_message(&long).chars().count(),
        PEER_MESSAGE_MAX_CHARS + 1
    );
}

#[test]
fn deserialize_rejects_non_object() {
    let result = serde_json::from_str::<JsonRpcMessage>(r#""not an object""#);
    assert!(result.is_err());
}

#[test]
fn frame_decoder_preserves_message_classification_payloads_and_errors() {
    for body in [
        r#"{"jsonrpc":"2.0","id":1,"result":{}}"#,
        r#"{"jsonrpc":"2.0","id":1,"result":null}"#,
        r#"{"jsonrpc":"2.0","id":1,"result":[false,{"value":0.125}]}"#,
        r#"{"jsonrpc":"2.0","id":1,"error":{"code":4294967296,"message":"wide","data":{"nested":[null,true]}}}"#,
        r#"{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"uncorrelated"}}"#,
        r#"{"jsonrpc":"2.0","method":"notify","params":{"text":"value"}}"#,
        r#"{"jsonrpc":"2.0","method":"notify","params":null,"result":false,"error":false}"#,
        r#"{"jsonrpc":"2.0","id":2,"method":"request","params":[1,null,true]}"#,
        r#"{"jsonrpc":"2.0","id":2,"method":"request","result":false,"error":false}"#,
        r#"{"jsonrpc":"2.0","id":2,"met\u0068od":"request","params":{}}"#,
        r#"{"jsonrpc":"2.0","id":1,"result":{},"extra":{"nested":[1,2]}}"#,
        r#"{"jsonrpc":"2.0","id":1,"id":2,"result":{}}"#,
        r#"{"jsonrpc":"2.0","method":false,"method":"notify","params":{}}"#,
        r#"{"jsonrpc":"2.0","method":"notify","params":{},"params":[1,2]}"#,
        r#"{"jsonrpc":"1.0","id":1,"result":{}}"#,
        r#"{"jsonrpc":false,"id":1,"result":{}}"#,
        r#"{"id":1,"result":{}}"#,
        r#"{"jsonrpc":"2.0","id":null,"result":{}}"#,
        r#"{"jsonrpc":"2.0","id":null,"method":"request"}"#,
        r#"{"jsonrpc":"2.0","id":1,"method":null}"#,
        r#"{"jsonrpc":"2.0","id":-1,"result":{}}"#,
        r#"{"jsonrpc":"2.0","id":1.5,"result":{}}"#,
        r#"{"jsonrpc":"2.0","id":"string","result":{}}"#,
        r#"{"jsonrpc":"2.0","id":1,"error":false}"#,
        r#"{"jsonrpc":"2.0","id":null,"error":null}"#,
        r#"{"jsonrpc":"2.0","result":{}}"#,
        r#"["2.0",1,"request",{},null,null]"#,
        r#"null"#,
        r#""text""#,
        r#"{"jsonrpc":"2.0","id":1,"result":"\ud83d"}"#,
        r#"{"jsonrpc":"2.0","id":1,"result":{}} trailing"#,
        r#"{"jsonrpc":"2.0","id":1,"result":{},}"#,
    ] {
        let expected = serde_json::from_str::<JsonRpcMessage>(body)
            .map(|message| serde_json::to_value(message).unwrap())
            .map_err(|error| error.to_string());
        let actual = JsonRpcMessage::from_slice(body.as_bytes())
            .map(|message| serde_json::to_value(message).unwrap())
            .map_err(|error| error.to_string());
        assert_eq!(actual, expected, "{body}");
    }
}

#[test]
fn deserialize_preserves_optional_payloads() {
    for payload in [
        None,
        Some(Value::Null),
        Some(serde_json::json!(false)),
        Some(serde_json::json!(42)),
        Some(serde_json::json!("text")),
        Some(serde_json::json!([{"nested": [1, null, true]}])),
        Some(serde_json::json!({"rows": [{"content": "result"}]})),
    ] {
        for mut envelope in [
            serde_json::json!({"jsonrpc": "2.0", "method": "notify"}),
            serde_json::json!({"jsonrpc": "2.0", "id": 1, "method": "request"}),
            serde_json::json!({"jsonrpc": "2.0", "id": 1}),
        ] {
            let (payload_key, ignored_key) = if envelope.get("method").is_some() {
                ("params", "result")
            } else {
                ("result", "params")
            };
            envelope[ignored_key] = serde_json::json!({"ignored": "opposite payload"});
            if let Some(payload) = &payload {
                envelope[payload_key] = payload.clone();
            }
            let actual = match serde_json::from_value::<JsonRpcMessage>(envelope).unwrap() {
                JsonRpcMessage::Request(request) => request.params,
                JsonRpcMessage::Response(response) => response.result,
                JsonRpcMessage::Notification(notification) => notification.params,
                JsonRpcMessage::UncorrelatedError(error) => {
                    panic!("no envelope here has a null id: {error:?}")
                }
            };
            assert_eq!(actual, payload.clone().filter(|value| !value.is_null()));
        }
    }
}

#[test]
fn deserialize_rejects_invalid_metadata() {
    for json in [
        r#"{"jsonrpc":null,"method":"notify","params":{"nested":[1]}}"#,
        r#"{"jsonrpc":"2.0","method":42,"params":{"nested":[1]}}"#,
        r#"{"jsonrpc":"2.0","id":null,"result":{}}"#,
        r#"{"jsonrpc":null,"id":null,"error":{"code":-32700,"message":"m"}}"#,
        r#"{"jsonrpc":"2.0","id":"1","result":{}}"#,
        r#"{"jsonrpc":"2.0","id":-1,"result":{}}"#,
        r#"{"jsonrpc":"2.0","id":1,"method":null,"params":{}}"#,
        r#"{"jsonrpc":"2.0","id":1,"result":{},"error":{"code":"bad","message":"error"}}"#,
    ] {
        assert!(
            serde_json::from_str::<JsonRpcMessage>(json).is_err(),
            "{json}"
        );
    }
}

#[test]
fn request_new_sets_version() {
    let req = JsonRpcRequest::new(42, "test.method", None);
    assert_eq!(req.jsonrpc, "2.0");
    assert_eq!(req.id, 42);
    assert_eq!(req.method, "test.method");
    assert!(req.params.is_none());
}

#[test]
fn request_serializes_camel_case() {
    let req = JsonRpcRequest::new(1, "ping", Some(serde_json::json!({})));
    let json = serde_json::to_string(&req).unwrap();
    assert!(json.contains(r#""jsonrpc":"2.0""#));
    assert!(json.contains(r#""id":1"#));
    assert!(json.contains(r#""method":"ping""#));
}

/// The frame the published framing wrote: the header, then `to_vec`'s body.
fn published_frame<T: serde::Serialize>(message: &T) -> Vec<u8> {
    let body = serde_json::to_vec(message).unwrap();
    let mut frame = format!("Content-Length: {}\r\n\r\n", body.len()).into_bytes();
    frame.extend_from_slice(&body);
    frame
}

#[test]
fn encode_frame_writes_the_published_frame() {
    let message = serde_json::json!({
        "jsonrpc": "2.0",
        "id": 7,
        "result": {"content": "a \"quoted\" line\n"}
    });
    assert_eq!(
        encode_frame(&message).unwrap().as_bytes(),
        published_frame(&message)
    );
    // The length gains a digit at 10, 100, 1000 and 10000 bytes. Each body is a
    // JSON string: its characters and two quotes.
    for body_len in [9, 10, 99, 100, 999, 1000, 9999, 10000] {
        let message = "x".repeat(body_len - 2);
        let frame = encode_frame(&message).unwrap();
        assert!(
            frame
                .as_bytes()
                .starts_with(format!("Content-Length: {body_len}\r\n\r\n").as_bytes())
        );
        assert_eq!(frame.as_bytes(), published_frame(&message));
    }
}

#[test]
fn encode_frame_gives_back_large_spare_capacity() {
    // A 64 KiB string is written in one piece, and its closing quote then
    // doubles the buffer to about twice the frame's size.
    let message = "x".repeat(64 * 1024);
    let frame = encode_frame(&message).unwrap();
    assert_eq!(frame.as_bytes(), published_frame(&message));
    assert!(
        frame.buf.capacity() <= frame.buf.len() + 4096,
        "a {}-byte frame keeps {} bytes",
        frame.buf.len(),
        frame.buf.capacity()
    );
}

#[test]
fn encode_frame_writes_the_header_into_the_room_before_the_body() {
    // A 100-byte body: a JSON string of 98 characters.
    let message = "x".repeat(98);
    let frame = encode_frame(&message).unwrap();
    let header: &[u8] = b"Content-Length: 100\r\n\r\n";
    assert_eq!(frame.start, FRAME_PREFIX - header.len());
    assert_eq!(&frame.buf[frame.start..FRAME_PREFIX], header);
    assert_eq!(
        &frame.buf[FRAME_PREFIX..],
        serde_json::to_vec(&message).unwrap().as_slice()
    );
}

#[test]
fn notification_without_params_omits_field() {
    let n = JsonRpcNotification {
        jsonrpc: "2.0".into(),
        method: "ping".into(),
        params: None,
    };
    let json = serde_json::to_string(&n).unwrap();
    assert!(!json.contains("params"));
}

/// `Value::Null` inside `levels` nested arrays.
fn nested(levels: usize) -> Value {
    let mut value = Value::Null;
    for _ in 0..levels {
        value = Value::Array(vec![value]);
    }
    value
}

/// `PEER_MAX_NESTING` is what the CLI's parser, `serde_json::from_slice` with
/// its default recursion limit, reads: a response that deep decodes, one level
/// deeper does not, and the guard agrees on both, for a result and for an
/// error's data. A serde_json change to the limit fails this test.
#[test]
fn peer_max_nesting_is_what_serde_json_reads() {
    fn decodes(response: &JsonRpcResponse) -> bool {
        serde_json::from_slice::<Value>(&serde_json::to_vec(response).unwrap()).is_ok()
    }
    let with_result = |levels| JsonRpcResponse {
        jsonrpc: "2.0".into(),
        id: 1,
        result: Some(nested(levels)),
        error: None,
    };
    let with_data = |levels| JsonRpcResponse {
        jsonrpc: "2.0".into(),
        id: 1,
        result: None,
        error: Some(JsonRpcError {
            code: -1,
            message: "m".into(),
            data: Some(nested(levels)),
        }),
    };
    // The response object is one level, and an error object another.
    for (case, at_limit, too_deep) in [
        (
            "result",
            with_result(PEER_MAX_NESTING - 1),
            with_result(PEER_MAX_NESTING),
        ),
        (
            "error data",
            with_data(PEER_MAX_NESTING - 2),
            with_data(PEER_MAX_NESTING - 1),
        ),
    ] {
        assert!(
            decodes(&at_limit),
            "{case}: serde_json reads {PEER_MAX_NESTING} levels"
        );
        assert!(
            !decodes(&too_deep),
            "{case}: serde_json refuses one level more"
        );
        assert!(
            !at_limit.nests_too_deep_for_peer(),
            "{case}: the guard passes the readable response"
        );
        assert!(
            too_deep.nests_too_deep_for_peer(),
            "{case}: the guard stops the unreadable one"
        );
    }
}

/// A request is held to the same limit as a response: params that make the
/// frame `PEER_MAX_NESTING` deep decode and pass the guard, and one level
/// deeper does neither, so the SDK fails that request instead of sending a
/// frame the CLI cannot identify.
#[test]
fn a_request_passes_the_guard_exactly_when_serde_json_reads_it() {
    fn decodes(request: &JsonRpcRequest) -> bool {
        serde_json::from_slice::<Value>(&serde_json::to_vec(request).unwrap()).is_ok()
    }
    // The request object is one level.
    let at_limit = JsonRpcRequest::new(1, "m", Some(nested(PEER_MAX_NESTING - 1)));
    let too_deep = JsonRpcRequest::new(1, "m", Some(nested(PEER_MAX_NESTING)));
    assert!(
        decodes(&at_limit),
        "serde_json reads a request {PEER_MAX_NESTING} levels deep"
    );
    assert!(
        !decodes(&too_deep),
        "serde_json refuses a request one level deeper"
    );
    assert!(
        !at_limit.nests_too_deep_for_peer(),
        "the request guard passes the readable request"
    );
    assert!(
        too_deep.nests_too_deep_for_peer(),
        "the request guard stops the unreadable request"
    );
}

#[test]
fn response_without_error_omits_field() {
    let r = JsonRpcResponse {
        jsonrpc: "2.0".into(),
        id: 1,
        result: Some(serde_json::json!(true)),
        error: None,
    };
    let json = serde_json::to_string(&r).unwrap();
    assert!(!json.contains("error"));
}

#[tokio::test]
async fn request_after_the_read_loop_ended_leaves_no_pending_entry() {
    for eager in [false, true] {
        let (client_write, _server_read) = tokio::io::duplex(4096);
        let (server_write, client_read) = tokio::io::duplex(4096);
        let (notification_tx, _) = broadcast::channel(16);
        let (request_tx, _request_rx) = mpsc::unbounded_channel();
        let client = JsonRpcClient::new(client_write, client_read, notification_tx, request_tx);
        let closed = client.connection_closed_token();
        // The peer closes its side: the read loop ends and drains its requests.
        drop(server_write);
        tokio::time::timeout(std::time::Duration::from_secs(5), closed.cancelled())
            .await
            .expect("the read loop did not end");

        let error = if eager {
            match client.begin_request_with_inline_callback("ping", None, None) {
                Err(error) => error,
                Ok(_) => panic!("the eager request after the close was not refused"),
            }
        } else {
            tokio::time::timeout(
                std::time::Duration::from_secs(5),
                client.send_request("ping", None),
            )
            .await
            .expect("the request after the close was not refused")
            .unwrap_err()
        };
        assert_eq!(error.kind(), &ErrorKind::Io);
        assert!(
            client.pending_requests.read().is_empty(),
            "the refused request left its entry (eager: {eager})"
        );
    }
}

#[tokio::test]
async fn notification_receivers_share_one_parsed_notification() {
    let (client_write, _server_read) = tokio::io::duplex(4096);
    let (mut server_write, client_read) = tokio::io::duplex(4096);
    let (notification_tx, mut first) = broadcast::channel(16);
    let mut second = notification_tx.subscribe();
    let (request_tx, _request_rx) = mpsc::unbounded_channel();
    let _client = JsonRpcClient::new(client_write, client_read, notification_tx, request_tx);

    let body = br#"{"jsonrpc":"2.0","method":"session.event","params":{"sessionId":"s1","event":{"data":{"deltaContent":"hi"}}}}"#;
    server_write
        .write_all(format!("Content-Length: {}\r\n\r\n", body.len()).as_bytes())
        .await
        .unwrap();
    server_write.write_all(body).await.unwrap();

    let deadline = std::time::Duration::from_secs(5);
    let first = tokio::time::timeout(deadline, first.recv())
        .await
        .expect("first receiver got no notification")
        .unwrap();
    let second = tokio::time::timeout(deadline, second.recv())
        .await
        .expect("second receiver got no notification")
        .unwrap();
    // Each receiver gets the same parsed notification, not a deep copy of it.
    assert!(Arc::ptr_eq(&first, &second));
    assert_eq!(first.method, "session.event");
    assert_eq!(
        first.params.as_ref().unwrap()["event"]["data"]["deltaContent"],
        "hi"
    );
}

#[tokio::test]
async fn a_frame_body_is_reserved_as_it_arrives_not_as_declared() {
    let (client_write, _server_read) = tokio::io::duplex(4096);
    let (mut server_write, client_read) = tokio::io::duplex(4096);
    let (notification_tx, _) = broadcast::channel(16);
    let (request_tx, _request_rx) = mpsc::unbounded_channel();
    let client = JsonRpcClient::new(client_write, client_read, notification_tx, request_tx);
    let closed = client.connection_closed_token();

    // No address space holds a 1 PiB body, so reserving the declared length
    // before the body arrives fails the allocation and aborts the process.
    server_write
        .write_all(b"Content-Length: 1125899906842624\r\n\r\n{\"jsonrpc\":\"2.0\"")
        .await
        .unwrap();
    tokio::time::sleep(std::time::Duration::from_millis(100)).await;
    assert!(
        !closed.is_cancelled(),
        "the connection ended while the peer was still sending the frame"
    );

    // The peer closes mid-frame: the truncated read ends the connection.
    drop(server_write);
    tokio::time::timeout(std::time::Duration::from_secs(5), closed.cancelled())
        .await
        .expect("the read loop did not end at the truncated frame");
}

#[tokio::test]
async fn a_frame_body_larger_than_the_first_reserve_arrives_whole() {
    let (client_write, _server_read) = tokio::io::duplex(4096);
    let (mut server_write, client_read) = tokio::io::duplex(4096);
    let (notification_tx, mut notifications) = broadcast::channel(16);
    let (request_tx, _request_rx) = mpsc::unbounded_channel();
    let _client = JsonRpcClient::new(client_write, client_read, notification_tx, request_tx);

    // Several reserve steps, the last one partial, each fed through a pipe
    // far smaller than the body.
    let text = "x".repeat(FRAME_BODY_FIRST_RESERVE * 5 + 17);
    let body = serde_json::to_vec(&serde_json::json!({
        "jsonrpc": "2.0",
        "method": "session.event",
        "params": { "text": text },
    }))
    .unwrap();
    let writer = tokio::spawn(async move {
        server_write
            .write_all(format!("Content-Length: {}\r\n\r\n", body.len()).as_bytes())
            .await
            .unwrap();
        server_write.write_all(&body).await.unwrap();
        server_write
    });

    let notification =
        tokio::time::timeout(std::time::Duration::from_secs(5), notifications.recv())
            .await
            .expect("the large notification did not arrive")
            .unwrap();
    assert_eq!(notification.params.as_ref().unwrap()["text"], text);
    drop(writer.await.unwrap());
}