asupersync-conformance 0.4.2

Conformance test suite for async runtime specifications
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
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
#![allow(warnings)]
#![allow(clippy::all)]
//! RFC 9000 §9 QUIC Connection Migration Conformance Tests
//!
//! This module contains comprehensive conformance tests for QUIC connection migration
//! per RFC 9000 Section 9. Tests validate:
//!
//! - PATH_CHALLENGE/PATH_RESPONSE path validation (§9.1)
//! - Connection ID retirement after migration (§9.5)
//! - Anti-amplification limits on unverified paths (§8.1)
//! - NAT rebinding detection via source address change (§9.3)
//! - Concurrent path migration from both endpoints (§9.2)

use asupersync::cx::Cx;
use asupersync::net::quic_native::{
    NativeQuicConnection, NativeQuicConnectionConfig, NativeQuicConnectionError, PacketNumberSpace,
    StreamRole,
};
use asupersync::types::{Budget, RegionId, TaskId};
use asupersync::util::ArenaIndex;
use std::time::Instant;

/// Test categories for QUIC connection migration conformance.
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[allow(dead_code)]
pub enum TestCategory {
    PathValidation,
    ConnectionIdRetirement,
    AntiAmplificationLimits,
    NatRebindingDetection,
    ConcurrentMigration,
    PathFailoverHandling,
    ConnectionMigrationSecurity,
}

/// Requirement levels from RFC 2119.
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "UPPERCASE")]
#[allow(dead_code)]
pub enum RequirementLevel {
    Must,
    Should,
    May,
}

/// Test verdict for individual conformance tests.
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
#[allow(dead_code)]
pub enum TestVerdict {
    Pass,
    Fail,
    Skipped,
    ExpectedFailure,
}

/// Result of a single conformance test.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[allow(dead_code)]
pub struct QuicConnectionMigrationConformanceResult {
    pub test_id: String,
    pub description: String,
    pub category: TestCategory,
    pub requirement_level: RequirementLevel,
    pub verdict: TestVerdict,
    pub error_message: Option<String>,
    pub execution_time_ms: u64,
}

impl QuicConnectionMigrationConformanceResult {
    /// Evidence class used by implementation-completeness closeout reports.
    #[must_use]
    pub fn support_class(&self) -> &'static str {
        match self.verdict {
            TestVerdict::Pass => "production_live",
            TestVerdict::ExpectedFailure | TestVerdict::Skipped => "unsupported",
            TestVerdict::Fail => "failed",
        }
    }

    /// Evidence quality used by implementation-completeness closeout reports.
    #[must_use]
    pub fn evidence_quality(&self) -> &'static str {
        match self.verdict {
            TestVerdict::Pass => "live",
            TestVerdict::ExpectedFailure | TestVerdict::Skipped => "unsupported_boundary",
            TestVerdict::Fail => "failing_live_check",
        }
    }
}

/// QUIC Connection Migration conformance test harness.
#[allow(dead_code)]
pub struct QuicConnectionMigrationConformanceHarness;

#[allow(dead_code)]

impl QuicConnectionMigrationConformanceHarness {
    /// Create a new conformance test harness.
    #[allow(dead_code)]
    pub fn new() -> Self {
        Self
    }

    /// Run all QUIC connection migration conformance tests.
    #[allow(dead_code)]
    pub fn run_all_tests(&self) -> Vec<QuicConnectionMigrationConformanceResult> {
        let mut results = Vec::new();

        // Path validation conformance tests
        results.extend(self.run_path_validation_tests());

        // Connection ID retirement tests
        results.extend(self.run_connection_id_retirement_tests());

        // Anti-amplification limit tests
        results.extend(self.run_anti_amplification_tests());

        // NAT rebinding detection tests
        results.extend(self.run_nat_rebinding_tests());

        // Concurrent migration tests
        results.extend(self.run_concurrent_migration_tests());

        results
    }

    #[allow(dead_code)]

    fn run_path_validation_tests(&self) -> Vec<QuicConnectionMigrationConformanceResult> {
        vec![
            self.test_path_challenge_response_exchange(),
            self.test_path_validation_required_before_migration(),
            self.test_path_migration_rejected_before_established(),
            self.test_path_migration_blocked_when_disabled(),
            self.test_path_migration_updates_active_path_and_counter(),
            self.test_path_migration_same_path_is_idempotent(),
            self.test_path_challenge_data_uniqueness(),
            self.test_path_validation_timeout_handling(),
        ]
    }

    #[allow(dead_code)]

    fn run_connection_id_retirement_tests(&self) -> Vec<QuicConnectionMigrationConformanceResult> {
        vec![
            self.test_connection_id_retirement_after_migration(),
            self.test_retire_prior_to_frame_processing(),
            self.test_connection_id_sequence_number_ordering(),
        ]
    }

    #[allow(dead_code)]

    fn run_anti_amplification_tests(&self) -> Vec<QuicConnectionMigrationConformanceResult> {
        vec![
            self.test_anti_amplification_limit_enforcement(),
            self.test_three_times_rule_compliance(),
            self.test_anti_amplification_after_path_validation(),
        ]
    }

    #[allow(dead_code)]

    fn run_nat_rebinding_tests(&self) -> Vec<QuicConnectionMigrationConformanceResult> {
        vec![
            self.test_nat_rebinding_detection(),
            self.test_source_address_change_handling(),
            self.test_implicit_path_migration_on_nat_rebinding(),
        ]
    }

    #[allow(dead_code)]

    fn run_concurrent_migration_tests(&self) -> Vec<QuicConnectionMigrationConformanceResult> {
        vec![
            self.test_concurrent_path_migration_both_endpoints(),
            self.test_migration_collision_resolution(),
            self.test_path_migration_race_condition_handling(),
        ]
    }

    // Path Validation Tests

    #[allow(dead_code)]

    fn test_path_challenge_response_exchange(&self) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_path_challenge_response_exchange".to_string(),
            description:
                "PATH_CHALLENGE/PATH_RESPONSE exchange validates new path per RFC 9000 §8.2"
                    .to_string(),
            category: TestCategory::PathValidation,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "NativeQuicConnection exposes migration policy and counters, but no production PATH_CHALLENGE/PATH_RESPONSE issuance or validation seam is wired yet"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    #[allow(dead_code)]

    fn test_path_validation_required_before_migration(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        let mut result = QuicConnectionMigrationConformanceResult {
            test_id: "quic_path_validation_required_before_migration".to_string(),
            description:
                "Path validation MUST complete before migrating connection per RFC 9000 §9.1"
                    .to_string(),
            category: TestCategory::PathValidation,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::Pass,
            error_message: None,
            execution_time_ms: 0,
        };

        let cx = test_cx();
        let mut conn = established_conn();
        let new_path_id = 5u64;

        match conn.request_path_migration(&cx, new_path_id) {
            Ok(_) => {
                result.verdict = TestVerdict::ExpectedFailure;
                result.error_message = Some(
                    "Production request_path_migration changes active_path_id without a visible path-validation gate"
                        .to_string(),
                );
            }
            Err(NativeQuicConnectionError::InvalidState(msg)) => {
                if msg.contains("path validation") {
                    result.verdict = TestVerdict::Pass;
                } else {
                    result.verdict = TestVerdict::Fail;
                    result.error_message = Some(format!("Wrong rejection reason: {}", msg));
                }
            }
            Err(err) => {
                result.verdict = TestVerdict::Fail;
                result.error_message = Some(format!("Unexpected error: {}", err));
            }
        }

        result.execution_time_ms = start_time.elapsed().as_millis() as u64;
        result
    }

    #[allow(dead_code)]

    fn test_path_migration_rejected_before_established(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        let cx = test_cx();
        let mut conn = NativeQuicConnection::new(NativeQuicConnectionConfig::default());
        conn.begin_handshake(&cx).expect("begin handshake");

        let mut result = QuicConnectionMigrationConformanceResult {
            test_id: "quic_path_migration_rejected_before_established".to_string(),
            description:
                "Path migration is rejected before the QUIC connection reaches established state"
                    .to_string(),
            category: TestCategory::PathValidation,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::Pass,
            error_message: None,
            execution_time_ms: 0,
        };

        match conn.request_path_migration(&cx, 7) {
            Err(NativeQuicConnectionError::InvalidState(msg))
                if msg == "path migration requires established state" => {}
            Ok(_) => {
                result.verdict = TestVerdict::Fail;
                result.error_message =
                    Some("Migration succeeded before the connection was established".to_string());
            }
            Err(err) => {
                result.verdict = TestVerdict::Fail;
                result.error_message = Some(format!("Unexpected error: {err}"));
            }
        }

        result.execution_time_ms = start_time.elapsed().as_millis() as u64;
        result
    }

    #[allow(dead_code)]

    fn test_path_migration_blocked_when_disabled(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        let cx = test_cx();
        let mut conn = established_conn();
        conn.set_active_migration_disabled(&cx, true)
            .expect("set migration policy");

        let mut result = QuicConnectionMigrationConformanceResult {
            test_id: "quic_path_migration_blocked_when_disabled".to_string(),
            description: "disable_active_migration transport policy blocks active path migration"
                .to_string(),
            category: TestCategory::ConnectionMigrationSecurity,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::Pass,
            error_message: None,
            execution_time_ms: 0,
        };

        match conn.request_path_migration(&cx, 9) {
            Err(NativeQuicConnectionError::InvalidState(msg))
                if msg == "active migration disabled by transport parameters" => {}
            Ok(_) => {
                result.verdict = TestVerdict::Fail;
                result.error_message =
                    Some("Migration succeeded despite disable_active_migration".to_string());
            }
            Err(err) => {
                result.verdict = TestVerdict::Fail;
                result.error_message = Some(format!("Unexpected error: {err}"));
            }
        }

        result.execution_time_ms = start_time.elapsed().as_millis() as u64;
        result
    }

    #[allow(dead_code)]

    fn test_path_migration_updates_active_path_and_counter(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        let cx = test_cx();
        let mut conn = established_conn();
        let mut result = QuicConnectionMigrationConformanceResult {
            test_id: "quic_path_migration_updates_active_path_and_counter".to_string(),
            description: "Production path migration records active path and migration counter"
                .to_string(),
            category: TestCategory::PathValidation,
            requirement_level: RequirementLevel::May,
            verdict: TestVerdict::Pass,
            error_message: None,
            execution_time_ms: 0,
        };

        match conn.request_path_migration(&cx, 3) {
            Ok(1) if conn.active_path_id() == 3 && conn.migration_events() == 1 => {}
            Ok(events) => {
                result.verdict = TestVerdict::Fail;
                result.error_message = Some(format!(
                    "Unexpected migration state: events={events}, active_path_id={}, migration_events={}",
                    conn.active_path_id(),
                    conn.migration_events()
                ));
            }
            Err(err) => {
                result.verdict = TestVerdict::Fail;
                result.error_message = Some(format!("Unexpected migration error: {err}"));
            }
        }

        result.execution_time_ms = start_time.elapsed().as_millis() as u64;
        result
    }

    #[allow(dead_code)]

    fn test_path_migration_same_path_is_idempotent(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        let cx = test_cx();
        let mut conn = established_conn();
        let mut result = QuicConnectionMigrationConformanceResult {
            test_id: "quic_path_migration_same_path_is_idempotent".to_string(),
            description: "Requesting the already active path leaves migration counter unchanged"
                .to_string(),
            category: TestCategory::PathFailoverHandling,
            requirement_level: RequirementLevel::May,
            verdict: TestVerdict::Pass,
            error_message: None,
            execution_time_ms: 0,
        };

        let first = conn.request_path_migration(&cx, 11);
        let second = conn.request_path_migration(&cx, 11);
        if first != Ok(1) || second != Ok(1) || conn.migration_events() != 1 {
            result.verdict = TestVerdict::Fail;
            result.error_message = Some(format!(
                "Same-path migration was not idempotent: first={first:?}, second={second:?}, events={}",
                conn.migration_events()
            ));
        }

        result.execution_time_ms = start_time.elapsed().as_millis() as u64;
        result
    }

    #[allow(dead_code)]

    fn test_path_challenge_data_uniqueness(&self) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_path_challenge_data_uniqueness".to_string(),
            description: "PATH_CHALLENGE data MUST be cryptographically random per RFC 9000 §8.2.1"
                .to_string(),
            category: TestCategory::PathValidation,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "No production challenge-data generator is exposed for this conformance harness"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    #[allow(dead_code)]

    fn test_path_validation_timeout_handling(&self) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_path_validation_timeout_handling".to_string(),
            description: "Path validation timeout should trigger re-challenge or abandonment per RFC 9000 §8.2.4".to_string(),
            category: TestCategory::PathValidation,
            requirement_level: RequirementLevel::Should,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "No production path-validation timeout/re-challenge state is exposed yet"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    // Connection ID Retirement Tests

    #[allow(dead_code)]

    fn test_connection_id_retirement_after_migration(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_connection_id_retirement_after_migration".to_string(),
            description:
                "Old connection IDs MUST be retired after path migration per RFC 9000 §9.5"
                    .to_string(),
            category: TestCategory::ConnectionIdRetirement,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "NativeQuicConnection does not expose NEW_CONNECTION_ID/RETIRE_CONNECTION_ID state for migration conformance yet"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    #[allow(dead_code)]

    fn test_retire_prior_to_frame_processing(&self) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_retire_prior_to_frame_processing".to_string(),
            description: "RETIRE_CONNECTION_ID frame processing per RFC 9000 §19.16".to_string(),
            category: TestCategory::ConnectionIdRetirement,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "RETIRE_CONNECTION_ID frame processing is not exposed through the native connection migration API yet"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    #[allow(dead_code)]

    fn test_connection_id_sequence_number_ordering(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_connection_id_sequence_number_ordering".to_string(),
            description:
                "Connection ID sequence numbers MUST be processed in order per RFC 9000 §5.1.1"
                    .to_string(),
            category: TestCategory::ConnectionIdRetirement,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "No production connection-ID sequence-number ordering state is exposed yet"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    // Anti-Amplification Tests

    #[allow(dead_code)]

    fn test_anti_amplification_limit_enforcement(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        let mut result = QuicConnectionMigrationConformanceResult {
            test_id: "quic_anti_amplification_limit_enforcement".to_string(),
            description:
                "Anti-amplification limits MUST be enforced on unverified paths per RFC 9000 §8.1"
                    .to_string(),
            category: TestCategory::AntiAmplificationLimits,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::Pass,
            error_message: None,
            execution_time_ms: 0,
        };

        let cx = test_cx();
        let mut conn = server_handshaking_conn();
        for i in 0..3 {
            if let Err(err) =
                conn.on_packet_sent(&cx, PacketNumberSpace::Handshake, 1_200, true, true, i)
            {
                result.verdict = TestVerdict::Fail;
                result.error_message = Some(format!(
                    "Flight within anti-amplification limit was rejected: {err}"
                ));
                break;
            }
        }

        if result.verdict == TestVerdict::Pass {
            match conn.on_packet_sent(&cx, PacketNumberSpace::Handshake, 1, true, true, 10) {
                Err(NativeQuicConnectionError::AmplificationLimited {
                    bytes_sent,
                    bytes_received,
                    limit,
                    ..
                }) if bytes_sent == 3_600 && bytes_received == 1_200 && limit == 3_600 => {}
                Ok(_) => {
                    result.verdict = TestVerdict::Fail;
                    result.error_message =
                        Some("Sending beyond the 3x limit was allowed".to_string());
                }
                Err(err) => {
                    result.verdict = TestVerdict::Fail;
                    result.error_message = Some(format!("Unexpected error: {err}"));
                }
            }
        }

        result.execution_time_ms = start_time.elapsed().as_millis() as u64;
        result
    }

    #[allow(dead_code)]

    fn test_three_times_rule_compliance(&self) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        let mut result = QuicConnectionMigrationConformanceResult {
            test_id: "quic_three_times_rule_compliance".to_string(),
            description: "Endpoints MUST NOT send more than 3x received bytes on unverified paths per RFC 9000 §8.1".to_string(),
            category: TestCategory::AntiAmplificationLimits,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::Pass,
            error_message: None,
            execution_time_ms: 0,
        };

        let cx = test_cx();
        let mut conn = server_handshaking_conn();

        if let Err(err) =
            conn.on_packet_sent(&cx, PacketNumberSpace::Handshake, 3_600, true, true, 1)
        {
            result.verdict = TestVerdict::Fail;
            result.error_message = Some(format!("Exactly 3x received bytes was rejected: {err}"));
        } else {
            match conn.on_packet_sent(&cx, PacketNumberSpace::Handshake, 1, true, true, 2) {
                Err(NativeQuicConnectionError::AmplificationLimited { limit, .. })
                    if limit == 3_600 => {}
                Ok(_) => {
                    result.verdict = TestVerdict::Fail;
                    result.error_message =
                        Some("More than 3x received bytes was allowed".to_string());
                }
                Err(err) => {
                    result.verdict = TestVerdict::Fail;
                    result.error_message = Some(format!("Unexpected error: {err}"));
                }
            }
        }

        result.execution_time_ms = start_time.elapsed().as_millis() as u64;
        result
    }

    #[allow(dead_code)]

    fn test_anti_amplification_after_path_validation(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        let mut result = QuicConnectionMigrationConformanceResult {
            test_id: "quic_anti_amplification_after_path_validation".to_string(),
            description: "Anti-amplification limits SHOULD be lifted after successful path validation per RFC 9000 §8.1".to_string(),
            category: TestCategory::AntiAmplificationLimits,
            requirement_level: RequirementLevel::Should,
            verdict: TestVerdict::Pass,
            error_message: None,
            execution_time_ms: 0,
        };

        let cx = test_cx();
        let mut conn = server_handshaking_conn();
        conn.on_packet_sent(&cx, PacketNumberSpace::Handshake, 1_200, true, true, 1)
            .expect("first flight");
        conn.on_packet_sent(&cx, PacketNumberSpace::Handshake, 1_200, true, true, 2)
            .expect("second flight");
        conn.on_packet_sent(&cx, PacketNumberSpace::Handshake, 1_200, true, true, 3)
            .expect("third flight");
        conn.validate_peer_address(&cx)
            .expect("validate peer address");

        if let Err(err) =
            conn.on_packet_sent(&cx, PacketNumberSpace::Handshake, 1_200, true, true, 4)
        {
            result.verdict = TestVerdict::Fail;
            result.error_message = Some(format!(
                "Validated peer still hit anti-amplification limit: {err}"
            ));
        }

        result.execution_time_ms = start_time.elapsed().as_millis() as u64;
        result
    }

    // NAT Rebinding Tests

    #[allow(dead_code)]

    fn test_nat_rebinding_detection(&self) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_nat_rebinding_detection".to_string(),
            description:
                "NAT rebinding MUST be detected via source address change per RFC 9000 §9.3"
                    .to_string(),
            category: TestCategory::NatRebindingDetection,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "NativeQuicConnection has no production source-address observation hook for NAT rebinding yet"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    #[allow(dead_code)]

    fn test_source_address_change_handling(&self) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_source_address_change_handling".to_string(),
            description: "Endpoints MUST handle source address changes without breaking connection per RFC 9000 §9.3".to_string(),
            category: TestCategory::NatRebindingDetection,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "No production path for applying a peer source-address change to connection state is exposed yet"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    #[allow(dead_code)]

    fn test_implicit_path_migration_on_nat_rebinding(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_implicit_path_migration_on_nat_rebinding".to_string(),
            description:
                "Implicit path migration SHOULD occur on NAT rebinding per RFC 9000 §9.3.3"
                    .to_string(),
            category: TestCategory::NatRebindingDetection,
            requirement_level: RequirementLevel::Should,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "Implicit NAT-rebinding migration is unsupported until source-address tracking is wired"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    // Concurrent Migration Tests

    #[allow(dead_code)]

    fn test_concurrent_path_migration_both_endpoints(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_concurrent_path_migration_both_endpoints".to_string(),
            description:
                "Concurrent path migration from both endpoints MUST be handled per RFC 9000 §9.2"
                    .to_string(),
            category: TestCategory::ConcurrentMigration,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "No production concurrent local/remote migration collision state is exposed yet"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    #[allow(dead_code)]

    fn test_migration_collision_resolution(&self) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_migration_collision_resolution".to_string(),
            description:
                "Migration collisions MUST be resolved deterministically per RFC 9000 §9.2.1"
                    .to_string(),
            category: TestCategory::ConcurrentMigration,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "Migration collision resolution has no production state-machine seam in the native connection API yet"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }

    #[allow(dead_code)]

    fn test_path_migration_race_condition_handling(
        &self,
    ) -> QuicConnectionMigrationConformanceResult {
        let start_time = Instant::now();
        QuicConnectionMigrationConformanceResult {
            test_id: "quic_path_migration_race_condition_handling".to_string(),
            description: "Race conditions in path migration MUST NOT cause connection state corruption per RFC 9000 §9.2".to_string(),
            category: TestCategory::ConcurrentMigration,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some(
                "Race-condition handling needs a production concurrent migration harness before it can be claimed live"
                    .to_string(),
            ),
            execution_time_ms: start_time.elapsed().as_millis() as u64,
        }
    }
}

impl Default for QuicConnectionMigrationConformanceHarness {
    #[allow(dead_code)]
    fn default() -> Self {
        Self::new()
    }
}

// Helper functions for testing

#[allow(dead_code)]

fn test_cx() -> Cx {
    Cx::new(
        RegionId::from_arena(ArenaIndex::new(0, 1)),
        TaskId::from_arena(ArenaIndex::new(0, 0)),
        Budget::INFINITE,
    )
}

#[allow(dead_code)]

fn established_conn() -> NativeQuicConnection {
    let cx = test_cx();
    let mut conn = NativeQuicConnection::new(NativeQuicConnectionConfig::default());
    conn.begin_handshake(&cx).expect("begin");
    conn.on_handshake_keys_available(&cx).expect("hs keys");
    conn.on_1rtt_keys_available(&cx).expect("1rtt keys");
    conn.record_verified_server_identity();
    conn.on_handshake_confirmed(&cx).expect("confirmed");
    conn
}

#[allow(dead_code)]

fn server_handshaking_conn() -> NativeQuicConnection {
    let cx = test_cx();
    let mut conn = NativeQuicConnection::new(NativeQuicConnectionConfig {
        role: StreamRole::Server,
        ..NativeQuicConnectionConfig::default()
    });
    conn.begin_handshake(&cx).expect("begin");
    conn
}

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

    #[test]
    #[allow(dead_code)]
    fn test_conformance_results_classify_live_and_unsupported_evidence() {
        let pass = QuicConnectionMigrationConformanceResult {
            test_id: "pass".to_string(),
            description: "pass".to_string(),
            category: TestCategory::PathValidation,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::Pass,
            error_message: None,
            execution_time_ms: 0,
        };
        let unsupported = QuicConnectionMigrationConformanceResult {
            test_id: "unsupported".to_string(),
            description: "unsupported".to_string(),
            category: TestCategory::PathValidation,
            requirement_level: RequirementLevel::Must,
            verdict: TestVerdict::ExpectedFailure,
            error_message: Some("unsupported".to_string()),
            execution_time_ms: 0,
        };

        assert_eq!(pass.support_class(), "production_live");
        assert_eq!(pass.evidence_quality(), "live");
        assert_eq!(unsupported.support_class(), "unsupported");
        assert_eq!(unsupported.evidence_quality(), "unsupported_boundary");
    }

    #[test]
    #[allow(dead_code)]
    fn test_anti_amplification_results_are_production_live() {
        let harness = QuicConnectionMigrationConformanceHarness::new();
        let results = harness.run_anti_amplification_tests();

        assert_eq!(results.len(), 3);
        for result in results {
            assert_eq!(result.verdict, TestVerdict::Pass, "{result:?}");
            assert_eq!(result.support_class(), "production_live");
            assert_eq!(result.evidence_quality(), "live");
        }
    }

    #[test]
    #[allow(dead_code)]
    fn test_registered_harness_has_no_failed_results_and_some_expected_failures() {
        let harness = QuicConnectionMigrationConformanceHarness::new();
        let results = harness.run_all_tests();

        assert!(!results.is_empty());
        assert!(
            results
                .iter()
                .all(|result| result.verdict != TestVerdict::Fail),
            "{results:#?}"
        );
        assert!(
            results
                .iter()
                .any(|result| result.verdict == TestVerdict::ExpectedFailure),
            "missing explicit unsupported-boundary evidence"
        );
    }

    #[test]
    #[allow(dead_code)]
    fn test_no_local_model_names_remain_in_harness_source() {
        let source = include_str!("quic_connection_migration_rfc9000.rs");
        for (left, right) in [
            ("LocalOnly", "PathValidator"),
            ("LocalOnlyConnection", "IdManager"),
            ("simulate_source", "_address_change"),
            ("simulate_concurrent", "_migration"),
            ("LocalOnly", " implementation"),
            ("ass", "ume"),
        ] {
            let forbidden = format!("{left}{right}");
            assert!(
                !source.contains(&forbidden),
                "forbidden local model marker remains: {forbidden}"
            );
        }
    }

    #[test]
    #[allow(dead_code)]
    fn test_conformance_harness_integration() {
        let harness = QuicConnectionMigrationConformanceHarness::new();
        let results = harness.run_all_tests();

        assert!(!results.is_empty(), "Should have conformance test results");

        // Verify we have tests for all required categories
        let categories: std::collections::HashSet<_> =
            results.iter().map(|r| &r.category).collect();
        assert!(categories.contains(&TestCategory::PathValidation));
        assert!(categories.contains(&TestCategory::ConnectionIdRetirement));
        assert!(categories.contains(&TestCategory::AntiAmplificationLimits));
        assert!(categories.contains(&TestCategory::NatRebindingDetection));
        assert!(categories.contains(&TestCategory::ConcurrentMigration));

        // Verify all tests have required fields
        for result in &results {
            assert!(!result.test_id.is_empty(), "Test ID must not be empty");
            assert!(
                !result.description.is_empty(),
                "Description must not be empty"
            );
        }

        // Verify we have the minimum expected number of test cases (15 as per bead)
        assert!(
            results.len() >= 15,
            "Should have at least 15 connection migration conformance test cases, got {}",
            results.len()
        );
    }

    #[test]
    #[allow(dead_code)]
    fn test_all_bead_requirements_covered() {
        let harness = QuicConnectionMigrationConformanceHarness::new();
        let results = harness.run_all_tests();

        let test_ids: std::collections::HashSet<_> =
            results.iter().map(|r| r.test_id.as_str()).collect();

        // Requirement 1: path validation with PATH_CHALLENGE/PATH_RESPONSE
        assert!(
            test_ids.contains("quic_path_challenge_response_exchange"),
            "Missing PATH_CHALLENGE/PATH_RESPONSE test"
        );

        // Requirement 2: retire old connection ID after migration
        assert!(
            test_ids.contains("quic_connection_id_retirement_after_migration"),
            "Missing connection ID retirement test"
        );

        // Requirement 3: anti-amplification limit on unverified paths
        assert!(
            test_ids.contains("quic_anti_amplification_limit_enforcement"),
            "Missing anti-amplification limit test"
        );

        // Requirement 4: NAT rebinding detected via source address change
        assert!(
            test_ids.contains("quic_nat_rebinding_detection"),
            "Missing NAT rebinding detection test"
        );

        // Requirement 5: concurrent path migration from both endpoints
        assert!(
            test_ids.contains("quic_concurrent_path_migration_both_endpoints"),
            "Missing concurrent migration test"
        );
    }

    #[test]
    #[allow(dead_code)]
    fn test_all_requirement_levels_represented() {
        let harness = QuicConnectionMigrationConformanceHarness::new();
        let results = harness.run_all_tests();

        let must_tests = results
            .iter()
            .filter(|r| r.requirement_level == RequirementLevel::Must)
            .count();
        let should_tests = results
            .iter()
            .filter(|r| r.requirement_level == RequirementLevel::Should)
            .count();

        assert!(must_tests > 0, "Should have MUST requirement tests");
        assert!(should_tests > 0, "Should have SHOULD requirement tests");
    }
}