ruststream 0.6.1

Async messaging framework for Rust: broker-agnostic traits, router, codecs, and a conformance harness for broker authors.
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
//! Integration tests for the raw `#[subscriber(.., raw)]` form: the handler receives each
//! delivery's payload bytes untouched, with no codec anywhere on the path.
//!
//! The codec-free path itself is additionally pinned by a feature-stripped compile:
//! `cargo check --no-default-features --features macros,memory,testing --test raw_subscriber`
//! builds this file with every codec-gated test compiled out.
#![cfg(all(feature = "macros", feature = "memory", feature = "testing"))]

use std::convert::Infallible;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};

use ruststream::memory::{
    ConnectedMemoryBroker, MemoryBroker, MemoryError, MemoryMessage, MemoryPublish, MemoryPublisher,
};
use ruststream::runtime::{AppInfo, Ctx, HandlerResult, Router, RustStream, State};
use ruststream::testing::TestApp;
use ruststream::{
    BuildContext, ContextField, FromRef, IncomingMessage, OutgoingMessage, PairError,
    PublishPolicy, Publisher, subscriber,
};

/// Deliberately not valid JSON (or UTF-8): a decode step anywhere on the path would fail it.
const FRAME: &[u8] = b"\x00\x01raw \xffbytes";

// --- the plain form: the handler sees the exact published bytes ---

static FRAMES: Mutex<Vec<Vec<u8>>> = Mutex::new(Vec::new());

// --8<-- [start:raw]
#[subscriber("frames", raw)]
async fn on_frame(frame: &[u8]) -> HandlerResult {
    FRAMES.lock().expect("frame log").push(frame.to_vec());
    HandlerResult::Ack
}
// --8<-- [end:raw]

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn raw_handler_receives_exact_bytes() {
    let app = RustStream::new(AppInfo::new("raw", "0.1.0"))
        .with_broker(MemoryBroker::new(), |b| b.include(on_frame));

    let tb = TestApp::start(app).await.expect("start");
    tb.broker::<MemoryBroker>()
        .publish_raw("frames", FRAME)
        .await
        .expect("publish");

    tb.broker::<MemoryBroker>()
        .subscriber("frames")
        .assert_called_once()
        .with_raw(FRAME)
        .settled(HandlerResult::Ack);
    assert_eq!(
        FRAMES.lock().expect("frame log").as_slice(),
        &[FRAME.to_vec()],
        "the handler saw the published bytes untouched"
    );
}

// --- the reply form: raw, publish_raw("dest") republishes the returned bytes as-is ---

// --8<-- [start:raw_reply]
#[subscriber("relay-in", raw, publish_raw("relay-out"))]
async fn relay(frame: &[u8]) -> Vec<u8> {
    let mut reply = frame.to_vec();
    reply.reverse();
    reply
}
// --8<-- [end:raw_reply]

#[subscriber("relay-out", raw)]
async fn relay_capture(_frame: &[u8]) -> HandlerResult {
    HandlerResult::Ack
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn raw_reply_round_trips_exact_bytes() {
    let app = RustStream::new(AppInfo::new("raw", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
        b.include(relay).publisher(MemoryPublish);
        b.include(relay_capture);
    });

    let tb = TestApp::start(app).await.expect("start");
    tb.broker::<MemoryBroker>()
        .publish_raw("relay-in", FRAME)
        .await
        .expect("publish");

    let mut expected = FRAME.to_vec();
    expected.reverse();
    tb.broker::<MemoryBroker>()
        .subscriber("relay-in")
        .assert_called_once()
        .with_raw(FRAME)
        .settled(HandlerResult::Ack);
    tb.broker::<MemoryBroker>()
        .subscriber("relay-out")
        .assert_called_once()
        .with_raw(&expected)
        .settled(HandlerResult::Ack);
}

// --- without .publisher(..) the reply commits with the broker's default publish policy ---

#[subscriber("relay-default-in", raw, publish_raw("relay-default-out"))]
async fn relay_default(frame: &[u8]) -> Vec<u8> {
    frame.to_vec()
}

#[subscriber("relay-default-out", raw)]
async fn relay_default_capture(_frame: &[u8]) -> HandlerResult {
    HandlerResult::Ack
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn raw_reply_defaults_to_the_brokers_publish_policy() {
    let app = RustStream::new(AppInfo::new("raw", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
        b.include(relay_default);
        b.include(relay_default_capture);
    });

    let tb = TestApp::start(app).await.expect("start");
    tb.broker::<MemoryBroker>()
        .publish_raw("relay-default-in", FRAME)
        .await
        .expect("publish");

    tb.broker::<MemoryBroker>()
        .subscriber("relay-default-out")
        .assert_called_once()
        .with_raw(FRAME)
        .settled(HandlerResult::Ack);
}

// --- the Result form: Err skips the publish and settles by the returned HandlerResult ---

#[subscriber("relay-checked-in", raw, publish_raw("relay-checked-out"))]
async fn relay_checked(frame: &[u8]) -> Result<Vec<u8>, HandlerResult> {
    if frame.is_empty() {
        return Err(HandlerResult::drop());
    }
    Ok(frame.to_vec())
}

#[subscriber("relay-checked-out", raw)]
async fn relay_checked_capture(_frame: &[u8]) -> HandlerResult {
    HandlerResult::Ack
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn raw_reply_result_form_controls_the_publish() {
    let app = RustStream::new(AppInfo::new("raw", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
        b.include(relay_checked).publisher(MemoryPublish);
        b.include(relay_checked_capture);
    });

    let tb = TestApp::start(app).await.expect("start");

    // The Err arm: nothing is published and the delivery settles by the returned result.
    tb.broker::<MemoryBroker>()
        .publish_raw("relay-checked-in", b"")
        .await
        .expect("publish empty");
    tb.broker::<MemoryBroker>()
        .subscriber("relay-checked-in")
        .assert_called_once()
        .settled(HandlerResult::drop());
    tb.broker::<MemoryBroker>()
        .subscriber("relay-checked-out")
        .assert_called(0);

    // The Ok arm publishes the bytes as-is.
    tb.broker::<MemoryBroker>()
        .publish_raw("relay-checked-in", FRAME)
        .await
        .expect("publish");
    tb.broker::<MemoryBroker>()
        .subscriber("relay-checked-in")
        .assert_called(2)
        .settled(HandlerResult::Ack);
    tb.broker::<MemoryBroker>()
        .subscriber("relay-checked-out")
        .assert_called_once()
        .with_raw(FRAME)
        .settled(HandlerResult::Ack);
}

// --- a failed reply publish nacks the delivery with requeue, like the typed reply form ---

/// A policy whose live publisher fails its first publish, then delegates to the real one:
/// exercises the reply-publish failure path without tearing a broker down.
struct FlakyPublish(Arc<AtomicBool>);

struct FlakyPublisher {
    inner: MemoryPublisher,
    fail_next: Arc<AtomicBool>,
}

impl Publisher for FlakyPublisher {
    type Error = MemoryError;

    async fn publish(&self, msg: OutgoingMessage<'_>) -> Result<(), MemoryError> {
        if self.fail_next.swap(false, Ordering::SeqCst) {
            return Err(MemoryError::ShutDown);
        }
        self.inner.publish(msg).await
    }
}

impl PublishPolicy<ConnectedMemoryBroker> for FlakyPublish {
    type Live = FlakyPublisher;

    async fn pair(self, connected: &ConnectedMemoryBroker) -> Result<FlakyPublisher, PairError> {
        Ok(FlakyPublisher {
            inner: connected.publisher(),
            fail_next: self.0,
        })
    }
}

#[subscriber("relay-flaky-in", raw, publish_raw("relay-flaky-out"))]
async fn relay_flaky(frame: &[u8]) -> Vec<u8> {
    frame.to_vec()
}

#[subscriber("relay-flaky-out", raw)]
async fn relay_flaky_capture(_frame: &[u8]) -> HandlerResult {
    HandlerResult::Ack
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn failed_raw_reply_publish_nacks_and_redelivers() {
    let fail_next = Arc::new(AtomicBool::new(true));
    let publisher_flag = Arc::clone(&fail_next);
    let app =
        RustStream::new(AppInfo::new("raw", "0.1.0")).with_broker(MemoryBroker::new(), move |b| {
            b.include(relay_flaky)
                .publisher(FlakyPublish(publisher_flag));
            b.include(relay_flaky_capture);
        });

    let tb = TestApp::start(app).await.expect("start");
    tb.broker::<MemoryBroker>()
        .publish_raw("relay-flaky-in", FRAME)
        .await
        .expect("publish");

    // The first delivery's reply publish fails, so it nacks with requeue; the redelivery
    // publishes and acks. The reply reaches the capture exactly once.
    tb.broker::<MemoryBroker>()
        .subscriber("relay-flaky-in")
        .assert_called(2)
        .settled(HandlerResult::Ack);
    tb.broker::<MemoryBroker>()
        .subscriber("relay-flaky-out")
        .assert_called_once()
        .with_raw(FRAME)
        .settled(HandlerResult::Ack);
    assert!(
        !fail_next.load(Ordering::SeqCst),
        "the flaky publisher consumed its failure"
    );
}

// --- publish_raw with a TYPED input: decode with the scope codec, reply bytes as-is ---

#[cfg(feature = "json")]
mod typed_in {
    use serde::Deserialize;

    use super::{
        AppInfo, FRAME, HandlerResult, MemoryBroker, MemoryPublish, RustStream, TestApp, subscriber,
    };

    #[derive(Debug, Deserialize)]
    struct Wrap {
        id: u32,
    }

    // --8<-- [start:raw_reply_typed]
    /// The gateway shape: a structured message in, a self-produced wire format out.
    #[subscriber("gateway-in", publish_raw("gateway-out"))]
    async fn gateway(wrap: &Wrap) -> Vec<u8> {
        wrap.id.to_be_bytes().to_vec()
    }
    // --8<-- [end:raw_reply_typed]

    /// The Result form keeps ack control: an odd id skips the publish and drops.
    #[subscriber("gateway-checked-in", publish_raw("gateway-checked-out"))]
    async fn gateway_checked(wrap: &Wrap) -> Result<Vec<u8>, HandlerResult> {
        if wrap.id % 2 == 1 {
            return Err(HandlerResult::drop());
        }
        Ok(wrap.id.to_be_bytes().to_vec())
    }

    #[subscriber("gateway-out", raw)]
    async fn gateway_capture(frame: &[u8]) -> HandlerResult {
        assert_eq!(frame, 7_u32.to_be_bytes(), "the reply bytes arrive as-is");
        HandlerResult::Ack
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn typed_input_replies_raw_bytes() {
        let app = RustStream::new(AppInfo::new("gateway", "0.1.0")).with_broker(
            MemoryBroker::new(),
            |b| {
                b.include(gateway).publisher(MemoryPublish);
                b.include(gateway_capture);
            },
        );

        let tb = TestApp::start(app).await.expect("start");
        tb.broker::<MemoryBroker>()
            .publish("gateway-in", &serde_json::json!({"id": 7}))
            .await
            .expect("publish");

        tb.broker::<MemoryBroker>()
            .subscriber("gateway-in")
            .assert_called_once()
            .settled(HandlerResult::Ack);
        tb.broker::<MemoryBroker>()
            .subscriber("gateway-out")
            .assert_called_once()
            .with_raw(7_u32.to_be_bytes().as_slice())
            .settled(HandlerResult::Ack);
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn typed_input_decode_and_result_control_apply() {
        let app = RustStream::new(AppInfo::new("gateway", "0.1.0")).with_broker(
            MemoryBroker::new(),
            |b| {
                // The default publish policy commits without an explicit .publisher call.
                b.include(gateway_checked);
            },
        );

        let tb = TestApp::start(app).await.expect("start");
        // Not valid JSON: the typed input side keeps the decode failure policy, unlike raw.
        tb.broker::<MemoryBroker>()
            .publish_raw("gateway-checked-in", FRAME)
            .await
            .expect("publish");
        tb.broker::<MemoryBroker>()
            .subscriber("gateway-checked-in")
            .assert_last_failed_to_decode();

        // An odd id decodes but the handler skips the publish via Err(drop()).
        tb.broker::<MemoryBroker>()
            .publish("gateway-checked-in", &serde_json::json!({"id": 3}))
            .await
            .expect("publish");
        tb.broker::<MemoryBroker>()
            .subscriber("gateway-checked-in")
            .settled(HandlerResult::drop());
        // A skipped reply must not publish.
        tb.broker::<MemoryBroker>()
            .subscriber("gateway-checked-out")
            .assert_not_called();
    }
}

// --- extractors and the ctx parameter keep working next to the raw payload ---

#[derive(FromRef)]
struct CountState {
    bytes_seen: Arc<AtomicUsize>,
}

#[subscriber("frames-state", raw)]
async fn with_state(
    frame: &[u8],
    ctx: &mut Context,
    State(bytes_seen): State<Arc<AtomicUsize>>,
) -> HandlerResult {
    assert_eq!(ctx.name(), "frames-state");
    bytes_seen.fetch_add(frame.len(), Ordering::Relaxed);
    HandlerResult::Ack
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn state_extractor_and_ctx_resolve_alongside_raw() {
    let bytes_seen = Arc::new(AtomicUsize::new(0));
    let state_bytes = bytes_seen.clone();
    let app = RustStream::new(AppInfo::new("raw", "0.1.0"))
        .on_startup(move |()| async move {
            Ok::<_, Infallible>(CountState {
                bytes_seen: state_bytes,
            })
        })
        .with_broker(MemoryBroker::new(), |b| b.include(with_state));

    let tb = TestApp::start(app).await.expect("start");
    tb.broker::<MemoryBroker>()
        .publish_raw("frames-state", FRAME)
        .await
        .expect("publish");

    tb.broker::<MemoryBroker>()
        .subscriber("frames-state")
        .assert_called_once()
        .settled(HandlerResult::Ack);
    assert_eq!(
        bytes_seen.load(Ordering::Relaxed),
        FRAME.len(),
        "the State extractor handed the counter to the raw handler"
    );
}

// --- a Ctx<K> extractor projects the broker context under raw, exactly as in the typed form ---

/// A broker-style per-delivery context built from the message, standing in for an offset /
/// delivery tag a real broker would expose.
struct FrameMeta {
    payload_len: usize,
}

impl BuildContext<MemoryMessage> for FrameMeta {
    fn build(msg: &MemoryMessage) -> Self {
        Self {
            payload_len: msg.payload().len(),
        }
    }
}

#[derive(Clone, Copy, Default)]
struct FrameLen;

impl ContextField for FrameLen {
    type Context = FrameMeta;
    type Value = usize;
    fn read(self, src: &FrameMeta) -> usize {
        src.payload_len
    }
}

static SEEN_LEN: AtomicUsize = AtomicUsize::new(0);

#[subscriber("frames-meta", raw)]
async fn measured(_frame: &[u8], Ctx(len): Ctx<FrameLen>) -> HandlerResult {
    SEEN_LEN.store(len, Ordering::Relaxed);
    HandlerResult::Ack
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn ctx_extractor_projects_the_context_under_raw() {
    let app = RustStream::new(AppInfo::new("raw", "0.1.0"))
        .with_broker(MemoryBroker::new(), |b| b.include(measured));

    let tb = TestApp::start(app).await.expect("start");
    tb.broker::<MemoryBroker>()
        .publish_raw("frames-meta", FRAME)
        .await
        .expect("publish");

    tb.broker::<MemoryBroker>()
        .subscriber("frames-meta")
        .assert_called_once()
        .settled(HandlerResult::Ack);
    assert_eq!(SEEN_LEN.load(Ordering::Relaxed), FRAME.len());
}

// --- workers(..) and on_failure(panic = ..) keep working on the raw form ---

#[subscriber("frames-workers", raw, workers(2), on_failure(panic = drop))]
async fn tolerant(frame: &[u8]) -> HandlerResult {
    assert_ne!(frame, b"boom", "poison frame");
    HandlerResult::Ack
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn workers_and_panic_policy_apply_to_raw() {
    let app = RustStream::new(AppInfo::new("raw", "0.1.0"))
        .with_broker(MemoryBroker::new(), |b| b.include(tolerant));

    let tb = TestApp::start(app).await.expect("start");
    tb.broker::<MemoryBroker>()
        .publish_raw("frames-workers", b"boom")
        .await
        .expect("publish");
    tb.broker::<MemoryBroker>()
        .subscriber("frames-workers")
        .assert_called_once()
        .panicked();

    // The panic policy dropped the poison frame; the app keeps serving.
    tb.broker::<MemoryBroker>()
        .publish_raw("frames-workers", b"ok")
        .await
        .expect("publish after panic");
    tb.broker::<MemoryBroker>()
        .subscriber("frames-workers")
        .assert_called(2)
        .with_raw(b"ok")
        .settled(HandlerResult::Ack);
}

// --- a Router mounts raw definitions through include_raw ---

static ROUTED: AtomicUsize = AtomicUsize::new(0);

#[subscriber("routed-raw", raw)]
async fn routed(frame: &[u8]) -> HandlerResult {
    ROUTED.fetch_add(frame.len(), Ordering::Relaxed);
    HandlerResult::Ack
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn router_mounts_raw_definitions() {
    let router = Router::<MemoryBroker>::new().include_raw(routed);
    let app = RustStream::new(AppInfo::new("raw", "0.1.0"))
        .with_broker(MemoryBroker::new(), |b| b.include_router(router));

    let tb = TestApp::start(app).await.expect("start");
    tb.broker::<MemoryBroker>()
        .publish_raw("routed-raw", FRAME)
        .await
        .expect("publish");

    tb.broker::<MemoryBroker>()
        .subscriber("routed-raw")
        .assert_called_once()
        .with_raw(FRAME)
        .settled(HandlerResult::Ack);
    assert_eq!(ROUTED.load(Ordering::Relaxed), FRAME.len());
}

// --- under a scope codec, raw mounts ignore it while typed neighbours decode with it ---

#[cfg(feature = "json")]
mod scope_codec {
    use super::*;

    use ruststream::codec::JsonCodec;
    use serde::{Deserialize, Serialize};

    #[derive(Serialize, Deserialize, Debug, PartialEq)]
    struct Order {
        id: u32,
    }

    static RAW_BYTES: Mutex<Vec<Vec<u8>>> = Mutex::new(Vec::new());
    static TYPED_ID: AtomicUsize = AtomicUsize::new(0);

    #[subscriber("mixed-raw", raw)]
    async fn raw_side(frame: &[u8]) -> HandlerResult {
        RAW_BYTES.lock().expect("raw log").push(frame.to_vec());
        HandlerResult::Ack
    }

    #[subscriber("mixed-typed")]
    async fn typed_side(order: &Order) -> HandlerResult {
        TYPED_ID.store(order.id as usize, Ordering::Relaxed);
        HandlerResult::Ack
    }

    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn raw_ignores_the_scope_codec() {
        let app = RustStream::new(AppInfo::new("raw", "0.1.0")).with_broker_codec(
            MemoryBroker::new(),
            JsonCodec,
            |b| {
                b.include(raw_side);
                b.include(typed_side);
            },
        );

        let tb = TestApp::start(app).await.expect("start");
        // Bytes no JSON decoder would accept reach the raw handler untouched...
        tb.broker::<MemoryBroker>()
            .publish_raw("mixed-raw", FRAME)
            .await
            .expect("publish raw");
        tb.broker::<MemoryBroker>()
            .subscriber("mixed-raw")
            .assert_called_once()
            .with_raw(FRAME)
            .settled(HandlerResult::Ack);
        assert_eq!(
            RAW_BYTES.lock().expect("raw log").as_slice(),
            &[FRAME.to_vec()]
        );

        // ...while the typed neighbour still decodes with the scope codec.
        tb.broker::<MemoryBroker>()
            .publish("mixed-typed", &Order { id: 9 })
            .await
            .expect("publish typed");
        tb.broker::<MemoryBroker>()
            .subscriber("mixed-typed")
            .assert_called_once()
            .with(&Order { id: 9 })
            .settled(HandlerResult::Ack);
        assert_eq!(TYPED_ID.load(Ordering::Relaxed), 9);
    }
}

// --- AsyncAPI: a raw subscriber has no input schema, but its channel is still listed ---

#[cfg(feature = "asyncapi")]
mod asyncapi_listing {
    use super::*;

    use ruststream::asyncapi::build_spec;

    /// Consumes raw frames.
    #[subscriber("frames-doc", raw)]
    async fn documented(_frame: &[u8]) {}

    #[test]
    fn raw_channel_is_listed_without_a_schema() {
        let app = RustStream::new(AppInfo::new("raw", "0.1.0"))
            .with_broker(MemoryBroker::new(), |b| b.include(documented));

        let spec = build_spec(&app);
        let json = spec.to_json().expect("serialize spec");
        assert!(
            json.contains("\"frames-doc\""),
            "the raw channel is listed: {json}"
        );
        assert!(
            json.contains("Consumes raw frames."),
            "the doc-comment description flows into the spec: {json}"
        );
    }
}