lifeloop-cli 0.2.0

Provider-neutral lifecycle abstraction and normalizer for AI harnesses
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
//! Permanent Lifeloop conformance fixture suite — issue #10.
//!
//! This is the post-extraction gate that proves Lifeloop adapters and
//! clients continue to satisfy the public contract independent of the
//! pre-extraction CCD reference corpus. Fixtures live as JSON under
//! `tests/conformance/` so they can be read by Lifeloop AND by an
//! external client implementation in another language without taking
//! a Rust-only dependency.
//!
//! # Layout
//!
//! Every JSON file under `tests/conformance/<category>/<name>.json`
//! is a self-describing fixture envelope:
//!
//! ```json
//! {
//!   "kind": "<contract type>",
//!   "expect": "valid" | "invalid",
//!   "expect_error":   "<optional substring of the validation error>",
//!   "description":    "<one-line human note>",
//!   "data":           { ... actual contract object ... }
//! }
//! ```
//!
//! The harness is data-driven: it discovers every `*.json` under
//! `tests/conformance/` at test time, deserializes by `kind`, and
//! asserts the `expect` outcome. Add a fixture by adding a file; no
//! Rust changes required for normal coverage growth.
//!
//! # Determinism
//!
//! No clock, no network, no random IDs. Stable strings throughout.
//! `at_epoch_s`, `observed_at_epoch_s`, etc. are pinned literals.

use std::collections::BTreeSet;
use std::fs;
use std::path::{Path, PathBuf};

use lifeloop::router::{
    LifeloopFailureMapper, TransportError, classes_for_negotiation_outcome,
    failure_class_for_transport, retry_class_for,
};
use lifeloop::telemetry::PressureObservation;
use lifeloop::{
    AdapterManifest, CallbackRequest, CallbackResponse, FailureClass, FrameContext,
    LifecycleEventKind, LifecycleReceipt, NegotiationOutcome, PayloadEnvelope, PlacementClass,
    RetryClass,
};
use serde::Deserialize;
use serde_json::Value;

// ---------------------------------------------------------------------------
// Fixture envelope
// ---------------------------------------------------------------------------

#[derive(Debug, Deserialize)]
struct Fixture {
    kind: String,
    expect: Expect,
    #[serde(default)]
    expect_error: Option<String>,
    #[serde(default)]
    description: Option<String>,
    data: Value,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "snake_case")]
enum Expect {
    Valid,
    Invalid,
}

// ---------------------------------------------------------------------------
// Discovery
// ---------------------------------------------------------------------------

fn conformance_root() -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("tests")
        .join("conformance")
}

/// Recursively gather every `*.json` file under `root`, sorted for
/// reproducible test order.
fn collect_fixtures(root: &Path) -> Vec<PathBuf> {
    let mut out = Vec::new();
    let mut stack = vec![root.to_path_buf()];
    while let Some(dir) = stack.pop() {
        let entries = match fs::read_dir(&dir) {
            Ok(entries) => entries,
            Err(_) => continue,
        };
        for entry in entries.flatten() {
            let path = entry.path();
            if path.is_dir() {
                stack.push(path);
            } else if path.extension().and_then(|s| s.to_str()) == Some("json") {
                out.push(path);
            }
        }
    }
    out.sort();
    out
}

fn load(path: &Path) -> Fixture {
    let bytes = fs::read(path).unwrap_or_else(|e| panic!("read {path:?}: {e}"));
    serde_json::from_slice::<Fixture>(&bytes)
        .unwrap_or_else(|e| panic!("parse fixture envelope {path:?}: {e}"))
}

// ---------------------------------------------------------------------------
// Per-kind dispatch
// ---------------------------------------------------------------------------

/// Run a fixture: deserialize `data` as the typed contract object,
/// invoke `validate()`, and assert `expect` matches the outcome.
///
/// Returns the textual outcome category for use in coverage assertions.
fn run_one(path: &Path, fixture: &Fixture) -> &'static str {
    let kind = fixture.kind.as_str();
    let result: Result<(), String> = match kind {
        "callback_request" => parse_and_validate::<CallbackRequest>(&fixture.data),
        "callback_response" => parse_and_validate::<CallbackResponse>(&fixture.data),
        "lifecycle_receipt" => parse_and_validate::<LifecycleReceipt>(&fixture.data),
        "payload_envelope" => parse_and_validate::<PayloadEnvelope>(&fixture.data),
        "frame_context" => parse_and_validate::<FrameContext>(&fixture.data),
        "adapter_manifest" => parse_and_validate::<AdapterManifest>(&fixture.data),
        "pressure_observation" => parse_only::<PressureObservation>(&fixture.data),
        "client_class" => run_client_class(&fixture.data),
        "capability_negotiation" => run_capability_negotiation(&fixture.data),
        "failure_mapping" => run_failure_mapping(&fixture.data),
        other => panic!("{path:?}: unknown fixture kind `{other}`"),
    };

    match (result, fixture.expect) {
        (Ok(()), Expect::Valid) => "valid_ok",
        (Err(msg), Expect::Invalid) => {
            if let Some(needle) = &fixture.expect_error {
                assert!(
                    msg.contains(needle),
                    "{path:?}: expected error containing `{needle}`, got `{msg}`"
                );
            }
            "invalid_ok"
        }
        (Ok(()), Expect::Invalid) => {
            panic!("{path:?}: fixture expected to be invalid but parsed and validated cleanly")
        }
        (Err(msg), Expect::Valid) => {
            panic!("{path:?}: fixture expected to be valid but failed: {msg}")
        }
    }
}

/// Generic deserialize-then-validate path for types with a `validate()`
/// method.
trait ContractObject: serde::de::DeserializeOwned {
    fn run_validate(&self) -> Result<(), String>;
}

impl ContractObject for CallbackRequest {
    fn run_validate(&self) -> Result<(), String> {
        self.validate().map_err(|e| e.to_string())
    }
}
impl ContractObject for CallbackResponse {
    fn run_validate(&self) -> Result<(), String> {
        self.validate().map_err(|e| e.to_string())
    }
}
impl ContractObject for LifecycleReceipt {
    fn run_validate(&self) -> Result<(), String> {
        self.validate().map_err(|e| e.to_string())
    }
}
impl ContractObject for PayloadEnvelope {
    fn run_validate(&self) -> Result<(), String> {
        self.validate().map_err(|e| e.to_string())
    }
}
impl ContractObject for FrameContext {
    fn run_validate(&self) -> Result<(), String> {
        self.validate().map_err(|e| e.to_string())
    }
}
impl ContractObject for AdapterManifest {
    fn run_validate(&self) -> Result<(), String> {
        self.validate().map_err(|e| e.to_string())
    }
}

fn parse_and_validate<T: ContractObject>(data: &Value) -> Result<(), String> {
    let typed: T = serde_json::from_value(data.clone()).map_err(|e| format!("deserialize: {e}"))?;
    typed.run_validate()
}

/// Types with no `validate()` (e.g. PressureObservation) — parse-only
/// roundtrip + reserialize confirms wire shape stability.
fn parse_only<T: serde::de::DeserializeOwned + serde::Serialize>(
    data: &Value,
) -> Result<(), String> {
    let typed: T = serde_json::from_value(data.clone()).map_err(|e| format!("deserialize: {e}"))?;
    let _back = serde_json::to_value(&typed).map_err(|e| format!("reserialize: {e}"))?;
    Ok(())
}

// ---------------------------------------------------------------------------
// Custom fixture kinds
// ---------------------------------------------------------------------------

/// Client-class fixtures describe how a particular client shape uses
/// the contract. They carry a stable `client_id`, the `payload_kind`
/// strings that client emits, and a worked example payload. The
/// harness verifies the example payload is a valid `PayloadEnvelope`.
#[derive(Debug, Deserialize)]
struct ClientClassFixture {
    client_id: String,
    description: String,
    payload_kinds: Vec<String>,
    example_payload: Value,
}

fn run_client_class(data: &Value) -> Result<(), String> {
    let cls: ClientClassFixture =
        serde_json::from_value(data.clone()).map_err(|e| format!("deserialize: {e}"))?;
    if cls.client_id.is_empty() {
        return Err("client_id must not be empty".into());
    }
    if cls.description.is_empty() {
        return Err("description must not be empty".into());
    }
    if cls.payload_kinds.is_empty() {
        return Err("payload_kinds must list at least one kind".into());
    }
    let payload: PayloadEnvelope = serde_json::from_value(cls.example_payload.clone())
        .map_err(|e| format!("example_payload deserialize: {e}"))?;
    payload.validate().map_err(|e| e.to_string())?;
    if payload.client_id != cls.client_id {
        return Err(format!(
            "example_payload.client_id `{}` must match fixture client_id `{}`",
            payload.client_id, cls.client_id
        ));
    }
    if !cls.payload_kinds.contains(&payload.payload_kind) {
        return Err(format!(
            "example_payload.payload_kind `{}` not in declared payload_kinds {:?}",
            payload.payload_kind, cls.payload_kinds
        ));
    }
    Ok(())
}

/// Capability-negotiation fixture: pins the (outcome, explicit) →
/// (failure_class, retry_class) projection from
/// `classes_for_negotiation_outcome`.
#[derive(Debug, Deserialize)]
struct CapabilityNegotiationFixture {
    outcome: NegotiationOutcome,
    #[serde(default)]
    explicit_failure_class: Option<FailureClass>,
    expected: Option<FailureRetryPair>,
}

#[derive(Debug, Deserialize)]
struct FailureRetryPair {
    failure_class: FailureClass,
    retry_class: RetryClass,
}

fn run_capability_negotiation(data: &Value) -> Result<(), String> {
    let fx: CapabilityNegotiationFixture =
        serde_json::from_value(data.clone()).map_err(|e| format!("deserialize: {e}"))?;
    let actual = classes_for_negotiation_outcome(fx.outcome, fx.explicit_failure_class);
    match (&actual, &fx.expected) {
        (None, None) => Ok(()),
        (Some((af, ar)), Some(exp)) => {
            if *af == exp.failure_class && *ar == exp.retry_class {
                Ok(())
            } else {
                Err(format!(
                    "negotiation projection mismatch: got ({af:?}, {ar:?}), expected ({:?}, {:?})",
                    exp.failure_class, exp.retry_class
                ))
            }
        }
        (None, Some(exp)) => Err(format!(
            "expected ({:?}, {:?}) but classes_for_negotiation_outcome returned None",
            exp.failure_class, exp.retry_class
        )),
        (Some(pair), None) => Err(format!(
            "expected None but classes_for_negotiation_outcome returned {pair:?}"
        )),
    }
}

/// Failure-mapping fixture: pins the FailureClass → RetryClass default
/// projection, and optionally a TransportError example.
#[derive(Debug, Deserialize)]
struct FailureMappingFixture {
    failure_class: FailureClass,
    expected_retry_class: RetryClass,
    #[serde(default)]
    transport_example: Option<TransportExample>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case", tag = "kind", content = "detail")]
enum TransportExample {
    Io(String),
    Timeout,
    Internal(String),
}

fn run_failure_mapping(data: &Value) -> Result<(), String> {
    let fx: FailureMappingFixture =
        serde_json::from_value(data.clone()).map_err(|e| format!("deserialize: {e}"))?;
    let actual_retry = retry_class_for(fx.failure_class);
    if actual_retry != fx.expected_retry_class {
        return Err(format!(
            "default retry for {:?}: got {actual_retry:?}, expected {:?}",
            fx.failure_class, fx.expected_retry_class
        ));
    }
    // Cross-check via FailureClass::default_retry — the spec table.
    if fx.failure_class.default_retry() != fx.expected_retry_class {
        return Err(format!(
            "FailureClass::{:?}::default_retry diverges from expected_retry_class",
            fx.failure_class
        ));
    }
    // Transport example, when present, must funnel through the mapper
    // and produce the declared (failure_class, retry_class) pair.
    if let Some(example) = fx.transport_example {
        let te = match example {
            TransportExample::Io(d) => TransportError::Io(d),
            TransportExample::Timeout => TransportError::Timeout,
            TransportExample::Internal(d) => TransportError::Internal(d),
        };
        let mapper = LifeloopFailureMapper::new();
        let (fc, rc) = mapper.map_transport_error(&te);
        let direct_fc = failure_class_for_transport(&te);
        if direct_fc != fc {
            return Err(format!("free-fn vs mapper drift: {direct_fc:?} vs {fc:?}"));
        }
        if fc != fx.failure_class {
            return Err(format!(
                "transport_example maps to {fc:?} but fixture declares {:?}",
                fx.failure_class
            ));
        }
        if rc != fx.expected_retry_class {
            return Err(format!(
                "transport_example retry {rc:?} != expected {:?}",
                fx.expected_retry_class
            ));
        }
    }
    Ok(())
}

// ---------------------------------------------------------------------------
// Top-level test: walks every fixture file
// ---------------------------------------------------------------------------

#[test]
fn conformance_suite_walks_every_fixture() {
    let root = conformance_root();
    let files = collect_fixtures(&root);
    assert!(
        !files.is_empty(),
        "no conformance fixtures found under {root:?}"
    );

    let mut counts = std::collections::BTreeMap::<String, usize>::new();
    for path in &files {
        let fixture = load(path);
        let outcome = run_one(path, &fixture);
        let bucket = format!("{}.{}", fixture.kind, outcome);
        *counts.entry(bucket).or_default() += 1;
    }

    // Surface the per-bucket counts in test output so a regression that
    // silently drops fixtures (e.g. accidental .gitignore) is visible.
    eprintln!("conformance fixture counts: {counts:#?}");
    eprintln!("conformance fixture total: {}", files.len());
}

// ---------------------------------------------------------------------------
// Coverage gates: every public enum variant must be represented
// ---------------------------------------------------------------------------

fn all_event_fixtures() -> Vec<Fixture> {
    collect_fixtures(&conformance_root().join("events"))
        .iter()
        .map(|p| load(p))
        .collect()
}

fn all_placement_fixtures() -> Vec<Fixture> {
    collect_fixtures(&conformance_root().join("placements"))
        .iter()
        .map(|p| load(p))
        .collect()
}

fn all_receipt_fixtures() -> Vec<Fixture> {
    collect_fixtures(&conformance_root().join("receipts"))
        .iter()
        .map(|p| load(p))
        .collect()
}

fn all_failure_fixtures() -> Vec<Fixture> {
    collect_fixtures(&conformance_root().join("failures"))
        .iter()
        .map(|p| load(p))
        .collect()
}

fn all_manifest_fixtures() -> Vec<Fixture> {
    collect_fixtures(&conformance_root().join("manifests"))
        .iter()
        .map(|p| load(p))
        .collect()
}

fn all_client_fixtures() -> Vec<Fixture> {
    collect_fixtures(&conformance_root().join("clients"))
        .iter()
        .map(|p| load(p))
        .collect()
}

fn all_renewal_fixtures() -> Vec<Fixture> {
    collect_fixtures(&conformance_root().join("renewal"))
        .iter()
        .map(|p| load(p))
        .collect()
}

#[test]
fn every_lifecycle_event_kind_has_an_event_fixture() {
    let mut covered = BTreeSet::new();
    for fx in all_event_fixtures() {
        assert_eq!(
            fx.kind, "callback_request",
            "events/ fixtures must be callback_request kind"
        );
        // Read the event field off the data blob.
        let event = fx
            .data
            .get("event")
            .and_then(|v| v.as_str())
            .unwrap_or_else(|| panic!("event fixture missing data.event: {:?}", fx.description));
        covered.insert(event.to_string());
    }
    let expected: BTreeSet<String> = LifecycleEventKind::ALL
        .iter()
        .map(|kind| {
            serde_json::to_value(kind)
                .unwrap()
                .as_str()
                .unwrap()
                .to_string()
        })
        .collect();
    let missing: Vec<_> = expected.difference(&covered).collect();
    assert!(
        missing.is_empty(),
        "events/ fixtures missing coverage for lifecycle event kinds: {missing:?}"
    );
}

#[test]
fn every_placement_class_has_a_placement_fixture() {
    let mut covered = BTreeSet::new();
    for fx in all_placement_fixtures() {
        assert_eq!(
            fx.kind, "payload_envelope",
            "placements/ fixtures must be payload_envelope kind"
        );
        // The first acceptable placement is what the fixture demonstrates.
        let placement = fx
            .data
            .get("acceptable_placements")
            .and_then(|v| v.as_array())
            .and_then(|arr| arr.first())
            .and_then(|p| p.get("placement"))
            .and_then(|v| v.as_str())
            .unwrap_or_else(|| {
                panic!(
                    "placement fixture missing acceptable_placements[0].placement: {:?}",
                    fx.description
                )
            });
        covered.insert(placement.to_string());
    }
    let expected: BTreeSet<String> = PlacementClass::ALL
        .iter()
        .map(|c| {
            serde_json::to_value(c)
                .unwrap()
                .as_str()
                .unwrap()
                .to_string()
        })
        .collect();
    let missing: Vec<_> = expected.difference(&covered).collect();
    assert!(
        missing.is_empty(),
        "placements/ fixtures missing coverage for placement classes: {missing:?}"
    );
}

#[test]
fn receipt_fixtures_cover_every_receipt_status_and_special_case() {
    // The contract requires applied/delivered, degraded, skipped, blocked,
    // failed, idempotency, conflict, and receipt-gap shapes. The blocked
    // surface in this contract is `Failed` + `OperatorRequired`; the
    // conformance fixture corpus carries it as `blocked.json`.
    let mut required: BTreeSet<&'static str> = [
        "delivered",
        "degraded",
        "skipped",
        "blocked",
        "failed",
        "idempotency",
        "conflict",
        "receipt_gap",
    ]
    .into_iter()
    .collect();
    for fx in all_receipt_fixtures() {
        if let Some(desc) = &fx.description {
            for tag in &required.clone() {
                if desc.contains(tag) {
                    required.remove(tag);
                }
            }
        }
    }
    assert!(
        required.is_empty(),
        "receipts/ corpus missing fixtures for: {required:?}"
    );
}

#[test]
fn failure_mapping_fixtures_cover_every_failure_class() {
    let mut covered = BTreeSet::new();
    for fx in all_failure_fixtures() {
        if fx.kind != "failure_mapping" {
            continue;
        }
        let class = fx
            .data
            .get("failure_class")
            .and_then(|v| v.as_str())
            .unwrap_or_else(|| panic!("failure_mapping fixture missing failure_class"));
        covered.insert(class.to_string());
    }
    let expected: BTreeSet<String> = FailureClass::ALL
        .iter()
        .map(|c| {
            serde_json::to_value(c)
                .unwrap()
                .as_str()
                .unwrap()
                .to_string()
        })
        .collect();
    let missing: Vec<_> = expected.difference(&covered).collect();
    assert!(
        missing.is_empty(),
        "failures/ corpus missing failure_mapping fixtures for: {missing:?}"
    );
}

#[test]
fn renewal_fixtures_cover_reset_prepare_and_continuation_delivery() {
    let mut payload_kinds = BTreeSet::new();
    for fx in all_renewal_fixtures() {
        assert_eq!(
            fx.kind, "lifecycle_receipt",
            "renewal/ fixtures must be lifecycle_receipt kind"
        );
        let receipts = fx
            .data
            .get("payload_receipts")
            .and_then(|v| v.as_array())
            .unwrap_or_else(|| panic!("renewal fixture missing payload_receipts"));
        for receipt in receipts {
            if let Some(kind) = receipt.get("payload_kind").and_then(|v| v.as_str()) {
                payload_kinds.insert(kind.to_string());
            }
        }
    }

    for required in [
        "lifeloop.renewal.reset_prepare",
        "lifeloop.renewal.continuation",
    ] {
        assert!(
            payload_kinds.contains(required),
            "renewal/ corpus missing payload kind `{required}`; saw {payload_kinds:?}"
        );
    }
}

#[test]
fn renewal_failure_mapping_fixtures_cover_issue_3_cases() {
    let mut descriptions = BTreeSet::new();
    for fx in all_failure_fixtures() {
        if let Some(desc) = fx.description {
            descriptions.insert(desc);
        }
    }
    for required in [
        "renewal reset unsupported",
        "renewal continuation delivery lost",
        "renewal capability went stale",
        "renewal path is manual-only",
    ] {
        assert!(
            descriptions.iter().any(|desc| desc.contains(required)),
            "failures/ corpus missing renewal case `{required}`"
        );
    }
}

#[test]
fn manifest_fixtures_cover_codex_and_claude_before_v1_freeze() {
    let mut ids = BTreeSet::new();
    for fx in all_manifest_fixtures() {
        if fx.kind != "adapter_manifest" {
            continue;
        }
        let id = fx
            .data
            .get("adapter_id")
            .and_then(|v| v.as_str())
            .unwrap_or_else(|| panic!("manifest fixture missing adapter_id"));
        ids.insert(id.to_string());
    }
    assert!(
        ids.contains("codex"),
        "manifests/ corpus missing codex (required for v1 freeze gate)"
    );
    assert!(
        ids.contains("claude"),
        "manifests/ corpus missing claude (required for v1 freeze gate)"
    );
}

#[test]
fn at_least_two_distinct_client_class_shapes_exist() {
    let mut clients = BTreeSet::new();
    for fx in all_client_fixtures() {
        assert_eq!(
            fx.kind, "client_class",
            "clients/ fixtures must be client_class"
        );
        let id = fx
            .data
            .get("client_id")
            .and_then(|v| v.as_str())
            .unwrap_or_else(|| panic!("client_class fixture missing client_id"));
        clients.insert(id.to_string());
    }
    assert!(
        clients.len() >= 2,
        "v1 freeze gate requires at least two client-class shapes; found: {clients:?}"
    );
}

// ---------------------------------------------------------------------------
// Spec-derived gate: the failure-class default retry table mirrored
// across every FailureClass variant via LifeloopFailureMapper. This
// runs even if a `failures/` fixture is dropped, so the table cannot
// silently drift away from the spec.
// ---------------------------------------------------------------------------

#[test]
fn failure_class_default_retry_table_is_complete_via_mapper() {
    // Each FailureClass variant must produce the same RetryClass
    // through both `FailureClass::default_retry()` and the
    // free-function `retry_class_for`, which the LifeloopFailureMapper
    // delegates to. This is the conformance-suite mirror of
    // `tests/spec_alignment.rs::failure_to_retry_default_table_matches_spec`.
    for fc in FailureClass::ALL {
        let direct = fc.default_retry();
        let via_helper = retry_class_for(*fc);
        assert_eq!(
            direct, via_helper,
            "FailureClass::{fc:?}: default_retry diverges from retry_class_for"
        );
    }
}