From 8dbda3e052a36384d9cc5557cf060219921e035a Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Wed, 8 Apr 2026 12:36:33 +0400 Subject: [PATCH] feat: --version flag with git hash + test script kill fix wzp-relay --version prints "wzp-relay ". Build hash also logged on startup: version=abc1234. Enables verifying deployed relay matches expected build. Also fixed federation-test.sh: use kill -INT (not SIGTERM) so clients save recordings before exit. Added save delay. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/wzp-relay/build.rs | 18 ++++++++++++++++++ crates/wzp-relay/src/main.rs | 8 ++++++++ scripts/federation-test.sh | 12 ++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 crates/wzp-relay/build.rs diff --git a/crates/wzp-relay/build.rs b/crates/wzp-relay/build.rs new file mode 100644 index 0000000..70707c7 --- /dev/null +++ b/crates/wzp-relay/build.rs @@ -0,0 +1,18 @@ +use std::process::Command; + +fn main() { + // Get git hash at build time + let output = Command::new("git") + .args(["rev-parse", "--short", "HEAD"]) + .output(); + + let hash = match output { + Ok(o) if o.status.success() => { + String::from_utf8_lossy(&o.stdout).trim().to_string() + } + _ => "unknown".to_string(), + }; + + println!("cargo:rustc-env=WZP_BUILD_HASH={hash}"); + println!("cargo:rerun-if-changed=.git/HEAD"); +} diff --git a/crates/wzp-relay/src/main.rs b/crates/wzp-relay/src/main.rs index 0c302ad..89fe7b0 100644 --- a/crates/wzp-relay/src/main.rs +++ b/crates/wzp-relay/src/main.rs @@ -135,6 +135,10 @@ fn parse_args() -> CliResult { args.get(i).expect("--debug-tap requires a room name (or '*' for all)").to_string(), ); } + "--version" | "-V" => { + println!("wzp-relay {}", env!("WZP_BUILD_HASH")); + std::process::exit(0); + } "--mesh-status" => { // Print mesh table from a fresh registry and exit. // In practice this is useful after the relay has been running; @@ -257,10 +261,14 @@ fn detect_public_ip() -> Option { None } +/// Build-time git hash, set by build.rs or env. +const BUILD_GIT_HASH: &str = env!("WZP_BUILD_HASH"); + #[tokio::main] async fn main() -> anyhow::Result<()> { let CliResult { mut config, identity_path, config_file, config_needs_create } = parse_args(); tracing_subscriber::fmt().init(); + info!(version = BUILD_GIT_HASH, "wzp-relay build"); rustls::crypto::ring::default_provider() .install_default() .expect("failed to install rustls crypto provider"); diff --git a/scripts/federation-test.sh b/scripts/federation-test.sh index e7a6865..1bf04d8 100755 --- a/scripts/federation-test.sh +++ b/scripts/federation-test.sh @@ -112,7 +112,7 @@ PIDS+=($!); sleep 2 RUST_LOG=error $CLIENT --room $ROOM --seed $SEED_A --send-tone $DURATION "$RELAY1" & PIDS+=($!); sleep $((DURATION + 3)) -kill ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null; wait ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null || true +kill -INT ${PIDS[-2]} 2>/dev/null; sleep 3; kill -INT ${PIDS[-1]} 2>/dev/null; wait ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null || true PIDS=("${PIDS[@]:0:${#PIDS[@]}-2}") analyze "$RESULTS/t1_b.raw" "Relay1→Relay2 audio" @@ -129,7 +129,7 @@ PIDS+=($!); sleep 2 RUST_LOG=error $CLIENT --room $ROOM --seed $SEED_B --send-tone $DURATION "$RELAY2" & PIDS+=($!); sleep $((DURATION + 3)) -kill ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null; wait ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null || true +kill -INT ${PIDS[-2]} 2>/dev/null; sleep 3; kill -INT ${PIDS[-1]} 2>/dev/null; wait ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null || true PIDS=("${PIDS[@]:0:${#PIDS[@]}-2}") analyze "$RESULTS/t2_a.raw" "Relay2→Relay1 audio" @@ -146,7 +146,7 @@ PIDS+=($!); sleep 2 RUST_LOG=error $CLIENT --room $ROOM --seed $SEED_A --send-tone $DURATION "$RELAY1" & PIDS+=($!); sleep $((DURATION + 3)) -kill ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null; wait ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null || true +kill -INT ${PIDS[-2]} 2>/dev/null; sleep 3; kill -INT ${PIDS[-1]} 2>/dev/null; wait ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null || true PIDS=("${PIDS[@]:0:${#PIDS[@]}-2}") analyze "$RESULTS/t3_c.raw" "Relay1→Relay3 (via Relay2) audio" @@ -163,7 +163,7 @@ PIDS+=($!); sleep 2 RUST_LOG=error $CLIENT --room $ROOM --seed $SEED_A --send-file "$AUDIO" "$RELAY1" & PIDS+=($!); sleep 20 # file is 60s but we only wait 20 -kill ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null; wait ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null || true +kill -INT ${PIDS[-2]} 2>/dev/null; sleep 3; kill -INT ${PIDS[-1]} 2>/dev/null; wait ${PIDS[-1]} ${PIDS[-2]} 2>/dev/null || true PIDS=("${PIDS[@]:0:${#PIDS[@]}-2}") analyze "$RESULTS/t4_b.raw" "File playback Relay1→Relay2" @@ -193,7 +193,7 @@ RUST_LOG=error $CLIENT --room $ROOM --seed $SEED_B --record "$RESULTS/t5_b_rejoi B_PID=$!; PIDS+=($B_PID) sleep 8 kill -INT $B_PID 2>/dev/null; wait $B_PID 2>/dev/null || true -kill $A_PID 2>/dev/null; wait $A_PID 2>/dev/null || true +kill -INT $A_PID 2>/dev/null; wait $A_PID 2>/dev/null || true analyze "$RESULTS/t5_b_first.raw" "B first join (before disconnect)" analyze "$RESULTS/t5_b_rejoin.raw" "B rejoin (after disconnect)" @@ -213,7 +213,7 @@ PIDS+=($!); sleep $((DURATION + 3)) # Kill all 3 for i in 1 2 3; do - kill ${PIDS[-$i]} 2>/dev/null || true + kill -INT ${PIDS[-$i]} 2>/dev/null || true done wait 2>/dev/null || true PIDS=()