blaze-host: make the build stamp trustworthy for evidence attribution

Committing updates refs/heads/<branch>, 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) <noreply@anthropic.com>
This commit is contained in:
funman300
2026-08-11 02:15:11 +00:00
parent 23374312bc
commit c84fd14cac
2 changed files with 24 additions and 1 deletions
+9
View File
@@ -66,4 +66,13 @@ fn main() {
println!("cargo:rerun-if-changed={p}");
}
}
// Committing updates refs/heads/<branch>, 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}");
}
}
}
+15 -1
View File
@@ -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