vela-protocol 0.123.0

Core library for the Vela scientific knowledge protocol: replayable frontier state, signed canonical events, and proof packets.
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
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
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
//! Cross-implementation reducer fixtures.
//!
//! Doctrine: "two implementations of the reducer must agree on the
//! mutation rules per kind." The cascade test in
//! `cascade_replay_at_scale.rs` already proves Rust agrees with Rust at
//! scale. This test exports the same cascade fixtures to JSON files
//! that a second-implementation reducer (e.g. `clients/python/vela_reducer.py`)
//! can consume and verify byte-equivalently.
//!
//! What gets exported per fixture:
//!   - `genesis_findings`: the initial finding bundles (FindingBundle JSON)
//!   - `event_log`: the canonical event log (StateEvent JSON)
//!   - `expected_states`: the post-replay reducer-effects array, sorted
//!     by finding id, capturing only the fields the reducer mutates
//!     (retracted, contested, review_state, confidence_score, annotation_ids)
//!
//! A second-implementation reducer reads `genesis_findings` + `event_log`,
//! applies its own per-kind mutation rules, builds the same shape from
//! its result, and asserts deep equality with `expected_states`. If two
//! implementations agree on this mutation surface across N fixtures with
//! cascade chains, the doctrine is no longer a single-implementation
//! claim.

use serde_json::{Map, Value, json};
use std::collections::BTreeMap;
use std::path::PathBuf;

use vela_protocol::access_tier::AccessTier;
use vela_protocol::bundle::{
    Artifact, Assertion, Author, Conditions, Confidence, ConfidenceKind, ConfidenceMethod, Entity,
    Evidence, Extraction, FindingBundle, Flags, Link, NegativeResult, NegativeResultKind,
    Provenance, Trajectory, TrajectoryStep, TrajectoryStepKind,
};
use vela_protocol::events::{
    self, FindingEventInput, NULL_HASH, StateActor, StateEvent, StateTarget,
};
use vela_protocol::reducer::replay_from_genesis;

const FIXTURE_FRONTIER_COUNT: usize = 3;
const FINDINGS_PER_FRONTIER: usize = 8;
const CASCADE_DEPTH: usize = 5;

fn fixture_timestamp(frontier_idx: usize, event_idx: usize) -> String {
    format!(
        "2026-05-02T{:02}:{:02}:{:02}Z",
        frontier_idx % 24,
        (event_idx / 60) % 60,
        event_idx % 60
    )
}

fn fixture_object_timestamp(frontier_idx: usize, object_idx: usize) -> String {
    format!(
        "2026-05-02T{:02}:30:{:02}Z",
        frontier_idx % 24,
        object_idx % 60
    )
}

fn pin_negative_result(
    mut nr: NegativeResult,
    frontier_idx: usize,
    object_idx: usize,
) -> NegativeResult {
    nr.created = fixture_object_timestamp(frontier_idx, object_idx);
    nr.id =
        NegativeResult::content_address(&nr.kind, &nr.deposited_by, &nr.created, &nr.conditions);
    nr
}

fn pin_trajectory(mut traj: Trajectory, frontier_idx: usize, object_idx: usize) -> Trajectory {
    traj.created = fixture_object_timestamp(frontier_idx, object_idx);
    traj.id = Trajectory::content_address(&traj.target_findings, &traj.deposited_by, &traj.created);
    traj
}

fn pin_artifact(mut artifact: Artifact, frontier_idx: usize, object_idx: usize) -> Artifact {
    artifact.created = fixture_object_timestamp(frontier_idx, object_idx);
    artifact
}

fn replace_event_id_strings(value: &mut Value, id_map: &BTreeMap<String, String>) {
    match value {
        Value::String(s) => {
            if let Some(replacement) = id_map.get(s) {
                *s = replacement.clone();
            }
        }
        Value::Array(items) => {
            for item in items {
                replace_event_id_strings(item, id_map);
            }
        }
        Value::Object(map) => {
            for item in map.values_mut() {
                replace_event_id_strings(item, id_map);
            }
        }
        _ => {}
    }
}

fn normalize_event_log(
    frontier_idx: usize,
    event_log: Vec<events::StateEvent>,
) -> Vec<events::StateEvent> {
    let mut id_map = BTreeMap::new();
    let mut normalized = Vec::with_capacity(event_log.len());

    for (event_idx, mut event) in event_log.into_iter().enumerate() {
        let old_id = event.id.clone();
        event.timestamp = fixture_timestamp(frontier_idx, event_idx);
        replace_event_id_strings(&mut event.payload, &id_map);
        event.id = events::compute_event_id(&event);

        if !old_id.is_empty() {
            id_map.insert(old_id, event.id.clone());
        }

        normalized.push(event);
    }

    normalized
}

fn make_finding(frontier_idx: usize, finding_idx: usize) -> FindingBundle {
    let assertion = Assertion {
        text: format!(
            "Cross-impl finding {finding_idx} in frontier {frontier_idx}: protein-X activates pathway-Y."
        ),
        assertion_type: "mechanism".into(),
        entities: vec![Entity {
            name: format!("ProteinX{finding_idx}"),
            entity_type: "protein".into(),
            identifiers: Map::new(),
            canonical_id: None,
            candidates: vec![],
            aliases: vec![],
            resolution_provenance: None,
            resolution_confidence: 1.0,
            resolution_method: None,
            species_context: None,
            needs_review: false,
        }],
        relation: Some("activates".into()),
        direction: Some("positive".into()),
        causal_claim: None,
        causal_evidence_grade: None,
    };
    let evidence = Evidence {
        evidence_type: "experimental".into(),
        model_system: "mouse".into(),
        species: Some("Mus musculus".into()),
        method: "Western blot".into(),
        sample_size: Some("n=30".into()),
        effect_size: None,
        p_value: Some("p<0.05".into()),
        replicated: true,
        replication_count: Some(3),
        evidence_spans: vec![],
    };
    let conditions = Conditions {
        text: "In vitro, mouse microglia".into(),
        species_verified: vec!["Mus musculus".into()],
        species_unverified: vec![],
        in_vitro: true,
        in_vivo: false,
        human_data: false,
        clinical_trial: false,
        concentration_range: None,
        duration: None,
        age_group: None,
        cell_type: Some("microglia".into()),
    };
    let confidence = Confidence {
        kind: ConfidenceKind::FrontierEpistemic,
        score: 0.7,
        basis: "Cross-impl test fixture".into(),
        method: ConfidenceMethod::LlmInitial,
        components: None,
        extraction_confidence: 0.9,
    };
    let provenance = Provenance {
        source_type: "published_paper".into(),
        doi: Some(format!(
            "10.0000/crossimpl.frontier{frontier_idx:04}.finding{finding_idx:04}"
        )),
        pmid: None,
        pmc: None,
        openalex_id: None,
        url: None,
        title: format!("Cross-impl paper {frontier_idx}-{finding_idx}"),
        authors: vec![Author {
            name: "Cross-Impl A".into(),
            orcid: None,
        }],
        year: Some(2026),
        journal: Some("Cross Journal".into()),
        license: None,
        publisher: None,
        funders: vec![],
        extraction: Extraction::default(),
        review: None,
        citation_count: Some(0),
    };
    let flags = Flags {
        gap: false,
        negative_space: false,
        contested: false,
        retracted: false,
        declining: false,
        gravity_well: false,
        review_state: None,
        superseded: false,
        signature_threshold: None,
        jointly_accepted: false,
    };
    let mut bundle = FindingBundle::new(
        assertion, evidence, conditions, confidence, provenance, flags,
    );
    bundle.created = fixture_object_timestamp(frontier_idx, finding_idx);
    if finding_idx + 1 < FINDINGS_PER_FRONTIER {
        let next_id = synthetic_id(frontier_idx, finding_idx + 1);
        bundle.links = vec![Link {
            target: next_id,
            link_type: "supports".into(),
            note: "synthetic dependency".into(),
            inferred_by: "vela-cross-impl-fixture/0".into(),
            created_at: "2026-05-02T00:00:00Z".into(),
            mechanism: None,
        }];
    }
    bundle
}

fn synthetic_id(frontier_idx: usize, finding_idx: usize) -> String {
    let assertion = Assertion {
        text: format!(
            "Cross-impl finding {finding_idx} in frontier {frontier_idx}: protein-X activates pathway-Y."
        ),
        assertion_type: "mechanism".into(),
        entities: vec![],
        relation: None,
        direction: None,
        causal_claim: None,
        causal_evidence_grade: None,
    };
    let provenance = Provenance {
        source_type: "published_paper".into(),
        doi: Some(format!(
            "10.0000/crossimpl.frontier{frontier_idx:04}.finding{finding_idx:04}"
        )),
        pmid: None,
        pmc: None,
        openalex_id: None,
        url: None,
        title: format!("Cross-impl paper {frontier_idx}-{finding_idx}"),
        authors: vec![],
        year: None,
        journal: None,
        license: None,
        publisher: None,
        funders: vec![],
        extraction: Extraction::default(),
        review: None,
        citation_count: None,
    };
    FindingBundle::content_address(&assertion, &provenance)
}

fn build_event_log(frontier_idx: usize, findings: &[FindingBundle]) -> Vec<events::StateEvent> {
    let mut log = Vec::new();
    let actor_id = format!("reviewer:cross-impl-{frontier_idx}");
    for f in findings {
        let proposal_id = format!("vpr_{}_{}", frontier_idx, &f.id[3..]);
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.asserted",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "cross-impl genesis assertion",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id}),
            caveats: vec![],
        }));
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.reviewed",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "cross-impl review",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id, "status": "accepted"}),
            caveats: vec![],
        }));
    }
    let root = &findings[0];
    let root_proposal = format!("vpr_{}_{}", frontier_idx, &root.id[3..]);
    let retract = events::new_finding_event(FindingEventInput {
        kind: "finding.retracted",
        finding_id: &root.id,
        actor_id: &actor_id,
        actor_type: "human",
        reason: "cross-impl retraction triggers cascade",
        before_hash: NULL_HASH,
        after_hash: NULL_HASH,
        payload: json!({
            "proposal_id": root_proposal,
            "affected": CASCADE_DEPTH,
        }),
        caveats: vec![],
    });
    let retract_event_id = retract.id.clone();
    let root_id = root.id.clone();
    log.push(retract);

    for depth in 1..=CASCADE_DEPTH {
        if depth >= findings.len() {
            break;
        }
        let dep = &findings[depth];
        let dep_proposal = format!("vpr_{}_{}", frontier_idx, &dep.id[3..]);
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.dependency_invalidated",
            finding_id: &dep.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "cross-impl cascade",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({
                "proposal_id": dep_proposal,
                "upstream_finding_id": root_id,
                "upstream_event_id": retract_event_id,
                "depth": depth as u64,
            }),
            caveats: vec![],
        }));
    }
    log
}

/// v0.49.3 — Coverage fixture: exercises every dispatch arm in the
/// reducer that the cascade fixtures don't already touch. Each
/// finding gets:
///   - finding.asserted (genesis)
///   - finding.reviewed (rotated through accepted/contested/needs_revision/rejected)
///   - finding.confidence_revised (alternating int and float new_score
///     values to lock the basis-string formatting and the 6-decimal
///     score boundary across implementations)
///
/// This is the fixture the engineer + integrator both flagged as
/// missing. After this, every per-kind branch in
/// reducer.rs::apply_event has at least one cross-impl reproducer.
fn build_review_branches_log(
    frontier_idx: usize,
    findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    let mut log = Vec::new();
    let actor_id = format!("reviewer:review-branches-{frontier_idx}");
    let statuses = ["accepted", "contested", "needs_revision", "rejected"];
    for (i, f) in findings.iter().enumerate() {
        let proposal_id = format!("vpr_{}_{}", frontier_idx, &f.id[3..]);
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.asserted",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "review-branch genesis",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id}),
            caveats: vec![],
        }));
        // Rotate through every status so all four arms in
        // apply_finding_reviewed land at least once.
        let status = statuses[i % statuses.len()];
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.reviewed",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "review-branch coverage",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id, "status": status}),
            caveats: vec![],
        }));
        // Alternate integer vs fractional new_score to stress the
        // basis-string formatting (Rust {:.3}, Python :.3f, JS
        // .toFixed(3)) and the digest 6-decimal boundary.
        let (prev, new) = if i % 2 == 0 {
            (0.7, 1.0)
        } else {
            (0.7, 0.42_f64)
        };
        let revise_reason = format!("revise to {new:.3}");
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.confidence_revised",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: &revise_reason,
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({
                "proposal_id": proposal_id,
                "previous_score": prev,
                "new_score": new,
            }),
            caveats: vec![],
        }));
    }
    log
}

/// v0.49.3 — Annotations fixture: exercises both annotation kinds
/// (finding.noted and finding.caveated) plus finding.rejected, the
/// last reducer arms not covered by cascade or review-branches.
fn build_annotations_log(
    frontier_idx: usize,
    findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    let mut log = Vec::new();
    let actor_id = format!("reviewer:annotations-{frontier_idx}");
    for (i, f) in findings.iter().enumerate() {
        let proposal_id = format!("vpr_{}_{}", frontier_idx, &f.id[3..]);
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.asserted",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "annotations-fixture genesis",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id}),
            caveats: vec![],
        }));
        // First half get a noted; second half a caveated. Both go
        // through apply_finding_annotation but are dispatched on
        // distinct kinds, so a future reducer that forgets the
        // caveated → annotation route will fail one half.
        let kind = if i < findings.len() / 2 {
            "finding.noted"
        } else {
            "finding.caveated"
        };
        let annotation_id = format!("ann_{}_{}", frontier_idx, i);
        log.push(events::new_finding_event(FindingEventInput {
            kind,
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "annotation coverage",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({
                "proposal_id": proposal_id,
                "annotation_id": annotation_id,
                "text": format!("note {i} on finding {}", &f.id[..8]),
                // Provenance with a doi satisfies the validator's
                // "at least one of doi/pmid/title" rule.
                "provenance": {
                    "doi": format!("10.0000/annot.{frontier_idx}.{i}"),
                },
            }),
            caveats: vec![],
        }));
    }
    // Reject the last finding — the only event kind that's not
    // exercised by cascade, review-branches, or annotations.
    if let Some(last) = findings.last() {
        let proposal_id = format!("vpr_{}_{}", frontier_idx, &last.id[3..]);
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.rejected",
            finding_id: &last.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "rejection coverage",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id}),
            caveats: vec![],
        }));
    }
    log
}

/// v0.49 — Coverage fixture: exercises every NegativeResult lifecycle
/// arm. Each frontier deposits two NegativeResults (one
/// `registered_trial`, one `exploratory`), reviews one as contested,
/// and retracts the other.
///
/// Cross-impl note: the post-replay digest in `finding_state` covers
/// finding-state only. A second-implementation reducer that ignores
/// `negative_result.*` events will pass this fixture's expected_states
/// because no field in `Finding[]` mutates. v0.50 introduces a
/// negative-result digest that closes that gap; for v0.49 the fixture's
/// job is registering the kinds for coverage, not enforcing cross-impl
/// agreement on the new state collection.
fn build_negative_results_log(
    frontier_idx: usize,
    findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    let mut log = Vec::new();
    let actor_id = format!("reviewer:negative-results-{frontier_idx}");
    // Genesis: all findings asserted so the surface is comparable to
    // the other fixtures.
    for f in findings {
        let proposal_id = format!("vpr_{}_{}", frontier_idx, &f.id[3..]);
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.asserted",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "negative-results-fixture genesis",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id}),
            caveats: vec![],
        }));
    }
    // First null: registered trial against findings[0] — adequately
    // powered, CI excludes the pre-registered MCID. The "informative
    // null" canonical shape.
    let trial_conditions = Conditions {
        text: format!("Phase III RCT, frontier {frontier_idx}"),
        species_verified: vec!["Homo sapiens".into()],
        species_unverified: vec![],
        in_vitro: false,
        in_vivo: true,
        human_data: true,
        clinical_trial: true,
        concentration_range: None,
        duration: Some("18 months".into()),
        age_group: Some("65+".into()),
        cell_type: None,
    };
    let trial_provenance = Provenance {
        source_type: "clinical_trial".into(),
        doi: None,
        pmid: None,
        pmc: None,
        openalex_id: None,
        url: None,
        title: format!("Trial readout, frontier {frontier_idx}"),
        authors: vec![],
        year: Some(2026),
        journal: None,
        license: None,
        publisher: None,
        funders: vec![],
        extraction: Extraction::default(),
        review: None,
        citation_count: Some(0),
    };
    let trial_kind = NegativeResultKind::RegisteredTrial {
        endpoint: format!("Primary endpoint frontier {frontier_idx}"),
        intervention: "intervention-arm".into(),
        comparator: "placebo".into(),
        population: "early symptomatic, biomarker-positive".into(),
        n_enrolled: 1200,
        power: 0.9,
        effect_size_ci: (-0.05, 0.05),
        effect_size_threshold: Some(0.4),
        registry_id: Some(format!("NCT{frontier_idx:08}")),
    };
    let trial_null = pin_negative_result(
        NegativeResult::new(
            trial_kind,
            vec![findings[0].id.clone()],
            format!("trial-pi:cross-impl-{frontier_idx}"),
            trial_conditions,
            trial_provenance,
            "Pre-registered primary endpoint did not meet MCID; CI excludes it.",
        ),
        frontier_idx,
        100,
    );
    let trial_id = trial_null.id.clone();
    let trial_proposal = format!("vpr_nr_{frontier_idx}_trial");
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "negative_result.asserted".to_string(),
        target: StateTarget {
            r#type: "negative_result".to_string(),
            id: trial_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "deposit informative null from pre-registered trial".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": trial_proposal,
            "negative_result": trial_null,
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    // Second null: exploratory wet-lab dead end. No statistical bound;
    // captures the reagent + observation tuple.
    let lab_conditions = Conditions {
        text: format!("In vitro, frontier {frontier_idx} synthesis attempts"),
        species_verified: vec![],
        species_unverified: vec![],
        in_vitro: true,
        in_vivo: false,
        human_data: false,
        clinical_trial: false,
        concentration_range: Some("1-10 mM".into()),
        duration: Some("72h".into()),
        age_group: None,
        cell_type: None,
    };
    let lab_provenance = Provenance {
        source_type: "lab_notebook".into(),
        doi: None,
        pmid: None,
        pmc: None,
        openalex_id: None,
        url: None,
        title: format!("Lab notebook excerpt, frontier {frontier_idx}"),
        authors: vec![],
        year: Some(2026),
        journal: None,
        license: None,
        publisher: None,
        funders: vec![],
        extraction: Extraction::default(),
        review: None,
        citation_count: Some(0),
    };
    let lab_kind = NegativeResultKind::Exploratory {
        reagent: format!("CompoundX-{frontier_idx}"),
        observation: "no measurable binding under any tested condition".into(),
        attempts: 4,
    };
    let lab_null = pin_negative_result(
        NegativeResult::new(
            lab_kind,
            vec![],
            format!("lab:cross-impl-{frontier_idx}"),
            lab_conditions,
            lab_provenance,
            "Exhausted reasonable parameter sweep; documenting before scope expansion.",
        ),
        frontier_idx,
        101,
    );
    let lab_id = lab_null.id.clone();
    let lab_proposal = format!("vpr_nr_{frontier_idx}_lab");
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "negative_result.asserted".to_string(),
        target: StateTarget {
            r#type: "negative_result".to_string(),
            id: lab_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "deposit exploratory wet-lab dead end".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": lab_proposal,
            "negative_result": lab_null,
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    // Review the trial null as contested (a second reviewer thinks the
    // CI is consistent with a smaller subgroup effect).
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "negative_result.reviewed".to_string(),
        target: StateTarget {
            r#type: "negative_result".to_string(),
            id: trial_id.clone(),
        },
        actor: StateActor {
            id: format!("reviewer:second-reader-{frontier_idx}"),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "subgroup analysis suggests effect concentrated in APOE4-positive".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_nr_{frontier_idx}_trial_review"),
            "status": "contested",
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    // Retract the lab null (the reagent batch turned out to have been
    // miscatalogued; the failure was not what was claimed).
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "negative_result.retracted".to_string(),
        target: StateTarget {
            r#type: "negative_result".to_string(),
            id: lab_id,
        },
        actor: StateActor {
            id: actor_id,
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "reagent batch miscatalogued; retract and re-deposit pending".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_nr_{frontier_idx}_lab_retract"),
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    log
}

/// v0.50 — Coverage fixture: exercises every Trajectory lifecycle
/// arm. Each frontier opens one trajectory targeting findings[0],
/// appends three steps (hypothesis → tried → ruled_out), reviews the
/// trajectory as needs_revision, and retracts a second trajectory
/// opened for findings[1] without steps.
///
/// Cross-impl note: same finding-state-only digest situation as the
/// negative_result fixture. v0.50 follow-up tightens the digest.
fn build_trajectories_log(
    frontier_idx: usize,
    findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    let mut log = Vec::new();
    let actor_id = format!("reviewer:trajectories-{frontier_idx}");
    for f in findings {
        let proposal_id = format!("vpr_{}_{}", frontier_idx, &f.id[3..]);
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.asserted",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "trajectories-fixture genesis",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id}),
            caveats: vec![],
        }));
    }

    // Trajectory 1: opens against findings[0], gets three steps,
    // is then reviewed as needs_revision.
    let traj1 = pin_trajectory(
        Trajectory::new(
            vec![findings[0].id.clone()],
            format!("agent:scout-{frontier_idx}"),
            format!(
                "Search path that arrived at finding {}",
                &findings[0].id[..8]
            ),
        ),
        frontier_idx,
        200,
    );
    let traj1_id = traj1.id.clone();
    let traj1_value = serde_json::to_value(&traj1).expect("serialize trajectory");
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "trajectory.created".to_string(),
        target: StateTarget {
            r#type: "trajectory".to_string(),
            id: traj1_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "open trajectory for cross-impl fixture".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_traj_{frontier_idx}_open"),
            "trajectory": traj1_value,
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    let step_kinds = [
        (
            TrajectoryStepKind::Hypothesis,
            "Considered: protein-X is the key regulator.",
        ),
        (
            TrajectoryStepKind::Tried,
            "Ran knockout in mouse model; observed partial phenotype.",
        ),
        (
            TrajectoryStepKind::RuledOut,
            "Ruled out: knockout phenotype attributable to compensating paralog, not protein-X.",
        ),
    ];
    for (i, (kind, desc)) in step_kinds.iter().enumerate() {
        let step = TrajectoryStep::new(
            &traj1_id,
            kind.clone(),
            desc.to_string(),
            format!("agent:scout-{frontier_idx}"),
            Some(format!("2026-05-04T0{i}:00:00Z")),
            vec![],
        );
        let step_value = serde_json::to_value(&step).expect("serialize step");
        log.push(StateEvent {
            schema: events::EVENT_SCHEMA.to_string(),
            id: String::new(),
            kind: "trajectory.step_appended".to_string(),
            target: StateTarget {
                r#type: "trajectory".to_string(),
                id: traj1_id.clone(),
            },
            actor: StateActor {
                id: format!("agent:scout-{frontier_idx}"),
                r#type: "agent".to_string(),
            },
            timestamp: chrono::Utc::now().to_rfc3339(),
            reason: format!("append step {i}"),
            before_hash: NULL_HASH.to_string(),
            after_hash: NULL_HASH.to_string(),
            payload: json!({
                "proposal_id": format!("vpr_step_{frontier_idx}_{i}"),
                "parent_trajectory_id": traj1_id,
                "step": step_value,
            }),
            caveats: vec![],
            signature: None,
            schema_artifact_id: None,
        });
    }

    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "trajectory.reviewed".to_string(),
        target: StateTarget {
            r#type: "trajectory".to_string(),
            id: traj1_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "step 3 needs more support before this is canonical".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_traj_{frontier_idx}_review"),
            "status": "needs_revision",
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    // Trajectory 2: opened, then immediately retracted (the search
    // turned out to be misframed; keep it in replay history).
    let traj2 = pin_trajectory(
        Trajectory::new(
            vec![findings[1].id.clone()],
            format!("agent:scout-{frontier_idx}"),
            format!("Misframed search against finding {}", &findings[1].id[..8]),
        ),
        frontier_idx,
        201,
    );
    let traj2_id = traj2.id.clone();
    let traj2_value = serde_json::to_value(&traj2).expect("serialize trajectory");
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "trajectory.created".to_string(),
        target: StateTarget {
            r#type: "trajectory".to_string(),
            id: traj2_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "open trajectory before noticing reframe".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_traj_{frontier_idx}_open2"),
            "trajectory": traj2_value,
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "trajectory.retracted".to_string(),
        target: StateTarget {
            r#type: "trajectory".to_string(),
            id: traj2_id,
        },
        actor: StateActor {
            id: actor_id,
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "premise of the search was wrong; reframing".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_traj_{frontier_idx}_retract"),
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    log
}

/// Coverage fixture: exercises every generic Artifact lifecycle arm.
/// Deposits two content-addressed records, reviews one as accepted,
/// reclassifies it as restricted, and retracts the other.
fn build_artifacts_log(frontier_idx: usize, findings: &[FindingBundle]) -> Vec<events::StateEvent> {
    let mut log = Vec::new();
    let actor_id = format!("reviewer:artifacts-{frontier_idx}");

    for f in findings {
        let proposal_id = format!("vpr_{}_{}", frontier_idx, &f.id[3..]);
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.asserted",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "artifact-fixture genesis",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id}),
            caveats: vec![],
        }));
    }

    let provenance = |title: String| Provenance {
        source_type: "clinical_trial".into(),
        doi: None,
        pmid: None,
        pmc: None,
        openalex_id: None,
        url: Some(format!("https://example.org/frontier-{frontier_idx}/trial")),
        title,
        authors: vec![],
        year: Some(2026),
        journal: None,
        license: Some("CC0-1.0".into()),
        publisher: None,
        funders: vec![],
        extraction: Extraction::default(),
        review: None,
        citation_count: Some(0),
    };

    let mut metadata = BTreeMap::new();
    metadata.insert("nct_id".to_string(), json!(format!("NCT{frontier_idx:08}")));
    metadata.insert("overall_status".to_string(), json!("COMPLETED"));

    let trial = pin_artifact(
        Artifact::new(
            "clinical_trial_record",
            format!("Cross-impl trial record {frontier_idx}"),
            "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            Some(2048),
            Some("application/json".into()),
            "remote",
            Some(format!(
                "https://clinicaltrials.gov/api/v2/studies/NCT{frontier_idx:08}"
            )),
            Some(format!(
                "https://clinicaltrials.gov/study/NCT{frontier_idx:08}"
            )),
            Some("Public domain".into()),
            vec![findings[0].id.clone()],
            provenance(format!("Cross-impl trial source {frontier_idx}")),
            metadata,
            AccessTier::Public,
        )
        .expect("valid trial artifact"),
        frontier_idx,
        300,
    );
    let trial_id = trial.id.clone();
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "artifact.asserted".to_string(),
        target: StateTarget {
            r#type: "artifact".to_string(),
            id: trial_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "deposit trial registry artifact for cross-impl fixture".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_artifact_{frontier_idx}_trial"),
            "artifact": trial,
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "artifact.reviewed".to_string(),
        target: StateTarget {
            r#type: "artifact".to_string(),
            id: trial_id.clone(),
        },
        actor: StateActor {
            id: format!("reviewer:artifact-second-reader-{frontier_idx}"),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "trial registry artifact verified against source locator".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_artifact_{frontier_idx}_trial_review"),
            "status": "accepted",
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "tier.set".to_string(),
        target: StateTarget {
            r#type: "artifact".to_string(),
            id: trial_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "artifact includes review notes under restricted read tier".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_artifact_{frontier_idx}_trial_tier"),
            "object_type": "artifact",
            "object_id": trial_id,
            "new_tier": "restricted",
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    let lab_file = pin_artifact(
        Artifact::new(
            "lab_file",
            format!("Cross-impl lab file {frontier_idx}"),
            "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
            Some(512),
            Some("text/plain".into()),
            "pointer",
            Some(format!("lab://frontier-{frontier_idx}/notebook-17")),
            None,
            Some("internal lab note".into()),
            vec![],
            provenance(format!("Cross-impl lab source {frontier_idx}")),
            BTreeMap::new(),
            AccessTier::Public,
        )
        .expect("valid lab artifact"),
        frontier_idx,
        301,
    );
    let lab_id = lab_file.id.clone();
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "artifact.asserted".to_string(),
        target: StateTarget {
            r#type: "artifact".to_string(),
            id: lab_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "deposit lab file pointer for cross-impl fixture".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_artifact_{frontier_idx}_lab"),
            "artifact": lab_file,
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "artifact.retracted".to_string(),
        target: StateTarget {
            r#type: "artifact".to_string(),
            id: lab_id,
        },
        actor: StateActor {
            id: actor_id,
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "lab file pointer was superseded by a verified blob".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_artifact_{frontier_idx}_lab_retract"),
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    log
}

/// v0.51 — Coverage fixture: exercises the `tier.set` reducer arm
/// across all three tierable kernel object types (finding,
/// negative_result, trajectory). Asserts findings, opens a
/// negative_result + trajectory targeting findings[0], then issues
/// `tier.set` events to reclassify each at restricted/classified
/// tiers. Cross-impl note: the post-replay digest in `finding_state`
/// covers finding-state only — this fixture exists for kind-coverage
/// of the `tier.set` arm; v0.51.x can extend the digest to include
/// the access_tier field on each kernel object.
fn build_tier_set_log(frontier_idx: usize, findings: &[FindingBundle]) -> Vec<events::StateEvent> {
    let mut log = Vec::new();
    let actor_id = format!("reviewer:tier-{frontier_idx}");

    for f in findings {
        let proposal_id = format!("vpr_{}_{}", frontier_idx, &f.id[3..]);
        log.push(events::new_finding_event(FindingEventInput {
            kind: "finding.asserted",
            finding_id: &f.id,
            actor_id: &actor_id,
            actor_type: "human",
            reason: "tier-set fixture genesis",
            before_hash: NULL_HASH,
            after_hash: NULL_HASH,
            payload: json!({"proposal_id": proposal_id}),
            caveats: vec![],
        }));
    }

    // Open one NegativeResult against findings[0] so we have one of
    // each tierable kind to reclassify.
    let nr_kind = NegativeResultKind::Exploratory {
        reagent: format!("ReagentX-{frontier_idx}"),
        observation: "no detectable activity at any tested concentration".into(),
        attempts: 2,
    };
    let nr_conditions = Conditions {
        text: "in vitro fixture".into(),
        species_verified: vec![],
        species_unverified: vec![],
        in_vitro: true,
        in_vivo: false,
        human_data: false,
        clinical_trial: false,
        concentration_range: None,
        duration: None,
        age_group: None,
        cell_type: None,
    };
    let nr_provenance = Provenance {
        source_type: "lab_notebook".into(),
        doi: None,
        pmid: None,
        pmc: None,
        openalex_id: None,
        url: None,
        title: format!("Tier fixture lab note {frontier_idx}"),
        authors: vec![],
        year: Some(2026),
        journal: None,
        license: None,
        publisher: None,
        funders: vec![],
        extraction: Extraction::default(),
        review: None,
        citation_count: Some(0),
    };
    let nr = pin_negative_result(
        NegativeResult::new(
            nr_kind,
            vec![findings[0].id.clone()],
            format!("lab:tier-fixture-{frontier_idx}"),
            nr_conditions,
            nr_provenance,
            "Fixture exploratory null for tier.set coverage.",
        ),
        frontier_idx,
        300,
    );
    let nr_id = nr.id.clone();
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "negative_result.asserted".to_string(),
        target: StateTarget {
            r#type: "negative_result".to_string(),
            id: nr_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "deposit null for tier-set fixture".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_tier_{frontier_idx}_nr"),
            "negative_result": nr,
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    // Open a Trajectory against findings[0].
    let traj = pin_trajectory(
        Trajectory::new(
            vec![findings[0].id.clone()],
            format!("agent:tier-fixture-{frontier_idx}"),
            "Fixture trajectory for tier.set coverage.",
        ),
        frontier_idx,
        301,
    );
    let traj_id = traj.id.clone();
    log.push(StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "trajectory.created".to_string(),
        target: StateTarget {
            r#type: "trajectory".to_string(),
            id: traj_id.clone(),
        },
        actor: StateActor {
            id: actor_id.clone(),
            r#type: "human".to_string(),
        },
        timestamp: chrono::Utc::now().to_rfc3339(),
        reason: "open trajectory for tier-set fixture".into(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_tier_{frontier_idx}_traj"),
            "trajectory": traj,
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    });

    // Reclassify findings[0] to restricted, the negative_result to
    // restricted, and the trajectory to classified.
    let reclassifications = [
        (
            "finding",
            findings[0].id.clone(),
            "restricted",
            "Finding reclassified for IBC review.",
        ),
        (
            "negative_result",
            nr_id,
            "restricted",
            "Null reclassified — readout includes capability-relevant detail.",
        ),
        (
            "trajectory",
            traj_id,
            "classified",
            "Trajectory reclassified — search path documents synthesis steps above DURC threshold.",
        ),
    ];
    for (i, (object_type, object_id, new_tier, reason)) in reclassifications.iter().enumerate() {
        log.push(StateEvent {
            schema: events::EVENT_SCHEMA.to_string(),
            id: String::new(),
            kind: "tier.set".to_string(),
            target: StateTarget {
                r#type: object_type.to_string(),
                id: object_id.clone(),
            },
            actor: StateActor {
                id: format!("reviewer:ibc-{frontier_idx}"),
                r#type: "human".to_string(),
            },
            timestamp: chrono::Utc::now().to_rfc3339(),
            reason: reason.to_string(),
            before_hash: NULL_HASH.to_string(),
            after_hash: NULL_HASH.to_string(),
            payload: json!({
                "proposal_id": format!("vpr_tier_set_{frontier_idx}_{i}"),
                "object_type": object_type,
                "object_id": object_id,
                "previous_tier": "public",
                "new_tier": new_tier,
            }),
            caveats: vec![],
            signature: None,
            schema_artifact_id: None,
        });
    }

    log
}

/// v0.56: Coverage fixture for the `evidence_atom.locator_repaired`
/// reducer arm. Builds a single hand-crafted event that targets a
/// stable atom id with a mechanically derivable locator. The arm
/// mutates `state.evidence_atoms[i].locator` only and leaves
/// `state.findings` untouched, so the cross-impl post-replay digest
/// (which covers `findings[]` only) treats it as a no-op. The TS or
/// Python reducer is expected to either implement the same arm or
/// silently ignore the event without dropping subsequent finding
/// events.
fn build_locator_repair_log(
    frontier_idx: usize,
    _findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    vec![StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "evidence_atom.locator_repaired".to_string(),
        target: StateTarget {
            r#type: "evidence_atom".to_string(),
            id: format!("vea_fixture_locator_{frontier_idx}"),
        },
        actor: StateActor {
            id: format!("agent:vela-curation-bot-{frontier_idx}"),
            r#type: "agent".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 0),
        reason: "Mechanical repair from parent source".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_locator_repair_{frontier_idx}"),
            "source_id": format!("vs_fixture_source_{frontier_idx}"),
            "locator": format!("doi:10.1/fixture-locator-{frontier_idx}"),
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    }]
}

/// v0.57: Coverage fixture for the `finding.span_repaired` reducer
/// arm. Builds a single hand-crafted event that targets a finding by
/// id with `{section, text}` payload. The arm appends to
/// `state.findings[i].evidence.evidence_spans` and is idempotent
/// under identical re-application.
fn build_span_repair_log(
    frontier_idx: usize,
    findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    let target_finding = &findings[0];
    vec![StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "finding.span_repaired".to_string(),
        target: StateTarget {
            r#type: "finding".to_string(),
            id: target_finding.id.clone(),
        },
        actor: StateActor {
            id: format!("reviewer:span-repair-fixture-{frontier_idx}"),
            r#type: "human".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 0),
        reason: "Mechanical evidence-span repair".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_span_repair_{frontier_idx}"),
            "section": "abstract",
            "text": format!("Fixture span body for span-repair coverage {frontier_idx}."),
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    }]
}

/// v0.57: Coverage fixture for the `finding.entity_resolved` reducer
/// arm. Builds an event targeting an entity by name on the first
/// fixture finding.
fn build_entity_resolve_log(
    frontier_idx: usize,
    findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    let target_finding = &findings[0];
    // make_finding seeds at least one entity; pick the first by name.
    let entity_name = target_finding
        .assertion
        .entities
        .first()
        .map(|e| e.name.clone())
        .unwrap_or_else(|| format!("fixture-entity-{frontier_idx}"));
    vec![StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "finding.entity_resolved".to_string(),
        target: StateTarget {
            r#type: "finding".to_string(),
            id: target_finding.id.clone(),
        },
        actor: StateActor {
            id: format!("reviewer:entity-resolve-fixture-{frontier_idx}"),
            r#type: "human".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 0),
        reason: "Mechanical entity resolution".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_entity_resolve_{frontier_idx}"),
            "entity_name": entity_name,
            "source": "fixture",
            "id": format!("F-{frontier_idx}"),
            "confidence": 0.95,
            "resolution_method": "manual",
            "resolution_provenance": "delegated_human_curation",
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    }]
}

/// v0.79: build a `finding.entity_added` log. Adds a new entity
/// tag to a finding that the make_finding seed didn't include,
/// proving the v0.79.1 reducer arm is exercised in cross-impl
/// fixtures. Idempotent: re-applying with the same name is a
/// no-op so the cross-impl byte-equivalence promise holds.
fn build_entity_added_log(
    frontier_idx: usize,
    findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    let target_finding = &findings[0];
    vec![StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "finding.entity_added".to_string(),
        target: StateTarget {
            r#type: "finding".to_string(),
            id: target_finding.id.clone(),
        },
        actor: StateActor {
            id: format!("reviewer:entity-add-fixture-{frontier_idx}"),
            r#type: "human".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 0),
        reason: "Fixture-level entity-add".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_entity_add_{frontier_idx}"),
            "entity_name": format!("fixture-tag-{frontier_idx}"),
            "entity_type": "other",
            "reason": "cross-impl fixture",
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    }]
}

/// v0.64: federation event fixture builder. Exercises the no-op
/// contract for `frontier.synced_with_peer`,
/// `frontier.conflict_detected`, and `frontier.conflict_resolved`
/// at the cross-impl fixture level. Each event lands at the
/// frontier-observation level; reducer arms are no-ops on
/// finding state. The cross-impl finding-effects digest covers
/// findings only, so these contribute zero to the digest by
/// design. The fixture's job is to prove that adding them to a
/// log doesn't perturb the cross-impl byte-equivalence promise.
fn build_federation_events_log(
    frontier_idx: usize,
    _findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    let frontier_id = format!("vfr_fixture_{frontier_idx:08x}");
    let conflict_event_id = format!("vev_fixture_conflict_{frontier_idx}");
    let synced = StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "frontier.synced_with_peer".to_string(),
        target: StateTarget {
            r#type: "frontier_observation".to_string(),
            id: frontier_id.clone(),
        },
        actor: StateActor {
            id: "federation".to_string(),
            r#type: "system".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 0),
        reason: "Fixture sync pass".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "peer_id": format!("peer:fixture-east-{frontier_idx}"),
            "peer_snapshot_hash": "fixture_peer_snapshot",
            "our_snapshot_hash": "fixture_our_snapshot",
            "divergence_count": 1,
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    };
    let detected = StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: conflict_event_id.clone(),
        kind: "frontier.conflict_detected".to_string(),
        target: StateTarget {
            r#type: "frontier_observation".to_string(),
            id: frontier_id.clone(),
        },
        actor: StateActor {
            id: "federation".to_string(),
            r#type: "system".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 1),
        reason: "Fixture conflict".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "peer_id": format!("peer:fixture-east-{frontier_idx}"),
            "finding_id": format!("vf_fixture_{frontier_idx}"),
            "kind": "verdict_disagreement",
            "detail": "Fixture peer disagrees on review_state",
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    };
    let resolved = StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "frontier.conflict_resolved".to_string(),
        target: StateTarget {
            r#type: "frontier_observation".to_string(),
            id: frontier_id.clone(),
        },
        actor: StateActor {
            id: format!("reviewer:fixture-{frontier_idx}"),
            r#type: "human".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 2),
        reason: "Fixture resolution".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "proposal_id": format!("vpr_fixture_resolve_{frontier_idx}"),
            "conflict_event_id": conflict_event_id,
            "resolved_by": format!("reviewer:fixture-{frontier_idx}"),
            "resolution_note": "Reviewer accepts our view",
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    };
    vec![synced, detected, resolved]
}

/// v0.67: bridge.reviewed fixture builder. The reducer arm is a
/// no-op on `Project.findings`; bridges live in `.vela/bridges/` as
/// a side table and the verdict is projected onto `Bridge.status` at
/// read time. The fixture's job is to prove that adding a
/// bridge.reviewed event to a log doesn't perturb the cross-impl
/// finding-effects digest.
fn build_bridge_reviewed_log(
    frontier_idx: usize,
    _findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    let bridge_id = format!("vbr_fixture_{frontier_idx:08x}");
    vec![StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "bridge.reviewed".to_string(),
        target: StateTarget {
            r#type: "bridge".to_string(),
            id: bridge_id.clone(),
        },
        actor: StateActor {
            id: format!("reviewer:bridge-fixture-{frontier_idx}"),
            r#type: "human".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 0),
        reason: "Fixture bridge review verdict".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload: json!({
            "bridge_id": bridge_id,
            "status": "confirmed",
            "note": "Fixture verdict for cross-impl coverage",
        }),
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    }]
}

/// v0.70: replication.deposited fixture builder. The reducer arm
/// appends a `Replication` to `Project.replications`. It does NOT
/// touch `Project.findings`, so the cross-impl finding-effects digest
/// is unchanged. The payload carries a real, content-addressed
/// `Replication` so the deposit succeeds and matches the v0.70
/// validator.
fn build_replication_deposited_log(
    frontier_idx: usize,
    findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    use vela_protocol::bundle::Replication;

    let target_finding = &findings[0];
    let attempted_by = format!("lab:fixture-replication-{frontier_idx}");
    let outcome = "replicated".to_string();
    let conditions = Conditions {
        text: format!("Fixture replication conditions {frontier_idx}"),
        species_verified: vec!["Mus musculus".into()],
        species_unverified: vec![],
        in_vitro: true,
        in_vivo: false,
        human_data: false,
        clinical_trial: false,
        concentration_range: None,
        duration: None,
        age_group: None,
        cell_type: Some("microglia".into()),
    };
    let evidence = Evidence {
        evidence_type: "experimental".into(),
        model_system: "mouse".into(),
        species: Some("Mus musculus".into()),
        method: "Independent replication, Western blot".into(),
        sample_size: Some("n=24".into()),
        effect_size: None,
        p_value: Some("p<0.05".into()),
        replicated: true,
        replication_count: Some(1),
        evidence_spans: vec![],
    };
    let provenance = Provenance {
        source_type: "preprint".into(),
        doi: Some(format!(
            "10.0000/crossimpl.replication.frontier{frontier_idx:04}"
        )),
        pmid: None,
        pmc: None,
        openalex_id: None,
        url: None,
        title: format!("Fixture replication report {frontier_idx}"),
        authors: vec![Author {
            name: "Cross-Impl Replicator".into(),
            orcid: None,
        }],
        year: Some(2026),
        journal: Some("Cross Replications".into()),
        license: None,
        publisher: None,
        funders: vec![],
        extraction: Extraction::default(),
        review: None,
        citation_count: Some(0),
    };
    // Build by hand so `created` is deterministic. `Replication::new`
    // would stamp `Utc::now()` and break fixture stability.
    let id = Replication::content_address(&target_finding.id, &attempted_by, &conditions, &outcome);
    let rep = Replication {
        id,
        target_finding: target_finding.id.clone(),
        attempted_by: attempted_by.clone(),
        outcome: outcome.clone(),
        evidence,
        conditions,
        provenance,
        notes: "Fixture replication note".to_string(),
        created: fixture_object_timestamp(frontier_idx, 0),
        previous_attempt: None,
    };
    let payload = json!({
        "proposal_id": format!("vpr_replication_deposit_{frontier_idx}"),
        "replication": rep,
    });
    vec![StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "replication.deposited".to_string(),
        target: StateTarget {
            r#type: "finding".to_string(),
            id: target_finding.id.clone(),
        },
        actor: StateActor {
            id: attempted_by,
            r#type: "human".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 0),
        reason: "Fixture replication deposit".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload,
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    }]
}

/// v0.70: prediction.deposited fixture builder. The reducer arm
/// appends a `Prediction` to `Project.predictions`. It does NOT
/// touch `Project.findings`, so the cross-impl finding-effects digest
/// is unchanged. The payload carries a real, content-addressed
/// `Prediction` so the deposit succeeds and matches the v0.70
/// validator.
fn build_prediction_deposited_log(
    frontier_idx: usize,
    findings: &[FindingBundle],
) -> Vec<events::StateEvent> {
    use vela_protocol::bundle::{ExpectedOutcome, Prediction};

    let target_finding = &findings[0];
    let made_by = format!("forecaster:fixture-prediction-{frontier_idx}");
    let claim_text =
        format!("Fixture prediction {frontier_idx}: replication will confirm at p<0.05.");
    let predicted_at = fixture_object_timestamp(frontier_idx, 0);
    let resolution_criterion =
        "An independent lab posts a replication with the same outcome.".to_string();
    let expected_outcome = ExpectedOutcome::Affirmed;
    let conditions = Conditions {
        text: format!("Fixture prediction conditions {frontier_idx}"),
        species_verified: vec!["Mus musculus".into()],
        species_unverified: vec![],
        in_vitro: true,
        in_vivo: false,
        human_data: false,
        clinical_trial: false,
        concentration_range: None,
        duration: None,
        age_group: None,
        cell_type: Some("microglia".into()),
    };
    let id = Prediction::content_address(
        &claim_text,
        &made_by,
        &predicted_at,
        &resolution_criterion,
        &expected_outcome,
    );
    let pred = Prediction {
        id,
        claim_text,
        target_findings: vec![target_finding.id.clone()],
        predicted_at,
        resolves_by: Some("2027-05-02T00:00:00Z".to_string()),
        resolution_criterion,
        expected_outcome,
        made_by: made_by.clone(),
        confidence: 0.6,
        conditions,
        expired_unresolved: false,
    };
    let payload = json!({
        "proposal_id": format!("vpr_prediction_deposit_{frontier_idx}"),
        "prediction": pred,
    });
    vec![StateEvent {
        schema: events::EVENT_SCHEMA.to_string(),
        id: String::new(),
        kind: "prediction.deposited".to_string(),
        target: StateTarget {
            r#type: "finding".to_string(),
            id: target_finding.id.clone(),
        },
        actor: StateActor {
            id: made_by,
            r#type: "human".to_string(),
        },
        timestamp: fixture_timestamp(frontier_idx, 0),
        reason: "Fixture prediction deposit".to_string(),
        before_hash: NULL_HASH.to_string(),
        after_hash: NULL_HASH.to_string(),
        payload,
        caveats: vec![],
        signature: None,
        schema_artifact_id: None,
    }]
}

/// v0.53: Reducer-effects digest per finding. v0.53 extends the v1
/// digest with `access_tier` so `tier.set` events on findings now
/// participate in the cross-impl byte-equivalence promise.
fn finding_state(f: &FindingBundle) -> Value {
    let review_state = f
        .flags
        .review_state
        .as_ref()
        .map(|s| match s {
            vela_protocol::bundle::ReviewState::Accepted => "accepted",
            vela_protocol::bundle::ReviewState::Contested => "contested",
            vela_protocol::bundle::ReviewState::NeedsRevision => "needs_revision",
            vela_protocol::bundle::ReviewState::Rejected => "rejected",
        })
        .unwrap_or("none");
    let mut annotation_ids: Vec<String> = f.annotations.iter().map(|a| a.id.clone()).collect();
    annotation_ids.sort();
    json!({
        "id": f.id,
        "retracted": f.flags.retracted,
        "contested": f.flags.contested,
        "review_state": review_state,
        // Format to 6 decimal places so f64 precision noise can't
        // cross the cross-implementation boundary.
        "confidence_score": format!("{:.6}", f.confidence.score),
        "annotation_ids": annotation_ids,
        "access_tier": f.access_tier.canonical(),
    })
}

/// v0.53: Reducer-effects digest per NegativeResult. Captures only
/// what the reducer mutates: review_state, retracted, access_tier.
/// The kind+conditions+provenance fields are static after deposit.
fn negative_result_state(n: &vela_protocol::bundle::NegativeResult) -> Value {
    let review_state = n
        .review_state
        .as_ref()
        .map(|s| match s {
            vela_protocol::bundle::ReviewState::Accepted => "accepted",
            vela_protocol::bundle::ReviewState::Contested => "contested",
            vela_protocol::bundle::ReviewState::NeedsRevision => "needs_revision",
            vela_protocol::bundle::ReviewState::Rejected => "rejected",
        })
        .unwrap_or("none");
    json!({
        "id": n.id,
        "retracted": n.retracted,
        "review_state": review_state,
        "access_tier": n.access_tier.canonical(),
    })
}

/// v0.53: Reducer-effects digest per Trajectory. Captures
/// review_state, retracted, access_tier, and the ordered list of
/// step ids so a divergent step-append produces a visible diff at
/// the digest level.
fn trajectory_state(t: &vela_protocol::bundle::Trajectory) -> Value {
    let review_state = t
        .review_state
        .as_ref()
        .map(|s| match s {
            vela_protocol::bundle::ReviewState::Accepted => "accepted",
            vela_protocol::bundle::ReviewState::Contested => "contested",
            vela_protocol::bundle::ReviewState::NeedsRevision => "needs_revision",
            vela_protocol::bundle::ReviewState::Rejected => "rejected",
        })
        .unwrap_or("none");
    let step_ids: Vec<String> = t.steps.iter().map(|s| s.id.clone()).collect();
    json!({
        "id": t.id,
        "retracted": t.retracted,
        "review_state": review_state,
        "access_tier": t.access_tier.canonical(),
        "step_ids": step_ids,
    })
}

/// v0.106.5: Reducer-effects digest per Replication. The v0.70
/// replication.deposited reducer arm is idempotent-append on
/// state["replications"]; the digest captures id, target_finding,
/// and outcome so a divergent deposit (different bucket, missed
/// idempotency check, dropped entry) becomes visible at the
/// digest level.
fn replication_state(r: &vela_protocol::bundle::Replication) -> Value {
    json!({
        "id": r.id,
        "target_finding": r.target_finding,
        "outcome": r.outcome,
    })
}

/// v0.106.5: Reducer-effects digest per Prediction. Same shape
/// rationale as Replication. Captures id, made_by, and
/// expired_unresolved so calibration drift (an implementation
/// flipping expired_unresolved differently) becomes visible.
fn prediction_state(p: &vela_protocol::bundle::Prediction) -> Value {
    json!({
        "id": p.id,
        "made_by": p.made_by,
        "expired_unresolved": p.expired_unresolved,
    })
}

/// Reducer-effects digest per Artifact. Captures the artifact lifecycle
/// fields and access tier. Static provenance and byte commitments remain
/// in the event payload itself.
fn artifact_state(a: &vela_protocol::bundle::Artifact) -> Value {
    let review_state = a
        .review_state
        .as_ref()
        .map(|s| match s {
            vela_protocol::bundle::ReviewState::Accepted => "accepted",
            vela_protocol::bundle::ReviewState::Contested => "contested",
            vela_protocol::bundle::ReviewState::NeedsRevision => "needs_revision",
            vela_protocol::bundle::ReviewState::Rejected => "rejected",
        })
        .unwrap_or("none");
    json!({
        "id": a.id,
        "kind": a.kind,
        "retracted": a.retracted,
        "review_state": review_state,
        "access_tier": a.access_tier.canonical(),
    })
}

/// Helper: replay an event log from a fresh genesis, sort by id,
/// extract the reducer-effects digest, and write the fixture.
fn export_one(
    out_dir: &PathBuf,
    fixture_idx: usize,
    scenario: &str,
    findings: Vec<FindingBundle>,
    event_log: Vec<events::StateEvent>,
) {
    let event_log = normalize_event_log(fixture_idx, event_log);
    let post = replay_from_genesis(
        findings.clone(),
        event_log.clone(),
        &format!("Cross-Impl Frontier {fixture_idx} ({scenario})"),
        "Cross-implementation reducer fixture",
        "2026-05-02T00:00:00Z",
        "vela-cross-impl/0",
    )
    .expect("replay must succeed");

    let mut sorted = post.findings.clone();
    sorted.sort_by(|a, b| a.id.cmp(&b.id));
    let expected_states: Vec<Value> = sorted.iter().map(finding_state).collect();

    // v0.53: extended digest covers negative_results and trajectories
    // so tier.set, negative_result.*, and trajectory.* events
    // participate in the cross-impl byte-equivalence promise.
    let mut sorted_nrs = post.negative_results.clone();
    sorted_nrs.sort_by(|a, b| a.id.cmp(&b.id));
    let expected_negative_results: Vec<Value> =
        sorted_nrs.iter().map(negative_result_state).collect();

    let mut sorted_trajs = post.trajectories.clone();
    sorted_trajs.sort_by(|a, b| a.id.cmp(&b.id));
    let expected_trajectories: Vec<Value> = sorted_trajs.iter().map(trajectory_state).collect();

    let mut sorted_artifacts = post.artifacts.clone();
    sorted_artifacts.sort_by(|a, b| a.id.cmp(&b.id));
    let expected_artifacts: Vec<Value> = sorted_artifacts.iter().map(artifact_state).collect();

    // v0.106.5: extend the digest to cover replications and
    // predictions. The v0.70 deposit arms idempotent-append to
    // state["replications"] / state["predictions"]; pre-v0.106.5
    // these collections were not part of the cross-impl
    // byte-equivalence promise, so a Python or third-language
    // implementation could silently drop a deposit and still pass
    // verify.py.
    let mut sorted_replications = post.replications.clone();
    sorted_replications.sort_by(|a, b| a.id.cmp(&b.id));
    let expected_replications: Vec<Value> =
        sorted_replications.iter().map(replication_state).collect();

    let mut sorted_predictions = post.predictions.clone();
    sorted_predictions.sort_by(|a, b| a.id.cmp(&b.id));
    let expected_predictions: Vec<Value> =
        sorted_predictions.iter().map(prediction_state).collect();

    // Inventory which event kinds appear in this fixture. Lets a
    // reviewer spot-check that the coverage promise is real per
    // fixture, not just "we ship some events."
    let mut kinds_seen: std::collections::BTreeMap<String, usize> =
        std::collections::BTreeMap::new();
    for ev in &event_log {
        *kinds_seen.entry(ev.kind.clone()).or_insert(0) += 1;
    }
    let kinds_value: Value = serde_json::to_value(&kinds_seen).unwrap();

    let fixture = json!({
        // v0.106.5: bumped from "3" to "4". The digest now includes
        // expected_replications and expected_predictions, covering
        // the v0.70 deposit reducer arms. v3 readers see five
        // collections; v4 readers see seven and fail loud on
        // divergence in either deposit collection.
        //
        // v0.55: bumped from "2" to "3". The digest now includes
        // expected_artifacts, covering artifact.asserted/reviewed/
        // retracted and artifact tier changes.
        //
        // v0.53: bumped from "1" to "2". The digest added
        // expected_negative_results, expected_trajectories, and
        // access_tier on each finding. Older v1 readers that only
        // check expected_states will still match the findings array
        // but won't see the new fields; v2 readers fail loud on a
        // mismatch in any of the three collections.
        "fixture_version": "4",
        "schema_url": "https://vela.science/schema/cross-impl-reducer-fixture/v4",
        "doctrine": "every reducer implementation must agree on per-kind mutation rules across findings, negative_results, trajectories, artifacts, replications, and predictions",
        "scenario": scenario,
        "frontier_idx": fixture_idx,
        "stats": {
            "findings": findings.len(),
            "negative_results": post.negative_results.len(),
            "trajectories": post.trajectories.len(),
            "artifacts": post.artifacts.len(),
            "replications": post.replications.len(),
            "predictions": post.predictions.len(),
            "events": event_log.len(),
            "cascade_depth": if scenario == "cascade" {
                CASCADE_DEPTH.min(findings.len() - 1)
            } else {
                0
            },
            "kinds_seen": kinds_value,
        },
        "genesis_findings": findings,
        "event_log": event_log,
        "expected_states": expected_states,
        "expected_negative_results": expected_negative_results,
        "expected_trajectories": expected_trajectories,
        "expected_artifacts": expected_artifacts,
        "expected_replications": expected_replications,
        "expected_predictions": expected_predictions,
    });

    let path = out_dir.join(format!("cascade-fixture-{fixture_idx:02}.json"));
    std::fs::write(&path, serde_json::to_string_pretty(&fixture).unwrap()).expect("write fixture");
    eprintln!("wrote {}", path.display());
}

#[test]
fn export_cross_impl_reducer_fixtures() {
    let out_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join("tests")
        .join("fixtures");
    std::fs::create_dir_all(&out_dir).expect("create fixtures dir");

    // Fixtures 00..02 — cascade scenario (the original 3).
    for frontier_idx in 0..FIXTURE_FRONTIER_COUNT {
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let event_log = build_event_log(frontier_idx, &findings);
        export_one(&out_dir, frontier_idx, "cascade", findings, event_log);
    }

    // Fixture 03 — review-branches + confidence-revised scenario.
    // Exercises every status arm of finding.reviewed plus the
    // confidence-revised path with both integer and fractional
    // new_score values.
    {
        let frontier_idx = FIXTURE_FRONTIER_COUNT;
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let event_log = build_review_branches_log(frontier_idx, &findings);
        export_one(
            &out_dir,
            frontier_idx,
            "review_branches",
            findings,
            event_log,
        );
    }

    // Fixture 04 — annotations + rejected scenario. Exercises both
    // finding.noted and finding.caveated (which share a reducer arm
    // but dispatch on distinct kinds) plus finding.rejected.
    {
        let frontier_idx = FIXTURE_FRONTIER_COUNT + 1;
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let event_log = build_annotations_log(frontier_idx, &findings);
        export_one(&out_dir, frontier_idx, "annotations", findings, event_log);
    }

    // Fixture 05 — NegativeResult lifecycle scenario. Exercises
    // negative_result.asserted (registered_trial + exploratory),
    // negative_result.reviewed, and negative_result.retracted.
    {
        let frontier_idx = FIXTURE_FRONTIER_COUNT + 2;
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let event_log = build_negative_results_log(frontier_idx, &findings);
        export_one(
            &out_dir,
            frontier_idx,
            "negative_results",
            findings,
            event_log,
        );
    }

    // Fixture 06 — Trajectory lifecycle scenario (v0.50). Exercises
    // trajectory.created (twice), trajectory.step_appended (3 steps:
    // hypothesis, tried, ruled_out), trajectory.reviewed
    // (needs_revision), and trajectory.retracted.
    {
        let frontier_idx = FIXTURE_FRONTIER_COUNT + 3;
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let event_log = build_trajectories_log(frontier_idx, &findings);
        export_one(&out_dir, frontier_idx, "trajectories", findings, event_log);
    }

    // Fixture 07 — tier.set lifecycle scenario (v0.51). Exercises
    // the dual-use access tier reclassification across all three
    // tierable object types (finding, negative_result, trajectory).
    {
        let frontier_idx = FIXTURE_FRONTIER_COUNT + 4;
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let event_log = build_tier_set_log(frontier_idx, &findings);
        export_one(&out_dir, frontier_idx, "tier_set", findings, event_log);
    }

    // Fixture 08: generic Artifact lifecycle scenario. Exercises
    // artifact.asserted, artifact.reviewed, artifact.retracted, and a
    // tier.set event whose target type is artifact.
    //
    // v0.73: also appends `bridge.reviewed`, `replication.deposited`,
    // and `prediction.deposited` events so the v0.67/v0.70/v0.71 event
    // kinds round-trip through Rust to JSON to Python at file level
    // (not just in-process). All three are no-ops on
    // findings/negative_results/trajectories/artifacts, so the existing
    // expected_* digests stay byte-identical and the no-op invariant is
    // proven across implementations. The replication/prediction
    // deposits land on Project.replications / Project.predictions; the
    // cross-impl finding-effects digest covers findings only, so digest
    // unchanged is the right invariant. A standalone deposits digest
    // is left for a future bump.
    {
        let frontier_idx = FIXTURE_FRONTIER_COUNT + 5;
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let mut event_log = build_artifacts_log(frontier_idx, &findings);
        event_log.extend(build_bridge_reviewed_log(frontier_idx, &findings));
        event_log.extend(build_replication_deposited_log(frontier_idx, &findings));
        event_log.extend(build_prediction_deposited_log(frontier_idx, &findings));
        export_one(&out_dir, frontier_idx, "artifacts", findings, event_log);
    }

    // v0.56: the locator-repair arm is exercised by
    // `build_locator_repair_log` in the coverage test below, but is
    // not exported as a standalone replayable fixture because its
    // atom-id references depend on the materialized evidence_atoms
    // produced by `sources::materialize_project`, which derives ids
    // from finding content. A self-consistent locator-repair fixture
    // needs the same materialization path the BBB curation work uses,
    // and that path lives in the integration test suite, not in the
    // genesis-only replay scaffold the cross-impl reducer relies on.

    // v0.105.7: export span-repair, entity-resolve, and entity-added
    // fixtures so the public conformance contract at
    // `conformance/fixtures/` exercises every reducer arm that
    // mutates a finding bundle in the genesis-only replay scaffold.
    // Pre-v0.105.7 the cross-impl coverage test asserted these arms
    // existed in some builder somewhere; v0.105.7 makes them part of
    // the exported fixture set so a second-implementation reducer
    // running `conformance/verify.py` exercises them too. The
    // post-replay finding digest covers `findings[]` only and these
    // arms each mutate a finding (evidence_spans, entity resolution
    // metadata, entities list), so the digest catches drift.

    // Fixture 09 — finding.span_repaired scenario (v0.57).
    {
        let frontier_idx = FIXTURE_FRONTIER_COUNT + 6;
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let event_log = build_span_repair_log(frontier_idx, &findings);
        export_one(&out_dir, frontier_idx, "span_repair", findings, event_log);
    }

    // Fixture 10 — finding.entity_resolved scenario (v0.57).
    {
        let frontier_idx = FIXTURE_FRONTIER_COUNT + 7;
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let event_log = build_entity_resolve_log(frontier_idx, &findings);
        export_one(
            &out_dir,
            frontier_idx,
            "entity_resolve",
            findings,
            event_log,
        );
    }

    // Fixture 11 — finding.entity_added scenario (v0.79).
    {
        let frontier_idx = FIXTURE_FRONTIER_COUNT + 8;
        let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
            .map(|i| make_finding(frontier_idx, i))
            .collect();
        let event_log = build_entity_added_log(frontier_idx, &findings);
        export_one(&out_dir, frontier_idx, "entity_added", findings, event_log);
    }

    // v0.107.4: write fixtures.manifest.json with SHA-256 of every
    // exported fixture. THREAT_MODEL.md A12 names tampered fixtures
    // as a real attack surface; the manifest closes the integrity
    // half (a future cycle adds maintainer-key signing on top).
    // verify.py reads the manifest and refuses to run if any
    // fixture's bytes drift from the recorded digest.
    write_fixtures_manifest(&out_dir);
}

/// v0.107.4: produce a fixtures.manifest.json alongside the
/// exported cascade-fixture-*.json files. Digest is SHA-256 of
/// the file's exact bytes; bytes is the file size on disk.
/// Sorted by path so the manifest is deterministic.
fn write_fixtures_manifest(out_dir: &PathBuf) {
    use sha2::{Digest, Sha256};
    let mut entries: Vec<serde_json::Value> = Vec::new();
    let mut paths: Vec<PathBuf> = std::fs::read_dir(out_dir)
        .expect("read fixtures dir")
        .filter_map(Result::ok)
        .map(|e| e.path())
        .filter(|p| {
            p.extension().is_some_and(|ext| ext == "json")
                && p.file_name()
                    .and_then(|n| n.to_str())
                    .is_some_and(|n| n.starts_with("cascade-fixture-"))
        })
        .collect();
    paths.sort();
    for path in &paths {
        let bytes = std::fs::read(path).expect("read fixture bytes");
        let digest = format!("sha256:{}", hex::encode(Sha256::digest(&bytes)));
        let name = path
            .file_name()
            .and_then(|n| n.to_str())
            .expect("fixture name utf8")
            .to_string();
        entries.push(json!({
            "path": name,
            "sha256": digest,
            "bytes": bytes.len(),
        }));
    }
    let manifest = json!({
        "schema": "vela.conformance-fixtures-manifest.v1",
        "doctrine": "every fixture's SHA-256 is recorded; verify.py refuses to run on a fixture whose bytes drift from the recorded digest. Closes THREAT_MODEL.md A12 (integrity half).",
        "fixtures": entries,
    });
    let manifest_path = out_dir.join("fixtures.manifest.json");
    std::fs::write(
        &manifest_path,
        serde_json::to_string_pretty(&manifest).expect("serialize manifest"),
    )
    .expect("write manifest");
    eprintln!("wrote {}", manifest_path.display());
}

/// Coverage-completeness assertion: the union of event kinds across
/// all exported fixtures must include every dispatch arm in
/// `apply_event`. v0.49.3 derives the required-kinds list from
/// `vela_protocol::reducer::REDUCER_MUTATION_KINDS` instead of a
/// hand-maintained mirror, so adding a new arm to the reducer
/// automatically extends the fixture coverage requirement (and the
/// `dispatch_handles_every_declared_kind` test in reducer.rs catches
/// the inverse drift).
#[test]
fn fixture_coverage_includes_every_reducer_arm() {
    use vela_protocol::reducer::REDUCER_MUTATION_KINDS;

    let frontier_idx = 0;
    let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
        .map(|i| make_finding(frontier_idx, i))
        .collect();

    let mut all_kinds: std::collections::BTreeSet<String> = std::collections::BTreeSet::new();
    for ev in build_event_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_review_branches_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_annotations_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_negative_results_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_trajectories_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_tier_set_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_artifacts_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_locator_repair_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_span_repair_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_entity_resolve_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }
    for ev in build_entity_added_log(frontier_idx, &findings) {
        all_kinds.insert(ev.kind);
    }

    for kind in REDUCER_MUTATION_KINDS {
        assert!(
            all_kinds.contains(*kind),
            "cross-impl fixture coverage missing reducer arm: {kind} \
             (declared in REDUCER_MUTATION_KINDS but not exercised by \
             any fixture builder)"
        );
    }
}

/// v0.64: federation event fixture builder smoke. The fixture is
/// intentionally not part of the cross-impl finding-effects digest
/// (federation events are no-ops on finding state). This test
/// proves the builder produces a well-formed three-event log
/// with the expected kinds and the conflict + resolved events
/// pair correctly by `conflict_event_id`.
#[test]
fn federation_events_fixture_pairs_conflict_with_resolution() {
    let frontier_idx = 7;
    let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
        .map(|i| make_finding(frontier_idx, i))
        .collect();
    let log = build_federation_events_log(frontier_idx, &findings);
    assert_eq!(log.len(), 3, "expected synced + detected + resolved");

    let kinds: Vec<&str> = log.iter().map(|e| e.kind.as_str()).collect();
    assert_eq!(
        kinds,
        vec![
            "frontier.synced_with_peer",
            "frontier.conflict_detected",
            "frontier.conflict_resolved",
        ]
    );

    let detected = &log[1];
    let resolved = &log[2];
    assert_eq!(
        detected.id,
        resolved
            .payload
            .get("conflict_event_id")
            .and_then(|v| v.as_str())
            .unwrap_or(""),
        "resolved event must reference detected event by id"
    );
}

/// v0.72 polish: the v0.67 + v0.70 + v0.71 event kinds
/// (`bridge.reviewed`, `replication.deposited`,
/// `prediction.deposited`) all leave `Project.findings` untouched.
/// This mirrors the v0.59 federation no-op test in
/// `reducer.rs::tests::federation_events_are_finding_state_noops` at
/// the cross-impl fixture level: each builder's event log applies to
/// an empty Project without error and leaves the finding-state
/// fingerprint identical. Replication and prediction events DO
/// mutate `Project.replications` / `Project.predictions`; the
/// cross-impl finding-effects digest covers findings only, so digest
/// unchanged is the right invariant.
#[test]
fn v067_v071_events_are_finding_state_noops() {
    use vela_protocol::project;
    use vela_protocol::reducer::apply_event;

    let frontier_idx = 8;
    let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
        .map(|i| make_finding(frontier_idx, i))
        .collect();

    let cases: Vec<(&str, Vec<events::StateEvent>)> = vec![
        (
            "bridge.reviewed",
            normalize_event_log(
                frontier_idx,
                build_bridge_reviewed_log(frontier_idx, &findings),
            ),
        ),
        (
            "replication.deposited",
            normalize_event_log(
                frontier_idx,
                build_replication_deposited_log(frontier_idx, &findings),
            ),
        ),
        (
            "prediction.deposited",
            normalize_event_log(
                frontier_idx,
                build_prediction_deposited_log(frontier_idx, &findings),
            ),
        ),
    ];

    for (label, log) in cases {
        let mut state = project::assemble(
            "v072-noop-fixture",
            findings.clone(),
            0,
            0,
            "Cross-impl no-op coverage for v0.67 + v0.70 + v0.71 event kinds",
        );
        let findings_before: Vec<FindingBundle> = state.findings.clone();
        let findings_before_bytes =
            serde_json::to_vec(&findings_before).expect("canonicalize findings_before");

        for event in &log {
            apply_event(&mut state, event)
                .unwrap_or_else(|e| panic!("{label} rejected by reducer: {e}"));
        }

        let findings_after_bytes =
            serde_json::to_vec(&state.findings).expect("canonicalize findings_after");
        assert_eq!(
            findings_before_bytes, findings_after_bytes,
            "{label} mutated Project.findings; expected no-op on finding state"
        );
    }
}

/// v0.72 polish: smoke test for each new builder. Each builder
/// produces a single, well-typed event of the expected kind. The
/// cross-impl harness already proves byte-equivalence on the
/// finding-state digest; this asserts the builder shape so a
/// regression in payload schema fails loudly here rather than
/// downstream in a Python parse error.
#[test]
fn v067_v071_builders_produce_well_typed_events() {
    let frontier_idx = 9;
    let findings: Vec<FindingBundle> = (0..FINDINGS_PER_FRONTIER)
        .map(|i| make_finding(frontier_idx, i))
        .collect();

    let bridge_log = build_bridge_reviewed_log(frontier_idx, &findings);
    assert_eq!(bridge_log.len(), 1);
    assert_eq!(bridge_log[0].kind, "bridge.reviewed");
    assert_eq!(bridge_log[0].target.r#type, "bridge");
    assert!(
        bridge_log[0]
            .payload
            .get("status")
            .and_then(|v| v.as_str())
            .map(|s| s == "confirmed" || s == "refuted")
            .unwrap_or(false),
        "bridge.reviewed payload.status must be 'confirmed' or 'refuted'"
    );

    let rep_log = build_replication_deposited_log(frontier_idx, &findings);
    assert_eq!(rep_log.len(), 1);
    assert_eq!(rep_log[0].kind, "replication.deposited");
    let rep_id = rep_log[0]
        .payload
        .get("replication")
        .and_then(|v| v.get("id"))
        .and_then(|v| v.as_str())
        .unwrap_or("");
    assert!(
        rep_id.starts_with("vrep_"),
        "replication.deposited payload.replication.id must start with 'vrep_', got {rep_id:?}"
    );

    let pred_log = build_prediction_deposited_log(frontier_idx, &findings);
    assert_eq!(pred_log.len(), 1);
    assert_eq!(pred_log[0].kind, "prediction.deposited");
    let pred_id = pred_log[0]
        .payload
        .get("prediction")
        .and_then(|v| v.get("id"))
        .and_then(|v| v.as_str())
        .unwrap_or("");
    assert!(
        pred_id.starts_with("vpred_"),
        "prediction.deposited payload.prediction.id must start with 'vpred_', got {pred_id:?}"
    );
}