Files
troupe-standup/wizard-work/sol/check_sol_lane_status_rederived.sh

53 lines
2.0 KiB
Bash

#!/usr/bin/env bash
# CHECK -- redrive of the 7 primary daily-ledger lanes.
# Recomputes live from the filesystem and diffs against the committed record.
# Exit 0 = committed JSON matches independent recompute; nonzero = wrong.
set -u
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
JSON=sol-lane-status-rederived-2026-10-27.json
OUT=/root/.hermes/wizard-outputs
LANE_LIST="forge ledger null quill sphinx sol spark"
python3 - "$JSON" "$OUT" "$LANE_LIST" <<'PY'
import json, os, sys, glob, time
json_path, out, lane_list = sys.argv[1:4]
lanes = lane_list.split()
now = time.time()
recomputed = {}
for L in lanes:
files = sorted(glob.glob(os.path.join(out, L + "-*.txt")))
latest = max(files, key=os.path.getmtime)
age = (now - os.path.getmtime(latest)) / 3600.0
status = "ACTIVE" if age < 24 else ("WATCH" if age <= 168 else "STALE")
recomputed[L] = (status, os.path.basename(latest))
with open(json_path) as f:
rec = json.load(f)
ok = True
for L in lanes:
jl = next((x for x in rec["lanes"] if x["id"] == L), None)
if jl is None:
print("FAIL: lane %s missing" % L); ok = False; continue
exp_status, exp_log = recomputed[L]
if jl.get("status") != exp_status or jl.get("latest_log") != exp_log:
print("FAIL: lane %s json=%s/%s recomputed=%s/%s" % (L, jl.get("status"), jl.get("latest_log"), exp_status, exp_log))
ok = False
counts = {}
for L in lanes:
st = recomputed[L][0]
counts[st] = counts.get(st, 0) + 1
if rec.get("status_counts") != counts:
print("FAIL: counts json=%s recomputed=%s" % (rec.get("status_counts"), counts)); ok = False
if not ok:
print("RECOMPUTE FAILED: redrive artifact does not match live filesystem")
sys.exit(1)
print("OK: lanes=%d statuses=%s counts=%s" % (len(lanes), ",".join("%s=%s" % (k, v) for k, v in sorted(recomputed.items())), rec.get("status_counts")))
sys.exit(0)
PY
rc=$?
if [ $rc -ne 0 ]; then
echo "FAIL: independent recompute disagrees with the committed redrive artifact" >&2
exit 1
fi
echo "PASS: redrive artifact verified against the live filesystem"
exit 0