From 2f51f2c463b37434c9f7f60b666b04e797460632 Mon Sep 17 00:00:00 2001 From: shoemoney Date: Tue, 23 Jun 2026 11:37:11 -0500 Subject: [PATCH] =?UTF-8?q?test(M8a):=20scripts/m8a-invite-fleet-verify.sh?= =?UTF-8?q?=20=E2=80=94=20cross-machine=20invite=20proof=20=F0=9F=A7=AA?= =?UTF-8?q?=F0=9F=8C=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-runnable two-host fleet test against an ISOLATED hub (never the live .10). Owner on one Pi invites bob editor; a device on ANOTHER Pi redeems via the join PoP flow, lands as bob/editor, and pushes an edit (snapshots 1->2). Bakes in the 64-char-token gotcha (randomBearer = 32 bytes; a {32} grep truncates it -> 401). Green on .13+.15 arm64; self-cleans both hosts. --- scripts/m8a-invite-fleet-verify.sh | 81 ++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 scripts/m8a-invite-fleet-verify.sh diff --git a/scripts/m8a-invite-fleet-verify.sh b/scripts/m8a-invite-fleet-verify.sh new file mode 100755 index 0000000..56ccbe4 --- /dev/null +++ b/scripts/m8a-invite-fleet-verify.sh @@ -0,0 +1,81 @@ +#!/usr/bin/env bash +# m8a-invite-fleet-verify.sh — prove the M8a device-facing invite flow end to end +# across TWO real machines, against an ISOLATED hub (never the live .10 hub). +# +# What it asserts on real hardware: +# 1. an owner publishes a share and invites a principal as editor; +# 2. a device on a DIFFERENT host redeems that invite via the join PoP flow and +# lands enrolled as the bound principal with the bound role (members shows it); +# 3. that invited editor can actually push (the role write-gate allows it). +# +# GOTCHA baked in: the invite token is 64 hex chars (randomBearer = 32 bytes). An +# earlier run grepped [0-9a-f]{32} and truncated it → 401 on redeem. We grep {64}. +# +# Usage: scripts/m8a-invite-fleet-verify.sh [hubPi] [peerPi] +# defaults: hubPi=192.168.1.13 peerPi=192.168.1.15 (arm64 Pis; pi4/.14 offline) +set -euo pipefail + +HUB_PI="${1:-192.168.1.13}" +PEER_PI="${2:-192.168.1.15}" +PORT="${PORT:-8099}" +KEY="${PI_KEY:-$HOME/.ssh/pi}" +SSH="ssh -o ConnectTimeout=8 -o StrictHostKeyChecking=no -i $KEY" +HUB_URL="http://$HUB_PI:$PORT" +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP"' EXIT + +say() { printf '\n=== %s ===\n' "$1"; } + +say "build linux/arm64 binaries" +CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o "$TMP/devbox" ./cmd/devbox +CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o "$TMP/devbox-hub" ./cmd/devbox-hub + +say "deploy (hub+devA → $HUB_PI, devB → $PEER_PI)" +scp -q -i "$KEY" "$TMP/devbox-hub" "$TMP/devbox" "shoemoney@$HUB_PI:/tmp/" +scp -q -i "$KEY" "$TMP/devbox" "shoemoney@$PEER_PI:/tmp/" + +cleanup_fleet() { + $SSH "shoemoney@$HUB_PI" 'pkill -9 -f devbox-hub 2>/dev/null; pkill -9 -f "devbox start" 2>/dev/null; rm -rf /tmp/devbox /tmp/devbox-hub /tmp/ivhub /tmp/devA /tmp/teamdir' 2>/dev/null || true + $SSH "shoemoney@$PEER_PI" 'pkill -9 -f "devbox start" 2>/dev/null; rm -rf /tmp/devbox /tmp/devB /tmp/devB-team' 2>/dev/null || true +} +trap 'cleanup_fleet; rm -rf "$TMP"' EXIT + +say "$HUB_PI: start isolated hub, devA join + publish + invite bob editor" +INV=$($SSH "shoemoney@$HUB_PI" bash </dev/null +set -e +pkill -9 -f devbox-hub 2>/dev/null || true +rm -rf /tmp/ivhub /tmp/devA /tmp/teamdir; mkdir -p /tmp/devA /tmp/teamdir +echo hello > /tmp/teamdir/readme.txt +nohup /tmp/devbox-hub serve --data /tmp/ivhub --listen $HUB_PI:$PORT >/tmp/ivhub.log 2>&1 & +sleep 2 +TOK=\$(/tmp/devbox-hub token --data /tmp/ivhub) +export XDG_CONFIG_HOME=/tmp/devA +/tmp/devbox join $HUB_URL "\$TOK" >/dev/null +/tmp/devbox publish /tmp/teamdir team >/dev/null +/tmp/devbox invite team bob editor | grep -oE '[0-9a-f]{64}' | head -1 +EOF +) +[ "${#INV}" -eq 64 ] || { echo "🛑 invite token not 64 chars (got ${#INV}) — extraction bug"; exit 1; } +echo "invite token ok (64 chars)" + +say "$PEER_PI: devB redeems the invite, then mounts + edits + syncs" +RESULT=$($SSH "shoemoney@$PEER_PI" bash </dev/null +set -e +rm -rf /tmp/devB /tmp/devB-team; mkdir -p /tmp/devB +export XDG_CONFIG_HOME=/tmp/devB +/tmp/devbox join $HUB_URL $INV >/dev/null +echo "MEMBERS:"; /tmp/devbox members team +/tmp/devbox mount team /tmp/devB-team >/dev/null +BEFORE=\$(/tmp/devbox log team | grep -c .) +echo "edit by the invited editor" >> /tmp/devB-team/readme.txt +timeout 12 /tmp/devbox start >/dev/null 2>&1 || true +AFTER=\$(/tmp/devbox log team | grep -c .) +echo "SNAPSHOTS:\$BEFORE->\$AFTER" +EOF +) +echo "$RESULT" + +say "verdict" +echo "$RESULT" | grep -q 'bob.*editor' || { echo "🛑 invite binding did NOT apply cross-machine"; exit 1; } +echo "$RESULT" | grep -qE 'SNAPSHOTS:1->2' || { echo "🛑 invited editor could not push (write gate wrong?)"; exit 1; } +echo "🎉 M8a invite flow fleet-verified: cross-machine redeem + role-gated push both work."