asupersync 0.3.1

Spec-first, cancel-correct, capability-secure async runtime for Rust.
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
//! HTTP/3 response body stream.

extern crate bytes as bytes_crate;
extern crate http as http_crate;

use bytes_crate::{Buf, Bytes, BytesMut};
use h3::error::Code;

use super::client::H3RequestStream;
use super::error::H3Error;
use crate::cx::Cx;
use http_crate::HeaderMap;

/// Streaming HTTP/3 response body.
pub struct H3Body {
    stream: H3RequestStream,
    done: bool,
}

impl H3Body {
    pub(crate) fn new(stream: H3RequestStream) -> Self {
        Self {
            stream,
            done: false,
        }
    }

    /// Read the next body chunk.
    ///
    /// Returns `None` when the body is fully consumed.
    pub async fn chunk(&mut self, cx: &Cx) -> Result<Option<Bytes>, H3Error> {
        if let Err(err) = cx.checkpoint() {
            self.cancel();
            return Err(err.into());
        }

        if self.done {
            return Ok(None);
        }

        let Some(mut buf) = self.stream.recv_data().await? else {
            self.done = true;
            return Ok(None);
        };

        let bytes = buf.copy_to_bytes(buf.remaining());
        Ok(Some(bytes))
    }

    /// Collect the full body into a single `Bytes` buffer.
    pub async fn collect(mut self, cx: &Cx) -> Result<Bytes, H3Error> {
        let mut out = BytesMut::new();
        while let Some(chunk) = self.chunk(cx).await? {
            out.extend_from_slice(&chunk);
        }
        Ok(out.freeze())
    }

    /// Receive trailing headers, if any.
    pub async fn trailers(&mut self, cx: &Cx) -> Result<Option<HeaderMap>, H3Error> {
        if let Err(err) = cx.checkpoint() {
            self.cancel();
            return Err(err.into());
        }

        Ok(self.stream.recv_trailers().await?)
    }

    fn cancel(&mut self) {
        let _ = self.stream.stop_sending(Code::H3_REQUEST_CANCELLED);
    }
}

#[cfg(all(test, feature = "http3"))]
mod flow_control_golden_tests {
    use super::*;
    use crate::cx::Cx;
    use crate::types::Time;
    use bytes_crate::{Bytes, BytesMut};
    use std::collections::VecDeque;
    use std::sync::{Arc, Mutex};

    // ─── Mock Flow Control State ───────────────────────────────────────────

    /// Mock flow control window for testing.
    #[derive(Debug, Clone)]
    struct MockFlowControlWindow {
        /// Maximum data window for the connection.
        max_data: u64,
        /// Current consumed data at connection level.
        consumed_data: u64,
        /// Per-stream max data windows.
        stream_max_data: std::collections::HashMap<u64, u64>,
        /// Per-stream consumed data.
        stream_consumed: std::collections::HashMap<u64, u64>,
        /// Queue of blocked streams waiting for flow control.
        blocked_streams: VecDeque<u64>,
        /// Connection-level blocked state.
        connection_blocked: bool,
    }

    impl MockFlowControlWindow {
        fn new(initial_max_data: u64) -> Self {
            Self {
                max_data: initial_max_data,
                consumed_data: 0,
                stream_max_data: std::collections::HashMap::new(),
                stream_consumed: std::collections::HashMap::new(),
                blocked_streams: VecDeque::new(),
                connection_blocked: false,
            }
        }

        fn add_stream(&mut self, stream_id: u64, max_stream_data: u64) {
            self.stream_max_data.insert(stream_id, max_stream_data);
            self.stream_consumed.insert(stream_id, 0);
        }

        fn consume_data(&mut self, stream_id: u64, bytes: u64) -> Result<(), FlowControlError> {
            // Check connection-level limit
            if self.consumed_data + bytes > self.max_data {
                self.connection_blocked = true;
                return Err(FlowControlError::ConnectionBlocked);
            }

            // Check stream-level limit
            let stream_consumed = self.stream_consumed.get_mut(&stream_id)
                .ok_or(FlowControlError::UnknownStream)?;
            let stream_max = *self.stream_max_data.get(&stream_id)
                .ok_or(FlowControlError::UnknownStream)?;

            if *stream_consumed + bytes > stream_max {
                self.blocked_streams.push_back(stream_id);
                return Err(FlowControlError::StreamBlocked(stream_id));
            }

            // Update consumption
            self.consumed_data += bytes;
            *stream_consumed += bytes;

            Ok(())
        }

        fn update_max_data(&mut self, new_max_data: u64) {
            self.max_data = new_max_data;
            if !self.connection_blocked && self.consumed_data <= self.max_data {
                self.connection_blocked = false;
            }
        }

        fn update_max_stream_data(&mut self, stream_id: u64, new_max_stream_data: u64) {
            if let Some(max_data) = self.stream_max_data.get_mut(&stream_id) {
                *max_data = new_max_stream_data;

                // Unblock stream if it's no longer blocked
                let consumed = *self.stream_consumed.get(&stream_id).unwrap_or(&0);
                if consumed <= new_max_stream_data {
                    self.blocked_streams.retain(|&id| id != stream_id);
                }
            }
        }

        fn available_connection_window(&self) -> u64 {
            self.max_data.saturating_sub(self.consumed_data)
        }

        fn available_stream_window(&self, stream_id: u64) -> u64 {
            let max = *self.stream_max_data.get(&stream_id).unwrap_or(&0);
            let consumed = *self.stream_consumed.get(&stream_id).unwrap_or(&0);
            max.saturating_sub(consumed)
        }
    }

    #[derive(Debug, Clone, PartialEq)]
    enum FlowControlError {
        ConnectionBlocked,
        StreamBlocked(u64),
        UnknownStream,
    }

    /// Mock DATA frame for testing fragmentation.
    #[derive(Debug, Clone)]
    struct MockDataFrame {
        stream_id: u64,
        data: Bytes,
        offset: u64,
        fin: bool,
    }

    impl MockDataFrame {
        fn new(stream_id: u64, data: Bytes, offset: u64, fin: bool) -> Self {
            Self { stream_id, data, offset, fin }
        }

        fn len(&self) -> usize {
            self.data.len()
        }

        /// Fragment this frame into smaller frames that fit within packet limits.
        fn fragment(&self, max_packet_size: usize) -> Vec<MockDataFrame> {
            let mut fragments = Vec::new();
            let mut offset = self.offset;
            let mut remaining = self.data.clone();

            while !remaining.is_empty() {
                let chunk_size = remaining.len().min(max_packet_size);
                let chunk = remaining.split_to(chunk_size);
                let is_last = remaining.is_empty();

                fragments.push(MockDataFrame::new(
                    self.stream_id,
                    chunk,
                    offset,
                    self.fin && is_last,
                ));

                offset += chunk_size as u64;
            }

            fragments
        }
    }

    // ─── Golden Test Results ───────────────────────────────────────────────

    /// Result of a flow control golden test.
    #[derive(Debug, Clone, PartialEq)]
    struct FlowControlGoldenResult {
        test_name: String,
        max_data_consumption: u64,
        stream_data_limits: Vec<(u64, u64, u64)>, // (stream_id, max, consumed)
        fragmented_frames: usize,
        blocked_streams: Vec<u64>,
        connection_blocked: bool,
    }

    impl FlowControlGoldenResult {
        fn to_golden_string(&self) -> String {
            format!(
                "test:{},max_data:{},streams:[{}],fragments:{},blocked_streams:[{}],conn_blocked:{}",
                self.test_name,
                self.max_data_consumption,
                self.stream_data_limits.iter()
                    .map(|(id, max, consumed)| format!("{}:{}/{}", id, consumed, max))
                    .collect::<Vec<_>>()
                    .join(","),
                self.fragmented_frames,
                self.blocked_streams.iter()
                    .map(|id| id.to_string())
                    .collect::<Vec<_>>()
                    .join(","),
                self.connection_blocked
            )
        }
    }

    // ─── Golden Test Functions ─────────────────────────────────────────────

    /// Golden Test 1: MAX_DATA frame consumption
    ///
    /// Verifies that MAX_DATA frames correctly update connection-level flow control
    /// windows and unblock streams waiting for connection-level flow control.
    #[test]
    fn golden_max_data_frame_consumption() {
        crate::test_utils::init_test_logging();
        crate::test_phase!("golden_max_data_frame_consumption");

        let mut flow_control = MockFlowControlWindow::new(1000); // 1KB initial window
        flow_control.add_stream(1, 500);
        flow_control.add_stream(2, 600);

        // Consume data up to connection limit
        assert!(flow_control.consume_data(1, 400).is_ok());
        assert!(flow_control.consume_data(2, 500).is_ok());
        assert_eq!(flow_control.consumed_data, 900);

        // Next consumption should block connection
        assert_eq!(
            flow_control.consume_data(1, 200),
            Err(FlowControlError::ConnectionBlocked)
        );
        assert!(flow_control.connection_blocked);

        // Update MAX_DATA to higher value
        flow_control.update_max_data(1500);
        assert!(!flow_control.connection_blocked);
        assert_eq!(flow_control.available_connection_window(), 600); // 1500 - 900

        // Should now be able to consume more data
        assert!(flow_control.consume_data(1, 100).is_ok());
        assert_eq!(flow_control.consumed_data, 1000);

        let result = FlowControlGoldenResult {
            test_name: "max_data_consumption".to_string(),
            max_data_consumption: flow_control.consumed_data,
            stream_data_limits: vec![(1, 500, 500), (2, 600, 500)],
            fragmented_frames: 0,
            blocked_streams: flow_control.blocked_streams.iter().copied().collect(),
            connection_blocked: flow_control.connection_blocked,
        };

        assert_golden_flow_control_state(
            &result,
            "max_data_consumption",
            "test:max_data_consumption,max_data:1000,streams:[1:500/500,2:500/600],fragments:0,blocked_streams:[],conn_blocked:false"
        );

        crate::test_complete!("golden_max_data_frame_consumption");
    }

    /// Golden Test 2: MAX_STREAM_DATA per-stream limits
    ///
    /// Verifies that per-stream flow control windows are enforced independently
    /// and that MAX_STREAM_DATA frames correctly update stream limits.
    #[test]
    fn golden_max_stream_data_per_stream_limits() {
        crate::test_utils::init_test_logging();
        crate::test_phase!("golden_max_stream_data_per_stream_limits");

        let mut flow_control = MockFlowControlWindow::new(10000); // Large connection window
        flow_control.add_stream(4, 300); // Stream 4: 300 bytes max
        flow_control.add_stream(8, 500); // Stream 8: 500 bytes max

        // Stream 4: consume up to limit
        assert!(flow_control.consume_data(4, 300).is_ok());
        assert_eq!(flow_control.available_stream_window(4), 0);

        // Stream 4: additional consumption should block
        assert_eq!(
            flow_control.consume_data(4, 1),
            Err(FlowControlError::StreamBlocked(4))
        );
        assert!(flow_control.blocked_streams.contains(&4));

        // Stream 8: should still work independently
        assert!(flow_control.consume_data(8, 400).is_ok());
        assert_eq!(flow_control.available_stream_window(8), 100);

        // Update MAX_STREAM_DATA for stream 4
        flow_control.update_max_stream_data(4, 600);
        assert!(!flow_control.blocked_streams.contains(&4));
        assert_eq!(flow_control.available_stream_window(4), 300); // 600 - 300

        // Stream 4: should now be able to consume more
        assert!(flow_control.consume_data(4, 200).is_ok());
        assert_eq!(flow_control.available_stream_window(4), 100);

        let result = FlowControlGoldenResult {
            test_name: "stream_data_limits".to_string(),
            max_data_consumption: flow_control.consumed_data,
            stream_data_limits: vec![
                (4, 600, 500),
                (8, 500, 400),
            ],
            fragmented_frames: 0,
            blocked_streams: flow_control.blocked_streams.iter().copied().collect(),
            connection_blocked: flow_control.connection_blocked,
        };

        assert_golden_flow_control_state(
            &result,
            "stream_data_limits",
            "test:stream_data_limits,max_data:900,streams:[4:500/600,8:400/500],fragments:0,blocked_streams:[],conn_blocked:false"
        );

        crate::test_complete!("golden_max_stream_data_per_stream_limits");
    }

    /// Golden Test 3: DATA frame fragmentation across QUIC packets
    ///
    /// Verifies that large DATA frames are correctly fragmented to fit within
    /// QUIC packet size limits.
    #[test]
    fn golden_data_frame_fragmentation() {
        crate::test_utils::init_test_logging();
        crate::test_phase!("golden_data_frame_fragmentation");

        let large_data = Bytes::from(vec![0x42; 2000]); // 2KB data
        let frame = MockDataFrame::new(12, large_data, 0, true);

        // Fragment for 1200-byte packets (typical QUIC packet size)
        let fragments = frame.fragment(1200);

        assert_eq!(fragments.len(), 2);

        // First fragment
        assert_eq!(fragments[0].stream_id, 12);
        assert_eq!(fragments[0].len(), 1200);
        assert_eq!(fragments[0].offset, 0);
        assert!(!fragments[0].fin); // Not the last fragment

        // Second fragment
        assert_eq!(fragments[1].stream_id, 12);
        assert_eq!(fragments[1].len(), 800); // Remaining data
        assert_eq!(fragments[1].offset, 1200);
        assert!(fragments[1].fin); // Last fragment

        // Test small frame (no fragmentation needed)
        let small_data = Bytes::from(vec![0x24; 500]);
        let small_frame = MockDataFrame::new(16, small_data, 100, false);
        let small_fragments = small_frame.fragment(1200);

        assert_eq!(small_fragments.len(), 1);
        assert_eq!(small_fragments[0].len(), 500);
        assert_eq!(small_fragments[0].offset, 100);
        assert!(!small_fragments[0].fin);

        let result = FlowControlGoldenResult {
            test_name: "data_fragmentation".to_string(),
            max_data_consumption: 0,
            stream_data_limits: vec![],
            fragmented_frames: fragments.len(),
            blocked_streams: vec![],
            connection_blocked: false,
        };

        assert_golden_flow_control_state(
            &result,
            "data_fragmentation",
            "test:data_fragmentation,max_data:0,streams:[],fragments:2,blocked_streams:[],conn_blocked:false"
        );

        crate::test_complete!("golden_data_frame_fragmentation");
    }

    /// Golden Test 4: Stream blocked state signaling
    ///
    /// Verifies that streams correctly signal when they become blocked
    /// due to flow control and are properly unblocked.
    #[test]
    fn golden_stream_blocked_state_signaling() {
        crate::test_utils::init_test_logging();
        crate::test_phase!("golden_stream_blocked_state_signaling");

        let mut flow_control = MockFlowControlWindow::new(5000);
        flow_control.add_stream(20, 400);
        flow_control.add_stream(24, 600);
        flow_control.add_stream(28, 300);

        // Block multiple streams
        assert!(flow_control.consume_data(20, 400).is_ok());
        assert_eq!(
            flow_control.consume_data(20, 1),
            Err(FlowControlError::StreamBlocked(20))
        );

        assert!(flow_control.consume_data(24, 600).is_ok());
        assert_eq!(
            flow_control.consume_data(24, 1),
            Err(FlowControlError::StreamBlocked(24))
        );

        // Stream 28 should still work
        assert!(flow_control.consume_data(28, 300).is_ok());

        assert_eq!(flow_control.blocked_streams.len(), 2);
        assert!(flow_control.blocked_streams.contains(&20));
        assert!(flow_control.blocked_streams.contains(&24));

        // Unblock stream 20
        flow_control.update_max_stream_data(20, 800);
        assert!(!flow_control.blocked_streams.contains(&20));
        assert!(flow_control.blocked_streams.contains(&24)); // Still blocked

        // Unblock stream 24
        flow_control.update_max_stream_data(24, 1000);
        assert!(flow_control.blocked_streams.is_empty());

        let result = FlowControlGoldenResult {
            test_name: "stream_blocked_signaling".to_string(),
            max_data_consumption: flow_control.consumed_data,
            stream_data_limits: vec![
                (20, 800, 400),
                (24, 1000, 600),
                (28, 300, 300),
            ],
            fragmented_frames: 0,
            blocked_streams: flow_control.blocked_streams.iter().copied().collect(),
            connection_blocked: flow_control.connection_blocked,
        };

        assert_golden_flow_control_state(
            &result,
            "stream_blocked_signaling",
            "test:stream_blocked_signaling,max_data:1300,streams:[20:400/800,24:600/1000,28:300/300],fragments:0,blocked_streams:[],conn_blocked:false"
        );

        crate::test_complete!("golden_stream_blocked_state_signaling");
    }

    /// Golden Test 5: Connection blocked propagation
    ///
    /// Verifies that connection-level blocking correctly propagates to all streams
    /// and is resolved when MAX_DATA is updated.
    #[test]
    fn golden_connection_blocked_propagation() {
        crate::test_utils::init_test_logging();
        crate::test_phase!("golden_connection_blocked_propagation");

        let mut flow_control = MockFlowControlWindow::new(1000);
        flow_control.add_stream(32, 600);
        flow_control.add_stream(36, 500);
        flow_control.add_stream(40, 400);

        // Consume most of connection window
        assert!(flow_control.consume_data(32, 500).is_ok());
        assert!(flow_control.consume_data(36, 400).is_ok());
        assert_eq!(flow_control.consumed_data, 900);

        // Connection should block all further consumption
        assert_eq!(
            flow_control.consume_data(40, 200),
            Err(FlowControlError::ConnectionBlocked)
        );
        assert!(flow_control.connection_blocked);

        // Even streams with available stream-level window should be blocked
        assert_eq!(
            flow_control.consume_data(32, 50), // Stream has 100 bytes available
            Err(FlowControlError::ConnectionBlocked)
        );

        // Increase connection window
        flow_control.update_max_data(2000);
        assert!(!flow_control.connection_blocked);

        // All streams should now be unblocked
        assert!(flow_control.consume_data(32, 100).is_ok());
        assert!(flow_control.consume_data(36, 100).is_ok());
        assert!(flow_control.consume_data(40, 300).is_ok());

        let result = FlowControlGoldenResult {
            test_name: "connection_blocked_propagation".to_string(),
            max_data_consumption: flow_control.consumed_data,
            stream_data_limits: vec![
                (32, 600, 600), // Fully consumed
                (36, 500, 500), // Fully consumed
                (40, 400, 300),
            ],
            fragmented_frames: 0,
            blocked_streams: flow_control.blocked_streams.iter().copied().collect(),
            connection_blocked: flow_control.connection_blocked,
        };

        assert_golden_flow_control_state(
            &result,
            "connection_blocked_propagation",
            "test:connection_blocked_propagation,max_data:1400,streams:[32:600/600,36:500/500,40:300/400],fragments:0,blocked_streams:[],conn_blocked:false"
        );

        crate::test_complete!("golden_connection_blocked_propagation");
    }

    /// Composite Golden Test: All flow control properties together
    ///
    /// Tests all flow control mechanisms in combination to catch interaction bugs.
    #[test]
    fn golden_composite_flow_control_properties() {
        crate::test_utils::init_test_logging();
        crate::test_phase!("golden_composite_flow_control_properties");

        let mut flow_control = MockFlowControlWindow::new(2000);
        flow_control.add_stream(44, 800);
        flow_control.add_stream(48, 600);

        // Test fragmentation + flow control interaction
        let large_data = Bytes::from(vec![0x55; 1500]);
        let frame = MockDataFrame::new(44, large_data, 0, true);
        let fragments = frame.fragment(500); // Small packets
        assert_eq!(fragments.len(), 3);

        // Simulate consuming fragmented data
        for fragment in &fragments {
            assert!(flow_control.consume_data(44, fragment.len() as u64).is_ok());
        }

        // Stream 44 should be near its limit (800 bytes max, consumed ~1500)
        // But we haven't enforced the limit yet in our consumption

        // Test stream blocking with remaining capacity
        assert!(flow_control.consume_data(48, 600).is_ok());
        assert_eq!(
            flow_control.consume_data(48, 1),
            Err(FlowControlError::StreamBlocked(48))
        );

        // Test connection-level interaction
        assert_eq!(flow_control.consumed_data, 2100); // This exceeds our 2000 limit

        // Create a fresh flow control to test the interaction properly
        let mut flow_control = MockFlowControlWindow::new(2000);
        flow_control.add_stream(44, 800);
        flow_control.add_stream(48, 600);

        // Consume within stream limits but approaching connection limit
        assert!(flow_control.consume_data(44, 700).is_ok());
        assert!(flow_control.consume_data(48, 500).is_ok());
        assert_eq!(flow_control.consumed_data, 1200);

        // Try to consume more - should hit connection limit first
        assert_eq!(
            flow_control.consume_data(44, 900), // Would exceed connection window
            Err(FlowControlError::ConnectionBlocked)
        );

        // Update connection window and verify stream limit is enforced
        flow_control.update_max_data(3000);
        assert_eq!(
            flow_control.consume_data(44, 200), // Would exceed stream window (700 + 200 > 800)
            Err(FlowControlError::StreamBlocked(44))
        );

        // But should be able to consume exact remaining stream capacity
        assert!(flow_control.consume_data(44, 100).is_ok()); // 700 + 100 = 800
        assert_eq!(flow_control.available_stream_window(44), 0);

        let result = FlowControlGoldenResult {
            test_name: "composite_flow_control".to_string(),
            max_data_consumption: flow_control.consumed_data,
            stream_data_limits: vec![
                (44, 800, 800),
                (48, 600, 500),
            ],
            fragmented_frames: fragments.len(),
            blocked_streams: flow_control.blocked_streams.iter().copied().collect(),
            connection_blocked: flow_control.connection_blocked,
        };

        assert_golden_flow_control_state(
            &result,
            "composite_flow_control",
            "test:composite_flow_control,max_data:1300,streams:[44:800/800,48:500/600],fragments:3,blocked_streams:[],conn_blocked:false"
        );

        crate::test_complete!("golden_composite_flow_control_properties");
    }

    // ─── Helper Functions ──────────────────────────────────────────────────

    fn assert_golden_flow_control_state(
        actual: &FlowControlGoldenResult,
        test_name: &str,
        expected_golden: &str,
    ) {
        let actual_golden = actual.to_golden_string();
        assert_eq!(
            actual_golden, expected_golden,
            "Flow control golden state mismatch for {}\nExpected: {}\nActual:   {}",
            test_name, expected_golden, actual_golden
        );
    }
}