feat(supabase): db:trial foundation (plan, create, start, stop, status)
scripts/db-trial.sh builds the persistent manual trial stack on literal faunosteo_trial_* names, loopback 58xxx ports, named volumes and a 700 state folder outside any git work tree; it refuses SANDBOX_* variables, a remote Docker daemon, a missing or failing ss, and checks each container's exact loopback publication and the gateway identity. The stub harness (scripts/db-trial-check.sh, 87 cases, no daemon reachable) proves it; db-sandbox.sh refuses a trial state folder (additions only). Nothing is created here.
This commit is contained in:
1 parent
9f60d841eb
commit
1a7b952f2f
6 files changed
+1712
-2
No files matched your search
@@ -222,7 +222,7 @@ merge or deploy; a script's interactive confirmation is never the owner's prior
|
||||
EXPECT: db-trial-check: ALL PASS
|
||||
EVIDENCE: pending
|
||||
18. [gated 2026-11-10] Static checks: shellcheck clean on `db-trial.sh`, the harness and `db-sandbox.sh`.
|
||||
CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && shellcheck scripts/db-trial.sh scripts/db-trial-check.sh && shellcheck -e SC1090,SC1091,SC2016 scripts/db-sandbox.sh && echo SHELLCHECK-OK
|
||||
CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && shellcheck -x scripts/db-trial.sh scripts/db-trial-check.sh && shellcheck -e SC1090,SC1091,SC2016 scripts/db-sandbox.sh && echo SHELLCHECK-OK
|
||||
EXPECT: SHELLCHECK-OK
|
||||
EVIDENCE: pending
|
||||
19. [gated 2026-11-10] Project suites green.
|
||||
|
||||
@@ -2242,7 +2242,8 @@ expect_run() { # name port inner memory pids [volume]
|
||||
if [ -n "${6:-}" ]; then grep -qF -- " -v $6 " <<<"$line"; else ! grep -qE -- ' -v ' <<<"$line"; fi
|
||||
}
|
||||
# Resource names plus the Supabase roles and the migrations schema that SQL text in argv may name.
|
||||
ALLOWED_NAMES='faunosteo_trial_(db|mail|auth|storage|rest|gateway|helper|net)|supabase_(admin|auth_admin|storage_admin|migrations)'
|
||||
# faunosteo_stack and faunosteo_trial: the gateway identity path and body (/__faunosteo_stack answers faunosteo_trial), not resource names.
|
||||
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'; }
|
||||
line_of() { grep -nF -- "$1" "$CASE/log" | head -n 1 | cut -d: -f1; }
|
||||
@@ -2448,6 +2449,24 @@ echo "-- $PASS passed, $FAIL failed"
|
||||
if [ "$FAIL" -eq 0 ] && [ "$PASS" -gt 0 ]; then echo "db-trial-check: ALL PASS"; else exit 1; fi
|
||||
```
|
||||
|
||||
#### Lot B1 review fixes (2026-11-10)
|
||||
|
||||
The files `scripts/db-trial.sh` and `scripts/db-trial-check.sh` intentionally differ from the B1 code blocks above:
|
||||
|
||||
- Harness: the equine-seed check is two checks (`stdin_has`, `stdin_lacks`); no unquoted `$stdin`, no read of the harness stdin.
|
||||
- Harness: `verify_stub_shadow` runs in every `run_script` with the case's own PATH (ss: the stub, or absent for the ss-absent case); a mismatch prints the reason and exits 1 for the whole run. PATH is applied after EXTRA; a PATH in EXTRA is refused.
|
||||
- `new_secrets_file`: written to `<file>.new` under umask 077, then `mv -f`; `.new` removed on failure.
|
||||
- Git guard: `refuse_inside_git` refuses a `.git` entry (file or folder) in any ancestor, then asks git with GIT_DIR, GIT_WORK_TREE and GIT_CEILING_DIRECTORIES unset (a subshell `unset`, not `env -u`: the harness `env` wrapper logs argv); only "not a git repository" (exit 128) is outside, any other answer dies.
|
||||
- `container_exists`, `volume_exists`, `network_exists` go through `resource_exists`: only an error matching, case-insensitively, "no such" or "not found" is absent (real wordings: `No such container: x`, `get x: no such volume`, `network x not found`), any other inspect error dies naming the resource. Docker stub: absent answers those three real wordings, `volume create` is idempotent, `fail/inspect-error`, `fail/helper` and `fail/networks-create-after` modes.
|
||||
- `create_state_folder`: lock taken right after mkdir and chmod, `secrets.env` check repeated under it, marker written after.
|
||||
- `FIRST_RESOURCE=yes` is set before `docker network create`; `create_stopped` then removes the state files only when no faunosteo_trial_ resource exists (existing case kept), else names what is present.
|
||||
- `take_lock` opens `.lock` under umask 077 (harness asserts 600).
|
||||
- `require_local_daemon` prints the endpoint without anything up to the last `@`.
|
||||
- `check_helper_image` message names its two causes and the `docker rm` way out.
|
||||
- `cmd_plan`, `cmd_create`, `cmd_status`, `status_database` split into helpers (`plan_*`, `create_*`, `status_*`), same output; plan sections append refusals through a nameref array.
|
||||
- Harness header: `hold_port` opens real loopback listeners on 58801, 5194 and 58300 for up to 30 s, closed at cleanup.
|
||||
- Kept for B2/B3: `client_key`, `gateway_identity`, `key_identity`, `restart_gateway` and the other helpers; no B2/B3 block relies on a changed behaviour (`new_secrets_file "$next" || true` stays correct).
|
||||
|
||||
---
|
||||
|
||||
### Lot B2: backup, restore, destroy, migrate, rotate-keys, rotate-secrets
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
"db:types": "bash scripts/supabase.sh gen types typescript --local --schema public | prettier --parser typescript > packages/supabase/src/database.types.ts",
|
||||
"db:types:check": "bash scripts/supabase.sh gen types typescript --local --schema public | prettier --parser typescript | diff - packages/supabase/src/database.types.ts",
|
||||
"db:sandbox": "bash scripts/db-sandbox.sh",
|
||||
"db:trial": "bash scripts/db-trial.sh",
|
||||
"assets:upload": "bash scripts/upload-sheet-assets.sh",
|
||||
"e2e:sheet-assets": "bash scripts/db-sandbox.sh sheet-assets-e2e",
|
||||
"build:preview": "SHEET_BUNDLE=draft pnpm --filter @faunosteo/app build",
|
||||
|
||||
@@ -68,6 +68,12 @@ REPO="$(realpath "$PWD")"
|
||||
case "$(realpath -m "$STATE")" in
|
||||
"$REPO" | "$REPO"/*) die "FAUNOSTEO_SANDBOX_DIR must be outside the repository" ;;
|
||||
esac
|
||||
# The db:trial state folder (scripts/db-trial.sh) is never the sandbox's: `down` would delete
|
||||
# files there while the trial volumes keep the matching passwords.
|
||||
TRIAL_STATE="$(realpath -m "${FAUNOSTEO_TRIAL_DIR:-$HOME/.cache/faunosteo-trial}")"
|
||||
if [ "$(realpath -m "$STATE")" = "$TRIAL_STATE" ] || [ -e "$STATE/.faunosteo-trial-state" ]; then
|
||||
die "FAUNOSTEO_SANDBOX_DIR is the db:trial state folder: refused, nothing was run"
|
||||
fi
|
||||
# Every value must be present: an empty password would turn --db-url into an
|
||||
# argument the CLI might read as absent and fall back to the DEV database.
|
||||
load_secrets() {
|
||||
|
||||
Executable
+604
@@ -0,0 +1,604 @@
|
||||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC2016
|
||||
# (file-wide: the `bash -c '…'` snippets of the checks expand their own positional parameters)
|
||||
#
|
||||
# `bash scripts/db-trial-check.sh`, run by hand (never a check:all stage): environment-free checks
|
||||
# of scripts/db-trial.sh and of the state-folder guard of scripts/db-sandbox.sh (TRIAL_STACK.md,
|
||||
# SUPABASE.md §5.2). Each case runs a script from a throwaway copy of the files it reads, under a
|
||||
# temporary HOME, with docker, curl, the Supabase CLI, Vite and the Rust tools replaced by stubs
|
||||
# that log their arguments and keep one file per pretend resource; ss, node and env pass through
|
||||
# wrappers that log their arguments, so no secret can hide in any argv. DOCKER_HOST names a socket
|
||||
# that does not exist, so no daemon is reachable even past a stub. The script reads the host's
|
||||
# real listening ports (ss) and memory: the preflight refuses to run (exit 2, never a FAIL) while
|
||||
# a trial port is in use or memory is short. Nothing is created, started, stopped or removed
|
||||
# outside the temporary folder, except that hold_port opens real loopback listeners on 58801, 5194
|
||||
# and 58300 (python3, one at a time, up to 30 s each), closed after their case and at cleanup.
|
||||
# Prints "db-trial-check: ALL PASS" only when every check passed.
|
||||
set -uo pipefail
|
||||
|
||||
preflight() {
|
||||
local port out mib
|
||||
for port in 58432 58999 58300 58500 58025 58801 5194; do
|
||||
out="$(ss -Hltn "sport = :$port")" || { echo "db-trial-check: cannot run while ss cannot list the ports: stop the trial stack/app first" >&2; exit 2; }
|
||||
if [ -n "$out" ]; then
|
||||
echo "db-trial-check: cannot run while port $port is in use: stop the trial stack/app first" >&2
|
||||
exit 2
|
||||
fi
|
||||
done
|
||||
mib="$(awk '/^MemAvailable:/ { print int($2 / 1024) }' /proc/meminfo)"
|
||||
if [ "$mib" -lt 2048 ]; then
|
||||
echo "db-trial-check: cannot run while only $mib MiB of memory are available (create needs 2048): stop the trial stack/app first" >&2
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
preflight
|
||||
|
||||
REPO="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||
TMP_ROOT="${TMPDIR:-/tmp}"
|
||||
WORK="$(mktemp -d "$TMP_ROOT/db-trial-check.XXXXXX")" || exit 1
|
||||
# Every later path hangs off WORK: it must be the fresh folder mktemp just made, nothing else.
|
||||
case "$WORK" in
|
||||
"$TMP_ROOT"/db-trial-check.?*) [ -d "$WORK" ] || exit 1 ;;
|
||||
*) echo "db-trial-check: unexpected temporary folder '$WORK': nothing was run" >&2; exit 1 ;;
|
||||
esac
|
||||
cleanup() { [ -z "${LISTENER:-}" ] || kill "$LISTENER" 2>/dev/null; ( cd "$WORK" && rm -rf -- ./repo ./bin ./bin-no-ss ./path-no-ss ./cases ./docker-config ); rmdir -- "$WORK" 2>/dev/null || true; }
|
||||
trap cleanup EXIT
|
||||
PASS=0 FAIL=0
|
||||
pass() { echo "PASS $1"; PASS=$((PASS + 1)); }
|
||||
fail() { echo "FAIL $1"; FAIL=$((FAIL + 1)); }
|
||||
check() { local name="$1"; shift; if "$@"; then pass "$name"; else fail "$name"; fi; }
|
||||
|
||||
SEED_REL=supabase/seed/anatomical-sheets/equine/draft
|
||||
mkdir -p "$WORK/repo/scripts" "$WORK/repo/$SEED_REL/assets" "$WORK/repo/node_modules/.bin" \
|
||||
"$WORK/repo/apps/app/node_modules/.bin" "$WORK/bin" "$WORK/cases" "$WORK/docker-config"
|
||||
cp "$REPO/scripts/db-trial.sh" "$REPO/scripts/db-sandbox.sh" "$REPO/scripts/dev-env.sh" "$WORK/repo/scripts/"
|
||||
cp "$REPO/supabase/config.toml" "$REPO/supabase/seed.sql" "$WORK/repo/supabase/"
|
||||
cp -R "$REPO/supabase/migrations" "$WORK/repo/supabase/migrations"
|
||||
for f in equine_draft.sql document.json sheet-ref.json assets.json; do cp "$REPO/$SEED_REL/$f" "$WORK/repo/$SEED_REL/"; done
|
||||
cp "$REPO/$SEED_REL/assets/"*.svg "$WORK/repo/$SEED_REL/assets/"
|
||||
|
||||
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
|
||||
# (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, <sql tag>. An absent resource answers in Docker's own wording per kind.
|
||||
set -uo pipefail
|
||||
st="$STUB_STATE"
|
||||
{ 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"; }
|
||||
sub="${1:-}"
|
||||
[ $# -eq 0 ] || shift
|
||||
case "$sub" in
|
||||
info) [ ! -f "$st/fail/daemon" ] || exit 1; echo /stub/docker-root ;;
|
||||
context)
|
||||
[ "${1:-}" = inspect ] || exit 97
|
||||
[ ! -f "$st/fail/context" ] || exit 1
|
||||
if [ -f "$st/answers/context" ]; then cat "$st/answers/context"; else echo unix:///stub/docker.sock; fi ;;
|
||||
ps) exit 0 ;;
|
||||
image) [ "${1:-}" = inspect ] || exit 97; [ ! -f "$st/fail/image" ] || exit 1 ;;
|
||||
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 [ ! -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 ;;
|
||||
esac
|
||||
exit 1
|
||||
fi ;;
|
||||
create)
|
||||
[ ! -f "$st/fail/$kind-create" ] || exit 1
|
||||
name="${*: -1}"
|
||||
# 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"
|
||||
[ ! -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 ;;
|
||||
*) exit 97 ;;
|
||||
esac ;;
|
||||
container)
|
||||
[ "${1:-}" = inspect ] || exit 97
|
||||
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; }
|
||||
case "$fmt" in
|
||||
'{{.State.Running}}') if [ "$(cat "$st/containers/$1")" = running ]; then echo true; else echo false; fi ;;
|
||||
'{{.Name}}') echo "/$1" ;;
|
||||
'') echo "stub: a bare inspect would print the env files" >&2; exit 98 ;;
|
||||
*) echo "$(cat "$st/containers/$1") stub-image" ;;
|
||||
esac ;;
|
||||
run)
|
||||
name='' port='' remove=0 input=0 args=("$@") i=0
|
||||
while [ "$i" -lt "${#args[@]}" ]; do
|
||||
case "${args[$i]}" in
|
||||
--name) name="${args[$((i + 1))]}"; i=$((i + 1)) ;;
|
||||
-p) port="${args[$((i + 1))]}"; i=$((i + 1)) ;;
|
||||
--rm) remove=1 ;;
|
||||
-i) input=1 ;;
|
||||
esac
|
||||
i=$((i + 1))
|
||||
done
|
||||
if [ "$remove" -eq 1 ]; then
|
||||
if [ "$name" = faunosteo_trial_helper ] && [ -f "$st/fail/helper" ]; then exit 1; fi
|
||||
if [ "$input" -eq 1 ]; then save_stdin >/dev/null; fi
|
||||
# Measure: 100 KiB and 2 entries ("." and "./content"), what the archive below lists.
|
||||
if printf '%s\n' "$@" | grep -q -- 'du -sk /volume'; then printf '100\n2\n'; fi
|
||||
if printf '%s\n' "$@" | grep -qx -- -cf; then
|
||||
[ ! -f "$st/fail/archive" ] || exit 3
|
||||
# A real (tiny) tar, so that the script's read-back has something to list. short-archive:
|
||||
# the root entry only, exit 0 (an archive cut at a member boundary).
|
||||
mkdir -p "$st/archive"; printf '%s\n' "$*" > "$st/archive/content"
|
||||
if [ -f "$st/short-archive" ]; then tar -cf - -C "$st/archive" --no-recursion .
|
||||
else tar -cf - -C "$st/archive" .; fi
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
[ -n "$name" ] && [ ! -f "$st/containers/$name" ] || exit 1
|
||||
echo running > "$st/containers/$name"
|
||||
if [ -n "$port" ]; then
|
||||
IFS=: read -r ip host inner <<<"$port"
|
||||
# publish-wide-<name>: Docker publishes that container on 0.0.0.0 whatever -p said.
|
||||
if [ -f "$st/publish-wide-$name" ]; then ip=0.0.0.0; fi
|
||||
echo "$inner/tcp -> $ip:$host" > "$st/ports/$name"
|
||||
fi
|
||||
echo "stub-id-$name" ;;
|
||||
start) for n in "$@"; do [ -f "$st/containers/$n" ] || exit 1; echo running > "$st/containers/$n"; done ;;
|
||||
restart)
|
||||
while [ "${1:-}" = -t ]; do shift 2; done
|
||||
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 ;;
|
||||
rm)
|
||||
if [ "${1:-}" = -f ]; then shift; fi
|
||||
for n in "$@"; do [ -f "$st/containers/$n" ] || exit 1; rm -f "$st/containers/$n" "$st/ports/$n"; done ;;
|
||||
port)
|
||||
[ -f "$st/ports/$1" ] || exit 1
|
||||
if [ $# -ge 2 ]; then sed 's/^.* -> //' "$st/ports/$1"; else cat "$st/ports/$1"; fi ;;
|
||||
exec)
|
||||
input=0
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in -i) input=1; shift ;; -e | -u) shift 2 ;; *) break ;; esac
|
||||
done
|
||||
[ "$(cat "$st/containers/$1" 2>/dev/null)" = running ] || exit 1
|
||||
shift
|
||||
# psql reads -c when given (stdin untouched, as the real psql does), else its stdin.
|
||||
query='' prev='' has_c=0
|
||||
for a in "$@"; do if [ "$prev" = -c ]; then query="$a"; has_c=1; fi; prev="$a"; done
|
||||
if [ "$input" -eq 1 ] && [ "$has_c" -eq 0 ]; then query="$(head -c 65536 "$(save_stdin)")"; fi
|
||||
tag="$(printf '%s\n' "$query" | sed -n 's/^-- db-trial:\([a-z-]*\)$/\1/p' | head -n 1)"
|
||||
# commit-then-fail: the rotation commits (its marker becomes the digest), then the exec stream
|
||||
# is lost. Without it, fail/rotate leaves the marker empty: not committed.
|
||||
if [ "$tag" = rotate ] && [ -f "$st/commit-then-fail" ]; then
|
||||
printf '%s\n' "${ROT_DIGEST:-}" > "$st/answers/rotation-marker"; echo "stub: stream lost" >&2; exit 3
|
||||
fi
|
||||
if [ -n "$tag" ] && [ -f "$st/fail/$tag" ]; then echo "stub: $tag refused" >&2; exit 3; fi
|
||||
if [ -n "$tag" ] && [ -f "$st/answers/$tag" ]; then cat "$st/answers/$tag"; fi
|
||||
exit 0 ;;
|
||||
*) echo "stub docker: unsupported $sub" >&2; exit 97 ;;
|
||||
esac
|
||||
STUB
|
||||
cat > "$WORK/bin/curl" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
# curl stand-in. The trial gateway's identity endpoint answers faunosteo_trial, or
|
||||
# answers/identity, or fails (fail/identity, curl -f's exit 22).
|
||||
{ printf 'curl'; for a in "$@"; do printf ' %s' "$a"; done; printf '\n'; } >> "$STUB_LOG"
|
||||
for a in "$@"; do
|
||||
case "$a" in
|
||||
@-) cat > "$STUB_STATE/stdin/curl-$(date +%s%N)" ;;
|
||||
# A header file (a process substitution): only a digest of what was sent is kept.
|
||||
@/dev/fd/*) sha256sum < "${a#@}" | cut -c1-16 > "$STUB_STATE/curl-header-sha" ;;
|
||||
esac
|
||||
done
|
||||
case "${*: -1}" in
|
||||
*/__faunosteo_stack)
|
||||
[ ! -f "$STUB_STATE/fail/identity" ] || exit 22
|
||||
if [ -f "$STUB_STATE/answers/identity" ]; then cat "$STUB_STATE/answers/identity"; else echo faunosteo_trial; fi ;;
|
||||
esac
|
||||
exit 0
|
||||
STUB
|
||||
# ss runs for real unless the case asks it to fail (it must then never read as "port free").
|
||||
cat > "$WORK/bin/ss" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
if [ -f "$STUB_STATE/fail/ss" ]; then echo "ss: cannot open netlink socket" >&2; exit 1; fi
|
||||
exec "$(cat "$(dirname "$0")/real-ss")" "$@"
|
||||
STUB
|
||||
command -v ss > "$WORK/bin/real-ss"
|
||||
# node and env run for real behind a wrapper that logs their argv (newlines as \n).
|
||||
cat > "$WORK/bin/passthrough" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
tool="$(basename "$0")"
|
||||
{ printf '%s' "$tool"; for a in "$@"; do printf ' %s' "${a//$'\n'/\\n}"; done; printf '\n'; } >> "$STUB_LOG"
|
||||
exec "$(cat "$(dirname "$0")/real-$tool")" "$@"
|
||||
STUB
|
||||
for tool in node env; do
|
||||
command -v "$tool" > "$WORK/bin/real-$tool"
|
||||
cp "$WORK/bin/passthrough" "$WORK/bin/$tool"
|
||||
done
|
||||
cat > "$WORK/repo/node_modules/.bin/supabase" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
{ printf 'supabase'; for a in "$@"; do printf ' %s' "$a"; done; printf ' PGPASSWORD=%s\n' "${PGPASSWORD:+set}"; } >> "$STUB_LOG"
|
||||
if [ "$*" = "--workdir . migration up --db-url postgresql://postgres@127.0.0.1:58432/postgres?sslmode=disable" ]; then
|
||||
for f in supabase/migrations/*.sql; do basename "$f" | cut -d_ -f1; done > "$STUB_STATE/answers/applied"
|
||||
if [ -f "$STUB_STATE/fail/migrate" ]; then echo "stub: a migration failed after the others applied" >&2; exit 3; fi
|
||||
exit 0
|
||||
fi
|
||||
exit 97
|
||||
STUB
|
||||
cat > "$WORK/repo/apps/app/node_modules/.bin/vite" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
{ printf 'vite'; for a in "$@"; do printf ' %s' "$a"; done; printf '\n'
|
||||
printf 'vite-env anon-sha=%s pgpassword=%s node-options=%s gateway=%s host=%s url=%s proxies=%s\n' \
|
||||
"$(printf '%s' "${VITE_SUPABASE_ANON_KEY:-}" | sha256sum | cut -c1-16)" "${PGPASSWORD:+set}" \
|
||||
"${NODE_OPTIONS:-}" "${FAUNOSTEO_TRIAL_GATEWAY:-}" "${FAUNOSTEO_TRIAL_HOST:-}" "${VITE_SUPABASE_URL:-}" \
|
||||
"${http_proxy:-}${HTTP_PROXY:-}${https_proxy:-}${HTTPS_PROXY:-}${all_proxy:-}${ALL_PROXY:-}${NODE_USE_ENV_PROXY:-}"; } >> "$STUB_LOG"
|
||||
STUB
|
||||
cat > "$WORK/repo/scripts/upload-sheet-assets.sh" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
{ printf 'upload'; for a in "$@"; do printf ' %s' "$a"; done; printf '\n'
|
||||
printf 'upload-env url=%s key-sha=%s dev-host=%s init-cwd=%s\n' "${SUPABASE_URL:-}" \
|
||||
"$(printf '%s' "${SUPABASE_SERVICE_ROLE_KEY:-}" | sha256sum | cut -c1-16)" \
|
||||
"${FAUNOSTEO_DEV_HOST:+set}" "${INIT_CWD:+set}"; } >> "$STUB_LOG"
|
||||
if [ "${1:-}" = --check ]; then
|
||||
echo "horse.svg 0ea5202fa3b95bac167b87c12ee969ab0272e085b60c2d34dbca6202c5f08541.svg: would object verified, row confirmed, nothing to do"
|
||||
else
|
||||
echo "horse.svg done"
|
||||
fi
|
||||
echo ok
|
||||
STUB
|
||||
cat > "$WORK/repo/scripts/import-equine.sh" <<'STUB'
|
||||
#!/usr/bin/env bash
|
||||
{ printf 'import-equine'; for a in "$@"; do printf ' %s' "$a"; done; printf '\n'; } >> "$STUB_LOG"
|
||||
STUB
|
||||
chmod +x "$WORK/bin/docker" "$WORK/bin/curl" "$WORK/bin/ss" "$WORK/bin/node" "$WORK/bin/env" \
|
||||
"$WORK/repo/node_modules/.bin/supabase" "$WORK/repo/apps/app/node_modules/.bin/vite"
|
||||
BASE_PATH="$PATH"
|
||||
# Run by every case, with that case's own PATH: docker, curl, node and env must resolve to the stub
|
||||
# folder (the first PATH entry), ss to the stub there or, when it has none, to nothing.
|
||||
verify_stub_shadow() {
|
||||
local stub_dir="${CASE_PATH%%:*}" tool found
|
||||
for tool in docker curl node env ss; do
|
||||
found="$(PATH="$CASE_PATH" command -v "$tool" || true)"
|
||||
if [ "$tool" = ss ] && [ ! -e "$stub_dir/ss" ]; then
|
||||
[ -z "$found" ] && continue
|
||||
elif [ "$found" = "$stub_dir/$tool" ]; then
|
||||
continue
|
||||
fi
|
||||
echo "db-trial-check: with the case's PATH, $tool resolves to '${found:-nothing}', not the stub in $stub_dir: nothing was run" >&2
|
||||
exit 1
|
||||
done
|
||||
}
|
||||
# A PATH with every tool but ss: the stubs (no ss wrapper), then a link to each executable of the
|
||||
# real PATH except ss. Used by the "ss is not installed" case only.
|
||||
mkdir -p "$WORK/bin-no-ss" "$WORK/path-no-ss"
|
||||
cp -p "$WORK/bin/docker" "$WORK/bin/curl" "$WORK/bin/node" "$WORK/bin/env" "$WORK/bin/real-node" "$WORK/bin/real-env" "$WORK/bin-no-ss/"
|
||||
IFS=: read -ra PATH_DIRS <<<"$BASE_PATH"
|
||||
for dir in "${PATH_DIRS[@]}"; do
|
||||
for exe in "$dir"/*; do
|
||||
name="${exe##*/}"
|
||||
if [ "$name" != ss ] && [ -x "$exe" ] && [ ! -e "$WORK/path-no-ss/$name" ]; then ln -s "$exe" "$WORK/path-no-ss/$name"; fi
|
||||
done
|
||||
done
|
||||
|
||||
ASSET_LINE="$(node -e 'for (const a of require(process.argv[1])) console.log(a.sha256 + " " + a.byte_size)' "$WORK/repo/$SEED_REL/assets.json")"
|
||||
new_case() { # name
|
||||
CASE="$WORK/cases/$1"
|
||||
mkdir -p "$CASE/home" "$CASE/stub/containers" "$CASE/stub/ports" "$CASE/stub/volumes" "$CASE/stub/networks" \
|
||||
"$CASE/stub/answers" "$CASE/stub/fail" "$CASE/stub/stdin"
|
||||
: > "$CASE/log"
|
||||
STATE_DIR="$CASE/home/.cache/faunosteo-trial"
|
||||
echo 'official=1 historical=1 versions=1 draft_equal=true accounts=0' > "$CASE/stub/answers/equine"
|
||||
printf '%s\n' "$ASSET_LINE" > "$CASE/stub/answers/asset-rows"
|
||||
echo 1 > "$CASE/stub/answers/assets-uploaded"
|
||||
echo 'granted false' > "$CASE/stub/answers/grant-catalog"
|
||||
EXTRA=()
|
||||
CASE_PATH="$WORK/bin:$BASE_PATH"
|
||||
# The no-daemon barrier: a unix socket that does not exist (so the script's local-daemon guard
|
||||
# accepts it and a real docker, were a stub missing, would still reach nothing), and a context
|
||||
# that does not exist for the cases that clear DOCKER_HOST.
|
||||
CASE_DOCKER_HOST="unix://$WORK/no-daemon.sock"
|
||||
}
|
||||
# Gives a script a terminal (a pty), types its stdin there, copies the output, returns the exit code.
|
||||
PTY_DRIVER='
|
||||
import os, pty, sys
|
||||
pid, fd = pty.fork()
|
||||
if pid == 0:
|
||||
os.execvp(sys.argv[1], sys.argv[1:])
|
||||
try:
|
||||
os.write(fd, sys.stdin.buffer.read())
|
||||
except OSError:
|
||||
pass
|
||||
while True:
|
||||
try:
|
||||
chunk = os.read(fd, 4096)
|
||||
except OSError:
|
||||
break
|
||||
if not chunk:
|
||||
break
|
||||
sys.stdout.buffer.write(chunk)
|
||||
sys.stdout.flush()
|
||||
_, status = os.waitpid(pid, 0)
|
||||
sys.exit(os.waitstatus_to_exitcode(status))
|
||||
'
|
||||
LAUNCH=()
|
||||
run_script() { # script args... → RC, output in $CASE/out; stdin as the caller set it
|
||||
local script="$1" entry
|
||||
shift
|
||||
# PATH comes after EXTRA below, so a case cannot override it; a PATH in EXTRA is refused outright.
|
||||
for entry in "${EXTRA[@]}"; do
|
||||
case "$entry" in PATH=*) echo "db-trial-check: EXTRA carries a PATH: nothing was run" >&2; exit 1 ;; esac
|
||||
done
|
||||
verify_stub_shadow
|
||||
( cd "$WORK/repo" && env -i HOME="$CASE/home" LANG=C.UTF-8 \
|
||||
DOCKER_HOST="$CASE_DOCKER_HOST" DOCKER_CONTEXT=faunosteo-check-no-such-context DOCKER_CONFIG="$WORK/docker-config" \
|
||||
STUB_LOG="$CASE/log" STUB_STATE="$CASE/stub" FAUNOSTEO_TRIAL_HOST=127.0.0.1 "${EXTRA[@]}" PATH="$CASE_PATH" \
|
||||
"${LAUNCH[@]}" bash "scripts/$script" "$@" ) > "$CASE/out" 2>&1
|
||||
RC=$?
|
||||
}
|
||||
trial() { LAUNCH=(); run_script db-trial.sh "$@" < /dev/null; }
|
||||
trial_input() { LAUNCH=(); run_script db-trial.sh "$@"; } # stdin from the caller (a pipe: no terminal)
|
||||
trial_tty() { # input args...: the input typed at the script's terminal
|
||||
local input="$1"
|
||||
shift
|
||||
LAUNCH=(python3 -c "$PTY_DRIVER")
|
||||
run_script db-trial.sh "$@" <<<"$input"
|
||||
LAUNCH=()
|
||||
}
|
||||
sandbox() { LAUNCH=(); run_script db-sandbox.sh "$@" < /dev/null; }
|
||||
fresh_log() { : > "$CASE/log"; }
|
||||
|
||||
docker_calls() { grep '^docker ' "$CASE/log" || true; }
|
||||
# Calls that change something: Docker writes, the CLI, the upload tool, Vite.
|
||||
changes() {
|
||||
grep -E '^(docker (run|start|restart|stop|rm|volume (create|rm)|network (create|rm))|supabase |upload |vite )' "$CASE/log" || true
|
||||
}
|
||||
out_has() { grep -qF -- "$1" "$CASE/out"; }
|
||||
log_has() { grep -qF -- "$1" "$CASE/log"; }
|
||||
refused() { [ "$RC" -ne 0 ] && [ -z "$(changes)" ] && out_has "$1"; }
|
||||
refused_early() { [ "$RC" -ne 0 ] && [ ! -s "$CASE/log" ] && out_has "$1"; }
|
||||
mode_is() { [ "$(stat -c %a "$1")" = "$2" ]; }
|
||||
values_absent_from() { # secrets file, files...
|
||||
local value file
|
||||
[ -f "$1" ] || return 1
|
||||
while IFS='=' read -r _ value; do
|
||||
[ -n "$value" ] || continue
|
||||
for file in "${@:2}"; do
|
||||
if [ -f "$file" ] && grep -qF -- "$value" "$file"; then return 1; fi
|
||||
done
|
||||
done < "$1"
|
||||
}
|
||||
# The log holds every argv of docker, curl, node, env, the CLI, Vite and the tools.
|
||||
secrets_absent() { values_absent_from "$1" "$CASE/log" "$CASE/out"; }
|
||||
stdin_files() { find "$CASE/stub/stdin" -type f; }
|
||||
stdin_has() { stdin_files | xargs -r grep -lF -- "$1" | grep -q .; }
|
||||
stdin_lacks() { ! stdin_has "$1"; }
|
||||
run_line() { docker_calls | grep -E "^docker run -d --name $1 " || true; }
|
||||
expect_run() { # name port inner memory pids [volume]
|
||||
local line
|
||||
line="$(run_line "$1")"
|
||||
[ "$(grep -c . <<<"$line")" -eq 1 ] || return 1
|
||||
grep -qF -- "--network faunosteo_trial_net --restart no --memory $4 --cpus 1 --pids-limit $5 -p 127.0.0.1:$2:$3 " <<<"$line" || return 1
|
||||
[ "$(grep -oE -- ' -p [^ ]+' <<<"$line" | wc -l)" -eq 1 ] || return 1
|
||||
if [ -n "${6:-}" ]; then grep -qF -- " -v $6 " <<<"$line"; else ! grep -qE -- ' -v ' <<<"$line"; fi
|
||||
}
|
||||
# Resource names plus the Supabase roles and the migrations schema that SQL text in argv may name.
|
||||
# faunosteo_stack and faunosteo_trial: the gateway identity path and body (/__faunosteo_stack answers faunosteo_trial), not resource names.
|
||||
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'; }
|
||||
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
|
||||
python3 -c 'import socket, sys, time
|
||||
s = socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s.bind(("127.0.0.1", int(sys.argv[1]))); s.listen(1); print("up", flush=True); time.sleep(30)' "$1" > "$CASE/listener" 2>&1 &
|
||||
LISTENER=$!
|
||||
for _ in $(seq 1 50); do if grep -q up "$CASE/listener"; then return 0; fi; sleep 0.1; done
|
||||
kill "$LISTENER" 2>/dev/null
|
||||
return 1
|
||||
}
|
||||
release_port() { kill "$LISTENER" 2>/dev/null; wait "$LISTENER" 2>/dev/null; }
|
||||
# Every logged curl starts with -q (no ~/.curlrc) and --noproxy '*' (no proxy variable).
|
||||
curls_pinned() { grep -q '^curl ' "$CASE/log" && ! grep '^curl ' "$CASE/log" | grep -v "^curl -q --noproxy \* " | grep -q .; }
|
||||
backup_count() { find "$STATE_DIR/backups" -mindepth 1 -maxdepth 1 -type d | wc -l; }
|
||||
# Rewrites one key line of a secrets file (default the case's secrets.env) with a key of the given
|
||||
# issuer and role, signed with that file's own secret or a random one, expiring in <offset> s.
|
||||
forge() { # var issuer own|other role [offset] [file]
|
||||
FORGE_FILE="${6:-$STATE_DIR/secrets.env}" node -e '
|
||||
const fs = require("fs"), c = require("crypto");
|
||||
const [name, iss, source, role, offset] = process.argv.slice(1);
|
||||
const file = process.env.FORGE_FILE;
|
||||
const lines = fs.readFileSync(file, "utf8").trim().split("\n");
|
||||
const own = lines.find((l) => l.startsWith("TR_JWT_SECRET=")).slice(14);
|
||||
const secret = source === "own" ? own : c.randomBytes(32).toString("hex");
|
||||
const b64 = (o) => Buffer.from(JSON.stringify(o)).toString("base64url");
|
||||
const h = b64({ alg: "HS256", typ: "JWT" }), now = Math.floor(Date.now() / 1000);
|
||||
const b = b64({ role, iss, iat: now - 7200, exp: now + Number(offset) });
|
||||
const jwt = h + "." + b + "." + c.createHmac("sha256", secret).update(h + "." + b).digest("base64url");
|
||||
fs.writeFileSync(file, lines.map((l) => l.startsWith(name + "=") ? name + "=" + jwt : l).join("\n") + "\n", { mode: 0o600 });
|
||||
' "$1" "$2" "$3" "$4" "${5:-3600}"
|
||||
}
|
||||
env_file_state() { # file → digest and mtime, to prove a refusal wrote nothing
|
||||
printf '%s %s\n' "$(sha256sum < "$1" | cut -d' ' -f1)" "$(stat -c %Y "$1")"
|
||||
}
|
||||
|
||||
echo "-- static"
|
||||
if command -v shellcheck >/dev/null; then
|
||||
check "shellcheck: db-trial.sh and this harness" bash -c 'cd "$1" && shellcheck -x scripts/db-trial.sh scripts/db-trial-check.sh' _ "$REPO"
|
||||
check "shellcheck: db-sandbox.sh (pre-existing SC1090, SC1091, SC2016 excluded)" shellcheck -e SC1090,SC1091,SC2016 "$REPO/scripts/db-sandbox.sh"
|
||||
else
|
||||
fail "shellcheck is not installed"
|
||||
fi
|
||||
check "db-sandbox.sh: additions only since b215b89 (its commands unchanged)" bash -c 'cd "$1" && [ "$(git diff --numstat b215b89 -- scripts/db-sandbox.sh | cut -f2)" = 0 ]' _ "$REPO"
|
||||
TRIAL_PORTS="$(grep -oE 'PORT_[A-Z_]+=[0-9]+' "$REPO/scripts/db-trial.sh" | cut -d= -f2 | sort -u)"
|
||||
SANDBOX_PORTS="$(grep -oE 'PORT_[A-Z_]+=[0-9]+' "$REPO/scripts/db-sandbox.sh" | cut -d= -f2 | sort -u)"
|
||||
DEV_PORTS="$(printf '%s\n' 5173 5191 5192 54321 54322 54323 54324 54325 | sort -u)"
|
||||
check "trial ports are the ratified ones" [ "$TRIAL_PORTS" = "$(printf '%s\n' 5194 58025 58300 58432 58500 58801 58999 | sort -u)" ]
|
||||
check "no trial port is a sandbox or DEV port" [ -z "$(comm -12 <(printf '%s\n' "$TRIAL_PORTS") <(printf '%s\n%s\n' "$SANDBOX_PORTS" "$DEV_PORTS" | sort -u))" ]
|
||||
check "db-trial.sh never runs a bare inspect" bash -c '! grep -nE "docker (container |volume |network |image )?inspect [^-]" "$1"' _ "$REPO/scripts/db-trial.sh"
|
||||
|
||||
echo "-- refusals before anything"
|
||||
new_case sandbox-env; EXTRA=(SANDBOX_AUTH_URL=http://127.0.0.1:57999); trial plan
|
||||
check "a SANDBOX_* variable stops every command before any call" refused_early "SANDBOX_AUTH_URL is set"
|
||||
new_case state-in-repo; EXTRA=(FAUNOSTEO_TRIAL_DIR="$WORK/repo/trial-state"); trial create
|
||||
check "a state folder inside the repository is refused" refused_early "outside the repository"
|
||||
new_case state-in-git; git init -q "$CASE/gitrepo"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/gitrepo/state"); trial create
|
||||
check "a state folder inside any git work tree is refused" refused_early "outside every git work tree"
|
||||
new_case state-git-file; mkdir -p "$CASE/outer"; : > "$CASE/outer/.git"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/outer/state"); trial create
|
||||
check "a state folder under an ancestor holding a .git FILE is refused" refused_early "outside every git work tree"
|
||||
new_case state-in-git-env; git init -q "$CASE/gitrepo"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/gitrepo/state" GIT_DIR="$CASE/no-such-git-dir" GIT_WORK_TREE="$CASE/home"); trial create
|
||||
check "a stray GIT_DIR / GIT_WORK_TREE does not hide a git work tree: still refused" refused_early "outside every git work tree"
|
||||
new_case state-symlink-repo; ln -s "$WORK/repo/trial-state" "$CASE/link"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/link"); trial create
|
||||
check "a state folder that is a symlink into the repository is refused (canonical path)" refused_early "outside the repository"
|
||||
new_case state-symlink-sandbox; mkdir -p "$CASE/sbstate"; ln -s "$CASE/sbstate" "$CASE/link"
|
||||
EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/link" FAUNOSTEO_SANDBOX_DIR="$CASE/sbstate"); trial create
|
||||
check "a state folder that is a symlink to the sandbox's state is refused" refused_early "sandbox's state folder"
|
||||
new_case ss-fails; : > "$CASE/stub/fail/ss"; trial create
|
||||
check "ss failing: create refuses, a port is never read as free" refused "ss cannot list the listening ports"
|
||||
new_case ss-absent; CASE_PATH="$WORK/bin-no-ss:$WORK/path-no-ss"; trial create
|
||||
check "ss absent from PATH: every command refuses before any call" refused_early "ss (iproute2) is not installed"
|
||||
new_case state-symlink-ok; mkdir -p "$CASE/real"; ln -s "$CASE/real" "$CASE/link"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/link")
|
||||
trial create; RC_CREATE=$RC; trial status; RC_STATUS=$RC; trial stop
|
||||
check "a state folder reached through a symlink works: create, status, stop on the real folder (700)" bash -c '[ "$1" -eq 0 ] && [ "$2" -eq 0 ] && [ "$3" -eq 0 ] && [ "$(stat -c %a "$4")" = 700 ] && [ -f "$4/secrets.env" ]' _ "$RC_CREATE" "$RC_STATUS" "$RC" "$CASE/real"
|
||||
new_case create-db-wide; : > "$CASE/stub/publish-wide-faunosteo_trial_db"; trial create
|
||||
check "create: Postgres published beyond 127.0.0.1 stops it before any migration" bash -c '[ "$1" -ne 0 ] && grep -qF "faunosteo_trial_db is not published on 127.0.0.1:58432 only" "$2" && ! grep -q "^supabase " "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
||||
new_case foreign-state; mkdir -p "$CASE/foreign"; : > "$CASE/foreign/secrets.sh"; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/foreign"); trial create
|
||||
check "a non-empty folder without the trial marker is refused" refused_early "holds no db:trial state"
|
||||
new_case sandbox-state; EXTRA=(FAUNOSTEO_TRIAL_DIR="$CASE/shared" FAUNOSTEO_SANDBOX_DIR="$CASE/shared"); trial create
|
||||
check "the sandbox's state folder is refused" refused_early "sandbox's state folder"
|
||||
new_case usage; trial
|
||||
check "no command prints the usage and runs nothing" refused_early "pnpm db:trial create"
|
||||
new_case remote-docker-host; CASE_DOCKER_HOST=tcp://10.0.0.1:2375; trial status
|
||||
check "a DOCKER_HOST that is not a unix socket is refused before any call" refused_early "is not a local unix socket"
|
||||
new_case remote-context; CASE_DOCKER_HOST=''; echo tcp://10.0.0.1:2376 > "$CASE/stub/answers/context"; trial status
|
||||
check "a current context that is not a unix socket is refused before any change" refused "is not a local unix socket"
|
||||
new_case remote-docker-host-credentials; CASE_DOCKER_HOST=tcp://deploy:s3cretpw@10.0.0.1:2375; trial status
|
||||
check "a refused endpoint never echoes its credentials" bash -c '[ "$1" -ne 0 ] && grep -qF "10.0.0.1:2375" "$2" && ! grep -qF -e s3cretpw -e deploy "$2" && [ ! -s "$3" ]' _ "$RC" "$CASE/out" "$CASE/log"
|
||||
new_case local-context; CASE_DOCKER_HOST=''; trial plan
|
||||
check "no DOCKER_HOST and a unix context: plan answers and prints that endpoint" bash -c '[ "$1" -eq 0 ] && grep -qF "Docker endpoint: unix:///stub/docker.sock" "$2"' _ "$RC" "$CASE/out"
|
||||
new_case unreadable-context; CASE_DOCKER_HOST=''; : > "$CASE/stub/fail/context"; trial status
|
||||
check "a current context that cannot be read is refused before any change" refused "cannot be read"
|
||||
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"
|
||||
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
|
||||
check "create: a failing helper check names its causes and stops before any resource" bash -c '[ "$1" -ne 0 ] && grep -qF "helper check failed: the image lacks tar or du, or a faunosteo_trial_helper container is left over (docker rm faunosteo_trial_helper)" "$2" && ! grep -qE "^docker (network|volume) create" "$3" && [ ! -e "$4" ]' _ "$RC" "$CASE/out" "$CASE/log" "$STATE_DIR"
|
||||
new_case existing-volume; : > "$CASE/stub/volumes/faunosteo_trial_db"; trial create
|
||||
check "an existing faunosteo_trial_ volume: create refuses, nothing changed" refused "already exist"
|
||||
new_case port-taken
|
||||
if hold_port 58801; then trial create; check "a taken port: create refuses, nothing changed" refused "58801 is taken"; release_port
|
||||
else fail "could not hold 127.0.0.1:58801 for the port case"; fi
|
||||
|
||||
echo "-- plan"
|
||||
new_case plan; trial plan
|
||||
check "plan: read-only, proceeds on a clean host" bash -c '[ "$1" -eq 0 ]' _ "$RC"
|
||||
check "plan: names the Docker endpoint" out_has "Docker endpoint: unix://"
|
||||
check "plan: no change" [ -z "$(changes)" ]
|
||||
check "plan: names every container, limit and volume place" bash -c 'grep -qF "faunosteo_trial_db" "$1" && grep -qF -- "--memory 1g" "$1" && grep -qF "/stub/docker-root/volumes/faunosteo_trial_storage/_data" "$1" && grep -qF "create would proceed" "$1"' _ "$CASE/out"
|
||||
|
||||
echo "-- create"
|
||||
new_case create-fails-early; : > "$CASE/stub/fail/networks-create"; trial create
|
||||
check "create dying before its first resource removes the state files it wrote" bash -c '[ "$1" -ne 0 ] && grep -qF "state files it wrote are removed" "$2" && [ ! -e "$3/secrets.env" ] && [ ! -e "$3/db.env" ] && [ ! -e "$3/stack.conf" ]' _ "$RC" "$CASE/out" "$STATE_DIR"
|
||||
check "create dying early: nothing to undo in Docker" bash -c '! grep -qE "^docker (volume create|run -d)" "$1"' _ "$CASE/log"
|
||||
new_case create-network-half; : > "$CASE/stub/fail/networks-create-after"; trial create
|
||||
check "create: a network made then reported failed keeps the state files and names the network" bash -c '[ "$1" -ne 0 ] && grep -qF "nothing was removed" "$2" && grep -qF "network faunosteo_trial_net" "$2" && [ -f "$3/secrets.env" ]' _ "$RC" "$CASE/out" "$STATE_DIR"
|
||||
new_case equine-mismatch; echo 'official=2 historical=1 versions=1 draft_equal=true accounts=0' > "$CASE/stub/answers/equine"; trial create
|
||||
check "create: an equine sheet that is not the seed's stops it, resources named" bash -c '[ "$1" -ne 0 ] && grep -qF "is not the seed" "$2" && grep -qF "nothing was removed" "$2" && ! grep -q "^docker run -d --name faunosteo_trial_rest " "$3"' _ "$RC" "$CASE/out" "$CASE/log"
|
||||
new_case asset-rows-mismatch; printf '%s\n' "0000 1" > "$CASE/stub/answers/asset-rows"; trial create
|
||||
check "create: drawing rows that differ from assets.json stop it" bash -c '[ "$1" -ne 0 ] && grep -qF "drawing rows differ" "$2"' _ "$RC" "$CASE/out"
|
||||
new_case create; trial create
|
||||
check "create succeeds on an empty host" [ "$RC" -eq 0 ]
|
||||
check "create: the Rust pipeline check runs before any change" before 'import-equine --check' 'docker network create'
|
||||
check "create: the helper image holds tar and du, checked before any resource" before 'docker run --rm --name faunosteo_trial_helper --network none --entrypoint sh public.ecr.aws/supabase/postgres:17.11.0.004 -c command -v tar && command -v du' 'docker network create'
|
||||
check "create: network and volumes under literal trial names" bash -c 'grep -qx "docker network create --label faunosteo.stack=trial faunosteo_trial_net" "$1" && grep -qx "docker volume create --label faunosteo.stack=trial faunosteo_trial_db" "$1" && grep -qx "docker volume create --label faunosteo.stack=trial faunosteo_trial_storage" "$1"' _ "$CASE/log"
|
||||
check "create: db name, loopback port, caps, volume" expect_run faunosteo_trial_db 58432 5432 1g 512 faunosteo_trial_db:/var/lib/postgresql/data
|
||||
check "create: mail" expect_run faunosteo_trial_mail 58025 8025 64m 64
|
||||
check "create: auth" expect_run faunosteo_trial_auth 58999 9999 128m 256
|
||||
check "create: storage with its volume" expect_run faunosteo_trial_storage 58500 5000 256m 256 faunosteo_trial_storage:/mnt
|
||||
check "create: rest" expect_run faunosteo_trial_rest 58300 3000 384m 256
|
||||
check "create: gateway" expect_run faunosteo_trial_gateway 58801 8000 64m 64
|
||||
check "create: GoTrue sign-up closed" bash -c 'grep -E "^docker run -d --name faunosteo_trial_auth " "$1" | grep -qF GOTRUE_DISABLE_SIGNUP=true' _ "$CASE/log"
|
||||
check "create: GoTrue mail links on the trial host's app origin" bash -c 'grep -E "^docker run -d --name faunosteo_trial_auth " "$1" | grep -qF "GOTRUE_SITE_URL=http://127.0.0.1:5194"' _ "$CASE/log"
|
||||
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: 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
|
||||
check "create: the seeded draft is compared with document.json" stdin_has '$faunosteo_trial_doc$'
|
||||
check "create: only trial names (and Supabase roles) in docker calls" only_trial_names
|
||||
check "create: no volume removal" no_volume_removal
|
||||
check "create: every curl pinned to its destination (-q, --noproxy)" curls_pinned
|
||||
check "create: every container checked on 127.0.0.1 only" log_has 'docker port faunosteo_trial_gateway'
|
||||
check "create: node ran behind the argv logger" log_has 'node -e '
|
||||
check "create: state folder 700, backups 700, files 600" bash -c 'for f in "$1" "$1/backups"; do [ "$(stat -c %a "$f")" = 700 ] || exit 1; done; for f in secrets.env db.env auth.env storage.env rest.env stack.conf migrations.sha256 .faunosteo-trial-state; do [ "$(stat -c %a "$1/$f")" = 600 ] || exit 1; done; ! ls "$1"/*.new >/dev/null 2>&1' _ "$STATE_DIR"
|
||||
check "create: the lock file is 600" mode_is "$STATE_DIR/.lock" 600
|
||||
check "create: keys for the issuer faunosteo-trial, one year" node -e '
|
||||
const lines = Object.fromEntries(require("fs").readFileSync(process.argv[1], "utf8").trim().split("\n").map((l) => [l.slice(0, l.indexOf("=")), l.slice(l.indexOf("=") + 1)]));
|
||||
for (const [name, role] of [["TR_ANON_KEY", "anon"], ["TR_SERVICE_KEY", "service_role"]]) {
|
||||
const p = JSON.parse(Buffer.from(lines[name].split(".")[1], "base64url"));
|
||||
if (p.iss !== "faunosteo-trial" || p.role !== role || p.exp - p.iat !== 31536000) process.exit(1);
|
||||
}' "$STATE_DIR/secrets.env"
|
||||
check "create: stack.conf records the six images, no host" bash -c '! grep -q "^TRIAL_HOST=" "$1" && [ "$(grep -c "^IMAGE_" "$1")" -eq 6 ]' _ "$STATE_DIR/stack.conf"
|
||||
check "create: one manifest line per migration file" [ "$(wc -l < "$STATE_DIR/migrations.sha256")" -eq "$(find "$WORK/repo/supabase/migrations" -name '*.sql' | wc -l)" ]
|
||||
check "create: no secret in any argv (docker, curl, node, env, tools) or output" secrets_absent "$STATE_DIR/secrets.env"
|
||||
fresh_log; trial create
|
||||
check "a second create refuses, nothing changed" refused "already holds a trial stack"
|
||||
|
||||
echo "-- stop, start, status"
|
||||
if hold_port 5194; then fresh_log; trial stop; check "stop while port 5194 is in use (the app): refused, nothing stopped" refused "5194 is in use"; release_port
|
||||
else fail "could not hold 127.0.0.1:5194 for the stop case"; fi
|
||||
fresh_log; trial stop
|
||||
check "stop: each container stopped, reverse order, nothing else" bash -c '[ "$1" -eq 0 ] && [ "$2" = "$(printf "docker stop -t 60 %s\n" faunosteo_trial_gateway faunosteo_trial_rest faunosteo_trial_storage faunosteo_trial_auth faunosteo_trial_mail faunosteo_trial_db)" ]' _ "$RC" "$(changes)"
|
||||
if hold_port 58300; then fresh_log; trial start; check "start: a taken port refuses before any container starts" refused "58300 is taken"; release_port
|
||||
else fail "could not hold 127.0.0.1:58300 for the start case"; fi
|
||||
cp -p "$CASE/stub/ports/faunosteo_trial_rest" "$CASE/rest.port"
|
||||
echo '3000/tcp -> 0.0.0.0:58300' > "$CASE/stub/ports/faunosteo_trial_rest"
|
||||
fresh_log; trial start
|
||||
check "start: a container published on 0.0.0.0 is refused" bash -c '[ "$1" -ne 0 ] && grep -qF "faunosteo_trial_rest is not published on 127.0.0.1:58300 only" "$2"' _ "$RC" "$CASE/out"
|
||||
cp -p "$CASE/rest.port" "$CASE/stub/ports/faunosteo_trial_rest"
|
||||
fresh_log; trial stop; fresh_log; trial start
|
||||
check "start: same containers in order, nothing created" bash -c '[ "$1" -eq 0 ] && [ "$2" = "$(printf "docker start %s\n" faunosteo_trial_db faunosteo_trial_mail faunosteo_trial_auth faunosteo_trial_storage faunosteo_trial_rest faunosteo_trial_gateway)" ]' _ "$RC" "$(changes)"
|
||||
rm -f "$CASE/stub/containers/faunosteo_trial_rest" "$CASE/stub/ports/faunosteo_trial_rest"
|
||||
fresh_log; trial start
|
||||
check "start: a missing container is recreated, then the running gateway restarted" bash -c '[ "$1" -eq 0 ] && [ "$(printf "%s\n" "$2" | grep -c .)" -eq 2 ] && printf "%s\n" "$2" | head -n 1 | grep -q "^docker run -d --name faunosteo_trial_rest " && printf "%s\n" "$2" | tail -n 1 | grep -qx "docker restart -t 10 faunosteo_trial_gateway"' _ "$RC" "$(changes)"
|
||||
check "start: the recreation leaves no secret in argv" secrets_absent "$STATE_DIR/secrets.env"
|
||||
fresh_log; trial status
|
||||
check "status: read-only, keys' expiry, no secret" bash -c '[ "$1" -eq 0 ] && [ -z "$2" ] && grep -qF "keys valid until" "$3"' _ "$RC" "$(changes)" "$CASE/out"
|
||||
check "status: no secret in its output" secrets_absent "$STATE_DIR/secrets.env"
|
||||
|
||||
echo "-- half-written state"
|
||||
cp -p "$STATE_DIR/secrets.env" "$CASE/secrets.good"
|
||||
printf 'TR_PW=short\n' > "$STATE_DIR/secrets.env"
|
||||
for action in start stop status; do
|
||||
fresh_log; trial "$action"
|
||||
check "malformed secrets: $action refuses, nothing changed" refused "malformed"
|
||||
done
|
||||
cp -p "$CASE/secrets.good" "$STATE_DIR/secrets.env"
|
||||
chmod 644 "$STATE_DIR/secrets.env"; fresh_log; trial status
|
||||
check "secrets readable by others: refused" refused "mode 600"
|
||||
chmod 600 "$STATE_DIR/secrets.env"
|
||||
|
||||
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
|
||||
check "db:sandbox down refuses a folder holding the trial marker, nothing run" refused_early "db:trial state folder"
|
||||
EXTRA=(FAUNOSTEO_SANDBOX_DIR="$CASE/same" FAUNOSTEO_TRIAL_DIR="$CASE/same"); sandbox down
|
||||
check "db:sandbox down refuses the db:trial state folder by path" refused_early "db:trial state folder"
|
||||
fresh_log; EXTRA=(FAUNOSTEO_SANDBOX_DIR="$CASE/sandbox-state"); sandbox down
|
||||
check "db:sandbox down on its own folder names faunosteo_dbsandbox_ resources only" bash -c '[ "$1" -eq 0 ] && grep -q "^docker rm -f faunosteo_dbsandbox_" "$2" && ! grep -oE "faunosteo_[a-z_]+" "$2" | grep -qv "^faunosteo_dbsandbox_"' _ "$RC" "$CASE/log"
|
||||
|
||||
echo "-- $PASS passed, $FAIL failed"
|
||||
if [ "$FAIL" -eq 0 ] && [ "$PASS" -gt 0 ]; then echo "db-trial-check: ALL PASS"; else exit 1; fi
|
||||
Executable
+1080
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user