greentic-deployer-dev 1.1.27219989263

Greentic deployer runtime for plan construction and deployment-pack dispatch
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
//! Black-box conformance bench for [`Deployer`] impls.
//!
//! [`run_conformance`] drives a candidate deployer through a small fixed
//! [`Environment`] and asserts the contract documented on the trait:
//! idempotency on every verb, structured rejection of `sum != 10000bps`
//! splits, independence across `deployment_id`, and projection
//! consistency for `report_runtime_config`. K8s/AWS slices call this
//! from a single integration test as the entry gate to declaring the
//! impl done.
//!
//! The fixture builds a 2-deployment / 3-revision env in memory — no
//! [`crate::environment::LocalFsStore`], no filesystem, no clock — so the
//! same harness runs identically against an in-process local-process
//! deployer and a kubectl-shelling-out K8s deployer.

use chrono::{TimeZone, Utc};
use greentic_deploy_spec::{
    BundleDeployment, BundleDeploymentStatus, BundleId, CustomerId, DeploymentId, EnvId,
    Environment, EnvironmentHostConfig, PackId, PackListEntry, PartyId, RevenueShareEntry,
    Revision, RevisionId, RevisionLifecycle, RouteBinding, SchemaVersion, TenantSelector,
    TrafficSplit, TrafficSplitEntry,
};
use thiserror::Error;
use ulid::Ulid;

use super::trait_def::{Deployer, DeployerError};

/// What can go wrong while running the bench.
///
/// Each variant pins the exact contract clause that failed so the
/// failing impl's author has a single line to chase.
#[derive(Debug, Error)]
pub enum ConformanceFailure {
    #[error("{verb}: first call returned Err: {source}")]
    HappyPathFailed {
        verb: &'static str,
        source: DeployerError,
    },

    #[error("{verb}: idempotent second call returned Err (impl is not idempotent): {source}")]
    NotIdempotent {
        verb: &'static str,
        source: DeployerError,
    },

    #[error(
        "apply_traffic_split: expected `DeployerError::InvalidSplit` for a sum={sum} split, got `Ok(_)` instead"
    )]
    InvalidSplitAccepted { sum: u64 },

    #[error(
        "apply_traffic_split: expected `DeployerError::InvalidSplit` for a sum={sum} split, got a different error variant: {source}"
    )]
    InvalidSplitWrongError { sum: u64, source: DeployerError },

    #[error(
        "apply_traffic_split: expected `DeployerError::SplitNotFound` for a deployment with no recorded split, got `Ok(_)` instead"
    )]
    MissingSplitAccepted,

    #[error(
        "apply_traffic_split: expected `DeployerError::SplitNotFound` for an unrecorded deployment, got a different error variant: {source}"
    )]
    MissingSplitWrongError { source: DeployerError },

    #[error(
        "{verb}: expected `DeployerError::RevisionNotFound` for an unknown revision id, got `Ok(_)` instead"
    )]
    UnknownRevisionAccepted { verb: &'static str },

    #[error(
        "{verb}: expected `DeployerError::RevisionNotFound` for an unknown revision id, got a different error variant: {source}"
    )]
    UnknownRevisionWrongError {
        verb: &'static str,
        source: DeployerError,
    },

    #[error(
        "report_runtime_config: projection does not match `materialize_runtime_config(env)`. \
         Override only if you splice provider-discovered values into existing blocks; do not \
         drop or reshape the spec projection."
    )]
    RuntimeConfigDrift,

    #[error(
        "apply_traffic_split: the impl's self-reported TrafficSplitOutcome does not match the \
         targeted deployment_id or the env's recorded entries (cross-deployment independence \
         violated or wrong deployment applied)"
    )]
    CrossDeploymentInterference,
}

/// Run the conformance bench against `deployer`.
///
/// On success, returns `Ok(())`. On failure, returns a single typed
/// [`ConformanceFailure`] naming the contract clause that broke — the
/// bench short-circuits at the first failure so the caller's test output
/// points at one cause, not a cascade.
pub async fn run_conformance<D: Deployer + ?Sized>(deployer: &D) -> Result<(), ConformanceFailure> {
    let env = build_fixture_env();
    let r_warm = env.revisions[0].revision_id;
    let r_drain = env.revisions[1].revision_id;
    let r_archive = env.revisions[2].revision_id;
    let dep_a = env.bundles[0].deployment_id;
    let dep_b = env.bundles[1].deployment_id;

    check_idempotent(
        "stage_revision",
        || deployer.stage_revision(&env, r_warm),
        || deployer.stage_revision(&env, r_warm),
    )
    .await?;
    check_idempotent(
        "warm_revision",
        || deployer.warm_revision(&env, r_warm),
        || deployer.warm_revision(&env, r_warm),
    )
    .await?;
    check_idempotent(
        "drain_revision",
        || deployer.drain_revision(&env, r_drain),
        || deployer.drain_revision(&env, r_drain),
    )
    .await?;
    check_idempotent(
        "archive_revision",
        || deployer.archive_revision(&env, r_archive),
        || deployer.archive_revision(&env, r_archive),
    )
    .await?;

    check_unknown_revision_rejected(deployer).await?;
    check_invalid_split_rejected(deployer).await?;
    check_missing_split_rejected(deployer).await?;

    check_idempotent(
        "apply_traffic_split",
        || deployer.apply_traffic_split(&env, dep_a),
        || deployer.apply_traffic_split(&env, dep_a),
    )
    .await?;
    check_idempotent(
        "apply_traffic_split[dep_b]",
        || deployer.apply_traffic_split(&env, dep_b),
        || deployer.apply_traffic_split(&env, dep_b),
    )
    .await?;
    check_cross_deployment_independence(deployer, &env, dep_a, dep_b).await?;

    check_runtime_config_projection(deployer, &env)?;

    Ok(())
}

async fn check_idempotent<T, Fut, F1, F2>(
    verb: &'static str,
    first: F1,
    second: F2,
) -> Result<(), ConformanceFailure>
where
    Fut: std::future::Future<Output = Result<T, DeployerError>>,
    F1: FnOnce() -> Fut,
    F2: FnOnce() -> Fut,
{
    if let Err(source) = first().await {
        return Err(ConformanceFailure::HappyPathFailed { verb, source });
    }
    match second().await {
        Ok(_) => Ok(()),
        Err(source) => Err(ConformanceFailure::NotIdempotent { verb, source }),
    }
}

async fn check_unknown_revision_rejected<D: Deployer + ?Sized>(
    deployer: &D,
) -> Result<(), ConformanceFailure> {
    let env = build_fixture_env();
    // 0xFFFF is distinct from every fixture ULID (those use small
    // single-digit u128 seeds — see `build_fixture_env`).
    let unknown = RevisionId(Ulid::from(0xFFFF_u128));
    classify_unknown_revision(
        "stage_revision",
        deployer.stage_revision(&env, unknown).await.map(|_| ()),
    )?;
    classify_unknown_revision(
        "warm_revision",
        deployer.warm_revision(&env, unknown).await.map(|_| ()),
    )?;
    classify_unknown_revision(
        "drain_revision",
        deployer.drain_revision(&env, unknown).await.map(|_| ()),
    )?;
    classify_unknown_revision(
        "archive_revision",
        deployer.archive_revision(&env, unknown).await.map(|_| ()),
    )?;
    Ok(())
}

fn classify_unknown_revision(
    verb: &'static str,
    result: Result<(), DeployerError>,
) -> Result<(), ConformanceFailure> {
    match result {
        Ok(()) => Err(ConformanceFailure::UnknownRevisionAccepted { verb }),
        Err(DeployerError::RevisionNotFound { .. }) => Ok(()),
        Err(source) => Err(ConformanceFailure::UnknownRevisionWrongError { verb, source }),
    }
}

async fn check_invalid_split_rejected<D: Deployer + ?Sized>(
    deployer: &D,
) -> Result<(), ConformanceFailure> {
    let env = build_env_with_invalid_split();
    let dep = env.bundles[0].deployment_id;
    let sum: u64 = env.traffic_splits[0]
        .entries
        .iter()
        .map(|e| u64::from(e.weight_bps))
        .sum();
    match deployer.apply_traffic_split(&env, dep).await {
        Ok(_) => Err(ConformanceFailure::InvalidSplitAccepted { sum }),
        Err(DeployerError::InvalidSplit { .. }) => Ok(()),
        Err(source) => Err(ConformanceFailure::InvalidSplitWrongError { sum, source }),
    }
}

async fn check_missing_split_rejected<D: Deployer + ?Sized>(
    deployer: &D,
) -> Result<(), ConformanceFailure> {
    let env = build_env_without_split();
    let dep = env.bundles[0].deployment_id;
    match deployer.apply_traffic_split(&env, dep).await {
        Ok(_) => Err(ConformanceFailure::MissingSplitAccepted),
        Err(DeployerError::SplitNotFound { .. }) => Ok(()),
        Err(source) => Err(ConformanceFailure::MissingSplitWrongError { source }),
    }
}

async fn check_cross_deployment_independence<D: Deployer + ?Sized>(
    deployer: &D,
    env: &Environment,
    dep_a: DeploymentId,
    dep_b: DeploymentId,
) -> Result<(), ConformanceFailure> {
    let expected_a = env
        .traffic_splits
        .iter()
        .find(|s| s.deployment_id == dep_a)
        .map(|s| s.entries.clone())
        .unwrap_or_default();
    let expected_b = env
        .traffic_splits
        .iter()
        .find(|s| s.deployment_id == dep_b)
        .map(|s| s.entries.clone())
        .unwrap_or_default();

    let outcome_a = deployer
        .apply_traffic_split(env, dep_a)
        .await
        .map_err(|source| ConformanceFailure::HappyPathFailed {
            verb: "apply_traffic_split[cross-dep:a]",
            source,
        })?;
    if outcome_a.applied_deployment_id != dep_a || outcome_a.applied_entries != expected_a {
        return Err(ConformanceFailure::CrossDeploymentInterference);
    }

    let outcome_b = deployer
        .apply_traffic_split(env, dep_b)
        .await
        .map_err(|source| ConformanceFailure::HappyPathFailed {
            verb: "apply_traffic_split[cross-dep:b]",
            source,
        })?;
    if outcome_b.applied_deployment_id != dep_b || outcome_b.applied_entries != expected_b {
        return Err(ConformanceFailure::CrossDeploymentInterference);
    }
    Ok(())
}

fn check_runtime_config_projection<D: Deployer + ?Sized>(
    deployer: &D,
    env: &Environment,
) -> Result<(), ConformanceFailure> {
    let reported = deployer.report_runtime_config(env);
    let expected = crate::environment::runtime_config::materialize_runtime_config(env);
    if reported != expected {
        return Err(ConformanceFailure::RuntimeConfigDrift);
    }
    Ok(())
}

// ---------- Fixture builders (internal — keep narrow) ----------

const FIXTURE_ENV_ID: &str = "conformance";
const FIXTURE_BUNDLE_A: &str = "bundle.a";
const FIXTURE_BUNDLE_B: &str = "bundle.b";

fn build_fixture_env() -> Environment {
    // Deterministic u128 seeds — fixture revisions/deployments stay
    // distinct from the unknown-revision sentinel (0xFFFF) used in
    // `check_unknown_revision_rejected`.
    let env_id = EnvId::try_from(FIXTURE_ENV_ID).expect("fixture env_id is valid");
    let dep_a = DeploymentId(Ulid::from(0x01_u128));
    let dep_b = DeploymentId(Ulid::from(0x02_u128));
    let bundle_a = BundleId::new(FIXTURE_BUNDLE_A);
    let bundle_b = BundleId::new(FIXTURE_BUNDLE_B);
    let r_warm = RevisionId(Ulid::from(0x10_u128));
    let r_drain = RevisionId(Ulid::from(0x20_u128));
    let r_archive = RevisionId(Ulid::from(0x30_u128));

    Environment {
        schema: SchemaVersion::new(SchemaVersion::ENVIRONMENT_V1),
        environment_id: env_id.clone(),
        name: env_id.as_str().to_string(),
        host_config: EnvironmentHostConfig {
            env_id: env_id.clone(),
            region: None,
            tenant_org_id: None,
            listen_addr: None,
            public_base_url: None,
        },
        packs: Vec::new(),
        credentials_ref: None,
        bundles: vec![
            make_bundle(&env_id, dep_a, &bundle_a),
            make_bundle(&env_id, dep_b, &bundle_b),
        ],
        revisions: vec![
            make_revision(&env_id, dep_a, &bundle_a, r_warm, RevisionLifecycle::Ready),
            make_revision(&env_id, dep_a, &bundle_a, r_drain, RevisionLifecycle::Ready),
            make_revision(
                &env_id,
                dep_b,
                &bundle_b,
                r_archive,
                RevisionLifecycle::Inactive,
            ),
        ],
        traffic_splits: vec![
            make_split(
                &env_id,
                dep_a,
                &bundle_a,
                vec![(r_warm, 5000), (r_drain, 5000)],
            ),
            make_split(&env_id, dep_b, &bundle_b, vec![(r_archive, 10000)]),
        ],
        messaging_endpoints: Vec::new(),
        extensions: Vec::new(),
        revocation: Default::default(),
        retention: Default::default(),
        health: Default::default(),
    }
}

fn build_env_with_invalid_split() -> Environment {
    let mut env = build_fixture_env();
    // First split now sums to 9000 — violates the 10000-bps invariant.
    env.traffic_splits[0].entries = vec![
        TrafficSplitEntry {
            revision_id: env.revisions[0].revision_id,
            weight_bps: 4000,
        },
        TrafficSplitEntry {
            revision_id: env.revisions[1].revision_id,
            weight_bps: 5000,
        },
    ];
    env
}

fn build_env_without_split() -> Environment {
    let mut env = build_fixture_env();
    let dep_a = env.bundles[0].deployment_id;
    env.traffic_splits.retain(|s| s.deployment_id != dep_a);
    env
}

fn make_bundle(
    env_id: &EnvId,
    deployment_id: DeploymentId,
    bundle_id: &BundleId,
) -> BundleDeployment {
    BundleDeployment {
        schema: SchemaVersion::new(SchemaVersion::BUNDLE_DEPLOYMENT_V1),
        deployment_id,
        env_id: env_id.clone(),
        bundle_id: bundle_id.clone(),
        customer_id: CustomerId::new("conformance-customer"),
        status: BundleDeploymentStatus::Active,
        current_revisions: Vec::new(),
        route_binding: RouteBinding {
            hosts: vec![format!("{}.conformance.local", bundle_id.as_str())],
            path_prefixes: Vec::new(),
            tenant_selector: TenantSelector {
                tenant: "default".to_string(),
                team: "default".to_string(),
            },
        },
        revenue_share: vec![RevenueShareEntry {
            party_id: PartyId::new("greentic"),
            basis_points: 10_000,
        }],
        revenue_policy_ref: std::path::PathBuf::from("revenue.json"),
        usage: None,
        created_at: Utc.with_ymd_and_hms(2026, 1, 1, 0, 0, 0).single().unwrap(),
        authorization_ref: std::path::PathBuf::from("auth.json"),
        config_overrides: Default::default(),
    }
}

fn make_revision(
    env_id: &EnvId,
    deployment_id: DeploymentId,
    bundle_id: &BundleId,
    revision_id: RevisionId,
    lifecycle: RevisionLifecycle,
) -> Revision {
    Revision {
        schema: SchemaVersion::new(SchemaVersion::REVISION_V1),
        revision_id,
        env_id: env_id.clone(),
        bundle_id: bundle_id.clone(),
        deployment_id,
        sequence: 1,
        created_at: Utc.with_ymd_and_hms(2026, 1, 1, 0, 0, 0).single().unwrap(),
        bundle_digest: "sha256:0000000000000000000000000000000000000000000000000000000000000000"
            .to_string(),
        pack_list: vec![PackListEntry::from_lock_primitives(
            PackId::new("greentic.fixture.pack"),
            "sha256:0000000000000000000000000000000000000000000000000000000000000000".to_string(),
        )],
        pack_list_lock_ref: std::path::PathBuf::from("pack-list.lock"),
        pack_config_refs: Vec::new(),
        config_digest: "sha256:0000".to_string(),
        signature_sidecar_ref: std::path::PathBuf::from("rev.sig"),
        lifecycle,
        staged_at: None,
        warmed_at: None,
        drain_seconds: 30,
        abort_metrics: Vec::new(),
    }
}

fn make_split(
    env_id: &EnvId,
    deployment_id: DeploymentId,
    bundle_id: &BundleId,
    entries: Vec<(RevisionId, u32)>,
) -> TrafficSplit {
    TrafficSplit {
        schema: SchemaVersion::new(SchemaVersion::TRAFFIC_SPLIT_V1),
        env_id: env_id.clone(),
        deployment_id,
        bundle_id: bundle_id.clone(),
        generation: 1,
        entries: entries
            .into_iter()
            .map(|(revision_id, weight_bps)| TrafficSplitEntry {
                revision_id,
                weight_bps,
            })
            .collect(),
        updated_at: Utc.with_ymd_and_hms(2026, 1, 1, 0, 0, 0).single().unwrap(),
        updated_by: "conformance".to_string(),
        idempotency_key: "conformance".to_string(),
        authorization_ref: std::path::PathBuf::from("auth.json"),
        previous_split_ref: None,
    }
}

#[cfg(test)]
mod tests {
    //! Self-checks on the bench itself, using a couple of stub `Deployer`
    //! impls. These guard the bench's assertion shape against drift — a
    //! real impl (local-process / K8s / AWS) gets a single
    //! `run_conformance` call from its own integration test, not these.

    use super::*;
    use async_trait::async_trait;

    /// A trivially-passing deployer: every verb succeeds, all
    /// preconditions checked correctly, default `report_runtime_config`.
    #[derive(Debug, Default)]
    struct NoopDeployer;

    #[async_trait]
    impl Deployer for NoopDeployer {
        async fn stage_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<StageOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(StageOutcome::default())
        }

        async fn warm_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<WarmOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(WarmOutcome::default())
        }

        async fn drain_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<DrainOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(DrainOutcome::default())
        }

        async fn archive_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<ArchiveOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(ArchiveOutcome::default())
        }

        async fn apply_traffic_split(
            &self,
            env: &Environment,
            deployment_id: DeploymentId,
        ) -> Result<TrafficSplitOutcome, DeployerError> {
            enforce_split_invariants(env, deployment_id)
        }
    }

    /// Imports `Deployer`'s associated outcome types + shared precondition
    /// helpers into scope so the test stubs line up with the canonical
    /// shape every Phase D impl uses.
    use super::super::trait_def::{
        ArchiveOutcome, DrainOutcome, StageOutcome, TrafficSplitOutcome, WarmOutcome,
        enforce_split_invariants, require_revision,
    };

    #[tokio::test]
    async fn noop_deployer_passes() {
        let d = NoopDeployer;
        run_conformance(&d)
            .await
            .expect("noop impl satisfies the contract");
    }

    /// Deployer that breaks idempotency on `warm_revision` — the bench
    /// must surface `NotIdempotent` pointing at that verb.
    #[derive(Debug, Default)]
    struct OneShotWarm {
        called: std::sync::atomic::AtomicBool,
    }

    #[async_trait]
    impl Deployer for OneShotWarm {
        async fn stage_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<StageOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(StageOutcome::default())
        }

        async fn warm_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<WarmOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            if self.called.swap(true, std::sync::atomic::Ordering::SeqCst) {
                return Err(DeployerError::Provider("already warmed".to_string()));
            }
            Ok(WarmOutcome::default())
        }

        async fn drain_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<DrainOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(DrainOutcome::default())
        }

        async fn archive_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<ArchiveOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(ArchiveOutcome::default())
        }

        async fn apply_traffic_split(
            &self,
            env: &Environment,
            deployment_id: DeploymentId,
        ) -> Result<TrafficSplitOutcome, DeployerError> {
            enforce_split_invariants(env, deployment_id)
        }
    }

    #[tokio::test]
    async fn bench_detects_non_idempotent_warm() {
        let d = OneShotWarm::default();
        let err = run_conformance(&d)
            .await
            .expect_err("warm is non-idempotent");
        assert!(
            matches!(
                err,
                ConformanceFailure::NotIdempotent {
                    verb: "warm_revision",
                    ..
                }
            ),
            "expected NotIdempotent(warm_revision), got {err:?}"
        );
    }

    /// Deployer that accepts an out-of-spec split sum — bench must
    /// surface `InvalidSplitAccepted`.
    #[derive(Debug, Default)]
    struct LaxSplit;

    #[async_trait]
    impl Deployer for LaxSplit {
        async fn stage_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<StageOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(StageOutcome::default())
        }
        async fn warm_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<WarmOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(WarmOutcome::default())
        }
        async fn drain_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<DrainOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(DrainOutcome::default())
        }
        async fn archive_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<ArchiveOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(ArchiveOutcome::default())
        }
        async fn apply_traffic_split(
            &self,
            _env: &Environment,
            deployment_id: DeploymentId,
        ) -> Result<TrafficSplitOutcome, DeployerError> {
            // Doesn't check the sum — should fail the bench.
            Ok(TrafficSplitOutcome {
                applied_deployment_id: deployment_id,
                applied_entries: Vec::new(),
            })
        }
    }

    #[tokio::test]
    async fn bench_detects_lax_split_validation() {
        let d = LaxSplit;
        let err = run_conformance(&d)
            .await
            .expect_err("invalid split must be rejected");
        assert!(
            matches!(err, ConformanceFailure::InvalidSplitAccepted { .. }),
            "expected InvalidSplitAccepted, got {err:?}"
        );
    }

    /// Deployer that always reports a fixed wrong `applied_deployment_id`
    /// in its `TrafficSplitOutcome`, regardless of the actual input.
    /// The bench must surface `CrossDeploymentInterference`.
    #[derive(Debug, Default)]
    struct WrongDeploymentReporter;

    #[async_trait]
    impl Deployer for WrongDeploymentReporter {
        async fn stage_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<StageOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(StageOutcome::default())
        }
        async fn warm_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<WarmOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(WarmOutcome::default())
        }
        async fn drain_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<DrainOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(DrainOutcome::default())
        }
        async fn archive_revision(
            &self,
            env: &Environment,
            revision_id: RevisionId,
        ) -> Result<ArchiveOutcome, DeployerError> {
            require_revision(env, revision_id)?;
            Ok(ArchiveOutcome::default())
        }
        async fn apply_traffic_split(
            &self,
            env: &Environment,
            deployment_id: DeploymentId,
        ) -> Result<TrafficSplitOutcome, DeployerError> {
            // Borrow the shared precondition path, then corrupt the
            // self-report so the bench's cross-deployment check fires.
            let mut outcome = enforce_split_invariants(env, deployment_id)?;
            outcome.applied_deployment_id = DeploymentId(Ulid::from(0xDEAD_u128));
            Ok(outcome)
        }
    }

    #[tokio::test]
    async fn bench_detects_wrong_deployment_id_in_outcome() {
        let d = WrongDeploymentReporter;
        let err = run_conformance(&d)
            .await
            .expect_err("wrong deployment id in outcome must be caught");
        assert!(
            matches!(err, ConformanceFailure::CrossDeploymentInterference),
            "expected CrossDeploymentInterference, got {err:?}"
        );
    }
}