vld-http-common 0.6.0

Shared HTTP helpers for vld web-framework integrations (internal)
Documentation
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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
//! Shared HTTP conformance suite for the `vld` web adapters (test support).
//!
//! Enabled by the `conformance` feature; only the adapters' dev-dependencies
//! turn it on. Every adapter mounts the same routes, using the schemas below:
//!
//! | Route | Extractor | 200 body |
//! |---|---|---|
//! | `POST /json` | JSON `User` | `"{name}:{age}"` |
//! | `POST /form` | form `User` | `"{name}:{age}"` |
//! | `GET /query` | query `Query` | `"{tag joined by ,}\|{q}"` (+ `"\|{page}"` when set) |
//! | `GET /path/{id}` | path `PathId` | `"id={id}"` |
//! | `GET /pstr/{s}` | path `PathStr` | `"{s}"` |
//! | `GET /pnone` (no params) | path `PathNone` | `PathNone::reply` |
//! | `GET /headers` | headers `Headers` | `"{x_tag}"` |
//! | `GET /cookie` | cookies `Cookies` | `"{sid}"` |
//!
//! Body limits stay at the adapter/framework defaults; the oversized cases
//! send [`OVERSIZED_LEN`](crate::conformance::OVERSIZED_LEN) bytes, above every default.
//!
//! Each case is a function in [`cases`](crate::conformance::cases); adapters list the cases they support
//! with [`conformance_suite!`](crate::conformance_suite), marking known
//! failures with `#[ignore = "BUG: ..."]`.

use std::future::Future;

/// Body size used by the oversized cases: above [`DEFAULT_BODY_LIMIT`](crate::DEFAULT_BODY_LIMIT)
/// and every framework default limit.
pub const OVERSIZED_LEN: usize = crate::DEFAULT_BODY_LIMIT + 4096;

vld::schema! {
    /// `POST /json` and `POST /form` body.
    #[derive(Debug, Clone)]
    pub struct User {
        /// At least 2 characters.
        pub name: String => vld::string().min(2),
        /// Non-negative integer.
        pub age: i64 => vld::number().int().min(0),
    }
}

vld::schema! {
    /// `GET /query` parameters.
    #[derive(Debug, Clone)]
    pub struct Query {
        /// Repeated `tag=` parameters.
        pub tag: Vec<String> => vld::array(vld::string()),
        /// Required search text.
        pub q: String => vld::string(),
        /// Optional page number.
        pub page: Option<i64> => vld::number().int().optional(),
    }
}

vld::schema! {
    /// `GET /path/{id}` parameters.
    #[derive(Debug, Clone)]
    pub struct PathId {
        /// Positive integer id.
        pub id: i64 => vld::number().int().min(1),
    }
}

vld::schema! {
    /// `GET /pstr/{s}` parameters.
    #[derive(Debug, Clone)]
    pub struct PathStr {
        /// Any string segment.
        pub s: String => vld::string(),
    }
}

vld::schema! {
    /// `GET /pnone` (a route without parameters) — every field optional.
    #[derive(Debug, Clone)]
    pub struct PathNone {
        /// Absent on this route.
        pub id: Option<i64> => vld::number().int().optional(),
    }
}

vld::schema! {
    /// `GET /headers` headers (`x-tag` → `x_tag`).
    #[derive(Debug, Clone)]
    pub struct Headers {
        /// The `x-tag` header.
        pub x_tag: String => vld::string(),
    }
}

vld::schema! {
    /// `GET /cookie` cookies.
    #[derive(Debug, Clone)]
    pub struct Cookies {
        /// The `sid` cookie.
        pub sid: String => vld::string(),
    }
}

impl User {
    /// The 200 body for `/json` and `/form`.
    pub fn reply(&self) -> String {
        format!("{}:{}", self.name, self.age)
    }
}

impl Query {
    /// The 200 body for `/query`; `|{page}` is appended when `page` is set.
    pub fn reply(&self) -> String {
        let mut out = format!("{}|{}", self.tag.join(","), self.q);
        if let Some(page) = self.page {
            out.push_str(&format!("|{page}"));
        }
        out
    }
}

impl PathId {
    /// The 200 body for `/path/{id}`.
    pub fn reply(&self) -> String {
        format!("id={}", self.id)
    }
}

impl PathNone {
    /// The 200 body for `/pnone`: `"none"` or `"id={id}"`.
    pub fn reply(&self) -> String {
        self.id
            .map_or_else(|| "none".into(), |id| format!("id={id}"))
    }
}

/// A framework-independent request.
#[derive(Debug, Clone)]
pub struct Request {
    /// HTTP method (`"GET"`, `"POST"`).
    pub method: &'static str,
    /// Path and query, e.g. `/query?q=1`.
    pub uri: String,
    /// Header name/value pairs; values may be non-UTF-8.
    pub headers: Vec<(&'static str, Vec<u8>)>,
    /// Request body.
    pub body: Vec<u8>,
}

/// A framework-independent response.
#[derive(Debug, Clone)]
pub struct Response {
    /// HTTP status code.
    pub status: u16,
    /// Response body.
    pub body: Vec<u8>,
}

impl Response {
    fn text(&self) -> String {
        String::from_utf8_lossy(&self.body).into_owned()
    }

    fn json(&self) -> serde_json::Value {
        serde_json::from_slice(&self.body)
            .unwrap_or_else(|e| panic!("response body is not JSON ({e}): {}", self.text()))
    }
}

/// What a case expects back.
#[derive(Debug, Clone)]
pub enum Expect {
    /// 200 with exactly this text body.
    Ok(String),
    /// 422 `{"error":"Validation failed","issues":[...]}` whose issues are
    /// exactly these `(path, code)` pairs (in order; `code` is
    /// [`IssueCode::key()`](vld::error::IssueCode::key)).
    Invalid(Vec<(&'static str, &'static str)>),
    /// 413 `{"error":"Payload too large"}`.
    TooLarge,
    /// 415 `{"error":"Unsupported Media Type","message":"..."}`.
    Unsupported,
}

/// One conformance case.
#[derive(Debug, Clone)]
pub struct Case {
    /// Case name, shown when it fails.
    pub name: &'static str,
    /// The request to send.
    pub request: Request,
    /// What must come back.
    pub expect: Expect,
}

impl Case {
    /// Prefix the request path (e.g. a framework mount point).
    pub fn with_prefix(mut self, prefix: &str) -> Self {
        self.request.uri = format!("{prefix}{}", self.request.uri);
        self
    }

    /// Send the request through `send` and assert the response.
    pub async fn check<F, Fut>(self, send: F)
    where
        F: FnOnce(Request) -> Fut,
        Fut: Future<Output = Response>,
    {
        let name = self.name;
        let resp = send(self.request).await;
        match self.expect {
            Expect::Ok(text) => {
                assert_eq!(resp.status, 200, "[{name}] body: {}", resp.text());
                assert_eq!(resp.text(), text, "[{name}]");
            }
            Expect::Invalid(issues) => {
                assert_eq!(resp.status, 422, "[{name}] body: {}", resp.text());
                let body = resp.json();
                assert_eq!(body["error"], "Validation failed", "[{name}] {body}");
                let got: Vec<(&str, &str)> = body["issues"]
                    .as_array()
                    .unwrap_or_else(|| panic!("[{name}] no issues array: {body}"))
                    .iter()
                    .map(|i| {
                        assert!(
                            i["message"].is_string(),
                            "[{name}] issue without message: {i}"
                        );
                        (
                            i["path"].as_str().unwrap_or("<no path>"),
                            i["code"].as_str().unwrap_or("<no code>"),
                        )
                    })
                    .collect();
                assert_eq!(got, issues, "[{name}] issues (path, code): {body}");
            }
            Expect::TooLarge => {
                assert_eq!(resp.status, 413, "[{name}] body: {}", resp.text());
                assert_eq!(
                    resp.json(),
                    serde_json::json!({"error": "Payload too large"}),
                    "[{name}]"
                );
            }
            Expect::Unsupported => {
                assert_eq!(resp.status, 415, "[{name}] body: {}", resp.text());
                let body = resp.json();
                assert_eq!(body["error"], "Unsupported Media Type", "[{name}] {body}");
                assert!(body["message"].is_string(), "[{name}] {body}");
            }
        }
    }
}

fn req(method: &'static str, uri: &str) -> Request {
    Request {
        method,
        uri: uri.to_string(),
        headers: Vec::new(),
        body: Vec::new(),
    }
}

fn post(uri: &str, content_type: &str, body: impl Into<Vec<u8>>) -> Request {
    let mut r = req("POST", uri);
    r.headers
        .push(("content-type", content_type.as_bytes().to_vec()));
    r.body = body.into();
    r
}

fn case(name: &'static str, request: Request, expect: Expect) -> Case {
    Case {
        name,
        request,
        expect,
    }
}

fn ok(text: &str) -> Expect {
    Expect::Ok(text.to_string())
}

const FORM: &str = "application/x-www-form-urlencoded";

/// Every conformance case, one function each.
pub mod cases {
    use super::*;

    /// Valid JSON body: 200 `Alice:25`.
    pub fn json_valid() -> Case {
        case(
            "json_valid",
            post("/json", "application/json", r#"{"name":"Alice","age":25}"#),
            ok("Alice:25"),
        )
    }

    /// Media types are case-insensitive and may carry parameters.
    pub fn json_content_type_case_insensitive() -> Case {
        case(
            "json_content_type_case_insensitive",
            post(
                "/json",
                "Application/JSON; charset=utf-8",
                r#"{"name":"Alice","age":25}"#,
            ),
            ok("Alice:25"),
        )
    }

    /// Malformed JSON is a 422 with the validation shape (one root issue).
    /// A bare parameter name is tolerated (only the media type matters).
    pub fn json_content_type_bare_param() -> Case {
        case(
            "json_content_type_bare_param",
            post(
                "/json",
                "application/json;charset",
                r#"{"name":"Alice","age":25}"#,
            ),
            ok("Alice:25"),
        )
    }

    /// An unterminated quoted parameter is tolerated too.
    pub fn json_content_type_unterminated_quote() -> Case {
        case(
            "json_content_type_unterminated_quote",
            post(
                "/json",
                "application/json; charset=\"utf-8",
                r#"{"name":"Alice","age":25}"#,
            ),
            ok("Alice:25"),
        )
    }

    /// `application/+json` has an empty subtype before `+json`: 415.
    pub fn json_content_type_empty_suffix() -> Case {
        case(
            "json_content_type_empty_suffix",
            post("/json", "application/+json", r#"{"name":"Alice","age":25}"#),
            Expect::Unsupported,
        )
    }

    /// Structured `+json` suffixes are JSON (`application/vnd.api+json`).
    pub fn json_content_type_json_suffix() -> Case {
        case(
            "json_content_type_json_suffix",
            post(
                "/json",
                "application/vnd.api+json",
                r#"{"name":"Alice","age":25}"#,
            ),
            ok("Alice:25"),
        )
    }

    /// A `+json` suffix with parameters (`application/problem+json; charset=utf-8`).
    pub fn json_content_type_json_suffix_params() -> Case {
        case(
            "json_content_type_json_suffix_params",
            post(
                "/json",
                "application/problem+json; charset=utf-8",
                r#"{"name":"Alice","age":25}"#,
            ),
            ok("Alice:25"),
        )
    }

    /// A JSON body without a `Content-Type` header: 415.
    pub fn json_content_type_missing() -> Case {
        let mut r = req("POST", "/json");
        r.body = br#"{"name":"Alice","age":25}"#.to_vec();
        case("json_content_type_missing", r, Expect::Unsupported)
    }

    /// A JSON body sent as `text/plain`: 415.
    pub fn json_content_type_not_json() -> Case {
        case(
            "json_content_type_not_json",
            post("/json", "text/plain", r#"{"name":"Alice","age":25}"#),
            Expect::Unsupported,
        )
    }

    /// Malformed JSON: 422 with a root `parse_error`.
    pub fn json_malformed() -> Case {
        case(
            "json_malformed",
            post("/json", "application/json", "{"),
            Expect::Invalid(vec![("", "parse_error")]),
        )
    }

    /// JSON that fails the schema: 422 with both field issues.
    pub fn json_validation_error() -> Case {
        case(
            "json_validation_error",
            post("/json", "application/json", r#"{"name":"A","age":-1}"#),
            Expect::Invalid(vec![(".name", "too_small"), (".age", "too_small")]),
        )
    }

    /// JSON body above the size limit: 413.
    pub fn json_oversized() -> Case {
        let pad = "x".repeat(OVERSIZED_LEN);
        case(
            "json_oversized",
            post(
                "/json",
                "application/json",
                format!(r#"{{"name":"{pad}","age":1}}"#),
            ),
            Expect::TooLarge,
        )
    }

    /// Valid form body (`+` decodes to a space): 200.
    pub fn form_valid() -> Case {
        case(
            "form_valid",
            post("/form", FORM, "name=Al+ice&age=25"),
            ok("Al ice:25"),
        )
    }

    /// The form media type is case-insensitive and may carry parameters.
    pub fn form_content_type_params() -> Case {
        case(
            "form_content_type_params",
            post(
                "/form",
                "Application/X-WWW-Form-Urlencoded; charset=UTF-8",
                "name=Alice&age=25",
            ),
            ok("Alice:25"),
        )
    }

    /// A form extractor requires `application/x-www-form-urlencoded`.
    pub fn form_wrong_content_type() -> Case {
        case(
            "form_wrong_content_type",
            post("/form", "application/json", "name=Alice&age=25"),
            Expect::Unsupported,
        )
    }

    /// More than `MAX_FORM_FIELDS` fields is a 422 parse error.
    pub fn form_too_many_fields() -> Case {
        let body = format!("name=Alice&age=25{}", "&a".repeat(crate::MAX_FORM_FIELDS));
        case(
            "form_too_many_fields",
            post("/form", FORM, body),
            Expect::Invalid(vec![("", "parse_error")]),
        )
    }

    /// Form body that fails the schema: 422 with both field issues.
    pub fn form_validation_error() -> Case {
        case(
            "form_validation_error",
            post("/form", FORM, "name=A&age=x"),
            Expect::Invalid(vec![(".name", "too_small"), (".age", "invalid_type")]),
        )
    }

    /// A form body that is not UTF-8 is a 422 parse error.
    pub fn form_non_utf8() -> Case {
        case(
            "form_non_utf8",
            post("/form", FORM, b"name=\xff\xfe&age=1".to_vec()),
            Expect::Invalid(vec![("", "parse_error")]),
        )
    }

    /// Form body above the size limit: 413.
    pub fn form_oversized() -> Case {
        let pad = "x".repeat(OVERSIZED_LEN);
        case(
            "form_oversized",
            post("/form", FORM, format!("name={pad}&age=1")),
            Expect::TooLarge,
        )
    }

    /// `%C3%A9` decodes to `é`, `+` to a space.
    pub fn query_percent_decoding() -> Case {
        case(
            "query_percent_decoding",
            req("GET", "/query?tag=caf%C3%A9&tag=a+b&q=caf%C3%A9"),
            ok("café,a b|café"),
        )
    }

    /// Repeated keys become an array; non-canonical numbers stay strings.
    pub fn query_repeated_keys() -> Case {
        case(
            "query_repeated_keys",
            req("GET", "/query?tag=a&tag=b&tag=c&q=01234"),
            ok("a,b,c|01234"),
        )
    }

    /// Query values follow the schema: a numeric-looking value fills a string
    /// field, a single value fills an array, an integer field is coerced.
    pub fn query_coercion_follows_schema() -> Case {
        case(
            "query_coercion_follows_schema",
            req("GET", "/query?q=123&tag=a&page=30"),
            ok("a|123|30"),
        )
    }

    /// A non-numeric value for an integer field is an `invalid_type` issue.
    pub fn query_int_invalid() -> Case {
        case(
            "query_int_invalid",
            req("GET", "/query?q=x&tag=a&page=abc"),
            Expect::Invalid(vec![(".page", "invalid_type")]),
        )
    }

    /// Query without the required `q`: 422 `missing_field`.
    pub fn query_missing_field() -> Case {
        case(
            "query_missing_field",
            req("GET", "/query?tag=a&tag=b"),
            Expect::Invalid(vec![(".q", "missing_field")]),
        )
    }

    /// Valid path parameter: 200 `id=42`.
    pub fn path_valid() -> Case {
        case("path_valid", req("GET", "/path/42"), ok("id=42"))
    }

    /// Path parameter below the minimum: 422 `too_small`.
    pub fn path_invalid() -> Case {
        case(
            "path_invalid",
            req("GET", "/path/0"),
            Expect::Invalid(vec![(".id", "too_small")]),
        )
    }

    /// Path values are percent-decoded exactly once, `%2F`/`%25`/`%2B`
    /// included; `+` stays a plus.
    pub fn path_percent_decoding() -> Case {
        case(
            "path_percent_decoding",
            req("GET", "/pstr/a%2Fb%25c%2Bd%20e"),
            ok("a/b%c+d e"),
        )
    }

    /// `%2541` is `%41`, not `A`: decoded once only.
    pub fn path_no_double_decoding() -> Case {
        case(
            "path_no_double_decoding",
            req("GET", "/pstr/%2541"),
            ok("%41"),
        )
    }

    /// Invalid UTF-8 after decoding becomes `U+FFFD`.
    pub fn path_invalid_utf8() -> Case {
        case("path_invalid_utf8", req("GET", "/pstr/%FF"), ok("\u{FFFD}"))
    }

    /// A route without parameters is an empty object, not an error.
    pub fn path_no_params_optional() -> Case {
        case("path_no_params_optional", req("GET", "/pnone"), ok("none"))
    }

    /// Header names map `x-tag` → `x_tag`; values may be non-ASCII UTF-8.
    pub fn headers_valid() -> Case {
        let mut r = req("GET", "/headers");
        r.headers.push(("x-tag", "café".as_bytes().to_vec()));
        case("headers_valid", r, ok("café"))
    }

    /// A name containing `_` is ignored: `x_tag` neither fills `x_tag` nor
    /// merges with `x-tag`.
    pub fn headers_underscore_ignored() -> Case {
        let mut r = req("GET", "/headers");
        r.headers.push(("x_tag", b"evil".to_vec()));
        r.headers.push(("x-tag", b"good".to_vec()));
        case("headers_underscore_ignored", r, ok("good"))
    }

    /// Only `x_tag` (underscore) is sent: it is ignored, so 422 `missing_field`.
    pub fn headers_underscore_only() -> Case {
        let mut r = req("GET", "/headers");
        r.headers.push(("x_tag", b"evil".to_vec()));
        case(
            "headers_underscore_only",
            r,
            Expect::Invalid(vec![(".x_tag", "missing_field")]),
        )
    }

    /// Required header absent: 422 `missing_field`.
    pub fn headers_missing() -> Case {
        case(
            "headers_missing",
            req("GET", "/headers"),
            Expect::Invalid(vec![(".x_tag", "missing_field")]),
        )
    }

    /// Quoted cookie values are unquoted and percent-decoded.
    pub fn cookie_quoted_encoded() -> Case {
        let mut r = req("GET", "/cookie");
        r.headers
            .push(("cookie", b"other=1; sid=\"abc%20def\"".to_vec()));
        case("cookie_quoted_encoded", r, ok("abc def"))
    }

    /// Every `Cookie` header is read (HTTP/2 sends one per cookie).
    pub fn cookie_multiple_headers() -> Case {
        let mut r = req("GET", "/cookie");
        r.headers.push(("cookie", b"other=1".to_vec()));
        r.headers.push(("cookie", b"sid=abc".to_vec()));
        case("cookie_multiple_headers", r, ok("abc"))
    }

    /// The first occurrence of a cookie name wins (no cookie tossing).
    pub fn cookie_duplicate_first_wins() -> Case {
        let mut r = req("GET", "/cookie");
        r.headers.push(("cookie", b"sid=legit; sid=evil".to_vec()));
        case("cookie_duplicate_first_wins", r, ok("legit"))
    }

    /// A raw UTF-8 value does not drop the whole header.
    pub fn cookie_non_ascii() -> Case {
        let mut r = req("GET", "/cookie");
        r.headers.push(("cookie", "sid=café".as_bytes().to_vec()));
        case("cookie_non_ascii", r, ok("café"))
    }

    /// A numeric-looking cookie value fills a string field.
    pub fn cookie_numeric_value() -> Case {
        let mut r = req("GET", "/cookie");
        r.headers.push(("cookie", b"sid=42".to_vec()));
        case("cookie_numeric_value", r, ok("42"))
    }

    /// Required cookie absent: 422 `missing_field`.
    pub fn cookie_missing() -> Case {
        let mut r = req("GET", "/cookie");
        r.headers.push(("cookie", b"other=1".to_vec()));
        case(
            "cookie_missing",
            r,
            Expect::Invalid(vec![(".sid", "missing_field")]),
        )
    }
}

/// Generate one test per listed case.
///
/// ```ignore
/// vld_http_common::conformance_suite! {
///     runtime = tokio::test,
///     send = send,
///     cases = [json_valid, #[ignore = "BUG: ..."] form_non_utf8],
/// }
/// ```
///
/// `send` is an `async fn(conformance::Request) -> conformance::Response`.
/// An optional `prefix = "/api",` prefixes every request path.
#[macro_export]
macro_rules! conformance_suite {
    (
        runtime = $rt:meta,
        send = $send:path,
        cases = [ $( $(#[$m:meta])* $case:ident ),* $(,)? ] $(,)?
    ) => {
        $crate::conformance_suite! {
            runtime = $rt,
            send = $send,
            prefix = "",
            cases = [ $( $(#[$m])* $case ),* ],
        }
    };
    (
        runtime = $rt:meta,
        send = $send:path,
        prefix = $prefix:expr,
        cases = [ $( $(#[$m:meta])* $case:ident ),* $(,)? ] $(,)?
    ) => {
        $(
            $(#[$m])*
            #[$rt]
            async fn $case() {
                $crate::conformance::cases::$case()
                    .with_prefix($prefix)
                    .check($send)
                    .await;
            }
        )*
    };
}