asupersync 0.3.4

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
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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
//! WebTransport adapter for ATP over HTTP/3.
//!
//! Implements ATP-over-WebTransport for browser compatibility while preserving
//! ATP's verification, stream semantics, and proof generation capabilities.

use super::{AdapterNegotiation, AdapterType, FeatureSupport, PerformanceCaveat, SessionStats};
use crate::atp::object::ObjectId;
use crate::error::{Error, ErrorKind, Result};
use crate::types::TraceId;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::{Duration, SystemTime};

/// WebTransport-specific configuration parameters.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebTransportConfig {
    /// WebTransport session configuration
    pub session_config: WebTransportSessionConfig,
    /// Stream configuration
    pub stream_config: StreamConfig,
    /// Datagram configuration
    pub datagram_config: DatagramConfig,
    /// Browser security policy
    pub security_policy: BrowserSecurityPolicy,
}

/// WebTransport session configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebTransportSessionConfig {
    /// Maximum bidirectional streams
    pub max_bidirectional_streams: u32,
    /// Maximum unidirectional streams
    pub max_unidirectional_streams: u32,
    /// Session timeout
    pub session_timeout: Duration,
    /// Close timeout
    pub close_timeout: Duration,
}

/// Stream configuration for WebTransport.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamConfig {
    /// Default stream priority
    pub default_priority: u8,
    /// Flow control window
    pub flow_control_window: u32,
    /// Maximum frame size
    pub max_frame_size: u32,
    /// Stream idle timeout
    pub idle_timeout: Duration,
}

/// Datagram configuration for WebTransport.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatagramConfig {
    /// Maximum datagram size
    pub max_datagram_size: usize,
    /// Datagram queue size
    pub queue_size: usize,
    /// Enable datagram flow control
    pub flow_control: bool,
}

/// Browser security policy constraints.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BrowserSecurityPolicy {
    /// CORS policy enforcement
    pub cors_policy: CorsPolicy,
    /// Certificate validation requirements
    pub cert_validation: CertValidationPolicy,
    /// Origin restrictions
    pub origin_restrictions: Vec<String>,
    /// Feature permissions
    pub feature_permissions: FeaturePermissions,
}

/// CORS policy configuration.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CorsPolicy {
    /// Allowed origins
    pub allowed_origins: Vec<String>,
    /// Allowed headers
    pub allowed_headers: Vec<String>,
    /// Allow credentials
    pub allow_credentials: bool,
    /// Max age for preflight cache
    pub max_age: Duration,
}

/// Certificate validation policy for WebTransport.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CertValidationPolicy {
    /// Require valid certificate chain
    RequireValid,
    /// Allow self-signed for development
    AllowSelfSigned,
    /// Custom validation logic
    CustomValidation,
}

/// Feature permissions in browser environment.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FeaturePermissions {
    /// Allow WebTransport connections
    pub webtransport_enabled: bool,
    /// Allow datagram usage
    pub datagrams_enabled: bool,
    /// Allow streams
    pub streams_enabled: bool,
    /// File system access for proof storage
    pub filesystem_access: bool,
}

/// WebTransport adapter implementation.
#[derive(Debug)]
pub struct WebTransportAdapter {
    /// Adapter configuration
    config: WebTransportConfig,
    /// Active sessions
    sessions: HashMap<String, WebTransportSession>,
    /// Adapter statistics
    stats: WebTransportStats,
}

/// WebTransport session state.
#[derive(Debug, Clone)]
pub struct WebTransportSession {
    /// Session identifier
    pub session_id: String,
    /// WebTransport connection state
    pub connection_state: ConnectionState,
    /// Active streams
    pub active_streams: HashMap<u64, StreamInfo>,
    /// Datagram payloads accepted for transmission by the WebTransport session.
    pub outbound_datagrams: Vec<Vec<u8>>,
    /// Session statistics
    pub session_stats: SessionStats,
    /// Created timestamp
    pub created_at: SystemTime,
}

/// WebTransport connection state.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ConnectionState {
    /// Connection is being established
    Connecting,
    /// Connection is ready for use
    Connected,
    /// Connection is closing gracefully
    Closing,
    /// Connection is closed
    Closed,
    /// Connection failed
    Failed,
}

/// Information about active stream.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamInfo {
    /// Stream ID
    pub stream_id: u64,
    /// Stream type (bidirectional or unidirectional)
    pub stream_type: StreamType,
    /// Current stream state
    pub state: StreamState,
    /// Bytes sent on this stream
    pub bytes_sent: u64,
    /// Bytes received on this stream
    pub bytes_received: u64,
    /// Frames accepted for transmission on this stream.
    pub outbound_frames: Vec<Vec<u8>>,
    /// Stream priority
    pub priority: u8,
    /// Created timestamp
    pub created_at: SystemTime,
}

/// WebTransport stream type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum StreamType {
    /// Bidirectional stream
    Bidirectional,
    /// Unidirectional outbound stream
    UnidirectionalOutbound,
    /// Unidirectional inbound stream
    UnidirectionalInbound,
}

/// Stream state tracking.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum StreamState {
    /// Stream is open and active
    Open,
    /// Stream is half-closed (local)
    HalfClosedLocal,
    /// Stream is half-closed (remote)
    HalfClosedRemote,
    /// Stream is fully closed
    Closed,
    /// Stream reset by peer
    Reset,
}

/// WebTransport adapter statistics.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebTransportStats {
    /// Total sessions created
    pub total_sessions: u64,
    /// Current active sessions
    pub active_sessions: u64,
    /// Total streams created
    pub total_streams: u64,
    /// Total datagrams sent
    pub total_datagrams_sent: u64,
    /// Total datagrams received
    pub total_datagrams_received: u64,
    /// Connection failures
    pub connection_failures: u64,
    /// Stream errors
    pub stream_errors: u64,
    /// Average session duration
    pub avg_session_duration: Duration,
    /// Last updated
    pub last_updated: SystemTime,
}

impl WebTransportAdapter {
    /// Create new WebTransport adapter with configuration.
    pub fn new(config: WebTransportConfig) -> Self {
        Self {
            config,
            sessions: HashMap::new(),
            stats: WebTransportStats::new(),
        }
    }

    /// Negotiate WebTransport adapter capabilities.
    pub async fn negotiate(&self, trace_id: TraceId) -> Result<AdapterNegotiation> {
        // Check browser WebTransport support
        if !self
            .config
            .security_policy
            .feature_permissions
            .webtransport_enabled
        {
            return Err(Error::new(ErrorKind::ConnectionRefused));
        }

        let mut performance_caveats = Vec::new();

        // WebTransport-specific performance characteristics
        performance_caveats.push(PerformanceCaveat::NestedTransportOverhead);

        // Browser sandbox limitations
        if !self
            .config
            .security_policy
            .feature_permissions
            .filesystem_access
        {
            performance_caveats.push(PerformanceCaveat::ReliabilityConcerns(
                "Limited proof storage in browser sandbox".to_string(),
            ));
        }

        // Add latency caveat for browser overhead
        performance_caveats.push(PerformanceCaveat::IncreasedLatency(Duration::from_millis(
            20,
        )));

        Ok(AdapterNegotiation {
            selected_adapter: AdapterType::WebTransport,
            feature_parity: self.get_feature_parity(),
            downgrade_reasons: Vec::new(),
            performance_caveats,
            adapter_metadata: self.build_metadata(trace_id),
            negotiated_at: SystemTime::now(),
        })
    }

    /// Start WebTransport session for object transfer.
    pub async fn start_session(&mut self, object_id: ObjectId, url: &str) -> Result<String> {
        validate_webtransport_url(url)?;

        let session_id = format!(
            "wt-{}-{}",
            object_id,
            SystemTime::now()
                .duration_since(std::time::UNIX_EPOCH)
                .unwrap()
                .as_millis()
        );

        let session = WebTransportSession {
            session_id: session_id.clone(),
            connection_state: ConnectionState::Connected,
            active_streams: HashMap::new(),
            outbound_datagrams: Vec::new(),
            session_stats: SessionStats::new(),
            created_at: SystemTime::now(),
        };

        self.sessions.insert(session_id.clone(), session);
        self.stats.total_sessions += 1;
        self.stats.active_sessions += 1;
        self.stats.last_updated = SystemTime::now();

        Ok(session_id)
    }

    /// Create bidirectional stream for ATP communication.
    pub async fn create_stream(&mut self, session_id: &str, priority: u8) -> Result<u64> {
        let session = self
            .sessions
            .get_mut(session_id)
            .ok_or_else(|| Error::new(ErrorKind::ConnectionLost))?;

        if session.connection_state != ConnectionState::Connected {
            return Err(Error::new(ErrorKind::ConnectionLost));
        }

        // Check stream limits
        let bidirectional_count = session
            .active_streams
            .values()
            .filter(|s| s.stream_type == StreamType::Bidirectional)
            .count();

        if bidirectional_count >= self.config.session_config.max_bidirectional_streams as usize {
            return Err(Error::new(ErrorKind::ChannelFull));
        }

        // Generate new stream ID (even numbers for bidirectional streams)
        let stream_id = (session.active_streams.len() as u64) * 2;

        let stream_info = StreamInfo {
            stream_id,
            stream_type: StreamType::Bidirectional,
            state: StreamState::Open,
            bytes_sent: 0,
            bytes_received: 0,
            outbound_frames: Vec::new(),
            priority,
            created_at: SystemTime::now(),
        };

        session.active_streams.insert(stream_id, stream_info);
        self.stats.total_streams += 1;
        self.stats.last_updated = SystemTime::now();

        Ok(stream_id)
    }

    /// Send ATP frame over WebTransport stream.
    pub async fn send_frame(
        &mut self,
        session_id: &str,
        stream_id: u64,
        data: &[u8],
    ) -> Result<()> {
        let session = self
            .sessions
            .get_mut(session_id)
            .ok_or_else(|| Error::new(ErrorKind::ConnectionLost))?;

        let stream = session
            .active_streams
            .get_mut(&stream_id)
            .ok_or_else(|| Error::new(ErrorKind::StreamEnded))?;

        if stream.state != StreamState::Open {
            return Err(Error::new(ErrorKind::StreamEnded));
        }

        if data.len() > self.config.stream_config.max_frame_size as usize {
            return Err(Error::new(ErrorKind::DataTooLarge));
        }

        stream.bytes_sent += data.len() as u64;
        stream.outbound_frames.push(data.to_vec());
        session.session_stats.bytes_sent += data.len() as u64;

        Ok(())
    }

    /// Send datagram over WebTransport.
    pub async fn send_datagram(&mut self, session_id: &str, data: &[u8]) -> Result<()> {
        let session = self
            .sessions
            .get_mut(session_id)
            .ok_or_else(|| Error::new(ErrorKind::ConnectionLost))?;

        if session.connection_state != ConnectionState::Connected {
            return Err(Error::new(ErrorKind::ConnectionLost));
        }

        if !self
            .config
            .security_policy
            .feature_permissions
            .datagrams_enabled
        {
            return Err(Error::new(ErrorKind::ConnectionRefused));
        }

        if data.len() > self.config.datagram_config.max_datagram_size {
            return Err(Error::new(ErrorKind::DataTooLarge));
        }

        if session.outbound_datagrams.len() >= self.config.datagram_config.queue_size {
            return Err(Error::new(ErrorKind::ChannelFull));
        }

        session.outbound_datagrams.push(data.to_vec());
        session.session_stats.bytes_sent += data.len() as u64;
        self.stats.total_datagrams_sent += 1;
        self.stats.last_updated = SystemTime::now();

        Ok(())
    }

    /// Get adapter statistics.
    pub fn stats(&self) -> &WebTransportStats {
        &self.stats
    }

    /// Close WebTransport session.
    pub async fn close_session(&mut self, session_id: &str) -> Result<()> {
        if let Some(mut session) = self.sessions.remove(session_id) {
            session.connection_state = ConnectionState::Closing;

            // Close all active streams
            for stream in session.active_streams.values_mut() {
                stream.state = StreamState::Closed;
            }

            // Update statistics
            if self.stats.active_sessions > 0 {
                self.stats.active_sessions -= 1;
            }

            let session_duration = SystemTime::now()
                .duration_since(session.created_at)
                .unwrap_or(Duration::from_secs(0));

            // Update average session duration
            self.stats.avg_session_duration = if self.stats.total_sessions > 1 {
                Duration::from_millis(
                    (self.stats.avg_session_duration.as_millis() as u64
                        * (self.stats.total_sessions - 1)
                        + session_duration.as_millis() as u64)
                        / self.stats.total_sessions,
                )
            } else {
                session_duration
            };

            self.stats.last_updated = SystemTime::now();
        }

        Ok(())
    }

    /// Get feature parity for WebTransport adapter.
    fn get_feature_parity(&self) -> crate::atp::adapter::AdapterParity {
        crate::atp::adapter::AdapterParity {
            object_support: FeatureSupport::Full,
            stream_support: FeatureSupport::Full,
            proof_support: FeatureSupport::Partial, // Limited by browser sandbox
            path_support: FeatureSupport::Partial,  // Limited path control
            repair_support: FeatureSupport::Partial, // Limited repair strategies
            datagram_support: FeatureSupport::Full,
            mailbox_support: FeatureSupport::Full,
            swarm_support: FeatureSupport::Partial, // Limited coordination
            diagnostic_support: FeatureSupport::Partial, // Limited diagnostics
        }
    }

    /// Build adapter metadata.
    fn build_metadata(&self, trace_id: TraceId) -> crate::atp::adapter::AdapterMetadata {
        use crate::atp::adapter::{
            AdapterMetadata, CertValidationMode, SecurityParams, TransportPath,
        };

        AdapterMetadata {
            version: "1.0.0".to_string(),
            path_info: TransportPath {
                local_endpoint: "browser".to_string(),
                remote_endpoint: "server.example.com:443".to_string(),
                intermediate_hops: vec!["HTTP/3".to_string(), "WebTransport".to_string()],
                path_mtu: Some(1200), // Conservative for browser
            },
            relay_info: None,
            security_params: SecurityParams {
                tls_version: Some("TLS 1.3".to_string()),
                cipher_suite: Some("TLS_AES_128_GCM_SHA256".to_string()),
                cert_validation: CertValidationMode::Full,
                security_flags: vec![
                    "WebTransport".to_string(),
                    "CORS".to_string(),
                    "SOP".to_string(), // Same-Origin Policy
                ],
            },
            replay_pointer: Some(format!("webtransport-trace-{}", trace_id.as_u128())),
        }
    }
}

fn validate_webtransport_url(url: &str) -> Result<()> {
    let authority = url
        .strip_prefix("https://")
        .ok_or_else(|| Error::new(ErrorKind::InvalidInput))?;
    let authority = authority.split('/').next().unwrap_or_default();
    if authority.is_empty() {
        return Err(Error::new(ErrorKind::InvalidInput));
    }
    Ok(())
}

impl Default for WebTransportConfig {
    fn default() -> Self {
        Self {
            session_config: WebTransportSessionConfig {
                max_bidirectional_streams: 100,
                max_unidirectional_streams: 100,
                session_timeout: Duration::from_secs(300),
                close_timeout: Duration::from_secs(5),
            },
            stream_config: StreamConfig {
                default_priority: 128,
                flow_control_window: 65536,
                max_frame_size: 16384,
                idle_timeout: Duration::from_secs(30),
            },
            datagram_config: DatagramConfig {
                max_datagram_size: 1200,
                queue_size: 100,
                flow_control: true,
            },
            security_policy: BrowserSecurityPolicy {
                cors_policy: CorsPolicy {
                    allowed_origins: vec!["*".to_string()],
                    allowed_headers: vec!["*".to_string()],
                    allow_credentials: false,
                    max_age: Duration::from_secs(3600),
                },
                cert_validation: CertValidationPolicy::RequireValid,
                origin_restrictions: Vec::new(),
                feature_permissions: FeaturePermissions {
                    webtransport_enabled: true,
                    datagrams_enabled: true,
                    streams_enabled: true,
                    filesystem_access: false, // Typically limited in browsers
                },
            },
        }
    }
}

impl WebTransportStats {
    fn new() -> Self {
        Self {
            total_sessions: 0,
            active_sessions: 0,
            total_streams: 0,
            total_datagrams_sent: 0,
            total_datagrams_received: 0,
            connection_failures: 0,
            stream_errors: 0,
            avg_session_duration: Duration::from_secs(0),
            last_updated: SystemTime::now(),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use futures_lite::future::block_on;

    #[test]
    fn test_webtransport_config_default() {
        let config = WebTransportConfig::default();
        assert_eq!(config.session_config.max_bidirectional_streams, 100);
        assert_eq!(config.datagram_config.max_datagram_size, 1200);
        assert!(
            config
                .security_policy
                .feature_permissions
                .webtransport_enabled
        );
    }

    #[test]
    fn test_webtransport_session_lifecycle() {
        block_on(async {
            let mut adapter = WebTransportAdapter::new(WebTransportConfig::default());
            let object_id = ObjectId::Content(crate::atp::object::ContentId::new([1; 32]));

            // Start session
            let session_id = adapter
                .start_session(object_id, "https://example.com")
                .await
                .unwrap();
            assert_eq!(adapter.stats.active_sessions, 1);

            // Create stream
            let stream_id = adapter.create_stream(&session_id, 128).await.unwrap();
            assert_eq!(stream_id, 0); // First stream should be ID 0

            // Send frame
            let data = b"ATP frame data";
            adapter
                .send_frame(&session_id, stream_id, data)
                .await
                .unwrap();

            // Send datagram
            let datagram_data = b"ATP datagram";
            adapter
                .send_datagram(&session_id, datagram_data)
                .await
                .unwrap();

            // Close session
            adapter.close_session(&session_id).await.unwrap();
            assert_eq!(adapter.stats.active_sessions, 0);
        });
    }

    #[test]
    fn test_webtransport_negotiation() {
        block_on(async {
            let adapter = WebTransportAdapter::new(WebTransportConfig::default());
            let trace_id = TraceId::from_parts(1, 1);

            let negotiation = adapter.negotiate(trace_id).await.unwrap();
            assert_eq!(negotiation.selected_adapter, AdapterType::WebTransport);
            assert_eq!(
                negotiation.feature_parity.object_support,
                FeatureSupport::Full
            );
            assert_eq!(
                negotiation.feature_parity.proof_support,
                FeatureSupport::Partial
            );
        });
    }

    #[test]
    fn test_stream_limits() {
        block_on(async {
            let config = WebTransportConfig {
                session_config: WebTransportSessionConfig {
                    max_bidirectional_streams: 1, // Limit to 1 stream
                    max_unidirectional_streams: 1,
                    session_timeout: Duration::from_secs(300),
                    close_timeout: Duration::from_secs(5),
                },
                ..Default::default()
            };

            let mut adapter = WebTransportAdapter::new(config);
            let object_id = ObjectId::Content(crate::atp::object::ContentId::new([1; 32]));
            let session_id = adapter
                .start_session(object_id, "https://example.com")
                .await
                .unwrap();

            // First stream should succeed
            adapter.create_stream(&session_id, 128).await.unwrap();

            // Second stream should fail due to limit
            let result = adapter.create_stream(&session_id, 128).await;
            assert!(result.is_err());
        });
    }

    #[test]
    fn test_stream_frame_and_datagram_queues() {
        block_on(async {
            let mut adapter = WebTransportAdapter::new(WebTransportConfig::default());
            let object_id = ObjectId::Content(crate::atp::object::ContentId::new([1; 32]));
            let session_id = adapter
                .start_session(object_id, "https://example.com/atp")
                .await
                .unwrap();
            let stream_id = adapter.create_stream(&session_id, 128).await.unwrap();

            adapter
                .send_frame(&session_id, stream_id, b"stream-frame")
                .await
                .unwrap();
            adapter
                .send_datagram(&session_id, b"datagram")
                .await
                .unwrap();

            let session = adapter.sessions.get(&session_id).unwrap();
            let stream = session.active_streams.get(&stream_id).unwrap();
            assert_eq!(stream.outbound_frames, vec![b"stream-frame".to_vec()]);
            assert_eq!(session.outbound_datagrams, vec![b"datagram".to_vec()]);
        });
    }

    #[test]
    fn test_invalid_webtransport_url_is_rejected() {
        block_on(async {
            let mut adapter = WebTransportAdapter::new(WebTransportConfig::default());
            let object_id = ObjectId::Content(crate::atp::object::ContentId::new([1; 32]));

            let result = adapter.start_session(object_id, "http://example.com").await;

            assert!(matches!(
                result,
                Err(err) if err.kind() == ErrorKind::InvalidInput
            ));
        });
    }
}