Skip to content

Commit 992f2b5

Browse files
committed
refactor(cluster): use compile-time assertions for wire version invariants
Replace the two unit tests in wire_version.rs with const assertions that are evaluated at compile time, so violations fail the build rather than a test run. Also reorder a pair of pub use items in nodedb-cluster to match the module declaration order, and collapse a multi-line format string in the RPC codec header error to a single line.
1 parent 3c8bd50 commit 992f2b5

3 files changed

Lines changed: 8 additions & 21 deletions

File tree

nodedb-cluster/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ pub use bootstrap::{
5858
ClusterConfig, ClusterState, JoinRetryPolicy, start_cluster, start_cluster_subsystems,
5959
};
6060
pub use catalog::ClusterCatalog;
61+
pub use circuit_breaker::BreakerSnapshot;
62+
pub use closed_timestamp::ClosedTimestampTracker;
6163
pub use cluster_epoch::{
6264
bump_local_cluster_epoch, current_local_cluster_epoch, init_local_cluster_epoch_from_catalog,
6365
observe_peer_cluster_epoch, set_local_cluster_epoch,
6466
};
65-
pub use circuit_breaker::BreakerSnapshot;
66-
pub use closed_timestamp::ClosedTimestampTracker;
6767
pub use cluster_info::{
6868
ClusterInfoSnapshot, ClusterObserver, GroupSnapshot, GroupStatusProvider, PeerSnapshot,
6969
};

nodedb-cluster/src/rpc_codec/header.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ pub fn write_frame(rpc_type: u8, payload: &[u8], out: &mut Vec<u8>) -> Result<()
9494
pub fn parse_frame(data: &[u8]) -> Result<(u8, &[u8])> {
9595
if data.is_empty() {
9696
return Err(ClusterError::Codec {
97-
detail: format!(
98-
"frame too short: 0 bytes, need {HEADER_SIZE_V2}"
99-
),
97+
detail: format!("frame too short: 0 bytes, need {HEADER_SIZE_V2}"),
10098
});
10199
}
102100

nodedb-types/src/wire_version.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,8 @@ pub const WIRE_FORMAT_VERSION: u16 = 4;
2121
/// below this are rejected.
2222
pub const MIN_WIRE_FORMAT_VERSION: u16 = 1;
2323

24-
#[cfg(test)]
25-
mod tests {
26-
use super::*;
27-
28-
#[test]
29-
fn min_does_not_exceed_current() {
30-
assert!(MIN_WIRE_FORMAT_VERSION <= WIRE_FORMAT_VERSION);
31-
}
32-
33-
#[test]
34-
fn current_is_nonzero() {
35-
// Version 0 is reserved for "unknown / legacy" handling on
36-
// downstream paths and must never be the active version.
37-
assert!(WIRE_FORMAT_VERSION > 0);
38-
}
39-
}
24+
// Compile-time invariants — these constants must satisfy:
25+
// - MIN_WIRE_FORMAT_VERSION <= WIRE_FORMAT_VERSION
26+
// - WIRE_FORMAT_VERSION > 0 (version 0 is reserved for "unknown/legacy")
27+
const _: () = assert!(MIN_WIRE_FORMAT_VERSION <= WIRE_FORMAT_VERSION);
28+
const _: () = assert!(WIRE_FORMAT_VERSION > 0);

0 commit comments

Comments
 (0)