File size: 65,294 Bytes
2955ecc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
from __future__ import annotations

import json
import sys
import unittest
from copy import deepcopy
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "src"
if str(SRC) not in sys.path:
    sys.path.insert(0, str(SRC))

from datacenter_verification.observable_algorithm import (
    _capacity_claim_contradictions,
    _concurrent_peak,
    _max,
    evaluate_site,
)


class ObservableAlgorithmTest(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        payload = json.loads((ROOT / "synthetic" / "sites.json").read_text(encoding="utf-8"))
        cls.sites = {site["scenario_key"]: site for site in payload["sites"]}
        cls.results = {key: evaluate_site(site) for key, site in cls.sites.items()}

    def result(self, key: str) -> dict:
        return self.results[key]

    def stage(self, key: str, stage: str) -> dict:
        return self.result(key)["stage_outputs"][stage]

    def suppress_identity_pathways(self, site: dict, keep_participant: bool = False) -> None:
        signals = site.setdefault("normalized_signals", {})
        signals["collective_cadence_score"] = 0.0
        signals["checkpoint_periodicity_score"] = 0.0
        signals["checkpoint_burst_count"] = 0.0
        signals["activity_fabric_overlap_fraction"] = 0.0
        signals["checkpoint_activity_adjacency_fraction"] = 0.0
        if not keep_participant:
            signals["participant_count"] = 0.0
        for record in site.setdefault("raw_features", {}).get("fabric_port_device_sample_counters", []):
            if record.get("counter_name") == "collective_cadence_score":
                record["counter_value"] = 0.0
            if not keep_participant and record.get("counter_name") == "participant_count":
                record["counter_value"] = 0.0

    def set_raw_rate_integral(self, site: dict, operations: float) -> None:
        duration = 30 * 24 * 3600
        for record in site.setdefault("raw_features", {}).get("generic_achieved_operation_rate", []):
            record["operation_rate"] = operations / duration

    def test_all_synthetic_expected_outputs_match(self) -> None:
        for key, site in self.sites.items():
            with self.subTest(key=key):
                result = self.results[key]
                expected = site["expected"]
                self.assertEqual(expected["A_capacity_gate_label"], self.stage(key, "A_capacity_gate")["label"])
                self.assertEqual(expected["final_route"], result["final_route"])
                self.assertEqual(expected["capacity_short_circuit"], self.stage(key, "A_capacity_gate")["short_circuited"])
                b_labels = self.stage(key, "B_training_candidate_detection")["labels"]
                c_labels = self.stage(key, "C_discrepancy_and_explanation_review")["labels"]
                for label in expected["B_training_candidate_detection_labels"]:
                    self.assertIn(label, b_labels)
                for label in expected["C_discrepancy_and_explanation_review_labels"]:
                    self.assertIn(label, c_labels)

    def test_capacity_ruleout_short_circuits_b_and_c(self) -> None:
        result = self.result("C_capacity_ruled_out")
        self.assertEqual("capacity_ruled_out_for_scope", result["final_route"])
        self.assertTrue(self.stage("C_capacity_ruled_out", "A_capacity_gate")["short_circuited"])
        self.assertEqual("skipped_due_to_capacity_ruleout", self.stage("C_capacity_ruled_out", "B_training_candidate_detection")["mode"])
        self.assertEqual("skipped_due_to_capacity_ruleout", self.stage("C_capacity_ruled_out", "C_discrepancy_and_explanation_review")["mode"])

    def test_clean_training_reaches_high_warning(self) -> None:
        result = self.result("A_clean_threshold_training")
        b = self.stage("A_clean_threshold_training", "B_training_candidate_detection")
        c = self.stage("A_clean_threshold_training", "C_discrepancy_and_explanation_review")
        self.assertEqual("high_training_like_warning", result["final_route"])
        self.assertIn("distributed_training_like_candidate", b["labels"])
        self.assertIn("checkpoint_training_like_candidate", b["labels"])
        self.assertEqual("C2_candidate_conflict_adjudication", c["mode"])
        self.assertFalse(c["discrepancies"])
        self.assertFalse(c["missing_channels"])

    def test_algorithm_version_is_v0_3(self) -> None:
        self.assertEqual("observable_staged_v0.3", self.result("A_clean_threshold_training")["algorithm_version"])

    def test_large_compute_alone_does_not_become_medium_or_high_training(self) -> None:
        result = self.result("K_large_compute_alone")
        b = self.stage("K_large_compute_alone", "B_training_candidate_detection")
        self.assertEqual("weak_training_like_candidate", result["final_route"])
        self.assertIn("large_compute_candidate", b["labels"])
        self.assertNotIn("distributed_training_like_candidate", b["labels"])
        self.assertNotIn("checkpoint_training_like_candidate", b["labels"])
        self.assertIn("large_compute_training_identity_unresolved", result["caveats"])

    def test_activity_alone_stays_clean_negative(self) -> None:
        result = self.result("L_activity_alone")
        b = self.stage("L_activity_alone", "B_training_candidate_detection")
        c = self.stage("L_activity_alone", "C_discrepancy_and_explanation_review")
        self.assertEqual("no_training_like_candidate_detected_in_covered_live_segment", result["final_route"])
        self.assertEqual([], b["labels"])
        self.assertEqual("C1_negative_screen_integrity", c["mode"])
        self.assertIn("negative_screen_coverage_sufficient", c["labels"])

    def test_fabric_alone_and_storage_alone_route_integrity(self) -> None:
        cases = {
            "M_fabric_alone": "fabric_without_job_or_topology_mapping_conflict",
            "N_storage_writes_alone": "checkpoint_writes_without_activity_conflict",
        }
        for key, discrepancy in cases.items():
            with self.subTest(case=key):
                result = self.result(key)
                b = self.stage(key, "B_training_candidate_detection")
                c = self.stage(key, "C_discrepancy_and_explanation_review")
                self.assertEqual("integrity_review_required", result["final_route"])
                self.assertEqual([], b["labels"])
                self.assertEqual("C1_negative_screen_integrity", c["mode"])
                self.assertIn("negative_screen_incoherence_conflict", c["labels"])
                self.assertIn(discrepancy, c["discrepancies"])

    def test_storage_explanation_demotes_checkpoint_candidate(self) -> None:
        result = self.result("E_storage_operation_explains_checkpoint")
        b = self.stage("E_storage_operation_explains_checkpoint", "B_training_candidate_detection")
        c = self.stage("E_storage_operation_explains_checkpoint", "C_discrepancy_and_explanation_review")
        self.assertIn("checkpoint_training_like_candidate", b["labels"])
        self.assertIn("candidate_explained_by_storage_operation", c["labels"])
        self.assertEqual("candidate_explained_or_demoted", result["final_route"])

    def test_serving_counterevidence_demotes_large_compute_candidate(self) -> None:
        result = self.result("F_serving_inference_counterevidence")
        c = self.stage("F_serving_inference_counterevidence", "C_discrepancy_and_explanation_review")
        self.assertIn("candidate_explained_by_serving", c["labels"])
        self.assertEqual("candidate_explained_or_demoted", result["final_route"])

    def test_benchmark_and_hpc_alternative_demotes_fabric_candidate(self) -> None:
        result = self.result("G_hpc_mpi_benchmark_alternative")
        c = self.stage("G_hpc_mpi_benchmark_alternative", "C_discrepancy_and_explanation_review")
        self.assertIn("candidate_benchmark_like", c["labels"])
        self.assertIn("candidate_hpc_mpi_alternative", c["labels"])
        self.assertEqual("candidate_explained_or_demoted", result["final_route"])

    def test_covered_negative_and_missing_negative_screen_routes(self) -> None:
        covered = self.result("B_covered_negative")
        missing = self.result("D_missingness_blocks_negative_screen")
        self.assertEqual("no_training_like_candidate_detected_in_covered_live_segment", covered["final_route"])
        self.assertIn(
            "negative_screen_coverage_sufficient",
            self.stage("B_covered_negative", "C_discrepancy_and_explanation_review")["labels"],
        )
        self.assertEqual("inconclusive_due_to_missingness", missing["final_route"])
        self.assertIn(
            "negative_screen_blocked_by_missingness",
            self.stage("D_missingness_blocks_negative_screen", "C_discrepancy_and_explanation_review")["labels"],
        )

    def test_capacity_and_activity_attribution_conflicts_route_integrity(self) -> None:
        capacity = self.result("H_capacity_claim_conflict")
        attribution = self.result("I_activity_attribution_conflict")
        self.assertEqual("integrity_review_required", capacity["final_route"])
        self.assertIn(
            "capacity_claim_conflict",
            self.stage("H_capacity_claim_conflict", "C_discrepancy_and_explanation_review")["labels"],
        )
        self.assertEqual("integrity_review_required", attribution["final_route"])
        self.assertIn(
            "activity_attribution_conflict",
            self.stage("I_activity_attribution_conflict", "C_discrepancy_and_explanation_review")["labels"],
        )

    # --- FIX 3 (F1, predicate A2'): C1 incoherence integrity ---

    def _f1_probe(self, fabric: float | None = None, checkpoint: float | None = None) -> dict:
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        probe["normalized_signals"]["activity_score"] = 0.30
        for key in (
            "accelerator_busy_or_utilization_fraction",
            "tensor_matrix_mxu_neuron_or_engine_active_fraction",
        ):
            if key in probe.get("raw_features", {}):
                probe["raw_features"][key] = [{"value": 0.30}]
        probe["normalized_signals"]["achieved_operations"] = 5e24
        if fabric is not None:
            probe["normalized_signals"]["collective_cadence_score"] = fabric
        if checkpoint is not None:
            probe["normalized_signals"]["checkpoint_periodicity_score"] = checkpoint
        return probe

    def test_f1_shaped_activity_does_not_certify_clean_negative(self) -> None:
        result = evaluate_site(self._f1_probe())
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertEqual(
            "C1_negative_screen_integrity",
            result["stage_outputs"]["C_discrepancy_and_explanation_review"]["mode"],
        )

    def test_f1_fabric_only_variant_routes_integrity(self) -> None:
        result = evaluate_site(self._f1_probe(checkpoint=0.0))
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("fabric_without_job_or_topology_mapping_conflict", result["discrepancy_findings"])

    def test_f1_checkpoint_only_variant_routes_integrity(self) -> None:
        result = evaluate_site(self._f1_probe(fabric=0.0))
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("checkpoint_writes_without_activity_conflict", result["discrepancy_findings"])

    def test_f1_covered_negative_and_storage_explained_unaffected(self) -> None:
        self.assertEqual(
            "no_training_like_candidate_detected_in_covered_live_segment",
            self.result("B_covered_negative")["final_route"],
        )
        self.assertEqual(
            "candidate_explained_or_demoted",
            self.result("E_storage_operation_explains_checkpoint")["final_route"],
        )

    # --- high-activity alignment shading cannot certify absence ---

    def _alignment_shading_probe(
        self,
        activity: float = 0.91,
        fabric_overlap: float = 0.49,
        checkpoint_adjacency: float = 0.49,
        achieved: float = 9.0e24,
        fabric_score: float = 0.86,
        checkpoint_score: float = 0.82,
    ) -> dict:
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        sig = probe["normalized_signals"]
        sig["activity_score"] = activity
        sig["activity_fabric_overlap_fraction"] = fabric_overlap
        sig["checkpoint_activity_adjacency_fraction"] = checkpoint_adjacency
        sig["achieved_operations"] = achieved
        sig["collective_cadence_score"] = fabric_score
        sig["checkpoint_periodicity_score"] = checkpoint_score
        for key in (
            "accelerator_busy_or_utilization_fraction",
            "tensor_matrix_mxu_neuron_or_engine_active_fraction",
        ):
            if key in probe.get("raw_features", {}):
                probe["raw_features"][key] = [{"value": activity}]
        return probe

    def test_fatal1_exact_alignment_shading_does_not_certify_absence(self) -> None:
        result = evaluate_site(self._alignment_shading_probe())
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("fabric_activity_alignment_incoherence_conflict", result["discrepancy_findings"])
        self.assertIn("checkpoint_activity_alignment_incoherence_conflict", result["discrepancy_findings"])
        self.assertNotIn(
            result["final_route"],
            {"capacity_ruled_out_for_scope", "no_training_like_candidate_detected_in_covered_live_segment"},
        )

    def test_fatal1_alignment_shading_activity_band_variants(self) -> None:
        for activity in (0.55, 0.70, 0.95):
            with self.subTest(activity=activity):
                result = evaluate_site(self._alignment_shading_probe(activity=activity))
                self.assertEqual("integrity_review_required", result["final_route"])

    def test_fatal1_single_alignment_shaded_variants_do_not_certify_absence(self) -> None:
        cases = [
            ("fabric_only", 0.49, 0.78, "checkpoint_training_like_candidate"),
            ("checkpoint_only", 0.82, 0.49, "distributed_training_like_candidate"),
        ]
        for name, fabric_overlap, checkpoint_adj, surviving_b_label in cases:
            with self.subTest(name=name):
                result = evaluate_site(
                    self._alignment_shading_probe(
                        fabric_overlap=fabric_overlap,
                        checkpoint_adjacency=checkpoint_adj,
                    )
                )
                self.assertNotIn(
                    result["final_route"],
                    {"capacity_ruled_out_for_scope", "no_training_like_candidate_detected_in_covered_live_segment"},
                )
                self.assertIn(surviving_b_label, result["stage_outputs"]["B_training_candidate_detection"]["labels"])

    def test_fatal1_alignment_gate_boundary_forms_candidates_normally(self) -> None:
        result = evaluate_site(
            self._alignment_shading_probe(
                fabric_overlap=0.50,
                checkpoint_adjacency=0.50,
                achieved=1.15e25,
            )
        )
        b_labels = result["stage_outputs"]["B_training_candidate_detection"]["labels"]
        self.assertIn("distributed_training_like_candidate", b_labels)
        self.assertIn("checkpoint_training_like_candidate", b_labels)
        self.assertEqual("high_training_like_warning", result["final_route"])

    def test_fatal1_capacity_adjustment_deflation_with_raw_capacity_witness_is_blocked(self) -> None:
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        probe["normalized_signals"]["capacity_adjustment_factor"] = 0.20
        probe["normalized_signals"]["achieved_operations"] = 6.0e24
        self.set_raw_rate_integral(probe, 6.0e24)
        result = evaluate_site(probe)
        self.assertEqual("integrity_review_required", result["final_route"])
        contradictions = _capacity_claim_contradictions(result["derived_signals"], probe)
        self.assertIn("capacity_adjustment_deflates_raw_threshold_capacity", contradictions)

    def test_fatal1_benign_explanation_does_not_suppress_alignment_incoherence(self) -> None:
        probe = self._alignment_shading_probe(
            fabric_overlap=0.0,
            checkpoint_adjacency=0.0,
            achieved=0.0,
        )
        self.set_raw_rate_integral(probe, 0.0)
        probe["normalized_signals"]["storage_operation_overlap_fraction"] = 0.80
        probe["normalized_signals"]["bytes_explained_fraction"] = 0.70
        result = evaluate_site(probe)
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("negative_screen_incoherence_conflict", result["stage_outputs"]["C_discrepancy_and_explanation_review"]["labels"])
        self.assertIn("fabric_activity_alignment_incoherence_conflict", result["discrepancy_findings"])
        self.assertIn("checkpoint_activity_alignment_incoherence_conflict", result["discrepancy_findings"])

    def test_fatal1_zero_count_does_not_capacity_ruleout_with_witnesses_standing(self) -> None:
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        for record in probe["raw_features"].get("accelerator_count_by_family_sku", []):
            record["count"] = 0.0
        result = evaluate_site(probe)
        a = result["stage_outputs"]["A_capacity_gate"]
        self.assertEqual("capacity_unknown_due_to_missing_inputs", a["label"])
        self.assertFalse(a["short_circuited"])
        self.assertIn("accelerator_count_by_family_sku", a["missing_inputs"])
        self.assertNotEqual("capacity_ruled_out_for_scope", result["final_route"])

    def test_absent_serving_evidence_does_not_count_as_nonserving_identity(self) -> None:
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        sig = probe["normalized_signals"]
        sig["checkpoint_periodicity_score"] = 0.0
        sig["checkpoint_burst_count"] = 0.0
        sig["checkpoint_activity_adjacency_fraction"] = 0.0
        sig.pop("serving_counterevidence_score", None)
        sig.pop("non_serving_score", None)
        result = evaluate_site(probe)
        b = result["stage_outputs"]["B_training_candidate_detection"]
        self.assertEqual("medium_training_like_warning", result["final_route"])
        self.assertEqual(1, b["identity_category_count"])
        self.assertIn("distributed_training_like_candidate", b["labels"])
        self.assertNotIn("checkpoint_training_like_candidate", b["labels"])

    def test_invalid_audit_window_does_not_capacity_ruleout(self) -> None:
        probe = deepcopy(self.sites["C_capacity_ruled_out"])
        probe["audit_window"] = {
            "start": "2026-05-01T00:00:00Z",
            "end": "2026-04-01T00:00:00Z",
        }
        result = evaluate_site(probe)
        a = result["stage_outputs"]["A_capacity_gate"]
        c = result["stage_outputs"]["C_discrepancy_and_explanation_review"]
        self.assertEqual("capacity_unknown_due_to_missing_inputs", a["label"])
        self.assertFalse(a["short_circuited"])
        self.assertIn("audit_window", a["missing_inputs"])
        self.assertEqual("inconclusive_due_to_missingness", result["final_route"])
        self.assertIn("audit_window", c["missing_channels"])

    def test_unknown_unit_raw_rate_does_not_create_large_compute_candidate(self) -> None:
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        self.suppress_identity_pathways(probe)
        probe["normalized_signals"].pop("achieved_operations", None)
        duration = 30 * 24 * 3600
        probe["raw_features"]["generic_achieved_operation_rate"] = [
            {
                "sample_time": "2026-04-16T00:00:00Z",
                "operation_rate": 2.0e25 / duration,
                "operation_unit": "unknown_vendor_units",
                "counter_scope": "accelerator_pool",
            }
        ]
        result = evaluate_site(probe)
        achieved = result["derived_signals"]["achieved_operation_integral"]
        b = result["stage_outputs"]["B_training_candidate_detection"]
        self.assertEqual(0.0, achieved["operation_count"])
        self.assertFalse(achieved["unit_normalized"])
        self.assertTrue(achieved["ignored_raw_rate_unit"])
        self.assertNotIn("large_compute_candidate", b["labels"])
        self.assertNotIn(result["final_route"], {"weak_training_like_candidate", "medium_training_like_warning", "high_training_like_warning"})

    def test_negative_capacity_adjustment_factor_does_not_capacity_ruleout(self) -> None:
        probe = deepcopy(self.sites["C_capacity_ruled_out"])
        probe["normalized_signals"]["capacity_adjustment_factor"] = -1.0
        result = evaluate_site(probe)
        a = result["stage_outputs"]["A_capacity_gate"]
        cap = result["derived_signals"]["capacity_upper_bound_flop"]
        self.assertTrue(cap["invalid_capacity_adjustment_factor"])
        self.assertEqual("capacity_unknown_due_to_missing_inputs", a["label"])
        self.assertFalse(a["short_circuited"])
        self.assertIn("capacity_adjustment_factor", a["missing_inputs"])
        self.assertNotEqual("capacity_ruled_out_for_scope", result["final_route"])

    def test_fatal1_raw_threshold_rate_blocks_covered_negative(self) -> None:
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        probe["normalized_signals"]["achieved_operations"] = 0.0
        probe["normalized_signals"]["activity_duration_seconds"] = 1799.0
        probe["normalized_signals"]["checkpoint_periodicity_score"] = 0.54
        result = evaluate_site(probe)
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn(
            "raw_rate_threshold_compute_without_candidate_conflict",
            result["discrepancy_findings"],
        )

    # --- FIX 1 (M1): achieved_ops in the negative screen ---

    def test_negative_screen_blocks_on_missing_achieved_ops(self) -> None:
        site = deepcopy(self.sites["B_covered_negative"])
        site["coverage"]["achieved_ops"] = 0.0
        result = evaluate_site(site)
        self.assertEqual("inconclusive_due_to_missingness", result["final_route"])
        self.assertIn("achieved_ops", result["missing_channels"])

    # --- FIX 2 (M3): polarity-correct certification coverage ---

    def test_omitted_certification_key_does_not_increase_confidence(self) -> None:
        site = deepcopy(self.sites["B_covered_negative"])
        del site["coverage"]["achieved_ops"]
        self.assertEqual("inconclusive_due_to_missingness", evaluate_site(site)["final_route"])

    def test_omitting_attribution_does_not_disable_integrity_guard(self) -> None:
        site = deepcopy(self.sites["I_activity_attribution_conflict"])
        del site["coverage"]["attribution"]
        self.assertEqual("integrity_review_required", evaluate_site(site)["final_route"])

    def test_omitting_capacity_blocks_capacity_ruleout(self) -> None:
        site = deepcopy(self.sites["C_capacity_ruled_out"])
        del site["coverage"]["capacity"]
        result = evaluate_site(site)
        self.assertNotEqual("capacity_ruled_out_for_scope", result["final_route"])
        self.assertFalse(result["stage_outputs"]["A_capacity_gate"]["short_circuited"])

    def test_omitting_achieved_ops_on_integrity_fixture_routes_inconclusive(self) -> None:
        site = deepcopy(self.sites["I_activity_attribution_conflict"])
        del site["coverage"]["achieved_ops"]
        result = evaluate_site(site)
        self.assertEqual("inconclusive_due_to_missingness", result["final_route"])
        self.assertIn("achieved_ops", result["missing_channels"])

    # --- FIX 4 (M-2): per-category serving/storage carve-outs ---

    def test_serving_shape_does_not_demote_independent_checkpoint_pathway(self) -> None:
        instance = deepcopy(self.sites["A_clean_threshold_training"])
        sig = instance["normalized_signals"]
        sig["activity_fabric_overlap_fraction"] = 0.49
        sig["serving_counterevidence_score"] = 0.75
        sig["serving_activity_overlap_fraction"] = 0.80
        result = evaluate_site(instance)
        self.assertTrue(result["final_route"].endswith("_warning"))
        self.assertNotEqual("candidate_explained_or_demoted", result["final_route"])
        c = result["stage_outputs"]["C_discrepancy_and_explanation_review"]
        self.assertIn("candidate_explained_by_serving", c["labels"])
        self.assertTrue(c["surviving_identity_pathway"])
        self.assertIn("checkpoint_training_like_candidate", result["stage_outputs"]["B_training_candidate_detection"]["labels"])

    def test_storage_relabel_does_not_demote_live_fabric_pathway(self) -> None:
        instance = deepcopy(self.sites["A_clean_threshold_training"])
        sig = instance["normalized_signals"]
        sig["checkpoint_activity_adjacency_fraction"] = 0.49
        sig["storage_operation_overlap_fraction"] = 0.85
        sig["bytes_explained_fraction"] = 0.80
        result = evaluate_site(instance)
        self.assertTrue(result["final_route"].endswith("_warning"))
        self.assertNotEqual("candidate_explained_or_demoted", result["final_route"])
        c = result["stage_outputs"]["C_discrepancy_and_explanation_review"]
        self.assertIn("candidate_explained_by_storage_operation", c["labels"])
        self.assertTrue(c["surviving_identity_pathway"])
        self.assertIn("distributed_training_like_candidate", result["stage_outputs"]["B_training_candidate_detection"]["labels"])

    def test_model_parallel_inference_serving_still_suppressed(self) -> None:
        result = self.result("F_serving_inference_counterevidence")
        c = self.stage("F_serving_inference_counterevidence", "C_discrepancy_and_explanation_review")
        self.assertEqual("candidate_explained_or_demoted", result["final_route"])
        self.assertIn("candidate_explained_by_serving", c["labels"])
        self.assertFalse(c["surviving_identity_pathway"])

    # --- FIX 5 (F2): forged capacity rule-out via under-reported accelerator count ---

    def _f2_count_shaded_probe(self, count: float = 100.0) -> dict:
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        raw = probe.get("raw_features", {})
        for record in raw.get("accelerator_count_by_family_sku", []):
            record["count"] = count
        for record in raw.get("allocated_accelerator_count_by_sku", []):
            if "count" in record:
                record["count"] = count
        return probe

    def test_f2_count_shaded_ruleout_routes_integrity_without_disturbing_legit_ruleouts(self) -> None:
        # (1) F2 PROBE: a genuine positive whose accelerator count is shaded down so the
        # capacity upper bound drops below T_sys must NOT certify a capacity rule-out while the
        # untouched, well-covered achieved-operation integral still exceeds that shaded bound.
        probe = evaluate_site(self._f2_count_shaded_probe())
        achieved = probe["derived_signals"]["achieved_operation_integral"]
        self.assertGreater(achieved["operation_count_to_capacity_upper_bound_ratio"], 1.0)
        self.assertGreaterEqual(achieved["coverage_fraction"], 0.75)
        self.assertEqual("integrity_review_required", probe["final_route"])
        self.assertNotEqual("capacity_ruled_out_for_scope", probe["final_route"])
        self.assertFalse(probe["stage_outputs"]["A_capacity_gate"]["short_circuited"])
        self.assertIn("capacity_claim_conflict", probe["discrepancy_findings"])

        # (2) LEGITIMATE RULE-OUT: the synthetic clean rule-out fixture must STILL rule out.
        # Additional low-ratio and sequential-reuse rule-out locks below replace the old
        # external sweep dependency.
        fixture = self.result("C_capacity_ruled_out")
        self.assertEqual("capacity_ruled_out_for_scope", fixture["final_route"])
        self.assertTrue(fixture["stage_outputs"]["A_capacity_gate"]["short_circuited"])

        # (3) I2 FIXTURE: the existing capacity_claim_conflict fixture still routes to integrity.
        i2 = self.result("H_capacity_claim_conflict")
        self.assertEqual("integrity_review_required", i2["final_route"])
        self.assertIn(
            "capacity_claim_conflict",
            self.stage("H_capacity_claim_conflict", "C_discrepancy_and_explanation_review")["labels"],
        )

    # --- service-power and low-coverage achieved witnesses ---

    def _ruleout_forge_base(
        self,
        count: float = 1000.0,
        achieved: float = 1e23,
        suppress_identity: bool = False,
    ) -> dict:
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        raw = probe.setdefault("raw_features", {})
        sig = probe.setdefault("normalized_signals", {})
        for record in raw.get("accelerator_count_by_family_sku", []):
            record["count"] = count
        sig["achieved_operations"] = achieved
        sig["participant_count"] = 0
        for record in raw.get("fabric_port_device_sample_counters", []):
            if record.get("counter_name") == "participant_count":
                record["counter_value"] = 0
        for key in (
            "allocated_accelerator_count_by_sku",
            "accelerator_compute_billing_usage_intervals",
            "compute_running_intervals",
            "scaleout_fabric_domain_graph",
            "capacity_reservation_intervals",
            "reservation_state_intervals",
            "instance_type_shape_machine_type",
            "local_accelerator_interconnect_domain",
        ):
            raw.pop(key, None)
        for record in raw.get("generic_achieved_operation_rate", []):
            record["operation_rate"] = 0.0
        if suppress_identity:
            self.suppress_identity_pathways(probe)
        probe["coverage"]["achieved_ops"] = 0.74
        return probe

    def test_major2_large_achieved_override_blocks_ruleout_under_shaded_coverage(self) -> None:
        probe = self._ruleout_forge_base(achieved=1.15e25)
        probe["raw_features"].pop("generic_achieved_operation_rate", None)
        result = evaluate_site(probe)
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])
        self.assertIn(
            "achieved_operations_exceed_capacity_bound",
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )

    def test_major2_raw_rate_blocks_ruleout_under_shaded_coverage(self) -> None:
        probe = self._ruleout_forge_base(achieved=1e23)
        duration = 30 * 24 * 3600
        probe["raw_features"]["generic_achieved_operation_rate"] = [
            {
                "sample_time": "2026-04-16T00:00:00Z",
                "operation_rate": 1.15e25 / duration,
                "operation_unit": "synthetic_normalized_operations",
                "counter_scope": "accelerator_pool",
            }
        ]
        result = evaluate_site(probe)
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn(
            "raw_achieved_rate_integral_exceeds_capacity_bound",
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )

    def test_major2_below_bound_low_coverage_ruleout_preserved(self) -> None:
        probe = self._ruleout_forge_base(achieved=1e23, suppress_identity=True)
        probe["raw_features"].pop("electrical_service_status_intervals", None)
        result = evaluate_site(probe)
        self.assertEqual("capacity_ruled_out_for_scope", result["final_route"])
        self.assertEqual([], result["discrepancy_findings"])

    def test_major2_unit_safety_for_achieved_and_raw_rate(self) -> None:
        override = self._ruleout_forge_base(achieved=1.15e25, suppress_identity=True)
        override["normalized_signals"]["achieved_operations_unit_normalized"] = False
        override["raw_features"].pop("generic_achieved_operation_rate", None)
        override["raw_features"].pop("electrical_service_status_intervals", None)
        self.assertEqual("capacity_ruled_out_for_scope", evaluate_site(override)["final_route"])

        raw = self._ruleout_forge_base(achieved=1e23, suppress_identity=True)
        duration = 30 * 24 * 3600
        raw["raw_features"]["generic_achieved_operation_rate"] = [
            {
                "sample_time": "2026-04-16T00:00:00Z",
                "operation_rate": 1.15e25 / duration,
                "operation_unit": "unknown_vendor_units",
                "counter_scope": "accelerator_pool",
            }
        ]
        raw["raw_features"].pop("electrical_service_status_intervals", None)
        self.assertEqual("capacity_ruled_out_for_scope", evaluate_site(raw)["final_route"])

    def test_major1_scoped_service_power_floor_blocks_ruleout(self) -> None:
        probe = self._ruleout_forge_base(achieved=1e23)
        result = evaluate_site(probe)
        self.assertEqual("integrity_review_required", result["final_route"])
        notes = " ".join(result["stage_outputs"]["A_capacity_gate"]["notes"])
        self.assertIn("Independent capacity-scale witnesses", notes)
        self.assertNotIn("achieved-operation integral exceeds", notes)
        self.assertIn(
            "electrical_service_power_floor_exceeds_capacity_count",
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )

    def test_major1_service_power_floor_requires_scope_and_supporting_status(self) -> None:
        for field, value in (("service_class", "unscoped_facility_service"), ("service_status", "pending")):
            with self.subTest(field=field):
                probe = self._ruleout_forge_base(achieved=1e23, suppress_identity=True)
                for record in probe["raw_features"].get("electrical_service_status_intervals", []):
                    record[field] = value
                result = evaluate_site(probe)
                self.assertEqual("capacity_ruled_out_for_scope", result["final_route"])
                self.assertNotIn(
                    "electrical_service_power_floor_exceeds_capacity_count",
                    _capacity_claim_contradictions(result["derived_signals"], probe),
                )

    def test_major1_split_concurrent_scoped_service_floor_blocks_ruleout(self) -> None:
        probe = self._ruleout_forge_base(count=100.0, achieved=1e23, suppress_identity=True)
        proto = probe["raw_features"]["electrical_service_status_intervals"][0]
        probe["raw_features"]["electrical_service_status_intervals"] = [
            dict(
                proto,
                service_status="energized",
                service_class="synthetic_datacenter_service",
                service_capacity_mw=0.072,
                power_mw=0.0,
                mean_power_mw=0.0,
                max_power_mw=0.0,
            )
            for _ in range(40)
        ]
        result = evaluate_site(probe)
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn(
            "electrical_service_power_floor_exceeds_capacity_count",
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )

    def test_major1_sequential_scoped_service_floor_does_not_overcount(self) -> None:
        probe = self._ruleout_forge_base(count=100.0, achieved=1e23, suppress_identity=True)
        proto = probe["raw_features"]["electrical_service_status_intervals"][0]
        probe["raw_features"]["electrical_service_status_intervals"] = [
            dict(
                proto,
                start_time="2026-04-01T00:00:00Z",
                end_time="2026-04-16T00:00:00Z",
                service_capacity_mw=0.072,
            ),
            dict(
                proto,
                start_time="2026-04-16T00:00:00Z",
                end_time="2026-05-01T00:00:00Z",
                service_capacity_mw=0.072,
            ),
        ]
        result = evaluate_site(probe)
        self.assertEqual("capacity_ruled_out_for_scope", result["final_route"])
        self.assertNotIn(
            "electrical_service_power_floor_exceeds_capacity_count",
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )

    # --- FIX 6 (F3): generalized capacity-claim contradiction (coordinated forge) ---

    def _f3_probe(
        self,
        count: float = 100.0,
        achieved: float = 1e23,
        suppress_participant: bool = False,
        suppress_allocated: bool = False,
        suppress_billing: bool = False,
        suppress_running: bool = False,
        suppress_fabric_graph: bool = False,
        suppress_service: bool = False,
        suppress_identity: bool = False,
        keep_participant_identity: bool = False,
    ) -> dict:
        # Coordinated forge: shade the accelerator count down AND shade achieved-ops down in
        # lockstep so the achieved/capacity ratio stays below 1.0 (defeating the F2 guard).
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        raw = probe.setdefault("raw_features", {})
        signals = probe.setdefault("normalized_signals", {})
        for record in raw.get("accelerator_count_by_family_sku", []):
            record["count"] = count
        signals["achieved_operations"] = achieved
        # Shade BOTH the override and the raw achieved-rate witness in lockstep, so the
        # F4 raw-rate sub-check is also defeated (the full coordinated shading move).
        for record in raw.get("generic_achieved_operation_rate", []):
            record["operation_rate"] = 0.0
        if suppress_participant:
            signals["participant_count"] = 0
            for record in raw.get("fabric_port_device_sample_counters", []):
                if record.get("counter_name") == "participant_count":
                    record["counter_value"] = 0
        if suppress_allocated:
            raw.pop("allocated_accelerator_count_by_sku", None)
        if suppress_billing:
            raw.pop("accelerator_compute_billing_usage_intervals", None)
        # F5: the remaining device-population witnesses the four count-comparison checks
        # never read. The running-accelerator interval count and the scale-out fabric
        # node/switch counts must also be suppressed for the rule-out to forge.
        if suppress_running:
            raw.pop("compute_running_intervals", None)
        if suppress_fabric_graph:
            raw.pop("scaleout_fabric_domain_graph", None)
        if suppress_service:
            raw.pop("electrical_service_status_intervals", None)
        if suppress_identity:
            self.suppress_identity_pathways(probe, keep_participant=keep_participant_identity)
        return probe

    def _f3_full_suppression(self, count: float = 100.0, achieved: float = 1e23) -> dict:
        return self._f3_probe(
            count=count,
            achieved=achieved,
            suppress_participant=True,
            suppress_allocated=True,
            suppress_billing=True,
            suppress_running=True,
            suppress_fabric_graph=True,
            suppress_service=True,
            suppress_identity=True,
        )

    def test_f3_coordinated_forge_does_not_rule_out_while_scale_signal_survives(self) -> None:
        # The pure F3 maneuver: count shaded AND achieved-ops shaded so the F2 ratio guard is
        # below 1.0, yet participant_count / allocated / billed device-seconds still exceed the
        # claimed count. Must NOT certify a capacity rule-out; routes to integrity.
        base = evaluate_site(self._f3_probe())
        ratio = base["derived_signals"]["achieved_operation_integral"][
            "operation_count_to_capacity_upper_bound_ratio"
        ]
        self.assertLessEqual(ratio, 1.0)  # the F2 ratio guard does NOT fire here
        self.assertNotEqual("capacity_ruled_out_for_scope", base["final_route"])
        self.assertEqual("integrity_review_required", base["final_route"])
        self.assertIn("capacity_claim_conflict", base["discrepancy_findings"])

        # Each independent scale signal alone is sufficient to block the forge. Suppress the
        # others and confirm the surviving one still routes to integrity.
        participant_only = evaluate_site(
            self._f3_probe(
                suppress_allocated=True,
                suppress_billing=True,
                suppress_running=True,
                suppress_fabric_graph=True,
                suppress_service=True,
                suppress_identity=True,
                keep_participant_identity=True,
            )
        )
        self.assertEqual("integrity_review_required", participant_only["final_route"])

        allocated_only = evaluate_site(
            self._f3_probe(
                suppress_participant=True,
                suppress_billing=True,
                suppress_running=True,
                suppress_fabric_graph=True,
                suppress_service=True,
                suppress_identity=True,
            )
        )
        self.assertEqual("integrity_review_required", allocated_only["final_route"])

        billing_only = evaluate_site(
            self._f3_probe(
                suppress_participant=True,
                suppress_allocated=True,
                suppress_running=True,
                suppress_fabric_graph=True,
                suppress_service=True,
                suppress_identity=True,
            )
        )
        self.assertEqual("integrity_review_required", billing_only["final_route"])

    def test_f3_irreducible_residual_requires_suppressing_every_scale_signal(self) -> None:
        # The forge only succeeds when EVERY enumerated device-population witness is coherently
        # suppressed at once: achieved-ops shaded (override + raw rate), participant_count zeroed,
        # allocated removed, billing removed, the running-accelerator interval removed, and the
        # scale-out fabric graph removed, and strong fabric/checkpoint identity suppressed. With
        # no contradicting evidence present, the rule-out is vacuously consistent. This documents
        # the disclosed irreducible residual (the true limit of telemetry-grounded verification);
        # if a new witness were added the guard would need to cover it and this test would flip.
        residual = evaluate_site(self._f3_full_suppression())
        self.assertEqual("capacity_ruled_out_for_scope", residual["final_route"])
        self.assertEqual([], residual["discrepancy_findings"])

    def test_f5_running_accelerator_count_alone_blocks_forge(self) -> None:
        # F5 regression: the F3 minimal recipe that suppresses participant/allocated/billing/
        # achieved but leaves compute_running_intervals.accelerator_count honest must NOT forge a
        # rule-out. The running-accelerator count exceeds the shaded claimed count and routes to
        # integrity. (The fabric graph is also suppressed here so the running count is the ONLY
        # surviving witness, proving it alone is load-bearing.)
        probe = self._f3_probe(
            suppress_participant=True,
            suppress_allocated=True,
            suppress_billing=True,
            suppress_fabric_graph=True,
            suppress_service=True,
            suppress_identity=True,
        )
        result = evaluate_site(probe)
        derived = result["derived_signals"]
        running = _max(probe["raw_features"].get("compute_running_intervals", []), "accelerator_count")
        count = derived["capacity_upper_bound_flop"]["count"]
        self.assertGreater(running, count)
        self.assertIn(
            "running_accelerator_count_exceeds_capacity_count",
            _capacity_claim_contradictions(derived, probe),
        )
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])
        self.assertFalse(result["stage_outputs"]["A_capacity_gate"]["short_circuited"])

    def test_f5_fabric_node_count_alone_blocks_forge(self) -> None:
        # F5 regression: with every other witness suppressed (including compute_running), the
        # scale-out fabric node/switch counts still exceed the shaded claimed count and block the
        # forge. Each fabric node hosts at least one accelerator, so node_count is a physical
        # floor on the accelerator population.
        probe = self._f3_probe(
            suppress_participant=True,
            suppress_allocated=True,
            suppress_billing=True,
            suppress_running=True,
            suppress_service=True,
            suppress_identity=True,
        )
        result = evaluate_site(probe)
        self.assertIn(
            "fabric_node_count_exceeds_capacity_count",
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])
        self.assertFalse(result["stage_outputs"]["A_capacity_gate"]["short_circuited"])

    # --- FIX 7 (F6): additive witnesses aggregated by concurrent semantics, not _max ---

    def _f6_split_pool_probe(
        self, claimed: float = 100.0, per_record: int = 80, true_pop: int = 3072
    ) -> dict:
        # The F6 forge: shade the accelerator count to a small claim, mask both achieved
        # channels, falsify every _sum / counter / fabric witness to a value consistent
        # with the small claim, and report the genuinely large running pool HONESTLY as
        # many CONCURRENT sub-pool records (identical window), each accelerator_count
        # below the claimed count. Under _max the guard read only the largest sub-record
        # (per_record) and certified a rule-out; the overlap-aware concurrent peak now
        # sums the concurrent sub-pools back to the true population.
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        raw = probe.setdefault("raw_features", {})
        signals = probe.setdefault("normalized_signals", {})
        for record in raw.get("accelerator_count_by_family_sku", []):
            record["count"] = claimed
        signals["achieved_operations"] = 0.0
        raw.pop("generic_achieved_operation_rate", None)
        half = int(claimed) // 2
        for record in raw.get("allocated_accelerator_count_by_sku", []):
            record["count"] = half
        signals["participant_count"] = half
        for record in raw.get("fabric_port_device_sample_counters", []):
            if record.get("counter_name") == "participant_count":
                record["counter_value"] = half
        for record in raw.get("scaleout_fabric_domain_graph", []):
            record["node_count"] = half
            record["switch_count"] = half
        self.suppress_identity_pathways(probe)
        proto = raw["compute_running_intervals"][0]
        records = []
        remaining = true_pop
        while remaining > 0:
            chunk = min(per_record, remaining)
            records.append(dict(proto, accelerator_count=chunk))
            remaining -= chunk
        raw["compute_running_intervals"] = records
        return probe

    def test_f6_concurrent_subpool_split_routes_integrity(self) -> None:
        # Locking test: the split-pool / concurrent-sub-pool forge must route to integrity.
        # Every sub-record is individually below the claimed count (so _max would have read
        # 80 < 100 and stayed silent), but the records are concurrent so the true population
        # is their sum (3072), far above the claim.
        probe = self._f6_split_pool_probe()
        derived = evaluate_site(probe)["derived_signals"]
        records = probe["raw_features"]["compute_running_intervals"]
        count = derived["capacity_upper_bound_flop"]["count"]
        # each sub-record is below the claimed count
        self.assertTrue(all(r["accelerator_count"] < count for r in records))
        # _max would have been silent, the concurrent peak is the true population
        self.assertLessEqual(_max(records, "accelerator_count"), count)
        self.assertGreater(_concurrent_peak(records, "accelerator_count"), count)
        result = evaluate_site(probe)
        self.assertIn(
            "running_accelerator_count_exceeds_capacity_count",
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])
        self.assertFalse(result["stage_outputs"]["A_capacity_gate"]["short_circuited"])

    def test_f6_multidomain_fabric_split_routes_integrity(self) -> None:
        # The multi-domain fabric variant: a genuinely large cluster reported HONESTLY as
        # many concurrent fabric domains, each node_count below the claimed count. Domains
        # are spatial/concurrent, so node_count sums across them (the old _max read one
        # domain and stayed silent).
        probe = deepcopy(self.sites["A_clean_threshold_training"])
        raw = probe["raw_features"]
        signals = probe.setdefault("normalized_signals", {})
        for record in raw.get("accelerator_count_by_family_sku", []):
            record["count"] = 100.0
        signals["achieved_operations"] = 0.0
        raw.pop("generic_achieved_operation_rate", None)
        signals["participant_count"] = 50
        for record in raw.get("fabric_port_device_sample_counters", []):
            if record.get("counter_name") == "participant_count":
                record["counter_value"] = 50
        for record in raw.get("allocated_accelerator_count_by_sku", []):
            record["count"] = 50
        self.suppress_identity_pathways(probe)
        raw.pop("compute_running_intervals", None)
        proto = raw["scaleout_fabric_domain_graph"][0]
        raw["scaleout_fabric_domain_graph"] = [
            dict(proto, node_count=80, switch_count=10, link_count=80) for _ in range(40)
        ]
        result = evaluate_site(probe)
        self.assertIn(
            "fabric_node_count_exceeds_capacity_count",
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])

    def test_f6_sequential_reuse_of_small_pool_still_rules_out(self) -> None:
        # Locking the overlap-aware semantics from the OTHER side: a genuinely small pool
        # reused SEQUENTIALLY (back-to-back, non-overlapping windows) must NOT be summed
        # into a false contradiction. The concurrent peak stays at the small per-window
        # value, so an honest small-scope rule-out is preserved. A plain _sum would have
        # over-counted the sequential reuse and falsely blocked this legitimate rule-out.
        probe = deepcopy(self.sites["C_capacity_ruled_out"])
        raw = probe["raw_features"]
        count = raw["accelerator_count_by_family_sku"][0]["count"]
        small = int(count) // 2 or 1
        windows = [
            ("2026-04-01T00:00:00Z", "2026-04-08T00:00:00Z"),
            ("2026-04-08T00:00:00Z", "2026-04-15T00:00:00Z"),
            ("2026-04-15T00:00:00Z", "2026-04-22T00:00:00Z"),
            ("2026-04-22T00:00:00Z", "2026-04-29T00:00:00Z"),
        ]
        raw["compute_running_intervals"] = [
            {
                "start_time": start,
                "end_time": end,
                "compute_resource_state": "running",
                "accelerator_count": small,
                "accelerator_shape_or_sku": "SYN-ACCEL",
            }
            for start, end in windows
        ]
        records = raw["compute_running_intervals"]
        # the naive sum (4 * small) would exceed the count, but the genuine concurrent peak
        # is just `small` because the windows do not overlap
        self.assertGreater(sum(r["accelerator_count"] for r in records), count)
        self.assertLessEqual(_concurrent_peak(records, "accelerator_count"), count)
        result = evaluate_site(probe)
        self.assertNotIn(
            "running_accelerator_count_exceeds_capacity_count",
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )
        self.assertEqual("capacity_ruled_out_for_scope", result["final_route"])
        self.assertEqual([], result["discrepancy_findings"])

    def test_f4_peak_or_adjust_deflation_with_raw_rate_witness_routes_integrity(self) -> None:
        # F4 variant: deflate the bound through peak_rate / capacity_adjustment_factor (count
        # left honest, so participant/allocated/billing do NOT exceed it) and mask the
        # achieved_operations override down so the F2 ratio guard is below 1.0. The raw
        # generic_achieved_operation_rate witness still integrates above the claimed bound and
        # must block the forge.
        for channel in ("peak", "adjust"):
            with self.subTest(channel=channel):
                probe = deepcopy(self.sites["A_clean_threshold_training"])
                if channel == "peak":
                    for record in probe["raw_features"]["advertised_peak_rate_by_precision"]:
                        record["peak_rate"] *= 0.01
                else:
                    probe["normalized_signals"]["capacity_adjustment_factor"] = 0.01
                # mask the override only; leave the raw operation-rate witness intact
                probe["normalized_signals"]["achieved_operations"] = 1e23
                result = evaluate_site(probe)
                ratio = result["derived_signals"]["achieved_operation_integral"][
                    "operation_count_to_capacity_upper_bound_ratio"
                ]
                self.assertLessEqual(ratio, 1.0)  # the F2 override-ratio guard does NOT fire
                self.assertEqual("integrity_review_required", result["final_route"])
                self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])

    def test_participant_count_exceeding_inventory_routes_integrity(self) -> None:
        # A distributed-training participant set larger than the claimed accelerator inventory is
        # physically incoherent: it must block the rule-out even with achieved-ops fully shaded.
        # Every other device-population witness is suppressed so participant_count is the ONLY
        # surviving witness, proving it alone is load-bearing.
        probe = self._f3_probe(
            achieved=0.0,
            suppress_allocated=True,
            suppress_billing=True,
            suppress_running=True,
            suppress_fabric_graph=True,
            suppress_service=True,
            suppress_identity=True,
            keep_participant_identity=True,
        )
        result = evaluate_site(probe)
        participant = result["derived_signals"]["collective_cadence_score"]["participant_count"]
        count = result["derived_signals"]["capacity_upper_bound_flop"]["count"]
        self.assertGreater(participant, count)
        self.assertEqual(
            ["participant_count_exceeds_capacity_count"],
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])

    def test_raw_participant_count_floor_is_not_masked_by_normalized_zero(self) -> None:
        probe = self._f3_probe(
            count=100.0,
            achieved=0.0,
            suppress_allocated=True,
            suppress_billing=True,
            suppress_running=True,
            suppress_fabric_graph=True,
            suppress_service=True,
            suppress_identity=True,
        )
        probe["normalized_signals"]["participant_count"] = 0.0
        for record in probe["raw_features"].get("fabric_port_device_sample_counters", []):
            if record.get("counter_name") == "participant_count":
                record["counter_value"] = 6144.0
        result = evaluate_site(probe)
        self.assertEqual(
            ["participant_count_exceeds_capacity_count"],
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])

    def test_negative_capacity_count_row_cannot_cancel_positive_inventory(self) -> None:
        probe = self._f3_full_suppression(count=100.0, achieved=0.0)
        proto = probe["raw_features"]["accelerator_count_by_family_sku"][0]
        probe["raw_features"]["accelerator_count_by_family_sku"] = [
            dict(proto, count=8192.0),
            dict(proto, count=-8092.0),
        ]
        result = evaluate_site(probe)
        a = result["stage_outputs"]["A_capacity_gate"]
        self.assertEqual("capacity_unknown_due_to_missing_inputs", a["label"])
        self.assertIn("accelerator_count_by_family_sku", a["missing_inputs"])
        self.assertFalse(a["short_circuited"])
        self.assertNotEqual("capacity_ruled_out_for_scope", result["final_route"])

    def test_allocated_count_exceeding_inventory_routes_integrity(self) -> None:
        # Every other device-population witness suppressed so allocated_count is the only one left.
        probe = self._f3_probe(
            achieved=0.0,
            suppress_participant=True,
            suppress_billing=True,
            suppress_running=True,
            suppress_fabric_graph=True,
            suppress_service=True,
            suppress_identity=True,
        )
        result = evaluate_site(probe)
        self.assertEqual(
            ["allocated_count_exceeds_capacity_count"],
            _capacity_claim_contradictions(result["derived_signals"], probe),
        )
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])

    def test_negative_rows_do_not_cancel_positive_population_floors(self) -> None:
        duration = 30 * 24 * 3600

        def base() -> dict:
            probe = self._f3_full_suppression(count=100.0, achieved=0.0)
            raw = probe["raw_features"]
            for key in ("instance_type_shape_machine_type", "local_accelerator_interconnect_domain"):
                raw.pop(key, None)
            return probe

        cases = []

        allocated = base()
        allocated["raw_features"]["allocated_accelerator_count_by_sku"] = [
            {"accelerator_sku": "SYN", "count": 8192.0},
            {"accelerator_sku": "SYN", "count": -8092.0},
        ]
        cases.append(("allocated", allocated, "allocated_count_exceeds_capacity_count"))

        instance_shape = base()
        instance_shape["raw_features"]["instance_type_shape_machine_type"] = [
            {"machine_type": "synthetic-large", "accelerator_count": 8192.0},
            {"machine_type": "synthetic-large", "accelerator_count": -8092.0},
        ]
        cases.append(("instance_shape", instance_shape, "instance_shape_accelerator_count_exceeds_capacity_count"))

        local_fabric = base()
        local_fabric["raw_features"]["local_accelerator_interconnect_domain"] = [
            {"fabric_domain_id": "domain-a", "local_fabric_device_count": 8192.0},
            {"fabric_domain_id": "domain-b", "local_fabric_device_count": -8092.0},
        ]
        cases.append(("local_fabric", local_fabric, "local_fabric_device_count_exceeds_capacity_count"))

        fabric_graph = base()
        fabric_graph["raw_features"]["scaleout_fabric_domain_graph"] = [
            {"fabric_domain_id": "domain-a", "node_count": 8192.0, "switch_count": 8192.0, "link_count": 0.0},
            {"fabric_domain_id": "domain-b", "node_count": -8092.0, "switch_count": -8092.0, "link_count": 0.0},
        ]
        cases.append(("fabric_graph", fabric_graph, "fabric_node_count_exceeds_capacity_count"))
        cases.append(("fabric_graph", fabric_graph, "fabric_switch_count_exceeds_capacity_count"))

        billing = base()
        billing["raw_features"]["accelerator_compute_billing_usage_intervals"] = [
            {"usage_unit": "accelerator_seconds", "usage_quantity": 8192.0 * duration},
            {"usage_unit": "accelerator_seconds", "usage_quantity": -8092.0 * duration},
        ]
        cases.append(("billing", billing, "billing_device_hours_exceed_capacity_count"))

        for label, probe, expected in cases:
            with self.subTest(label=label, expected=expected):
                result = evaluate_site(probe)
                contradictions = _capacity_claim_contradictions(result["derived_signals"], probe)
                self.assertIn(expected, contradictions)
                self.assertEqual("integrity_review_required", result["final_route"])
                self.assertIn("capacity_claim_conflict", result["discrepancy_findings"])

    def test_offset_timestamps_are_parsed_for_concurrent_interval_floors(self) -> None:
        start = "2026-04-02T00:30:00+14:00"
        end = "2026-04-01T23:30:00-12:00"

        running = self._f3_probe(
            count=100.0,
            achieved=0.0,
            suppress_participant=True,
            suppress_allocated=True,
            suppress_billing=True,
            suppress_fabric_graph=True,
            suppress_service=True,
            suppress_identity=True,
        )
        running["raw_features"]["compute_running_intervals"] = [
            {
                "compute_resource_state": "running",
                "accelerator_shape_or_sku": "SYN-ACCEL",
                "accelerator_count": 80.0,
                "start_time": start,
                "end_time": end,
            }
            for _ in range(700)
        ]
        result = evaluate_site(running)
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn(
            "running_accelerator_count_exceeds_capacity_count",
            _capacity_claim_contradictions(result["derived_signals"], running),
        )

        service = self._ruleout_forge_base(count=100.0, achieved=1e23, suppress_identity=True)
        proto = service["raw_features"]["electrical_service_status_intervals"][0]
        service["raw_features"]["electrical_service_status_intervals"] = [
            dict(
                proto,
                service_status="energized",
                service_class="synthetic_datacenter_service",
                service_capacity_mw=0.072,
                power_mw=0.0,
                mean_power_mw=0.0,
                max_power_mw=0.0,
                start_time=start,
                end_time=end,
            )
            for _ in range(700)
        ]
        result = evaluate_site(service)
        self.assertEqual("integrity_review_required", result["final_route"])
        self.assertIn(
            "electrical_service_power_floor_exceeds_capacity_count",
            _capacity_claim_contradictions(result["derived_signals"], service),
        )

    def test_provider_account_style_honest_ruleout_with_no_scale_signals_still_rules_out(self) -> None:
        # An honest small-scope rule-out (the provider-account analogue) reports NONE of the scale
        # signals the guard checks, so no contradiction is present and the rule-out is preserved.
        site = {
            "site_id": "provider_account_style_honest_slice",
            "scenario_key": "provider_account_style_honest_slice",
            "scenario_name": "Honest small-scope rule-out with no participant/allocated/billing signals",
            "scope": "account_slice/accelerator_pool",
            "audit_window": {"start": "2026-06-04T00:00:00Z", "end": "2026-06-10T00:00:00Z"},
            "raw_features": {
                "accelerator_count_by_family_sku": [{"accelerator_sku": "SYN", "count": 370}],
                "advertised_peak_rate_by_precision": [{"peak_rate": 2.0e15}],
                "accelerator_busy_or_utilization_fraction": [{"value": 0.45}],
            },
            "coverage": {
                "capacity": 0.96,
                "activity": 0.9,
                "achieved_ops": 0.0,
                "fabric": 0.0,
                "storage": 0.0,
                "scope_mapping": 0.99,
                "clock_alignment": 0.93,
            },
            "normalized_signals": {
                "hidden_or_unmonitored_capacity_possible": False,
                "capacity_unit_normalized": True,
                "activity_score": 0.45,
                "achieved_operations": 3.0e23,
                "achieved_operations_unit_normalized": True,
            },
        }
        result = evaluate_site(site)
        cap = result["derived_signals"]["capacity_upper_bound_flop"]["capacity_upper_bound_operations"]
        self.assertLess(cap, 1e25)
        self.assertEqual("capacity_ruled_out_for_scope", result["final_route"])
        self.assertEqual([], result["discrepancy_findings"])


if __name__ == "__main__":
    unittest.main()