fix(supabase): db:trial closure review fixes
Strict absent detection (stderr sentence per kind, measured on Docker 29.9.3), tri-state container_running, empty-volume check before restore, quieter DB init and rotation logging, backup/migrate refuse while the app runs, lock first in start/stop, truthful rotate-secrets and post-create checks. Stub reproduces Docker's stdout/stderr split. Harness 364/0.
This commit is contained in:
1 parent
a78da9f4e2
commit
d3bdbbe0ba
5 files changed
+357
-54
No files matched your search
+180
-14
@@ -76,16 +76,31 @@ sed 's/kill -TERM/kill -INT/' "$WORK/term-trial.sh" > "$WORK/int-trial.sh"
|
||||
cat > "$WORK/bin/docker" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
# docker stand-in: one log line per call (newlines shown as \n), one file per pretend resource.
|
||||
# Files under $STUB_STATE/fail/ make one answer fail: daemon, networks-create, networks-create-after
|
||||
# Files under $STUB_STATE/fail/ make one answer fail: daemon (every call but `context`, with the real dial error),
|
||||
# daemon-lost (docker info answers, every inspect gets that dial error; daemon-lost-volume / -network / -container
|
||||
# for one kind), inspect-after-stop (container inspects fail once a docker stop ran), stop-noop (docker stop leaves
|
||||
# the container running), networks-create, networks-create-after
|
||||
# (the network is made, then the call fails), inspect-error (every inspect fails with an answer other
|
||||
# than "no such" or "not found"), helper, archive, extract (the restore's tar -x), image-nondb (every
|
||||
# image but the database's is absent), <sql tag>. Other hooks: term-in-archive (the script gets a
|
||||
# SIGTERM while it archives), append-on-rm (the file named inside gets a byte when a container is
|
||||
# removed), term-on (an ERE: the first call whose argv line, or tag:<sql tag> for an exec, matches it
|
||||
# sends the script a SIGTERM), answers/measure-kib (the volumes' measured size), answers/<tag>.seq (one line per call).
|
||||
# An absent resource answers in Docker's own wording per kind.
|
||||
# answers/volume-ls (what `ls -A /volume` prints: a non-empty volume).
|
||||
# Every failing `inspect -f` (an absent resource of any of the four kinds, a lost daemon) writes a
|
||||
# bare newline to stdout and the sentence to stderr, rc 1, as Docker 29.9.3 does (measured): the
|
||||
# script must judge stderr alone. Docker's own wording per kind:
|
||||
# "Error response from daemon: No such container: <name>", "... get <name>: no such volume",
|
||||
# "... network <name> not found", "... No such image: <name>".
|
||||
# daemon-lost-after-create: once a network or volume was created, every later call but `context`
|
||||
# and `info` gets the dial error (the daemon is lost part-way through a create).
|
||||
set -uo pipefail
|
||||
st="$STUB_STATE"
|
||||
dial_error() {
|
||||
echo
|
||||
echo "failed to connect to the docker API at unix:///stub/docker.sock; check if the path is correct and if the daemon is running: dial unix /stub/docker.sock: connect: no such file or directory" >&2
|
||||
exit 1
|
||||
}
|
||||
{ printf 'docker'; for a in "$@"; do printf ' %s' "${a//$'\n'/\\n}"; done; printf '\n'; } >> "$STUB_LOG"
|
||||
save_stdin() { local f; f="$st/stdin/$(date +%s%N)"; cat > "$f"; printf '%s' "$f"; }
|
||||
term_if() { # text: once, when it matches the term-on pattern
|
||||
@@ -95,8 +110,12 @@ term_if() { # text: once, when it matches the term-on pattern
|
||||
term_if "docker $*"
|
||||
sub="${1:-}"
|
||||
[ $# -eq 0 ] || shift
|
||||
if [ -f "$st/fail/daemon" ] && [ "$sub" != context ]; then dial_error; fi
|
||||
absent_error() { echo; echo "$1" >&2; exit 1; } # the failing inspect's two streams
|
||||
if [ -f "$st/lost-now" ] && [ "$sub" != context ] && [ "$sub" != info ]; then dial_error; fi
|
||||
lost() { [ -f "$st/fail/daemon-lost" ] || [ -f "$st/fail/daemon-lost-$1" ]; } # kind: its inspects hit the dial error
|
||||
case "$sub" in
|
||||
info) [ ! -f "$st/fail/daemon" ] || exit 1; echo /stub/docker-root ;;
|
||||
info) echo /stub/docker-root ;;
|
||||
context)
|
||||
[ "${1:-}" = inspect ] || exit 97
|
||||
[ ! -f "$st/fail/context" ] || exit 1
|
||||
@@ -104,22 +123,26 @@ case "$sub" in
|
||||
ps) exit 0 ;;
|
||||
image)
|
||||
[ "${1:-}" = inspect ] || exit 97
|
||||
[ ! -f "$st/fail/image" ] || exit 1
|
||||
if [ -f "$st/fail/image-nondb" ]; then case "${*: -1}" in *supabase/postgres*) ;; *) exit 1 ;; esac; fi ;;
|
||||
img="${*: -1}"
|
||||
if lost image; then dial_error; fi
|
||||
[ ! -f "$st/fail/image" ] || absent_error "Error response from daemon: No such image: $img"
|
||||
if [ -f "$st/fail/image-nondb" ]; then
|
||||
case "$img" in *supabase/postgres*) ;; *) absent_error "Error response from daemon: No such image: $img" ;; esac
|
||||
fi ;;
|
||||
network | volume)
|
||||
kind="${sub}s" op="${1:-}"
|
||||
shift
|
||||
case "$op" in
|
||||
inspect)
|
||||
if [ "${1:-}" = -f ]; then shift 2; fi
|
||||
if [ -f "$st/fail/inspect-error" ]; then echo "Error response from daemon: permission denied" >&2; exit 1; fi
|
||||
# Docker's real wordings (checked on a real host): they differ by kind.
|
||||
if lost "$sub"; then dial_error; fi
|
||||
if [ -f "$st/fail/inspect-error" ]; then absent_error "Error response from daemon: permission denied"; fi
|
||||
# Docker's real wordings: they differ by kind.
|
||||
if [ ! -f "$st/$kind/$1" ]; then
|
||||
case "$sub" in
|
||||
volume) echo "Error response from daemon: get $1: no such volume" >&2 ;;
|
||||
*) echo "Error response from daemon: network $1 not found" >&2 ;;
|
||||
volume) absent_error "Error response from daemon: get $1: no such volume" ;;
|
||||
*) absent_error "Error response from daemon: network $1 not found" ;;
|
||||
esac
|
||||
exit 1
|
||||
fi ;;
|
||||
create)
|
||||
[ ! -f "$st/fail/$kind-create" ] || exit 1
|
||||
@@ -127,6 +150,7 @@ case "$sub" in
|
||||
# Like Docker: a volume create on an existing name succeeds and prints the name.
|
||||
if [ -f "$st/$kind/$name" ]; then if [ "$sub" = volume ]; then echo "$name"; exit 0; fi; exit 1; fi
|
||||
: > "$st/$kind/$name"
|
||||
if [ -f "$st/fail/daemon-lost-after-create" ]; then : > "$st/lost-now"; fi
|
||||
[ ! -f "$st/fail/$kind-create-after" ] || exit 1
|
||||
echo "$name" ;;
|
||||
rm) for n in "$@"; do [ -f "$st/$kind/$n" ] || exit 1; rm -f "$st/$kind/$n"; done ;;
|
||||
@@ -137,8 +161,10 @@ case "$sub" in
|
||||
shift
|
||||
fmt=''
|
||||
if [ "${1:-}" = -f ]; then fmt="$2"; shift 2; fi
|
||||
if [ -f "$st/fail/inspect-error" ]; then echo "Error response from daemon: permission denied" >&2; exit 1; fi
|
||||
[ -f "$st/containers/$1" ] || { echo "Error response from daemon: No such container: $1" >&2; exit 1; }
|
||||
if lost container; then dial_error; fi
|
||||
if [ -f "$st/fail/inspect-error" ]; then absent_error "Error response from daemon: permission denied"; fi
|
||||
if [ -f "$st/fail/inspect-after-stop" ] && [ -f "$st/stopped" ]; then absent_error "Error response from daemon: permission denied"; fi
|
||||
[ -f "$st/containers/$1" ] || absent_error "Error response from daemon: No such container: $1"
|
||||
case "$fmt" in
|
||||
'{{.State.Running}}') if [ "$(cat "$st/containers/$1")" = running ]; then echo true; else echo false; fi ;;
|
||||
'{{.Name}}') echo "/$1" ;;
|
||||
@@ -160,6 +186,7 @@ case "$sub" in
|
||||
if [ "$name" = faunosteo_trial_helper ] && [ -f "$st/fail/helper" ]; then exit 1; fi
|
||||
if [ "$input" -eq 1 ]; then [ ! -f "$st/fail/extract" ] || exit 1; save_stdin >/dev/null; fi
|
||||
# Measure: 100 KiB and 2 entries ("." and "./content"), what the archive below lists.
|
||||
if printf '%s\n' "$@" | grep -qx -- 'ls -A /volume'; then cat "$st/answers/volume-ls" 2>/dev/null || true; fi
|
||||
if printf '%s\n' "$@" | grep -q -- 'du -sk /volume'; then
|
||||
printf '%s\n2\n' "$(cat "$st/answers/measure-kib" 2>/dev/null || echo 100)"
|
||||
fi
|
||||
@@ -189,7 +216,11 @@ case "$sub" in
|
||||
for n in "$@"; do [ -f "$st/containers/$n" ] || exit 1; echo running > "$st/containers/$n"; done ;;
|
||||
stop)
|
||||
while [ "${1:-}" = -t ]; do shift 2; done
|
||||
for n in "$@"; do [ -f "$st/containers/$n" ] || exit 1; echo exited > "$st/containers/$n"; done ;;
|
||||
: > "$st/stopped"
|
||||
for n in "$@"; do
|
||||
[ -f "$st/containers/$n" ] || exit 1
|
||||
[ -f "$st/fail/stop-noop" ] || echo exited > "$st/containers/$n"
|
||||
done ;;
|
||||
rm)
|
||||
if [ "${1:-}" = -f ]; then shift; fi
|
||||
if [ -f "$st/append-on-rm" ]; then printf x >> "$(cat "$st/append-on-rm")"; fi
|
||||
@@ -530,6 +561,18 @@ expect_run() { # name port inner memory pids [volume]
|
||||
ALLOWED_NAMES='faunosteo_trial_(db|mail|auth|storage|rest|gateway|helper|net)|supabase_(admin|auth_admin|storage_admin|migrations)|faunosteo_stack|faunosteo_trial'
|
||||
only_trial_names() { ! docker_calls | grep -oE '(faunosteo|supabase)_[A-Za-z0-9_]+' | grep -vxE "$ALLOWED_NAMES" | grep -q .; }
|
||||
no_volume_removal() { ! log_has 'docker volume rm'; }
|
||||
# Each whole line of the text comes before its first line matching the ERE, in the order given.
|
||||
lines_before_first() { # text pattern line...
|
||||
local text="$1" pattern="$2" first n line previous=0
|
||||
first="$(grep -nE -- "$pattern" <<<"$text" | head -n 1 | cut -d: -f1)"
|
||||
[ -n "$first" ] || return 1
|
||||
shift 2
|
||||
for line in "$@"; do
|
||||
n="$(grep -nxF -- "$line" <<<"$text" | head -n 1 | cut -d: -f1)"
|
||||
[ -n "$n" ] && [ "$n" -lt "$first" ] && [ "$n" -gt "$previous" ] || return 1
|
||||
previous="$n"
|
||||
done
|
||||
}
|
||||
line_of() { grep -nF -- "$1" "$CASE/log" | head -n 1 | cut -d: -f1; }
|
||||
before() { local a b; a="$(line_of "$1")"; b="$(line_of "$2")"; [ -n "$a" ] && [ -n "$b" ] && [ "$a" -lt "$b" ]; }
|
||||
hold_port() { # port → LISTENER pid, or returns 1 when the port cannot be held
|
||||
@@ -626,6 +669,8 @@ new_case daemon-down; : > "$CASE/stub/fail/daemon"; trial create
|
||||
check "Docker daemon down: create refuses, no state written" bash -c '[ "$1" -ne 0 ] && grep -qF "Docker daemon unreachable" "$2" && [ ! -e "$3" ]' _ "$RC" "$CASE/out" "$STATE_DIR"
|
||||
trial plan
|
||||
check "Docker daemon down: plan still answers and names it" bash -c '[ "$1" -eq 0 ] && grep -qF "Docker daemon is unreachable" "$2" && grep -qF "create would refuse" "$2"' _ "$RC" "$CASE/out"
|
||||
mkdir -p "$CASE/stub/volumes"; : > "$CASE/stub/volumes/faunosteo_trial_db"; trial plan
|
||||
check "Docker daemon down: plan lists no existing resource (one exists in the stub) and says so" bash -c '[ "$1" -eq 0 ] && grep -qF "existing containers, network and volumes are not listed" "$2" && ! grep -qF "already exists" "$2"' _ "$RC" "$CASE/out"
|
||||
new_case inspect-error; : > "$CASE/stub/fail/inspect-error"; trial create
|
||||
check "an inspect error other than 'No such' is never read as absent: create refuses before any change" bash -c '[ "$1" -ne 0 ] && grep -qF "docker container inspect faunosteo_trial_db failed" "$2" && [ -z "$3" ] && [ ! -e "$4" ]' _ "$RC" "$CASE/out" "$(changes)" "$STATE_DIR"
|
||||
new_case helper-fails; : > "$CASE/stub/fail/helper"; trial create
|
||||
@@ -669,6 +714,7 @@ check "create: GoTrue mail links on the trial host's app origin" bash -c 'grep -
|
||||
check "create: gateway refuses GoTrue's admin API" log_has 'location /auth/v1/admin/ { return 403; }'
|
||||
check "create: gateway names itself on /__faunosteo_stack" log_has 'location = /__faunosteo_stack { default_type text/plain; return 200 "faunosteo_trial\n"; }'
|
||||
check "create: the database init turns statement logging on errors off first" log_has 'set log_min_error_statement = panic;'
|
||||
check "create: the database init silences statement logging and verbose errors, in order, before the first ALTER" lines_before_first "$(run_line faunosteo_trial_db | sed 's/\\n/\n/g')" '^ALTER ' '\set VERBOSITY terse' "set log_statement = 'none';" 'set log_min_duration_statement = -1;' 'set log_min_error_statement = panic;' "set pgaudit.log = 'none';" 'set pg_stat_statements.track_utility = off;'
|
||||
check "create: migrations through the CLI on the trial URL only" log_has 'supabase --workdir . migration up --db-url postgresql://postgres@127.0.0.1:58432/postgres?sslmode=disable PGPASSWORD=set'
|
||||
check "create: equine_draft.sql loaded" stdin_has "-- Official equine anatomical sheet"
|
||||
check "create: seed.sql never loaded" stdin_lacks faunosteo.local
|
||||
@@ -807,6 +853,7 @@ rm -f "$CASE/stub/commit-then-fail" "$CASE/stub/answers/rotation-marker"
|
||||
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.before-rotation"
|
||||
fresh_log; trial rotate-secrets
|
||||
check "rotate-secrets: succeeds" [ "$RC" -eq 0 ]
|
||||
check "rotate-secrets: the final message does not claim sessions end" bash -c 'grep -qF "access tokens signed with the old secret are refused; refresh tokens and sessions stay valid" "$1" && grep -qF "account passwords and TOTP factors unchanged" "$1" && ! grep -qF "sign in again" "$1"' _ "$CASE/out"
|
||||
check "rotate-secrets: every value renewed" bash -c 'for k in TR_PW TR_JWT_SECRET TR_ANON_KEY TR_SERVICE_KEY; do [ "$(grep "^$k=" "$1")" != "$(grep "^$k=" "$2")" ] || exit 1; done' _ "$STATE_DIR/secrets.env" "$CASE/secrets.before-rotation"
|
||||
check "rotate-secrets: a restorable, protected backup holding the previous secrets (no secrets.prev needed)" bash -c 'd=$(ls -d "$1"/*-pre-rotate* | tail -n 1); [ -n "$d" ] && [ "$(stat -c %a "$d")" = 700 ] && for f in db.tar storage.tar secrets.env stack.conf migrations.sha256 SHA256SUMS; do [ "$(stat -c %a "$d/$f")" = 600 ] || exit 1; done && cd "$d" && sha256sum --quiet -c SHA256SUMS && cmp -s secrets.env "$2"' _ "$STATE_DIR/backups" "$CASE/secrets.before-rotation"
|
||||
check "rotate-secrets: values reach psql by environment names only" log_has 'docker exec -i -e PGPASSWORD -e PGAPPNAME -e NEW_PW -e NEW_JWT -e ROT_DIGEST faunosteo_trial_db psql -X -q -h 127.0.0.1 -U supabase_admin'
|
||||
@@ -851,6 +898,7 @@ check "restore: succeeds" [ "$RC" -eq 0 ]
|
||||
check "restore: says the backup brings back older secrets" out_has "holds other secrets than the current ones"
|
||||
check "restore: a backup of the current state first" before 'faunosteo_trial_db:/volume:ro --entrypoint tar' 'docker volume rm faunosteo_trial_db'
|
||||
check "restore: volumes replaced then filled by the helper" before 'docker volume create --label faunosteo.stack=trial faunosteo_trial_db' 'docker run --rm -i --name faunosteo_trial_helper --network none -v faunosteo_trial_db:/volume --entrypoint tar'
|
||||
check "restore: each fresh volume is checked empty by the helper before the extraction" before 'ls -A /volume' 'docker run --rm -i --name faunosteo_trial_helper'
|
||||
check "restore: the backup's secrets are back" cmp -s "$STATE_DIR/secrets.env" "$BK/secrets.env"
|
||||
check "restore: six containers recreated" bash -c 'for n in db mail auth storage rest gateway; do grep -q "^docker run -d --name faunosteo_trial_$n " "$1" || exit 1; done' _ "$CASE/log"
|
||||
check "restore: only trial names" only_trial_names
|
||||
@@ -997,7 +1045,7 @@ new_case b2-lock; trial create
|
||||
rm -f "$CASE/stub/volumes/faunosteo_trial_db"
|
||||
flock "$STATE_DIR/.lock" sleep 6 & LOCK_HOLDER=$!
|
||||
sleep 0.5
|
||||
for action in backup migrate rotate-keys rotate-secrets; do
|
||||
for action in backup migrate rotate-keys rotate-secrets start stop; do
|
||||
fresh_log; trial "$action"
|
||||
check "$action: the lock is taken before the stack is checked" bash -c '[ "$1" -ne 0 ] && grep -qF "another pnpm db:trial command is running" "$2"' _ "$RC" "$CASE/out"
|
||||
done
|
||||
@@ -1040,6 +1088,7 @@ rm -f "$CASE/stub/fail/rotate"; : > "$CASE/stub/commit-then-fail"; printf '1\n0\
|
||||
check "a rotation session active once then gone, marker equal: the rotation goes on" bash -c '[ "$1" -eq 0 ] && grep -qF "took the new secrets although psql failed" "$2" && [ "$3" -eq 2 ]' _ "$RC" "$CASE/out" "$(polls)"
|
||||
rm -f "$CASE/stub/commit-then-fail" "$CASE/stub/answers/rotation-marker"; fresh_log; trial rotate-secrets
|
||||
check "rotate-secrets: the SQL is one explicit transaction (begin before every alter, commit last)" sql_is_one_explicit_transaction "$(rotation_sql)"
|
||||
check "rotate-secrets: the rotation SQL silences every logging channel, in order, before any alter" lines_before_first "$(cat "$(rotation_sql)")" '^alter ' '\set VERBOSITY terse' 'begin;' "set local log_statement = 'none';" 'set local log_min_duration_statement = -1;' 'set local log_min_error_statement = panic;' "set local pgaudit.log = 'none';" 'set local pg_stat_statements.track_utility = off;'
|
||||
check "rotate-secrets: the rotation session is named (PGAPPNAME passed by name)" bash -c '[ "$1" -eq 0 ] && grep -qF -- "-e PGAPPNAME" "$2"' _ "$RC" "$CASE/log"
|
||||
check "rotate-secrets: no --single-transaction on the rotation session" no_single_transaction_rotation
|
||||
|
||||
@@ -1408,6 +1457,123 @@ check "app: the renewed anon key passes" [ "$RC" -eq 0 ]
|
||||
fresh_log; trial stop; fresh_log; trial app
|
||||
check "app: refused while the stack is stopped" refused "is not running"
|
||||
|
||||
echo "-- closure code-review fixes (2026-11-11)"
|
||||
# 1: a daemon lost between the dispatch check and an inspect is never read as "absent".
|
||||
lost_refused() { # inspect kind, resource name
|
||||
[ "$RC" -ne 0 ] && [ -z "$(changes)" ] && out_has "docker $1 inspect $2 failed (exit 1)"
|
||||
}
|
||||
new_case lost-create; : > "$CASE/stub/fail/daemon-lost"; trial create
|
||||
check "daemon lost mid-command: create refuses, nothing created, no state written" bash -c '[ "$1" -ne 0 ] && [ ! -e "$2" ]' _ "$RC" "$STATE_DIR"
|
||||
check "daemon lost mid-command: create names the container inspect" lost_refused container faunosteo_trial_db
|
||||
new_case lost-create-network; : > "$CASE/stub/fail/daemon-lost-network"; trial create
|
||||
check "daemon lost on a network inspect: create refuses, nothing created" lost_refused network faunosteo_trial_net
|
||||
new_case lost-create-volume; : > "$CASE/stub/fail/daemon-lost-volume"; trial create
|
||||
check "daemon lost on a volume inspect: create refuses, nothing created" lost_refused volume faunosteo_trial_db
|
||||
b2_stack lost-stack
|
||||
COUNT="$(backup_count)"; : > "$CASE/stub/fail/daemon-lost"
|
||||
fresh_log; trial_tty faunosteo_trial destroy
|
||||
check "daemon lost mid-command: destroy refuses, nothing removed, state files and backups kept" bash -c '[ -f "$1/secrets.env" ] && [ "$2" -eq "$3" ]' _ "$STATE_DIR" "$COUNT" "$(backup_count)"
|
||||
check "daemon lost mid-command: destroy names the inspect that failed" lost_refused container faunosteo_trial_db
|
||||
fresh_log; trial_tty "restore $RN" restore "$RN"
|
||||
check "daemon lost mid-command: restore refuses, nothing removed, no backup taken" bash -c '[ -f "$1/secrets.env" ] && [ "$2" -eq "$3" ]' _ "$STATE_DIR" "$COUNT" "$(backup_count)"
|
||||
check "daemon lost mid-command: restore names the inspect that failed (the recorded image, read first)" lost_refused image public.ecr.aws/supabase/postgres:17.11.0.004
|
||||
rm -f "$CASE/stub/fail/daemon-lost"
|
||||
|
||||
# 2: container_running is tri-state; backup proves the stack stopped.
|
||||
new_case stop-inspect; trial create
|
||||
: > "$CASE/stub/fail/inspect-after-stop"; fresh_log; trial backup
|
||||
check "backup: an inspect failing during the stop is refused, never read as stopped, no complete folder" bash -c '[ "$1" -ne 0 ] && grep -qF "failed (exit 1)" "$2" && ! ls "$3"/backups/*/SHA256SUMS >/dev/null 2>&1' _ "$RC" "$CASE/out" "$STATE_DIR"
|
||||
new_case stop-noop; trial create
|
||||
: > "$CASE/stub/fail/stop-noop"; COUNT="$(backup_count)"; fresh_log; trial backup
|
||||
check "backup: a container still running after the stop is refused, nothing archived, no folder kept" bash -c '[ "$1" -ne 0 ] && grep -qF "still runs after the stop" "$2" && ! grep -qF "stays stopped" "$2" && ! grep -qF -- "--entrypoint tar" "$3" && [ "$4" -eq "$5" ]' _ "$RC" "$CASE/out" "$CASE/log" "$COUNT" "$(backup_count)"
|
||||
|
||||
# 3: docker volume create succeeds on an existing name.
|
||||
b2_stack nonempty-volume
|
||||
echo lost+found > "$CASE/stub/answers/volume-ls"
|
||||
fresh_log; trial_tty "restore $RN" restore "$RN"
|
||||
check "restore: a volume not empty once created is refused, nothing extracted, the pre-restore backup named" bash -c '[ "$1" -ne 0 ] && grep -qF "is not empty after its creation" "$2" && grep -qE "pnpm db:trial restore [0-9]{8}T[0-9]{6}Z-pre-restore" "$2" && ! grep -qF "docker run --rm -i" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
||||
check "restore: the emptiness is read by the helper, read-only, no network" log_has 'docker run --rm --name faunosteo_trial_helper --network none -v faunosteo_trial_db:/volume:ro --entrypoint sh public.ecr.aws/supabase/postgres:17.11.0.004 -c ls -A /volume'
|
||||
|
||||
# 6: backup and migrate stop the stack, so they refuse while the app runs.
|
||||
new_case app-stop; trial create
|
||||
printf -- '-- harness\n' > "$WORK/repo/supabase/migrations/29991231000003_harness_app.sql"
|
||||
if hold_port 5194; then
|
||||
fresh_log; trial backup
|
||||
check "backup while port 5194 is in use (the app): refused, nothing stopped" refused "5194 is in use"
|
||||
fresh_log; trial migrate
|
||||
check "migrate while port 5194 is in use (the app): refused, nothing stopped, no backup" bash -c 'grep -qF "5194 is in use" "$1" && ! grep -qF faunosteo_trial_helper "$2"' _ "$CASE/out" "$CASE/log"
|
||||
check "migrate while port 5194 is in use: no stop, no migration" refused "5194 is in use"
|
||||
release_port
|
||||
else fail "could not hold 127.0.0.1:5194 for the backup and migrate cases"; fi
|
||||
rm -f "$WORK/repo/supabase/migrations/29991231000003_harness_app.sql"
|
||||
|
||||
# 7: the app host is checked before the first change.
|
||||
refused_keeping_backups() { refused "$1" && [ "$COUNT" -eq "$(backup_count)" ]; }
|
||||
b2_stack host-precheck
|
||||
COUNT="$(backup_count)"; EXTRA=(FAUNOSTEO_TRIAL_HOST=8.8.8.8)
|
||||
fresh_log; trial_tty "restore $RN" restore "$RN"
|
||||
check "restore with no usable app host: refused before the confirmation, no backup, nothing changed" bash -c '! grep -qF "to go on" "$1"' _ "$CASE/out"
|
||||
check "restore with no usable app host: refused on the host" refused_keeping_backups "must be loopback or a private address"
|
||||
fresh_log; trial rotate-secrets
|
||||
check "rotate-secrets with no usable app host: refused before any backup, nothing changed" refused_keeping_backups "must be loopback or a private address"
|
||||
EXTRA=()
|
||||
|
||||
# 9: an address with no account is told as such on the role path too.
|
||||
new_case no-account-grant; trial create
|
||||
echo no_account > "$CASE/stub/answers/grant-factor-count"
|
||||
for role in owner admin; do
|
||||
fresh_stdin; fresh_log; trial_tty "grant $role" grant ghost@trial.test "$role"
|
||||
check "grant $role for an address with no account: refused with the account hint, nothing granted" bash -c '[ "$1" -ne 0 ] && grep -qF "no account ghost@trial.test (pnpm db:trial account ghost@trial.test first): nothing was granted" "$2" && ! grep -qF "verified TOTP factor(s)" "$2"' _ "$RC" "$CASE/out"
|
||||
check "grant $role for an address with no account: no role SQL ran" no_role_assigned
|
||||
done
|
||||
check "grant: the factor count answers no_account from SQL, the email through -v" bash -c 'grep -qF "no_account" "$1" && grep -qF -- "-v email=ghost@trial.test" "$2"' _ "$(stdin_of grant-factor-count)" "$CASE/log"
|
||||
|
||||
echo "-- closure re-review fixes (2026-11-11)"
|
||||
# C1/C3: a failing inspect writes a bare newline to stdout and the sentence to stderr (Docker 29.9.3).
|
||||
stub_inspect() { # kind name → stdout bytes, then stderr, of the stub's failing inspect
|
||||
STUB_STATE="$CASE/stub" STUB_LOG="$CASE/log" "$WORK/bin/docker" "$1" inspect -f '{{.Id}}' "$2" 2>"$CASE/err" | od -An -c | tr -d ' '
|
||||
}
|
||||
stub_streams_split() {
|
||||
local kind
|
||||
for kind in container volume network image; do
|
||||
[ "$(stub_inspect "$kind" x1)" = '\n' ] || return 1
|
||||
[ -s "$CASE/err" ] && [ "$(wc -l < "$CASE/err")" -eq 1 ] || return 1
|
||||
done
|
||||
}
|
||||
new_case streams; trial plan; : > "$CASE/stub/fail/image"
|
||||
check "the stub's absent answers: a bare newline on stdout, one sentence on stderr, for all four kinds" stub_streams_split
|
||||
: > "$CASE/stub/fail/daemon-lost"
|
||||
check "the stub's daemon-lost answers split the streams the same way, image included" bash -c '[ "$1" = "\n" ] && [ "$2" = "\n" ]' _ "$(stub_inspect image x1)" "$(stub_inspect container x1)"
|
||||
new_case absent-plan; trial plan
|
||||
check "plan: stub-absent resources read as absent, nothing already exists" bash -c '[ "$1" -eq 0 ] && grep -qF "create would proceed" "$2" && ! grep -qF "already exists" "$2"' _ "$RC" "$CASE/out"
|
||||
new_case absent-flow; trial create
|
||||
check "create: the preflight reads every stub-absent resource as absent and goes on" [ "$RC" -eq 0 ]
|
||||
fresh_log; trial backup
|
||||
check "backup: the helper check reads the absent helper container as absent and goes on" bash -c '[ "$1" -eq 0 ] && ls "$2"/backups/*/SHA256SUMS >/dev/null 2>&1' _ "$RC" "$STATE_DIR"
|
||||
fresh_log; trial status
|
||||
check "status: reads absent resources as absent, no refusal" bash -c '[ "$1" -eq 0 ] && ! grep -qF "refused" "$2"' _ "$RC" "$CASE/out"
|
||||
new_case absent-status; trial status
|
||||
check "status without a stack: stub-absent resources, none listed, no refusal" bash -c '[ "$1" -eq 0 ] && ! grep -qF "present anyway" "$2" && ! grep -qF "refused" "$2"' _ "$RC" "$CASE/out"
|
||||
|
||||
# C2: a lost daemon is not "image not present locally".
|
||||
b2_stack lost-restore
|
||||
COUNT="$(backup_count)"; : > "$CASE/stub/fail/daemon-lost"
|
||||
fresh_log; trial_tty "restore $RN" restore "$RN"
|
||||
check "restore with the daemon lost: refused on the image inspect, never 'docker pull', nothing removed" bash -c '[ "$1" -ne 0 ] && grep -qF "cannot tell whether its images are present" "$2" && grep -qF "docker image inspect" "$2" && ! grep -qF "docker pull" "$2" && ! grep -qF "not present locally" "$2" && [ "$3" -eq "$4" ]' _ "$RC" "$CASE/out" "$COUNT" "$(backup_count)"
|
||||
check "restore with the daemon lost: no change at all" [ -z "$(changes)" ]
|
||||
|
||||
# M6: the create trap ends with its hint when its listing fails.
|
||||
new_case lost-after-create; : > "$CASE/stub/fail/daemon-lost-after-create"; trial create
|
||||
check "create with the daemon lost after the first resource: the trap runs, nothing removed, state files kept, the hint printed" bash -c '[ "$1" -ne 0 ] && grep -qF "nothing was removed" "$2" && grep -qF "the listing failed" "$2" && grep -qF "inspect the faunosteo_trial resources by hand" "$2" && grep -qF "pnpm db:trial status shows the state" "$2" && [ -f "$3/secrets.env" ] && [ -f "$3/stack.conf" ] && ! grep -qE "^docker (rm|volume rm|network rm) " "$4"' _ "$RC" "$CASE/out" "$STATE_DIR" "$CASE/log"
|
||||
|
||||
# M7: start checks the app host before it starts or recreates anything.
|
||||
new_case start-host; trial create; trial stop
|
||||
rm -f "$CASE/stub/containers/faunosteo_trial_rest" "$CASE/stub/ports/faunosteo_trial_rest"
|
||||
EXTRA=(FAUNOSTEO_TRIAL_HOST=8.8.8.8); fresh_log; trial start
|
||||
check "start with no usable app host: refused before any container is started or recreated" refused "must be loopback or a private address"
|
||||
EXTRA=()
|
||||
|
||||
|
||||
echo "-- db:sandbox state guard"
|
||||
new_case sandbox-guard; mkdir -p "$CASE/trialstate"; : > "$CASE/trialstate/.faunosteo-trial-state"
|
||||
EXTRA=(FAUNOSTEO_SANDBOX_DIR="$CASE/trialstate"); sandbox down
|
||||
|
||||
Reference in new issue
Block a user