From c84fd14cac1899852a1095d5a7dd066074531f8b Mon Sep 17 00:00:00 2001 From: funman300 Date: Tue, 11 Aug 2026 02:15:11 +0000 Subject: [PATCH] blaze-host: make the build stamp trustworthy for evidence attribution Committing updates refs/heads/, not the HEAD file, so watching HEAD alone left the stamp one commit behind -- observed live, the banner read a84a72e immediately after 2337431 was committed. build.rs now also watches the resolved branch ref. Belt and braces, since cargo still cannot see every source change: sidecar.sh compares the binary's stamped commit against the tree's real HEAD at launch and says so loudly on a mismatch. An evidence artefact that names the WRONG commit is worse than one that names none. Co-Authored-By: Claude Opus 5 (1M context) --- openfut-blaze-host/build.rs | 9 +++++++++ openfut-blaze-host/sidecar.sh | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/openfut-blaze-host/build.rs b/openfut-blaze-host/build.rs index f6eea38..0a465d0 100644 --- a/openfut-blaze-host/build.rs +++ b/openfut-blaze-host/build.rs @@ -66,4 +66,13 @@ fn main() { println!("cargo:rerun-if-changed={p}"); } } + // Committing updates refs/heads/, NOT the HEAD file, so watching + // HEAD alone leaves the stamp one commit behind. Observed: the banner read + // a84a72e immediately after committing 2337431. + if let Some(rf) = git(&["symbolic-ref", "-q", "HEAD"]) { + let path = format!("../.git/{rf}"); + if std::path::Path::new(&path).exists() { + println!("cargo:rerun-if-changed={path}"); + } + } } diff --git a/openfut-blaze-host/sidecar.sh b/openfut-blaze-host/sidecar.sh index 2cc00a9..1c47e96 100755 --- a/openfut-blaze-host/sidecar.sh +++ b/openfut-blaze-host/sidecar.sh @@ -116,6 +116,12 @@ cmd_start() { die "port $OPENFUT_BLAZE_HOST_PORT is already in use" fi + # The binary's stamp can lag the tree (cargo cannot know about every source + # change). Compare it with the tree's real HEAD at launch and say so, because + # an evidence artefact that names the wrong commit is worse than one that + # names none. + HEAD_NOW="$(git -C "$ROOT" rev-parse --short=7 HEAD 2>/dev/null || echo unknown)" + local tree tree="$(tree_state)" if [[ "$tree" == "DIRTY" ]]; then @@ -141,7 +147,15 @@ cmd_start() { fi if port_listening "$OPENFUT_BLAZE_HOST_PORT"; then echo "sidecar started: pid $pid, port $OPENFUT_BLAZE_HOST_PORT" - grep -m1 'openfut-blaze-host v' "$LOGFILE" 2>/dev/null | sed 's/^/ /' + local banner stamped + banner="$(grep -m1 'openfut-blaze-host v' "$LOGFILE" 2>/dev/null)" + echo " ${banner}" + stamped="$(sed -n 's/.*commit=\([0-9a-f]*\).*/\1/p' <<<"$banner")" + if [[ -n "$stamped" && "$stamped" != "unknown" && "$stamped" != "$HEAD_NOW" ]]; then + echo " !! STALE BUILD STAMP: binary says $stamped, HEAD is $HEAD_NOW" >&2 + echo " Rebuild before treating this run as evidence:" >&2 + echo " touch openfut-blaze-host/build.rs && cargo build -p openfut-blaze-host" >&2 + fi if grep -q 'WARNING: built from a modified working tree' "$LOGFILE" 2>/dev/null; then echo " !! DIRTY BUILD — results are not parity evidence" >&2 fi