rocketmq-protocol 1.0.0

Runtime-neutral RocketMQ wire protocol contracts
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
// Copyright 2023 The RocketMQ Rust Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Versioned wire contracts for release snapshots and Store checkpoints.

use std::collections::BTreeSet;
use std::fmt;

use rocketmq_error::Sensitive;
use serde::Deserialize;
use serde::Serialize;

use crate::ProtocolContractViolation;

/// Current checkpoint manifest schema.
pub const RELEASE_CHECKPOINT_SCHEMA_VERSION: u16 = 1;

/// Non-sensitive capabilities returned after privileged authentication.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct MaintenanceCapabilitiesResponse {
    pub schema_version: u16,
    pub policy_id: String,
    pub policy_version: u64,
    pub operations: Vec<String>,
    pub max_checkpoint_bytes: u64,
    pub max_store_members: u32,
    pub max_concurrent_operations: u32,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub store: Option<MaintenanceStoreCapabilities>,
}

/// Store identity returned by a Broker maintenance endpoint.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct MaintenanceStoreCapabilities {
    pub member_id: String,
    pub backend: ReleaseCheckpointBackend,
    pub storage_identity: ReleaseCheckpointStorageIdentity,
}

/// Store implementation that produced a checkpoint.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ReleaseCheckpointBackend {
    /// Local CommitLog/ConsumeQueue/Index files.
    Local,
    /// RocksDB-managed Store state.
    RocksDb,
}

/// Consistent Store offsets captured after the checkpoint flush barrier.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct ReleaseCheckpointOffsets {
    /// Exclusive end of data accepted by the primary log.
    pub appended_offset: i64,
    /// Exclusive end durably flushed before checkpoint capture.
    pub durable_offset: i64,
    /// Highest physical source offset represented by ConsumeQueue.
    pub consume_queue_offset: i64,
    /// Highest physical source offset represented by Index.
    pub index_offset: i64,
}

impl ReleaseCheckpointOffsets {
    /// Validates ordering between append, durable, and derived progress.
    ///
    /// # Errors
    ///
    /// Returns a typed invariant error for a negative or out-of-order offset.
    pub fn validate(self) -> Result<(), ProtocolContractViolation> {
        if self.appended_offset < 0 || self.durable_offset < 0 || self.consume_queue_offset < 0 || self.index_offset < 0
        {
            return Err(ProtocolContractViolation::InvalidCheckpointOffsets {
                reason: "checkpoint offsets cannot be negative",
            });
        }
        if self.durable_offset > self.appended_offset {
            return Err(ProtocolContractViolation::InvalidCheckpointOffsets {
                reason: "durable_offset cannot exceed appended_offset",
            });
        }
        if self.consume_queue_offset > self.durable_offset || self.index_offset > self.durable_offset {
            return Err(ProtocolContractViolation::InvalidCheckpointOffsets {
                reason: "derived offsets cannot exceed durable_offset",
            });
        }
        Ok(())
    }
}

/// Persistent storage identity that rollback must preserve.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct ReleaseCheckpointStorageIdentity {
    /// Stable PersistentVolume or local-volume identity.
    pub volume_id: String,
    /// Store/WAL generation expected after restore.
    pub wal_generation: u64,
}

impl ReleaseCheckpointStorageIdentity {
    fn validate(&self) -> Result<(), ProtocolContractViolation> {
        require_identifier("storageIdentity.volumeId", &self.volume_id)?;
        if self.wal_generation == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "storageIdentity.walGeneration",
                reason: "must be greater than zero",
            });
        }
        Ok(())
    }
}

/// Shared identity and integrity fields for one checkpoint artifact.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct ReleaseCheckpointArtifact {
    /// Manifest schema.
    pub schema_version: u16,
    /// Globally unique checkpoint ID.
    pub checkpoint_id: String,
    /// Set containing this artifact.
    pub checkpoint_set_id: String,
    /// Storage/release generation.
    pub generation: u64,
    /// Shared write barrier ID.
    pub barrier_id: String,
    /// Artifact creation timestamp.
    pub created_at_unix_millis: u64,
    /// Uncompressed payload length.
    pub length_bytes: u64,
    /// Lowercase SHA-256 of the deterministic artifact payload.
    pub sha256: String,
    /// Durable artifact location.
    pub uri: String,
}

impl ReleaseCheckpointArtifact {
    /// Validates schema, identity, length, checksum, and URI.
    ///
    /// # Errors
    ///
    /// Returns a typed validation error when the artifact is incomplete.
    pub fn validate(&self) -> Result<(), ProtocolContractViolation> {
        if self.schema_version != RELEASE_CHECKPOINT_SCHEMA_VERSION {
            return Err(ProtocolContractViolation::CheckpointSchemaVersion {
                expected: RELEASE_CHECKPOINT_SCHEMA_VERSION,
                actual: self.schema_version,
            });
        }
        require_identifier("checkpointId", &self.checkpoint_id)?;
        require_identifier("checkpointSetId", &self.checkpoint_set_id)?;
        require_identifier("barrierId", &self.barrier_id)?;
        if self.generation == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "generation",
                reason: "must be greater than zero",
            });
        }
        if self.created_at_unix_millis == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "createdAtUnixMillis",
                reason: "must be greater than zero",
            });
        }
        if self.length_bytes == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "lengthBytes",
                reason: "must be greater than zero",
            });
        }
        require_sha256(&self.sha256)?;
        if self.uri.trim().is_empty() || self.uri.bytes().any(|byte| matches!(byte, b'\r' | b'\n')) {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "uri",
                reason: "must be a non-empty single-line URI",
            });
        }
        Ok(())
    }
}

/// Request body for creating a Controller snapshot under a shared barrier.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct ControllerReleaseSnapshotRequest {
    pub checkpoint_id: String,
    pub checkpoint_set_id: String,
    pub generation: u64,
    pub barrier_id: String,
}

impl ControllerReleaseSnapshotRequest {
    /// Validates the checkpoint-set identity supplied to the Controller.
    ///
    /// # Errors
    ///
    /// Returns a typed validation error when an identifier is non-canonical or
    /// the requested storage generation is zero.
    pub fn validate(&self) -> Result<(), ProtocolContractViolation> {
        require_identifier("checkpointId", &self.checkpoint_id)?;
        require_identifier("checkpointSetId", &self.checkpoint_set_id)?;
        require_identifier("barrierId", &self.barrier_id)?;
        if self.generation == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "generation",
                reason: "must be greater than zero",
            });
        }
        Ok(())
    }
}

/// Checksummed Controller snapshot manifest.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct ControllerReleaseSnapshotManifest {
    /// Shared artifact identity and integrity metadata.
    pub artifact: ReleaseCheckpointArtifact,
    /// OpenRaft snapshot identity embedded in the checksummed payload.
    pub snapshot_id: String,
    /// Last applied Raft log index captured after ReadIndex.
    pub last_applied_index: u64,
    /// Raft term of the last applied entry.
    pub last_applied_term: u64,
    /// Voter node IDs captured in the snapshot membership.
    pub voter_ids: Vec<u64>,
}

impl ControllerReleaseSnapshotManifest {
    /// Validates Controller snapshot invariants.
    ///
    /// # Errors
    ///
    /// Returns a typed validation error for invalid artifact metadata, missing
    /// applied state, or empty/duplicate voter membership.
    pub fn validate(&self) -> Result<(), ProtocolContractViolation> {
        self.artifact.validate()?;
        require_identifier("snapshotId", &self.snapshot_id)?;
        if self.last_applied_index == 0 || self.last_applied_term == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "lastApplied",
                reason: "term and index must be greater than zero",
            });
        }
        let voters = self.voter_ids.iter().copied().collect::<BTreeSet<_>>();
        if voters.is_empty() || voters.len() != self.voter_ids.len() || voters.contains(&0) {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "voterIds",
                reason: "must contain unique non-zero Controller voters",
            });
        }
        Ok(())
    }
}

/// Request body for creating one Store member checkpoint.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct StoreReleaseCheckpointRequest {
    pub checkpoint_id: String,
    pub checkpoint_set_id: String,
    pub generation: u64,
    pub barrier_id: String,
    pub member_id: String,
    pub offsets: ReleaseCheckpointOffsets,
    pub storage_identity: ReleaseCheckpointStorageIdentity,
}

impl StoreReleaseCheckpointRequest {
    /// Validates the set binding and pre-flush Store observations.
    ///
    /// # Errors
    ///
    /// Returns a typed validation error when any required identity, generation,
    /// offset, or storage identity is invalid.
    pub fn validate(&self) -> Result<(), ProtocolContractViolation> {
        require_identifier("checkpointId", &self.checkpoint_id)?;
        require_identifier("checkpointSetId", &self.checkpoint_set_id)?;
        require_identifier("barrierId", &self.barrier_id)?;
        require_identifier("memberId", &self.member_id)?;
        if self.generation == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "generation",
                reason: "must be greater than zero",
            });
        }
        self.offsets.validate()?;
        self.storage_identity.validate()
    }
}

/// Checksummed Store checkpoint manifest.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct StoreReleaseCheckpointManifest {
    /// Shared artifact identity and integrity metadata.
    pub artifact: ReleaseCheckpointArtifact,
    /// Store member bound by the checkpoint set.
    pub member_id: String,
    /// Backend that created the artifact.
    pub backend: ReleaseCheckpointBackend,
    /// Offsets observed after all required flushes completed.
    pub offsets: ReleaseCheckpointOffsets,
    /// Persistent storage identity that rollback must retain.
    pub storage_identity: ReleaseCheckpointStorageIdentity,
    /// Explicit proof that WAL files remain part of the checkpoint contract.
    pub wal_retained: bool,
    /// Explicit proof that rollback must reuse the existing persistent volume.
    pub persistent_volume_retained: bool,
}

impl StoreReleaseCheckpointManifest {
    /// Validates Store checkpoint integrity and non-destructive rollback invariants.
    ///
    /// # Errors
    ///
    /// Returns a typed validation error for an incomplete artifact, invalid
    /// offsets/storage identity, or a policy that permits WAL/PVC replacement.
    pub fn validate(&self) -> Result<(), ProtocolContractViolation> {
        self.artifact.validate()?;
        require_identifier("memberId", &self.member_id)?;
        self.offsets.validate()?;
        self.storage_identity.validate()?;
        if !self.wal_retained || !self.persistent_volume_retained {
            return Err(ProtocolContractViolation::DestructiveRollback);
        }
        Ok(())
    }
}

/// Complete checkpoint set that binds Controller and all Store members.
#[derive(Clone, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct ReleaseCheckpointSetManifest {
    pub schema_version: u16,
    pub checkpoint_set_id: String,
    pub release_id: String,
    pub generation: u64,
    pub barrier_id: String,
    pub policy_version: u64,
    pub fencing_token: u64,
    pub created_at_unix_millis: u64,
    pub controller: ControllerReleaseSnapshotManifest,
    pub stores: Vec<StoreReleaseCheckpointManifest>,
}

impl fmt::Debug for ReleaseCheckpointSetManifest {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ReleaseCheckpointSetManifest")
            .field("schema_version", &self.schema_version)
            .field("checkpoint_set_id", &self.checkpoint_set_id)
            .field("release_id", &self.release_id)
            .field("generation", &self.generation)
            .field("barrier_id", &self.barrier_id)
            .field("policy_version", &self.policy_version)
            .field("fencing_token", &Sensitive::new(self.fencing_token))
            .field("created_at_unix_millis", &self.created_at_unix_millis)
            .field("controller", &self.controller)
            .field("stores", &self.stores)
            .finish()
    }
}

impl ReleaseCheckpointSetManifest {
    /// Validates the complete Controller/Store barrier and member set.
    ///
    /// # Errors
    ///
    /// Returns a typed validation error when schema, release identity, policy
    /// version, fencing, membership, or any cross-artifact binding differs.
    pub fn validate(&self) -> Result<(), ProtocolContractViolation> {
        if self.schema_version != RELEASE_CHECKPOINT_SCHEMA_VERSION {
            return Err(ProtocolContractViolation::CheckpointSchemaVersion {
                expected: RELEASE_CHECKPOINT_SCHEMA_VERSION,
                actual: self.schema_version,
            });
        }
        require_identifier("checkpointSetId", &self.checkpoint_set_id)?;
        require_identifier("releaseId", &self.release_id)?;
        require_identifier("barrierId", &self.barrier_id)?;
        if self.generation == 0 || self.policy_version == 0 || self.fencing_token == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "generation/policyVersion/fencingToken",
                reason: "must be greater than zero",
            });
        }
        if self.created_at_unix_millis == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "createdAtUnixMillis",
                reason: "must be greater than zero",
            });
        }
        self.controller.validate()?;
        if self.stores.is_empty() {
            return Err(ProtocolContractViolation::MissingStoreMembers);
        }

        self.validate_binding("Controller", &self.controller.artifact)?;
        let mut members = BTreeSet::new();
        for store in &self.stores {
            store.validate()?;
            self.validate_binding("Store", &store.artifact)?;
            if !members.insert(store.member_id.as_str()) {
                return Err(ProtocolContractViolation::DuplicateStoreMember);
            }
        }
        Ok(())
    }

    fn validate_binding(
        &self,
        member: &'static str,
        artifact: &ReleaseCheckpointArtifact,
    ) -> Result<(), ProtocolContractViolation> {
        if artifact.checkpoint_set_id != self.checkpoint_set_id
            || artifact.generation != self.generation
            || artifact.barrier_id != self.barrier_id
        {
            return Err(ProtocolContractViolation::CheckpointSetBindingMismatch { member });
        }
        Ok(())
    }
}

/// Result of non-destructive restore verification.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct ReleaseCheckpointRestoreVerification {
    pub checkpoint_id: String,
    pub generation: u64,
    pub verified_at_unix_millis: u64,
    pub checksum_verified: bool,
    pub offsets_verified: bool,
    pub storage_identity_verified: bool,
    pub wal_retained: bool,
    pub persistent_volume_retained: bool,
}

impl ReleaseCheckpointRestoreVerification {
    /// Validates that restore verification proved every production invariant.
    ///
    /// # Errors
    ///
    /// Returns a typed validation error when any integrity, offset, WAL, or PVC
    /// proof is absent.
    pub fn validate(&self) -> Result<(), ProtocolContractViolation> {
        require_identifier("checkpointId", &self.checkpoint_id)?;
        if self.generation == 0 || self.verified_at_unix_millis == 0 {
            return Err(ProtocolContractViolation::InvalidCheckpointField {
                field: "generation/verifiedAtUnixMillis",
                reason: "must be greater than zero",
            });
        }
        if !self.checksum_verified
            || !self.offsets_verified
            || !self.storage_identity_verified
            || !self.wal_retained
            || !self.persistent_volume_retained
        {
            return Err(ProtocolContractViolation::RestoreVerificationIncomplete);
        }
        Ok(())
    }
}

fn require_identifier(field: &'static str, value: &str) -> Result<(), ProtocolContractViolation> {
    if value.is_empty()
        || value.len() > 256
        || !value
            .bytes()
            .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'_' | b'-' | b':' | b'/' | b'@'))
    {
        return Err(ProtocolContractViolation::InvalidCheckpointField {
            field,
            reason: "must be a canonical identifier",
        });
    }
    Ok(())
}

fn require_sha256(value: &str) -> Result<(), ProtocolContractViolation> {
    if value.len() != 64
        || !value
            .bytes()
            .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte))
    {
        return Err(ProtocolContractViolation::InvalidCheckpointField {
            field: "sha256",
            reason: "must be 64 lowercase hexadecimal characters",
        });
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    fn artifact(id: &str) -> ReleaseCheckpointArtifact {
        ReleaseCheckpointArtifact {
            schema_version: 1,
            checkpoint_id: id.to_string(),
            checkpoint_set_id: "set-7".to_string(),
            generation: 7,
            barrier_id: "barrier-42".to_string(),
            created_at_unix_millis: 1_800_000_000_000,
            length_bytes: 512,
            sha256: "a".repeat(64),
            uri: format!("file:///checkpoints/{id}"),
        }
    }

    fn store(member: &str) -> StoreReleaseCheckpointManifest {
        StoreReleaseCheckpointManifest {
            artifact: artifact(&format!("store-{member}")),
            member_id: member.to_string(),
            backend: ReleaseCheckpointBackend::Local,
            offsets: ReleaseCheckpointOffsets {
                appended_offset: 120,
                durable_offset: 120,
                consume_queue_offset: 100,
                index_offset: 100,
            },
            storage_identity: ReleaseCheckpointStorageIdentity {
                volume_id: format!("pvc-{member}"),
                wal_generation: 7,
            },
            wal_retained: true,
            persistent_volume_retained: true,
        }
    }

    #[test]
    fn release_checkpoint_set_binds_controller_stores_and_offsets() {
        let manifest = ReleaseCheckpointSetManifest {
            schema_version: 1,
            checkpoint_set_id: "set-7".to_string(),
            release_id: "release-7".to_string(),
            generation: 7,
            barrier_id: "barrier-42".to_string(),
            policy_version: 3,
            fencing_token: 42,
            created_at_unix_millis: 1_800_000_000_000,
            controller: ControllerReleaseSnapshotManifest {
                artifact: artifact("controller"),
                snapshot_id: "snapshot-99".to_string(),
                last_applied_index: 99,
                last_applied_term: 3,
                voter_ids: vec![1, 2, 3],
            },
            stores: vec![store("broker-a"), store("broker-b")],
        };

        manifest.validate().expect("complete set should validate");
    }

    #[test]
    fn release_checkpoint_set_rejects_barrier_drift_and_destructive_restore() {
        let mut store = store("broker-a");
        store.artifact.barrier_id = "other-barrier".to_string();
        store.wal_retained = false;
        let manifest = ReleaseCheckpointSetManifest {
            schema_version: 1,
            checkpoint_set_id: "set-7".to_string(),
            release_id: "release-7".to_string(),
            generation: 7,
            barrier_id: "barrier-42".to_string(),
            policy_version: 3,
            fencing_token: 42,
            created_at_unix_millis: 1_800_000_000_000,
            controller: ControllerReleaseSnapshotManifest {
                artifact: artifact("controller"),
                snapshot_id: "snapshot-99".to_string(),
                last_applied_index: 99,
                last_applied_term: 3,
                voter_ids: vec![1],
            },
            stores: vec![store],
        };

        assert!(manifest.validate().is_err());
    }

    #[test]
    fn release_checkpoint_set_debug_redacts_fencing_token() {
        let manifest = ReleaseCheckpointSetManifest {
            schema_version: 1,
            checkpoint_set_id: "set-7".to_string(),
            release_id: "release-7".to_string(),
            generation: 7,
            barrier_id: "barrier-42".to_string(),
            policy_version: 3,
            fencing_token: 987_654_321,
            created_at_unix_millis: 1_800_000_000_000,
            controller: ControllerReleaseSnapshotManifest {
                artifact: artifact("controller"),
                snapshot_id: "snapshot-99".to_string(),
                last_applied_index: 99,
                last_applied_term: 3,
                voter_ids: vec![1],
            },
            stores: vec![store("broker-a")],
        };

        let debug = format!("{manifest:?}");

        assert!(debug.contains("<redacted>"));
        assert!(!debug.contains("987654321"));
    }
}