Files
faunosteo/scripts/sheet-assets-e2e.sh
T
bchanot 2c445063a4 feat(supabase): R5.5 upload-sheet-assets in Rust, R5.4 caps and FLOOR clarification
Core rules curation::upload (manifest, local destination, bytes through the SVG reader,
plan from observed state); binary upload-sheet-assets over ureq (handshake, no overwrite,
confirm after verify, bounded retries, key never printed); pnpm assets:upload repointed,
e2e:sheet-assets for the local stack. 4 MiB cap on changes.json and references.json.
FLOOR clarification for audit prose with its negative proof.
2026-10-23 21:15:22 +02:00

52 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# `pnpm e2e:sheet-assets`: the sheet-asset upload tool against the LOCAL Supabase stack (R5.5,
# docs/development/SUPABASE.md §3.1). Needs `pnpm db:start`. Run by hand: it uploads the equine
# draft drawing to the local bucket and confirms its row (idempotent; a rerun changes nothing).
# The keys are read from `pnpm supabase status`, held in variables, never printed.
#
# Checks: --check writes nothing; a first run uploads and confirms; a rerun has nothing to do;
# the anon key and a wrong key are refused; a destination that is not a local stack is refused
# before any request; an unreachable local port is a network error (exit 3).
set -uo pipefail
cd "$(dirname "$0")/.."
. scripts/rust-env.sh
SEED=supabase/seed/anatomical-sheets/equine/draft
BIN=target/release/upload-sheet-assets
FAIL=0
cargo build --release --locked -q -p faunosteo-core --features upload --bin upload-sheet-assets || exit 2
STATUS=$(bash scripts/supabase.sh status -o json 2>/dev/null) || { echo "stack not running (pnpm db:start)"; exit 2; }
field() { printf '%s' "$STATUS" | python3 -c "import json,sys;print(json.load(sys.stdin)['$1'])"; }
SERVICE=$(field SERVICE_ROLE_KEY)
ANON=$(field ANON_KEY)
LOCAL=http://127.0.0.1:54321
# expect <name> <expected exit> <url> <key> <args...>; output kept to grep, keys never echoed.
expect() {
local name=$1 want=$2 url=$3 key=$4; shift 4
local out rc
out=$(env -i PATH="$PATH" SUPABASE_URL="$url" SUPABASE_SERVICE_ROLE_KEY="$key" "$BIN" "$@" 2>&1); rc=$?
LAST=$out
if [ "$rc" -eq "$want" ] && ! grep -qF -e "$key" -e "$SERVICE" -e "$ANON" <<<"$out"; then
echo "PASS $name (exit $rc)"
else
echo "FAIL $name (exit $rc, wanted $want)"; FAIL=1
fi
}
expect "check writes nothing" 0 "$LOCAL" "$SERVICE" --check "$SEED"
expect "first run" 0 "$LOCAL" "$SERVICE" "$SEED"
expect "rerun" 0 "$LOCAL" "$SERVICE" "$SEED"
grep -q "nothing to do" <<<"$LAST" && echo "PASS rerun has nothing to do" || { echo "FAIL rerun did work"; FAIL=1; }
expect "anon key refused" 1 "$LOCAL" "$ANON" "$SEED"
expect "wrong key refused" 1 "$LOCAL" "not-a-valid-key" "$SEED"
expect "https refused" 1 "https://127.0.0.1:54321" "$SERVICE" "$SEED"
expect "non-local host refused" 1 "http://example.test:54321" "$SERVICE" "$SEED"
expect "no port refused" 1 "http://127.0.0.1" "$SERVICE" "$SEED"
expect "unreachable port" 3 "http://127.0.0.1:9" "$SERVICE" "$SEED"
expect "folder outside the seed" 1 "$LOCAL" "$SERVICE" --check crates/core/src
[ "$FAIL" -eq 0 ] && echo "e2e:sheet-assets OK" || echo "e2e:sheet-assets FAILED"
exit "$FAIL"