Add generic capture kit and repo-owned test memory watchdog

app/tool/capture: one Chrome DevTools capture CLI over the full-app fixture
(serve build or URL, private headless Chrome or --cdp attach, label/key/xy
clicks via Flutter semantics, type, press, scroll, screenshots, filmed
clicks with a canvas contact sheet, cleanup on exit/signal), README recipes
and an example script. The fixture entry gains ?theme=light|dark.

app/tool/memwatch: run.sh/full.sh watchdog moved from /tmp (output dir
created if missing, exit status propagated) plus install.sh for the legacy
/tmp/memwatch shims. app/AGENTS.md points tests at full.sh and UI review at
the capture kit.
This commit is contained in:
2026-11-01 21:22:08 +00:00
parent b57b494959
commit ea428d3c98
12 changed files with 754 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
# THE way to run app tests (from app/): tool/memwatch/full.sh test
# Also for focused runs: tool/memwatch/full.sh test/features/runs
# Concurrency 4, 12 GB cap for this run only (see run.sh beside this file).
CONC=4 CAP_KB=12000000 exec "$(dirname "$0")/run.sh" "$@"
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
# Points the legacy /tmp/memwatch/{run,full}.sh at the repo scripts, so older
# instructions keep working after /tmp is cleared (reboot). Each shim prefers
# the main clone's copy and falls back to the copy this was installed from (a
# worktree may be removed later). Shims are replaced atomically, so a run that
# is already executing the old file is unaffected.
#
# Usage: app/tool/memwatch/install.sh
set -eu
here=$(cd "$(dirname "$0")" && pwd)
common=$(git -C "$here" rev-parse --path-format=absolute --git-common-dir)
main="$(dirname "$common")/app/tool/memwatch"
dir=${MEMWATCH_DIR:-/tmp/memwatch}
mkdir -p "$dir"
for name in run full; do
tmp=$(mktemp "$dir/.$name.XXXXXX")
cat > "$tmp" <<EOF
#!/bin/bash
# Shim installed by app/tool/memwatch/install.sh; the repo script is the source.
for d in "$main" "$here"; do
[ -x "\$d/$name.sh" ] && exec "\$d/$name.sh" "\$@"
done
echo "memwatch: $name.sh not found in $main or $here" >&2; exit 127
EOF
chmod +x "$tmp"
mv -f "$tmp" "$dir/$name.sh"
done
echo "$dir/{run,full}.sh -> $main (fallback $here)"
+43
View File
@@ -0,0 +1,43 @@
#!/bin/bash
# Memory watchdog for Flutter tests. THE way to run app tests is full.sh (beside
# this file); use run.sh directly for a single file at the default 3 GB cap.
#
# Usage (from app/): tool/memwatch/run.sh "<test path> [args]"
# CONC flutter test --concurrency (default 1)
# CAP_KB total RSS cap for this run's own test processes (default 3 GB)
# MEMWATCH_DIR per-invocation output directory (default /tmp/memwatch)
# FLUTTER flutter executable
#
# Runs flutter test in the background and polls the RSS of ITS OWN descendant
# processes only; above CAP_KB it kills them (never another run's flutter_tester).
# Prints the peak and the suite's last line, and exits with flutter's status
# (137 when killed). A runaway test once grew to ~30 GB per process and crashed
# the Mac twice, so never run `flutter test` outside this watchdog.
CONC=${CONC:-1}; CAP_KB=${CAP_KB:-3000000}
MEMWATCH_DIR=${MEMWATCH_DIR:-/tmp/memwatch}
FLUTTER=${FLUTTER:-/Users/alan/development/flutter/bin/flutter}
# Called from elsewhere (for example the repo root): run in this script's app/.
[ -f pubspec.yaml ] || cd "$(dirname "$0")/../.." || exit 1
mkdir -p "$MEMWATCH_DIR" || exit 1
out=$(mktemp "$MEMWATCH_DIR/out.XXXXXX")
# $1 is deliberately unquoted: it carries the test path plus extra arguments.
"$FLUTTER" test --concurrency="$CONC" $1 > "$out" 2>&1 &
pid=$!
descendants() { local p; for p in $(pgrep -P "$1"); do echo "$p"; descendants "$p"; done; }
peak=0; killed=0
while kill -0 $pid 2>/dev/null; do
pids=$(descendants $pid | tr '\n' ',' | sed 's/,$//')
rss=0; [ -n "$pids" ] && rss=$(ps -o rss= -p "$pids" 2>/dev/null | awk '{s+=$1} END {print s+0}')
[ "$rss" -gt "$peak" ] && peak=$rss
if [ "$rss" -gt "$CAP_KB" ]; then
echo "KILLED at $((rss/1024)) MB: $1"
for p in $(descendants $pid); do kill -9 $p 2>/dev/null; done; kill -9 $pid 2>/dev/null
killed=1; break
fi
sleep 0.5
done
wait $pid 2>/dev/null; status=$?
[ $killed = 1 ] && status=137
echo "peak $((peak/1024)) MB: $1 :: $(tail -1 "$out")"
echo "full output: $out"
exit $status