docs: prepare repeatable V1 presentation

This commit is contained in:
golem
2026-08-21 04:04:03 -06:00
parent d1a86ad162
commit 2446f0b2ef
10 changed files with 848 additions and 10 deletions
+201
View File
@@ -0,0 +1,201 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)
PROCESS_LIB="$ROOT/tools/process-lib.sh"
RESET_SCRIPT="$ROOT/tools/reset-local.sh"
TEST_ROOT=$(mktemp -d /tmp/uups-bank-process-test.XXXXXX)
declare -a TEST_PIDS=()
PASSED=0
STARTED_PID=
cleanup() {
local pid
for pid in "${TEST_PIDS[@]}"; do
if [[ "$pid" =~ ^[0-9]+$ ]] && kill -0 "$pid" 2>/dev/null; then
kill -TERM -- "-$pid" 2>/dev/null || kill -TERM -- "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
fi
done
rm -rf -- "$TEST_ROOT"
}
trap cleanup EXIT
fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
pass() { PASSED=$((PASSED + 1)); printf 'ok %d - %s\n' "$PASSED" "$1"; }
assert_exists() { [[ -e "$1" ]] || fail "expected $1 to exist"; }
assert_absent() { [[ ! -e "$1" ]] || fail "expected $1 to be absent"; }
assert_dead() { ! kill -0 "$1" 2>/dev/null || fail "expected PID $1 to be stopped"; }
assert_alive() { kill -0 "$1" 2>/dev/null || fail "expected PID $1 to remain alive"; }
# RED gate: these are the missing production interfaces this suite specifies.
[[ -f "$PROCESS_LIB" ]] || fail "missing process library: $PROCESS_LIB"
[[ -x "$RESET_SCRIPT" ]] || fail "missing executable reset script: $RESET_SCRIPT"
# shellcheck source=process-lib.sh
source "$PROCESS_LIB"
make_root() {
local root="$TEST_ROOT/$1"
mkdir -p "$root/.demo" "$root/tools" "$root/deployments" "$root/web/public" "$root/web/src/generated"
cp "$PROCESS_LIB" "$RESET_SCRIPT" "$root/tools/"
chmod +x "$root/tools/reset-local.sh"
printf '%s\n' "$root"
}
write_record() {
local root=$1 kind=$2 pid=$3 start=$4 pgid=$5
printf '%s\n' "$pid" >"$root/.demo/$kind.pid"
printf '%s\n' "$start" >"$root/.demo/$kind.start"
printf '%s\n' "$pgid" >"$root/.demo/$kind.pgid"
}
start_tick() {
local stat rest
local -a fields
stat=$(<"/proc/$1/stat")
rest=${stat##*) }
read -r -a fields <<<"$rest"
printf '%s\n' "${fields[19]}"
}
start_owned() {
local root=$1 kind=$2 helper="$TEST_ROOT/bin/$2"
mkdir -p "$TEST_ROOT/bin"
cat >"$helper" <<'HELPER'
#!/usr/bin/env bash
sleep 120 &
wait
HELPER
chmod +x "$helper"
if [[ "$kind" == anvil ]]; then
setsid "$helper" --host 127.0.0.1 --port 8545 --chain-id 31337 >/dev/null 2>&1 &
else
setsid "$helper" web --host 127.0.0.1 --port 5173 >/dev/null 2>&1 &
fi
local pid=$!
TEST_PIDS+=("$pid")
write_record "$root" "$kind" "$pid" "$(start_tick "$pid")" "$pid"
STARTED_PID=$pid
}
printf '1..11\n'
# Catches cleanup treating a missing record as an error or signaling an inferred PID.
root=$(make_root absent)
demo_stop_recorded "$root" anvil
pass 'an absent PID file is a no-op'
# Catches stale PID metadata accumulating or being treated as a live target.
root=$(make_root stale)
write_record "$root" anvil 999999999 1 999999999
demo_stop_recorded "$root" anvil
assert_absent "$root/.demo/anvil.pid"
assert_absent "$root/.demo/anvil.start"
assert_absent "$root/.demo/anvil.pgid"
pass 'a stale numeric PID record is removed'
# Catches unvalidated PID text reaching kill or shell option parsing.
root=$(make_root nonnumeric)
write_record "$root" anvil 'not-a-pid' 1 1
if demo_stop_recorded "$root" anvil 2>/dev/null; then fail 'nonnumeric PID was accepted'; fi
assert_exists "$root/.demo/anvil.pid"
pass 'a nonnumeric PID is rejected'
# Catches PID collision signaling an unrelated live process with the wrong command.
root=$(make_root wrong-command)
setsid /bin/sleep 120 & wrong_pid=$!
TEST_PIDS+=("$wrong_pid")
write_record "$root" anvil "$wrong_pid" "$(start_tick "$wrong_pid")" "$wrong_pid"
if demo_stop_recorded "$root" anvil 2>/dev/null; then fail 'wrong command signature was accepted'; fi
assert_alive "$wrong_pid"
pass 'a live PID with the wrong command signature is never signaled'
# Catches recycled PID ownership being inferred from PID and command alone.
root=$(make_root reused)
start_owned "$root" anvil
reused_pid=$STARTED_PID
printf '%s\n' "$(( $(start_tick "$reused_pid") + 1 ))" >"$root/.demo/anvil.start"
if demo_stop_recorded "$root" anvil 2>/dev/null; then fail 'mismatched start tick was accepted'; fi
assert_alive "$reused_pid"
pass 'PID reuse is rejected by recorded process start tick'
# Catches a validated project child not being terminated and reaped.
root=$(make_root matching)
start_owned "$root" anvil
matching_pid=$STARTED_PID
demo_stop_recorded "$root" anvil
wait "$matching_pid" 2>/dev/null || true
assert_dead "$matching_pid"
assert_absent "$root/.demo/anvil.pid"
pass 'a matching project-started child is terminated and reaped'
# Catches stopping only the Vite leader and orphaning a child, or broad group signaling.
root=$(make_root group)
group_helper="$TEST_ROOT/bin/vite"
child_file="$TEST_ROOT/vite-child.pid"
cat >"$group_helper" <<'HELPER'
#!/usr/bin/env bash
sleep 120 &
printf '%s\n' "$!" >"$DEMO_CHILD_PID_FILE"
wait
HELPER
chmod +x "$group_helper"
DEMO_CHILD_PID_FILE="$child_file" setsid "$group_helper" web --host 127.0.0.1 --port 5173 & group_pid=$!
TEST_PIDS+=("$group_pid")
for _ in {1..50}; do [[ -s "$child_file" ]] && break; sleep 0.02; done
[[ -s "$child_file" ]] || fail 'Vite helper child did not start'
child_pid=$(<"$child_file")
setsid /bin/sleep 120 & unrelated_pid=$!
TEST_PIDS+=("$unrelated_pid")
write_record "$root" vite "$group_pid" "$(start_tick "$group_pid")" "$group_pid"
demo_stop_recorded "$root" vite
wait "$group_pid" 2>/dev/null || true
for _ in {1..50}; do ! kill -0 "$child_pid" 2>/dev/null && break; sleep 0.02; done
assert_dead "$child_pid"
assert_alive "$unrelated_pid"
pass 'an owned process group is stopped completely while an unrelated group survives'
# Catches reset deleting arbitrary neighbors or leaving known reproducible local artifacts.
root=$(make_root local-reset)
for kind in anvil vite; do printf 'log\n' >"$root/.demo/$kind.log"; printf '1\n' >"$root/.demo/$kind.start"; printf '1\n' >"$root/.demo/$kind.pgid"; done
printf 'sentinel\n' >"$root/.demo/sentinel"
for path in deployments/pending.json deployments/anvil.json deployments/active.json web/public/deployment.json; do
printf '{"network":"anvil","chainId":31337}\n' >"$root/$path"
done
printf 'generated ABI\n' >"$root/web/src/generated/contracts.ts"
(cd "$root" && bash tools/reset-local.sh >/dev/null)
for path in .demo/anvil.pid .demo/anvil.start .demo/anvil.pgid .demo/anvil.log .demo/vite.pid .demo/vite.start .demo/vite.pgid .demo/vite.log deployments/pending.json deployments/anvil.json deployments/active.json web/public/deployment.json web/src/generated/contracts.ts; do
assert_absent "$root/$path"
done
assert_exists "$root/.demo/sentinel"
pass 'reset removes only explicitly known local runtime and generated files'
# Catches a local reset corrupting a canonical Base Sepolia deployment.
root=$(make_root base-canonical)
printf '{"network":"baseSepolia","chainId":84532,"marker":"canonical"}\n' >"$root/deployments/base-sepolia.json"
before=$(sha256sum "$root/deployments/base-sepolia.json")
(cd "$root" && bash tools/reset-local.sh >/dev/null)
after=$(sha256sum "$root/deployments/base-sepolia.json")
[[ "$before" == "$after" ]] || fail 'Base canonical manifest changed'
pass 'a Base canonical manifest survives reset byte-for-byte'
# Catches a local reset deleting or rewriting selected and browser-copied Base state.
root=$(make_root base-active)
base='{"network":"baseSepolia","chainId":84532,"marker":"active"}'
printf '%s\n' "$base" >"$root/deployments/active.json"
printf '%s\n' "$base" >"$root/web/public/deployment.json"
active_before=$(sha256sum "$root/deployments/active.json")
browser_before=$(sha256sum "$root/web/public/deployment.json")
(cd "$root" && bash tools/reset-local.sh >/dev/null)
[[ "$active_before" == "$(sha256sum "$root/deployments/active.json")" ]] || fail 'Base active manifest changed'
[[ "$browser_before" == "$(sha256sum "$root/web/public/deployment.json")" ]] || fail 'Base browser manifest changed'
pass 'Base active and browser manifests survive reset byte-for-byte'
# Catches cleanup broadening from exact files to recursive .demo deletion.
root=$(make_root sentinel)
printf 'keep me\n' >"$root/.demo/adjacent.keep"
(cd "$root" && bash tools/reset-local.sh >/dev/null)
assert_exists "$root/.demo/adjacent.keep"
pass 'a sentinel adjacent to runtime records survives'
printf 'PASS: %d process-safety cases\n' "$PASSED"