veredictum 0.1.4

The independent conformance instrument for openEHR clinical data repositories: a machine-readable catalogue of spec-cited test cases, executed against any running CDR, judged by pure-function verdicts
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
// SPDX-FileCopyrightText: Veredictum contributors
// SPDX-License-Identifier: Apache-2.0

//! The per-stage wire realization.
//!
//! Each [`crate::perf::PerfOp`] maps to
//! its committed ITS-REST operation binding (`artifacts/bindings/its-rest/`
//! — create EHR / commit COMPOSITION / directory / contribution in the
//! created family with the uid via `ETag`/`Location`, versioned update via
//! `If-Match`, ad-hoc and stored query 200, template list/get 200, tags
//! 200). The driver sends `Prefer: return=minimal` on its writes, so the
//! created family accepts BOTH `201` and `204` (ITS-REST overview
//! `Requests_and_responses` §Prefer: "typically `201 Created`. If no
//! response body is returned, the service SHOULD use `204 No Content`").
//! Anything else observed counts as an error arrival.
//!
//! Dependent stages resolve prerequisites from the module's `CaptureStore` — the
//! journey-instance state earlier stages captured (a fresh EHR's id, a
//! commit's version uid) — falling back to the standing ward's seeded
//! state ([`crate::perf_run::corpus::WardPatient`]). NOTHING BLOCKS: a
//! prerequisite genuinely absent at fire time (the SUT has not landed the
//! earlier stage) is an honest error observation — that IS the
//! measurement.

use std::collections::HashMap;
use std::sync::Mutex;

use reqwest::StatusCode;

use crate::perf::PerfOp;
use crate::perf_run::client::{
    PerfClient, location_last_segment, object_uid_of, strip_weak_quotes,
};
use crate::perf_run::corpus::{
    ADHOC_AQL, ANALYTICS_AQL, STORED_QUERY_NAME, SeededCorpus, TERMINOLOGY_AQL, WARD_AQL,
};
use crate::perf_run::pack::{self, JourneyPack};
use crate::perf_run::schedule::{PlannedArrival, WardDoc};

/// Per-journey-instance captured state (fresh-EHR journeys) — written by
/// creates/commits, read by the instance's later stages, dropped at the
/// instance's last in-window stage.
#[derive(Debug, Default, Clone)]
struct JourneyState {
    ehr_id: Option<String>,
    last_commit_ovid: Option<String>,
    directory_ovid: Option<String>,
    contribution_uid: Option<String>,
    status_ovid: Option<String>,
    /// The demographic PARTY this instance registered: its
    /// `versioned_object_uid` and the latest `OBJECT_VERSION_ID` (the
    /// If-Match the amendment chains on).
    party_uid: Option<String>,
    party_ovid: Option<String>,
    /// The `PARTY_RELATIONSHIP` this instance committed (extension route).
    relationship_uid: Option<String>,
}

/// Per-patient rolling version state (standing-ward journeys): the latest
/// known `OBJECT_VERSION_ID` per ward document, advanced by each versioned
/// update so successive corrections chain `If-Match` correctly.
#[derive(Debug, Default)]
#[expect(
    clippy::struct_field_names,
    reason = "each field IS an ovid of a distinct document"
)]
struct PatientState {
    gp_ovid: Option<String>,
    medlist_ovid: Option<String>,
    directory_ovid: Option<String>,
    status_ovid: Option<String>,
}

/// The capture store: sharded mutexes (journeys by instance id, patients
/// by index) — contention stays negligible against second-scale stage
/// spacing.
#[derive(Debug)]
pub(crate) struct CaptureStore {
    journeys: Vec<Mutex<HashMap<u64, JourneyState>>>,
    patients: Vec<Mutex<HashMap<usize, PatientState>>>,
}

const SHARDS: usize = 64;

/// The shard a journey instance's state lives in: its id reduced modulo
/// the fixed shard count, so an instance always finds its own entry and
/// the ids spread across every shard.
fn shard_of(id: u64) -> usize {
    #[expect(
        clippy::as_conversions,
        reason = "the shard count widens exactly: usize is at most 64 bits on every supported target"
    )]
    let shards = SHARDS as u64;
    #[expect(
        clippy::expect_used,
        reason = "the remainder is below SHARDS, itself a usize, so the narrowing should be total"
    )]
    let shard = usize::try_from(id % shards).expect("a remainder below SHARDS should fit a usize");
    shard
}

impl CaptureStore {
    pub(crate) fn new() -> Self {
        Self {
            journeys: (0..SHARDS).map(|_| Mutex::new(HashMap::new())).collect(),
            patients: (0..SHARDS).map(|_| Mutex::new(HashMap::new())).collect(),
        }
    }

    // NOTE: a poisoned shard is RECOVERED, never dropped (FerroEHR#1853) — the guarded
    // value is a plain per-id map with no cross-entry invariant a panic
    // elsewhere can break, so `None` now means only "no such shard".
    fn journey<R>(&self, id: u64, f: impl FnOnce(&mut JourneyState) -> R) -> Option<R> {
        let shard = shard_of(id);
        let mut map = self
            .journeys
            .get(shard)?
            .lock()
            .unwrap_or_else(std::sync::PoisonError::into_inner);
        Some(f(map.entry(id).or_default()))
    }

    fn patient<R>(&self, index: usize, f: impl FnOnce(&mut PatientState) -> R) -> Option<R> {
        let shard = index % SHARDS;
        let mut map = self
            .patients
            .get(shard)?
            .lock()
            .unwrap_or_else(std::sync::PoisonError::into_inner);
        Some(f(map.entry(index).or_default()))
    }

    fn drop_journey(&self, id: u64) {
        let shard = shard_of(id);
        if let Some(mutex) = self.journeys.get(shard) {
            let mut map = mutex
                .lock()
                .unwrap_or_else(std::sync::PoisonError::into_inner);
            map.remove(&id);
        }
    }
}

/// Record the observed wire status (the failure-sampling channel: a
/// mismatched arrival reports WHAT the SUT answered, not just that it
/// mismatched).
///
/// The recorded channel is a bare `u16` because it is RENDERED into the run
/// record; the returned status stays typed so every caller compares against
/// a [`StatusCode`] constant.
fn note(observed: &mut Option<u16>, status: StatusCode) -> StatusCode {
    *observed = Some(status.as_u16());
    // A 429 anywhere invalidates the whole run: see
    // `crate::perf_run::rate_limited_observed`.
    if status == StatusCode::TOO_MANY_REQUESTS {
        crate::perf_run::note_rate_limited();
    }
    status
}

/// Whether a `Prefer: return=minimal` write landed in the created family.
/// ITS-REST overview `Requests_and_responses` §Prefer: the status is
/// "typically `201 Created`. If no response body is returned, the service
/// SHOULD use `204 No Content`" — both are conformant (upstream `EHRbase`
/// answers 204; this SUT answers 201). The identifying `ETag`/`Location`
/// is still demanded by each arm. Mirrors the seeder's acceptance
/// ([`crate::perf_run::corpus`]).
fn created(status: StatusCode) -> bool {
    status == StatusCode::CREATED || status == StatusCode::NO_CONTENT
}

/// Whether a `Prefer: return=minimal` versioned UPDATE landed: the same
/// §Prefer clause makes an empty body `204 No Content`, while a served
/// representation is `200 OK`.
fn updated(status: StatusCode) -> bool {
    status == StatusCode::OK || status == StatusCode::NO_CONTENT
}

/// Deterministic corpus addressing: a large odd stride cycles the pools.
///
/// The product is formed in `u128`, where the widest possible operand pair
/// (`u64::MAX` times the multiplier) needs 96 bits, so the multiply cannot
/// overflow and no fallback value has to exist.
fn stride(arrival: u64) -> u128 {
    u128::from(arrival) * 2_654_435_761
}

/// The pool entry one arrival addresses: the stride reduced modulo the
/// pool length, so the index addresses `0..len` and an empty pool addresses
/// entry 0 (the caller reports the empty pool).
///
/// The reduction happens in `u128`, so the full stride reaches the whole
/// pool on every supported target.
fn pool_index(arrival: u64, len: usize) -> usize {
    #[expect(
        clippy::as_conversions,
        reason = "the pool length widens exactly: usize is at most 64 bits on every supported target"
    )]
    let modulus = u128::from(len.max(1) as u64);
    #[expect(
        clippy::expect_used,
        reason = "the remainder is below `len`, itself a usize, so the narrowing should be total"
    )]
    let index = usize::try_from(stride(arrival) % modulus)
        .expect("a remainder below a usize pool length should fit a usize");
    index
}

/// Create the journey instance's own EHR and capture its id, which every
/// later stage of a fresh-EHR journey addresses.
///
/// Returns whether the create landed in the `Prefer: return=minimal`
/// created family WITH the identifying `Location`.
///
/// # Errors
/// A transport fault, which counts as an error observation at the call
/// site.
fn create_ehr(
    client: &PerfClient,
    journey: u64,
    captures: &CaptureStore,
    observed: &mut Option<u16>,
) -> Result<bool, String> {
    let reply = client.request(reqwest::Method::POST, "/ehr", None, true, None)?;
    if created(note(observed, reply.status))
        && let Some(id) = reply.location.as_deref().and_then(location_last_segment)
    {
        captures.journey(journey, |s| s.ehr_id = Some(id));
        Ok(true)
    } else {
        Ok(false)
    }
}

/// Execute one planned arrival against the SUT.
///
/// Returns whether the wire outcome matched the binding's expected kind.
///
/// # Errors
/// A transport fault or an unresolvable prerequisite — both count as error
/// observations at the call site, never run failures.
#[expect(
    clippy::too_many_lines,
    reason = "one match arm per closed-vocabulary operation"
)]
#[expect(
    clippy::disallowed_types,
    reason = "the AQL request bodies this sends are wire JSON whose shape belongs to the SUT"
)]
pub(crate) fn perform(
    client: &PerfClient,
    arrival_index: u64,
    planned: &PlannedArrival,
    corpus: &SeededCorpus,
    journey_pack: &JourneyPack,
    captures: &CaptureStore,
    observed: &mut Option<u16>,
) -> Result<bool, String> {
    let offset_s = planned.at.as_secs();
    let journey = planned.journey;

    // The EHR the stage addresses: the instance's fresh EHR, the standing
    // ward patient, or (read-only fallbacks) a corpus stride. The create
    // MAKES the EHR its journey's later stages address, so it is the one
    // stage that addresses none.
    let addressed: Option<String> = if planned.op == PerfOp::EhrCreate {
        None
    } else if let Some(patient) = planned.patient {
        Some(
            corpus
                .ehr_ids
                .get(corpus.ward.get(patient).map_or(patient, |w| w.ehr_index))
                .cloned()
                .ok_or_else(|| "ward patient outside the corpus".to_owned())?,
        )
    } else {
        Some(
            captures
                .journey(journey, |s| s.ehr_id.clone())
                .flatten()
                .ok_or_else(|| "prerequisite EHR not yet created (SUT stall)".to_owned())?,
        )
    };
    let Some(ehr_id) = addressed else {
        let ok = create_ehr(client, journey, captures, observed)?;
        if planned.last {
            captures.drop_journey(journey);
        }
        return Ok(ok);
    };
    let ward = planned.patient.and_then(|p| corpus.ward.get(p));

    let ok = match planned.op {
        PerfOp::EhrCreate => create_ehr(client, journey, captures, observed)?,
        PerfOp::EhrRead => {
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::EhrStatusRead => {
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}/ehr_status"),
                None,
                false,
                None,
            )?;
            let status = note(observed, reply.status);
            if status == StatusCode::OK
                && let Some(ovid) = reply.etag.as_deref().map(strip_weak_quotes)
            {
                if let Some(patient) = planned.patient {
                    captures.patient(patient, |s| s.status_ovid = Some(ovid));
                } else {
                    captures.journey(journey, |s| s.status_ovid = Some(ovid));
                }
            }
            status == StatusCode::OK
        }
        PerfOp::EhrStatusUpdate => {
            // If-Match from the journey's own status read (the ADT flow
            // reads before updating); an unread status is a stall.
            let preceding = planned
                .patient
                .and_then(|p| captures.patient(p, |s| s.status_ovid.clone()))
                .flatten()
                .or_else(|| {
                    captures
                        .journey(journey, |s| s.status_ovid.clone())
                        .flatten()
                })
                .ok_or_else(|| "prerequisite EHR_STATUS read has not landed".to_owned())?;
            let reply = client.request(
                reqwest::Method::PUT,
                &format!("/ehr/{ehr_id}/ehr_status"),
                Some(("application/json", pack::ehr_status_body(offset_s))),
                true,
                Some(&preceding),
            )?;
            let ok = updated(note(observed, reply.status));
            let ovid = if ok {
                reply.etag.as_deref().map(strip_weak_quotes)
            } else {
                refresh_current_ovid(client, &format!("/ehr/{ehr_id}/ehr_status"))
            };
            if let Some(ovid) = ovid {
                if let Some(patient) = planned.patient {
                    captures.patient(patient, |s| s.status_ovid = Some(ovid));
                } else {
                    captures.journey(journey, |s| s.status_ovid = Some(ovid));
                }
            }
            ok
        }
        PerfOp::CompositionCommit => {
            let template = planned
                .template
                .and_then(|i| journey_pack.get(i))
                .ok_or_else(|| "commit stage without a pack template".to_owned())?;
            let body = pack::composition_body(template, offset_s, arrival_index)?;
            let reply = client.request(
                reqwest::Method::POST,
                &format!("/ehr/{ehr_id}/composition"),
                Some(("application/json", body)),
                true,
                None,
            )?;
            if created(note(observed, reply.status))
                && let Some(uid) = reply.etag.as_deref().map(strip_weak_quotes)
            {
                captures.journey(journey, |s| s.last_commit_ovid = Some(uid));
                true
            } else {
                false
            }
        }
        PerfOp::CompositionRead => {
            // A committed-corpus read: the scale pool, stride-addressed.
            let index = pool_index(arrival_index, corpus.compositions.len());
            let (ehr_index, uid) = corpus
                .compositions
                .get(index)
                .ok_or_else(|| "corpus has no compositions".to_owned())?;
            let read_ehr = corpus
                .ehr_ids
                .get(*ehr_index)
                .ok_or_else(|| "corpus composition references a missing EHR".to_owned())?;
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{read_ehr}/composition/{uid}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::CompositionReadCurrent => {
            // The journey's own document: the instance's last commit, else
            // the ward chart (versioned-object read → latest version).
            let uid = captures
                .journey(journey, |s| s.last_commit_ovid.clone())
                .flatten()
                .map(|ovid| object_uid_of(&ovid))
                .or_else(|| ward.map(|w| object_uid_of(&w.gp_ovid)))
                .ok_or_else(|| "prerequisite commit has not landed (SUT stall)".to_owned())?;
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}/composition/{uid}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::CompositionRevisionHistory => {
            let uid = current_doc_object_uid(planned, captures, ward)
                .ok_or_else(|| "no document for revision history".to_owned())?;
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}/versioned_composition/{uid}/revision_history"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::CompositionUpdate => {
            let template = planned
                .template
                .and_then(|i| journey_pack.get(i))
                .ok_or_else(|| "update stage without a pack template".to_owned())?;
            let patient = planned
                .patient
                .ok_or_else(|| "versioned update addresses a ward patient".to_owned())?;
            // The rolling latest ovid (seeded, advanced per correction).
            let preceding = captures
                .patient(patient, |s| match planned.doc {
                    WardDoc::MedList => s.medlist_ovid.clone(),
                    WardDoc::Gp => s.gp_ovid.clone(),
                })
                .flatten()
                .or_else(|| {
                    ward.map(|w| match planned.doc {
                        WardDoc::MedList => w.medlist_ovid.clone(),
                        WardDoc::Gp => w.gp_ovid.clone(),
                    })
                })
                .ok_or_else(|| "no seeded ward document to update".to_owned())?;
            let object_uid = object_uid_of(&preceding);
            let body = pack::composition_body(template, offset_s, arrival_index)?;
            let reply = client.request(
                reqwest::Method::PUT,
                &format!("/ehr/{ehr_id}/composition/{object_uid}"),
                Some(("application/json", body)),
                true,
                Some(&preceding),
            )?;
            let ok = updated(note(observed, reply.status));
            let next = if ok {
                reply.etag.as_deref().map(strip_weak_quotes)
            } else {
                // Conflict/failure: re-resolve the current version so the
                // NEXT amendment chains correctly (see `refresh_current_ovid`).
                refresh_current_ovid(client, &format!("/ehr/{ehr_id}/composition/{object_uid}"))
            };
            if let Some(next) = next {
                captures.patient(patient, |s| match planned.doc {
                    WardDoc::MedList => s.medlist_ovid = Some(next),
                    WardDoc::Gp => s.gp_ovid = Some(next),
                });
            }
            ok
        }
        PerfOp::CompositionDelete => {
            // Deletes the journey's own commit (the deletion journey
            // commits first) — never a shared ward document.
            let preceding = captures
                .journey(journey, |s| s.last_commit_ovid.clone())
                .flatten()
                .ok_or_else(|| "prerequisite commit has not landed (SUT stall)".to_owned())?;
            let reply = client.request(
                reqwest::Method::DELETE,
                &format!("/ehr/{ehr_id}/composition/{preceding}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::NO_CONTENT
        }
        PerfOp::DirectoryCreate => {
            // Fresh-EHR journeys create their episode tree; the standing
            // ward already has one (seeded), so a 409/400 on re-create is
            // a real error — admission journeys always run on fresh EHRs.
            let reply = client.request(
                reqwest::Method::POST,
                &format!("/ehr/{ehr_id}/directory"),
                Some(("application/json", pack::folder_body(false))),
                true,
                None,
            )?;
            let ok = created(note(observed, reply.status));
            if ok && let Some(ovid) = reply.etag.as_deref().map(strip_weak_quotes) {
                captures.journey(journey, |s| s.directory_ovid = Some(ovid));
            }
            ok
        }
        PerfOp::DirectoryRead => {
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}/directory"),
                None,
                false,
                None,
            )?;
            let status = note(observed, reply.status);
            if status == StatusCode::OK
                && let Some(patient) = planned.patient
                && let Some(ovid) = reply.etag.as_deref().map(strip_weak_quotes)
            {
                captures.patient(patient, |s| s.directory_ovid = Some(ovid));
            }
            status == StatusCode::OK
        }
        PerfOp::DirectoryUpdate => {
            let preceding = planned
                .patient
                .and_then(|p| captures.patient(p, |s| s.directory_ovid.clone()))
                .flatten()
                .or_else(|| ward.map(|w| w.directory_ovid.clone()))
                .or_else(|| {
                    captures
                        .journey(journey, |s| s.directory_ovid.clone())
                        .flatten()
                })
                .ok_or_else(|| "no directory version to update".to_owned())?;
            let reply = client.request(
                reqwest::Method::PUT,
                &format!("/ehr/{ehr_id}/directory"),
                Some(("application/json", pack::folder_body(true))),
                true,
                Some(&preceding),
            )?;
            let ok = updated(note(observed, reply.status));
            let next = if ok {
                reply.etag.as_deref().map(strip_weak_quotes)
            } else {
                refresh_current_ovid(client, &format!("/ehr/{ehr_id}/directory"))
            };
            if let Some(next) = next {
                if let Some(patient) = planned.patient {
                    captures.patient(patient, |s| s.directory_ovid = Some(next));
                } else {
                    captures.journey(journey, |s| s.directory_ovid = Some(next));
                }
            }
            ok
        }
        PerfOp::ContributionCommit => {
            let template = planned
                .template
                .and_then(|i| journey_pack.get(i))
                .ok_or_else(|| "contribution stage without a pack template".to_owned())?;
            let body = pack::contribution_body(template, offset_s, arrival_index)?;
            let reply = client.request(
                reqwest::Method::POST,
                &format!("/ehr/{ehr_id}/contribution"),
                Some(("application/json", body)),
                true,
                None,
            )?;
            if created(note(observed, reply.status)) {
                let uid = reply
                    .location
                    .as_deref()
                    .and_then(location_last_segment)
                    .or_else(|| reply.etag.as_deref().map(strip_weak_quotes));
                if let Some(uid) = uid {
                    captures.journey(journey, |s| s.contribution_uid = Some(uid));
                }
                true
            } else {
                false
            }
        }
        PerfOp::ContributionRead => {
            let uid = captures
                .journey(journey, |s| s.contribution_uid.clone())
                .flatten()
                .or_else(|| ward.map(|w| w.contribution_uid.clone()))
                .ok_or_else(|| "no contribution to inspect".to_owned())?;
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}/contribution/{uid}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::AdhocQuery => {
            let body = serde_json::json!({
                "q": ADHOC_AQL,
                "query_parameters": { "ehr_id": ehr_id }
            });
            let bytes = serde_json::to_vec(&body).map_err(|e| e.to_string())?;
            let reply = client.request(
                reqwest::Method::POST,
                "/query/aql",
                Some(("application/json", bytes)),
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::WardQuery => {
            let body = serde_json::json!({ "q": WARD_AQL });
            let bytes = serde_json::to_vec(&body).map_err(|e| e.to_string())?;
            let reply = client.request(
                reqwest::Method::POST,
                "/query/aql",
                Some(("application/json", bytes)),
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::StoredQueryExecute => {
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/query/{STORED_QUERY_NAME}?ehr_id={ehr_id}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::TemplateList => {
            let reply = client.request(
                reqwest::Method::GET,
                "/definition/template/adl1.4",
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::TemplateGet => {
            // Stride across the pack (integration engines poll them all).
            let index = pool_index(arrival_index, journey_pack.templates.len());
            let template = journey_pack
                .get(index)
                .ok_or_else(|| "pack is empty".to_owned())?;
            let encoded = urlencoding::encode(&template.template_id);
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/definition/template/adl1.4/{encoded}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::TagsPut => {
            let uid = current_doc_object_uid(planned, captures, ward)
                .ok_or_else(|| "no document to tag".to_owned())?;
            let reply = client.request(
                reqwest::Method::PUT,
                &format!("/ehr/{ehr_id}/composition/{uid}/tags"),
                Some(("application/json", pack::tags_body(offset_s))),
                false,
                None,
            )?;
            // 200 (stored collection), 201 (first collection) or 204 (no
            // content) — each is the successful full-collection replace.
            let status = note(observed, reply.status);
            updated(status) || status == StatusCode::CREATED
        }
        PerfOp::TagsRead => {
            let uid = current_doc_object_uid(planned, captures, ward)
                .ok_or_else(|| "no document to read tags from".to_owned())?;
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}/composition/{uid}/tags"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::CompositionVersionRead => {
            // The ORIGINAL_VERSION envelope (the signature carrier): the
            // instance's own commit, else the ward chart's seeded version.
            let ovid = current_version_uid(planned, captures, ward)
                .ok_or_else(|| "no committed version to read".to_owned())?;
            let vo_uid = object_uid_of(&ovid);
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}/versioned_composition/{vo_uid}/version/{ovid}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::CompositionCommitFlat => {
            let flat = journey_pack
                .aux
                .flat
                .as_ref()
                .ok_or_else(|| "the pack carries no Simplified-FLAT payload".to_owned())?;
            let reply = client.request_negotiated(
                reqwest::Method::POST,
                &format!("/ehr/{ehr_id}/composition"),
                Some(("application/openehr.wt.flat+json", pack::flat_body(flat)?)),
                true,
                None,
                None,
                // ITS-REST overview Requests_and_responses §openehr-template-id
                // — a Simplified-Format commit names the template it is
                // constrained by, the format carrying no archetype details.
                &[("openehr-template-id", flat.template_id.clone())],
            )?;
            if created(note(observed, reply.status))
                && let Some(uid) = reply.etag.as_deref().map(strip_weak_quotes)
            {
                captures.journey(journey, |s| s.last_commit_ovid = Some(uid));
                true
            } else {
                false
            }
        }
        PerfOp::CompositionReadFlat => {
            let ovid = current_version_uid(planned, captures, ward)
                .ok_or_else(|| "no committed version to read as FLAT".to_owned())?;
            let reply = client.request_negotiated(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}/composition/{ovid}"),
                None,
                false,
                None,
                Some("application/openehr.wt.flat+json"),
                &[],
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::PartyCreate => {
            let person = journey_pack
                .aux
                .person
                .as_ref()
                .ok_or_else(|| "the pack carries no PERSON payload".to_owned())?;
            let reply = client.request(
                reqwest::Method::POST,
                "/demographic/person",
                Some((
                    "application/json",
                    pack::person_body(person, arrival_index)?,
                )),
                true,
                None,
            )?;
            if created(note(observed, reply.status))
                && let Some(ovid) = reply
                    .etag
                    .as_deref()
                    .map(strip_weak_quotes)
                    .or_else(|| reply.location.as_deref().and_then(location_last_segment))
            {
                let uid = object_uid_of(&ovid);
                captures.journey(journey, |s| {
                    s.party_uid = Some(uid);
                    s.party_ovid = Some(ovid);
                });
                true
            } else {
                false
            }
        }
        PerfOp::PartyRead => {
            let uid = captures
                .journey(journey, |s| s.party_uid.clone())
                .flatten()
                .ok_or_else(|| "prerequisite PARTY has not landed (SUT stall)".to_owned())?;
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/demographic/person/{uid}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::PartyUpdate => {
            let amended = journey_pack
                .aux
                .person_amended
                .as_ref()
                .ok_or_else(|| "the pack carries no amended PERSON payload".to_owned())?;
            let (uid, preceding) = captures
                .journey(journey, |s| s.party_uid.clone().zip(s.party_ovid.clone()))
                .flatten()
                .ok_or_else(|| "prerequisite PARTY has not landed (SUT stall)".to_owned())?;
            let reply = client.request(
                reqwest::Method::PUT,
                &format!("/demographic/person/{uid}"),
                Some((
                    "application/json",
                    pack::person_body(amended, arrival_index)?,
                )),
                true,
                Some(&preceding),
            )?;
            let ok = updated(note(observed, reply.status));
            if ok && let Some(next) = reply.etag.as_deref().map(strip_weak_quotes) {
                captures.journey(journey, |s| s.party_ovid = Some(next));
            }
            ok
        }
        PerfOp::PartyRelationshipCreate => {
            let relationship = journey_pack
                .aux
                .party_relationship
                .as_ref()
                .ok_or_else(|| "the pack carries no PARTY_RELATIONSHIP payload".to_owned())?;
            let source = captures
                .journey(journey, |s| s.party_uid.clone())
                .flatten()
                .ok_or_else(|| "prerequisite PARTY has not landed (SUT stall)".to_owned())?;
            let reply = client.request(
                reqwest::Method::POST,
                "/demographic/party_relationship",
                Some((
                    "application/json",
                    pack::party_relationship_body(relationship, &source)?,
                )),
                true,
                None,
            )?;
            if created(note(observed, reply.status))
                && let Some(ovid) = reply
                    .etag
                    .as_deref()
                    .map(strip_weak_quotes)
                    .or_else(|| reply.location.as_deref().and_then(location_last_segment))
            {
                captures.journey(journey, |s| s.relationship_uid = Some(object_uid_of(&ovid)));
                true
            } else {
                false
            }
        }
        PerfOp::PartyRelationshipRead => {
            let uid = captures
                .journey(journey, |s| s.relationship_uid.clone())
                .flatten()
                .ok_or_else(|| {
                    "prerequisite PARTY_RELATIONSHIP has not landed (SUT stall)".to_owned()
                })?;
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/demographic/party_relationship/{uid}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::TemplateExample => {
            let index = pool_index(arrival_index, journey_pack.templates.len());
            let template = journey_pack
                .get(index)
                .ok_or_else(|| "pack is empty".to_owned())?;
            let encoded = urlencoding::encode(&template.template_id);
            let reply = client.request(
                reqwest::Method::GET,
                // The two query parameters the released operation declares
                // (`type`, `detail_level`).
                &format!(
                    "/definition/template/adl1.4/{encoded}/example?type=input&detail_level=required"
                ),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::TemplateAdl2List => {
            let reply = client.request(
                reqwest::Method::GET,
                "/definition/template/adl2",
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::ArchetypeAdl2List => {
            // EXTENSION route (register AMB-37) — no openEHR spec governs it;
            // it loads the ADL 2 archetype listing this product serves of its
            // own design.
            let reply = client.request(
                reqwest::Method::GET,
                "/definition/archetype/adl2",
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::AdminContributionReport => {
            // EXTENSION route (register AMB-33) — no openEHR spec governs it.
            // The EHR service is the only versioned-content service this
            // arrival reports on (SM platform_service.adoc); the count is a
            // pure read and mutates nothing.
            let reply = client.request(
                reqwest::Method::GET,
                "/admin/report/contribution/count?a_service=Ehr",
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::EhrExtractExport => {
            // EXTENSION route (register AMB-34) — no openEHR spec governs it.
            // A pure read: the EHR's content as a `List<EXTRACT>`.
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/message/export/{ehr_id}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::TddImport => {
            // EXTENSION route (register AMB-34) — no openEHR spec governs it.
            // The document converts against its operational template and
            // commits through the ordinary validated COMPOSITION path, so this
            // arrival is a real write.
            let tdd = journey_pack
                .aux
                .tdd
                .as_ref()
                .ok_or_else(|| "the pack carries no TDD payload".to_owned())?;
            let reply = client.request(
                reqwest::Method::POST,
                &format!("/message/tdd/{ehr_id}"),
                Some(("application/xml", tdd.document.as_bytes().to_vec())),
                false,
                None,
            )?;
            created(note(observed, reply.status))
        }
        PerfOp::AnalyticsQuery => {
            let body = serde_json::json!({
                "q": ANALYTICS_AQL,
                "query_parameters": { "ehr_id": ehr_id }
            });
            let bytes = serde_json::to_vec(&body).map_err(|e| e.to_string())?;
            let reply = client.request(
                reqwest::Method::POST,
                "/query/aql",
                Some(("application/json", bytes)),
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::TerminologyQuery => {
            let body = serde_json::json!({ "q": TERMINOLOGY_AQL });
            let bytes = serde_json::to_vec(&body).map_err(|e| e.to_string())?;
            let reply = client.request(
                reqwest::Method::POST,
                "/query/aql",
                Some(("application/json", bytes)),
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::SystemOptions => {
            let reply = client.request(reqwest::Method::OPTIONS, "/", None, false, None)?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::SmartConfigurationRead => {
            // Addressed at the PLATFORM base the ixit's `smart` lane names —
            // a different path root from the openEHR REST base (ITS-REST
            // docs/smart_app_launch/master04-service_discovery.adoc
            // §Service Discovery).
            let reply = client.request(
                reqwest::Method::GET,
                "/.well-known/smart-configuration",
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::OK
        }
        PerfOp::UnauthenticatedProbe => {
            // The DENY branch is the measured outcome: a credential-less
            // read must be refused, so 401 is the arrival's success and
            // anything else — 200 above all — is an error arrival.
            let reply = client.request(
                reqwest::Method::GET,
                &format!("/ehr/{ehr_id}"),
                None,
                false,
                None,
            )?;
            note(observed, reply.status) == StatusCode::UNAUTHORIZED
        }
        PerfOp::ReadonlyWriteDenied => {
            let template = planned
                .template
                .and_then(|i| journey_pack.get(i))
                .ok_or_else(|| "denied-write stage without a pack template".to_owned())?;
            let body = pack::composition_body(template, offset_s, arrival_index)?;
            let reply = client.request(
                reqwest::Method::POST,
                &format!("/ehr/{ehr_id}/composition"),
                Some(("application/json", body)),
                true,
                None,
            )?;
            // 403 is the arrival's success: the write is refused, so the
            // measured population is untouched by this probe.
            note(observed, reply.status) == StatusCode::FORBIDDEN
        }
    };

    if planned.last {
        captures.drop_journey(journey);
    }
    Ok(ok)
}

/// The versioned-object uid of the document a governance stage addresses:
/// the journey's own last commit, else the ward chart.
/// Re-resolve a ward document's CURRENT version after a failed versioned
/// update — what every real EHR client does on an optimistic-concurrency
/// conflict (re-read, then amend from the fresh version). Without it a
/// single lost race (409) or timed-out update leaves the tracked
/// `OBJECT_VERSION_ID` stale forever and every later update on that
/// patient fails — an instrument-made error cascade the first corrected-
/// pack ladder measured as a false knee (398/409 update failures at one
/// rung while the SUT answered every stale If-Match correctly). The
/// refresh rides INSIDE the failed arrival (its latency is that arrival's
/// honest conflict cost); the arrival still records as an error.
fn refresh_current_ovid(client: &PerfClient, path: &str) -> Option<String> {
    let reply = client
        .request(reqwest::Method::GET, path, None, false, None)
        .ok()?;
    if reply.status == StatusCode::OK {
        reply.etag.as_deref().map(strip_weak_quotes)
    } else {
        None
    }
}

/// The `OBJECT_VERSION_ID` of the version a provenance stage addresses:
/// the journey's own last commit, else the ward chart's seeded version.
fn current_version_uid(
    planned: &PlannedArrival,
    captures: &CaptureStore,
    ward: Option<&crate::perf_run::corpus::WardPatient>,
) -> Option<String> {
    captures
        .journey(planned.journey, |s| s.last_commit_ovid.clone())
        .flatten()
        .or_else(|| {
            ward.map(|w| match planned.doc {
                WardDoc::MedList => w.medlist_ovid.clone(),
                WardDoc::Gp => w.gp_ovid.clone(),
            })
        })
}

fn current_doc_object_uid(
    planned: &PlannedArrival,
    captures: &CaptureStore,
    ward: Option<&crate::perf_run::corpus::WardPatient>,
) -> Option<String> {
    captures
        .journey(planned.journey, |s| s.last_commit_ovid.clone())
        .flatten()
        .map(|ovid| object_uid_of(&ovid))
        .or_else(|| {
            ward.map(|w| match planned.doc {
                WardDoc::MedList => object_uid_of(&w.medlist_ovid),
                WardDoc::Gp => object_uid_of(&w.gp_ovid),
            })
        })
}

#[cfg(test)]
#[expect(
    clippy::disallowed_types,
    reason = "the ixit fixtures are authored as wire JSON, the shape the loader reads"
)]
mod tests {
    use super::*;

    #[test]
    fn the_capture_store_scopes_journeys_and_drops_them() {
        let store = CaptureStore::new();
        store.journey(7, |s| s.ehr_id = Some("e-7".to_owned()));
        store.journey(7 + 64, |s| s.ehr_id = Some("e-71".to_owned()));
        assert_eq!(
            store.journey(7, |s| s.ehr_id.clone()).flatten().as_deref(),
            Some("e-7")
        );
        assert_eq!(
            store
                .journey(7 + 64, |s| s.ehr_id.clone())
                .flatten()
                .as_deref(),
            Some("e-71")
        );
        store.drop_journey(7);
        assert_eq!(store.journey(7, |s| s.ehr_id.clone()).flatten(), None);
        // patient state rolls forward
        store.patient(3, |s| s.gp_ovid = Some("g::s::1".to_owned()));
        store.patient(3, |s| s.gp_ovid = Some("g::s::2".to_owned()));
        assert_eq!(
            store.patient(3, |s| s.gp_ovid.clone()).flatten().as_deref(),
            Some("g::s::2")
        );
    }

    /// A poisoned shard is recovered on the CLEANUP path too. A worker that
    /// panics while holding a shard poisons it for the rest of the window,
    /// and a cleanup that skipped the poisoned lock would leak every entry
    /// hashing there — the read path already recovers, so the two agree.
    #[test]
    fn the_cleanup_path_recovers_a_poisoned_shard() {
        let store = CaptureStore::new();
        store.journey(7, |s| s.ehr_id = Some("e-7".to_owned()));

        let previous = std::panic::take_hook();
        std::panic::set_hook(Box::new(|_| {}));
        let panicked = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
            let held = store.journeys[shard_of(7)].lock().unwrap();
            assert!(held.contains_key(&7));
            panic!("a worker dies holding the shard");
        }));
        std::panic::set_hook(previous);
        assert!(panicked.is_err(), "the holder must have unwound");
        assert!(
            store.journeys[shard_of(7)].is_poisoned(),
            "the shard must be poisoned for the test to mean anything"
        );

        store.drop_journey(7);
        assert_eq!(
            store.journey(7, |s| s.ehr_id.clone()).flatten(),
            None,
            "the poisoned shard leaked the dropped instance"
        );
    }

    /// The failure-sampling channel is a RECORDED wire number: `window.rs`
    /// renders it into the run's progress record, so `note` must leave a bare
    /// `u16` there however the status is held while comparing.
    #[test]
    fn the_failure_sampling_channel_records_a_bare_wire_number() {
        let mut observed = None;
        let returned = note(&mut observed, StatusCode::NOT_FOUND);
        assert_eq!(returned, StatusCode::NOT_FOUND, "the caller compares typed");
        assert_eq!(observed, Some(404), "the recorded channel stays a number");
        assert_eq!(
            observed.map(|status| format!("unexpected wire status {status}")),
            Some("unexpected wire status 404".to_owned())
        );
    }

    /// The two `Prefer: return=minimal` acceptance families, pinned against
    /// the neighbouring codes a numeric comparison could have confused.
    #[test]
    fn the_prefer_minimal_families_accept_exactly_their_codes() {
        assert!(created(StatusCode::CREATED) && created(StatusCode::NO_CONTENT));
        assert!(!created(StatusCode::OK) && !created(StatusCode::ACCEPTED));
        assert!(updated(StatusCode::OK) && updated(StatusCode::NO_CONTENT));
        assert!(!updated(StatusCode::CREATED) && !updated(StatusCode::RESET_CONTENT));
    }

    /// The EHR a stage addresses is resolved BEFORE the wire, and only the
    /// create addresses none. A fresh-EHR journey whose create has not
    /// landed refuses its later stage without sending anything, so an
    /// unresolved prerequisite is never a wire observation.
    #[test]
    fn a_fresh_ehr_stage_refuses_before_the_wire_when_the_create_has_not_landed() {
        let ixit: crate::ixit::Ixit = serde_json::from_value(serde_json::json!({
            "instances": { "sut": { "base_url": "http://stub", "auth": { "mode": "none" } } }
        }))
        .unwrap();
        let client = PerfClient::from_instance(ixit.default_instance().unwrap(), &ixit).unwrap();
        let corpus = SeededCorpus {
            corpus: "cnf.scale.10k".to_owned(),
            ehr_ids: Vec::new(),
            compositions: Vec::new(),
            ward: Vec::new(),
        };
        let pack = JourneyPack {
            templates: Vec::new(),
            aux: pack::AuxPayloads::default(),
        };
        let planned = PlannedArrival {
            at: std::time::Duration::ZERO,
            op: PerfOp::EhrRead,
            template: None,
            journey: 3,
            patient: None,
            doc: WardDoc::Gp,
            recorded: true,
            last: false,
        };
        let captures = CaptureStore::new();
        let mut observed = None;
        let error = perform(
            &client,
            0,
            &planned,
            &corpus,
            &pack,
            &captures,
            &mut observed,
        )
        .expect_err("an unresolved EHR refuses the stage");
        assert_eq!(error, "prerequisite EHR not yet created (SUT stall)");
        assert_eq!(observed, None, "nothing reached the wire");
    }

    #[test]
    fn strides_cycle_the_pool() {
        let a = stride(1) % 97;
        let b = stride(2) % 97;
        assert_ne!(a, b);
    }
}