Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ bash scripts/run-local.sh <branch>...

It starts the backend if it's down (`client-dev`, or `scylla-dev` plus `cargo run` when a target changes `scylla-server/`), and serves each target's client on the next free port; parallel runs (one per session or agent) each get their own. With no branches it reports what's running.

Report each branch's client URL and the backend. A failed compile or a stale-backend warning is a finding: show it to the user. Stop a client with `kill <pid>` from its line. When every port is taken it lists what holds each; clients from other checkouts are the user's, so ask before stopping them.
Report each branch's client URL and the backend. A failed compile or a stale-backend warning is a finding: show it to the user. Stop a client with `kill <pid>` from its line. When every port is taken it lists what holds each; clients from other checkouts are the user's, so ask before stopping them. When it brings the stack up it arms `teardown-storage`'s timer if the workspace has one set; on `teardown=unset`, use `teardown-storage` to ask the user once and store their choice.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
# piece. The backend (first listener on 8000-8090, step 10) is started if down:
# ./argos.sh client-dev when no target changes scylla-server/, else scylla-dev plus `cargo run` in the
# one worktree that does. Each target's client is then served by serve.sh on its own port. With no
# branches, reports what is running.
# branches, reports what is running. The dev projects it starts are recorded for teardown-storage,
# whose timer it arms for the workspace's `argos.teardown` minutes (git config), or prints teardown=unset.
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
# shellcheck source=/dev/null
. "${DELPHI_ROOT:?unset: start the session at the workspace root, on Delphi 0.2.0+ (pull its ws/ branch), or source <root>/.delphi/paths.sh}/.delphi/paths.sh"
state=${TMPDIR:-/tmp}; state=${state%/}/argos-run-local
up() { (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null || (exec 3<>"/dev/tcp/::1/$1") 2>/dev/null; } # ng serve binds ::1
backend() { for p in $(seq 8000 10 8090); do up "$p" && echo "http://localhost:$p" && return; done; echo none; }
projects() { docker ps -a --format '{{.Label "com.docker.compose.project"}}' 2>/dev/null | grep -Ex 'odyssey_(client-dev|scylla-dev)(_.+)?' | sort -u || true; }
scylla() {
if docker ps --filter name=scylla-server --format '{{.Names}}' 2>/dev/null | grep -q .; then echo docker
elif [ "$(backend)" != none ]; then echo local
Expand Down Expand Up @@ -41,20 +43,28 @@ done
[ ${#rust[@]} -le 1 ] || { echo "run-local: several targets change scylla-server/; run them one at a time" >&2 && exit 1; }

if [ "$(backend)" = none ]; then
mkdir -p "$state"
mkdir -p "$state" && had=$(projects)
if [ ${#rust[@]} = 0 ]; then
(cd "${wts[0]}" && ./argos.sh client-dev up -d) >"$state/compose.log" 2>&1 ||
{ echo "run-local: ./argos.sh client-dev up failed:" >&2 && tail -20 "$state/compose.log" >&2 && exit 1; }
else
(cd "${rust[0]}" && ./argos.sh scylla-dev up -d) >"$state/compose.log" 2>&1 ||
{ echo "run-local: ./argos.sh scylla-dev up failed:" >&2 && tail -20 "$state/compose.log" >&2 && exit 1; }
(cd "${rust[0]}/scylla-server" &&
(cd "${rust[0]}/scylla-server" || exit 1
DATABASE_URL=${DATABASE_URL:-postgresql://postgres:password@127.0.0.1:${ODYSSEY_DB_PORT:-5432}/postgres} \
nohup cargo run >"$state/scylla.log" 2>&1 &)
nohup cargo run >"$state/scylla.log" 2>&1 &
echo $! >"$state/scylla.pid")
echo "run-local: cargo run started for $(basename "${rust[0]}"); log $state/scylla.log"
fi
comm -13 <(printf '%s\n' "$had") <(projects) >>"$state/projects" # what teardown-storage removes
for _ in $(seq 600); do [ "$(backend)" != none ] && break; sleep 1; done
[ "$(backend)" != none ] || { echo "run-local: backend not up after 600s; see $state/" >&2 && exit 1; }
m=$(git -C "$DELPHI_ROOT" config argos.teardown || true)
case $m in
off) ;;
'') echo "teardown=unset (ask the user whether to tear the stack down automatically; see teardown-storage)" ;;
*) bash "$here/../../teardown-storage/scripts/teardown.sh" in "$m" ;;
esac
elif [ ${#rust[@]} = 1 ] && [ "$(scylla)" = docker ]; then
echo "run-local: warning: backend is the scylla-server image but $(basename "${rust[0]}") changes scylla-server/;" \
"stop it (./argos.sh client-dev down) and re-run to test that branch's backend" >&2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: teardown-storage
description: Tear down what run-local brought up — its clients and `cargo run`, and the dev compose stacks it started with their database volume, networks and images — now, on a timer, or automatically after every run-local. Use when the user wants the local Argos stack gone, or when run-local reports teardown=unset.
---

It touches only what run-local started (recorded in its state); other stacks, images and Docker's build cache stay. It doesn't ask: run it when the user wants the stack gone, and report the space freed. Close this session's Playwright CLI sessions first (`playwright-cli list`, then `playwright-cli -s=<name> close`).

- Now: `bash scripts/teardown.sh`
- Later: `bash scripts/teardown.sh in <minutes>` (replaces an earlier timer).
- After every run-local: `bash scripts/teardown.sh auto <minutes|off>` stores the workspace's choice, and run-local arms the timer each time it brings the stack up; `bash scripts/teardown.sh auto` prints it. When run-local reports `teardown=unset`, ask the user once whether to tear the stack down automatically and after how many minutes, store the answer with `auto`, and arm this run with `in`.

With Docker stopped it stops the processes and keeps the record; start Docker and run it again.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# teardown.sh [in <minutes> | auto [<minutes>|off]]: tear down what run-local brought up on this
# machine, and nothing else: the processes in its state (clients, `cargo run`, a pending timer), the
# compose projects it started (its state's `projects`) with their containers, volumes (the database
# too), networks and the images only they used, then its state; prints the space freed. With Docker
# stopped it stops the processes, keeps the record and exits 1. `in <minutes>` does it later, in the
# background, replacing an earlier timer. `auto` prints or sets the minutes run-local arms that timer
# with when it brings the stack up (git config argos.teardown in the workspace; off: never).
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
state=${TMPDIR:-/tmp}; state=${state%/}/argos-run-local
usage() { echo "usage: teardown.sh [in <minutes> | auto [<minutes>|off]]" >&2 && exit 2; }
minutes() { [ -n "$1" ] && [ -z "${1//[0-9]/}" ] && [ "$1" -gt 0 ]; }
case ${1:-now} in
auto)
root=${DELPHI_ROOT:?unset: start the session at the workspace root}
if [ $# -ge 2 ]; then
[ "$2" = off ] || minutes "$2" || usage
git -C "$root" config argos.teardown "$2"
fi
git -C "$root" config argos.teardown || echo unset
exit 0 ;;
in)
minutes "${2:-}" || usage
mkdir -p "$state"
[ ! -f "$state/timer.pid" ] || { pkill -P "$(cat "$state/timer.pid")" 2>/dev/null || true; }
# shellcheck disable=SC2016 # expanded by the inner bash
nohup bash -c 'sleep "$1" && exec bash "$2"' _ $(($2 * 60)) "$here/teardown.sh" >"$state.log" 2>&1 &
echo $! >"$state/timer.pid"
echo "teardown in $2m (pid $!, log $state.log)"
exit 0 ;;
now) ;;
*) usage ;;
esac

[ -d "$state" ] || { echo "teardown: run-local brought nothing up" && exit 0; }
for f in "$state"/*.pid; do # children first: npx and cargo leave their servers behind otherwise
[ -f "$f" ] && pid=$(cat "$f") && [ "$pid" != $$ ] || continue
pkill -P "$pid" 2>/dev/null || true; kill "$pid" 2>/dev/null || true
done
rm -f "$state"/*.pid
if [ -s "$state/projects" ] && ! docker info >/dev/null 2>&1; then
echo "teardown: stopped run-local's processes; start Docker and re-run for $(tr '\n' ' ' <"$state/projects")" >&2
exit 1
fi
total() { docker system df --format '{{.Size}}' | awk '{ s = $1; u = s; sub(/^[0-9.]+/, "", u)
t += s * (u ~ /^[kK]B$/ ? 1e3 : u == "MB" ? 1e6 : u == "GB" ? 1e9 : u == "TB" ? 1e12 : 1) } END { printf "%.0f\n", t }'; }
if [ -s "$state/projects" ]; then
before=$(total)
while IFS= read -r proj; do
l=label=com.docker.compose.project=$proj
images=$(docker ps -a --filter "$l" --format '{{.Image}}' | sort -u)
for c in $(docker ps -aq --filter "$l"); do docker rm -f "$c" >/dev/null; done
for v in $(docker volume ls -q --filter "$l"); do docker volume rm "$v" >/dev/null; done
for n in $(docker network ls -q --filter "$l"); do docker network rm "$n" >/dev/null; done
for i in $images; do docker image rm "$i" >/dev/null 2>&1 || echo "kept image $i (another container uses it)"; done
echo "removed $proj"
done <"$state/projects"
awk -v n=$((before - $(total))) 'BEGIN { print "freed " (n >= 1e9 ? sprintf("%.2fGB", n / 1e9) : sprintf("%.1fMB", n / 1e6)) }'
fi
rm -rf "$state"
35 changes: 35 additions & 0 deletions tests/e2e.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,41 @@ grep -q 'each workspace has its own .fixture/config.ini' "$t/err" || fail "regis
[ ! -e "$d/$F/.fixture/config.ini" ] || fail "protected native configuration was written to main"
ok "new registry entries protect their declared native configuration without validator changes"

# --- 13b. Argos teardown-storage: removes only what run-local recorded (its processes, then each recorded
# project's containers, volumes, networks and images), now or on a timer; `auto` stores the workspace's minutes
mkdir -p "$t/dk/bin" "$t/dk/tmp" && git init -q "$t/dk/root"
cat >"$t/dk/bin/docker" <<EOF
#!/usr/bin/env bash
case "\$*" in
info) [ ! -e "$t/dk/down" ] ;;
"ps -a --filter "*) printf '%s\n' postgres:17.2 odyssey_client-dev-scylla-server postgres:17.2 ;;
"ps -aq "*) printf '%s\n' c1 c2 ;;
"volume ls "*) echo odyssey_client-dev_db-data ;;
"network ls "*) echo odyssey_client-dev_default ;;
"system df "*) if [ -e "$t/dk/removed" ]; then echo 1GB; else echo 2.5GB; fi ;;
*) echo "docker \$*" >>"$t/dk/log" && touch "$t/dk/removed" && [ "\$*" != "image rm postgres:17.2" ] ;;
esac
EOF
chmod +x "$t/dk/bin/docker" && touch "$t/dk/log"
td() { PATH="$t/dk/bin:$PATH" TMPDIR=$t/dk/tmp DELPHI_ROOT=$t/dk/root bash "$src/software/application-software/argos/workspace-inherit/.claude/skills/teardown-storage/scripts/teardown.sh" "$@"; }
gone() { for _ in $(seq 30); do kill -0 "$1" 2>/dev/null || return 0; sleep 0.1; done; return 1; }
st=$t/dk/tmp/argos-run-local
{ [ "$(td auto)" = unset ] && [ "$(td auto 90)" = 90 ] && [ "$(td auto off)" = off ] && ! td auto 0 2>/dev/null &&
! td in x 2>/dev/null && [ "$(td)" = "teardown: run-local brought nothing up" ]; } || fail "teardown auto/usage"
mkdir -p "$st" && echo odyssey_client-dev >"$st/projects" && (sleep 300 >/dev/null 2>&1 & echo $! >"$st/x.pid")
{ td in 5 >/dev/null && t1=$(cat "$st/timer.pid") && kill -0 "$t1" && td in 7 >/dev/null && t2=$(cat "$st/timer.pid") &&
[ "$t1" != "$t2" ] && gone "$t1" && kill -0 "$t2"; } || fail "teardown in <minutes> doesn't replace its timer"
c=$(cat "$st/x.pid") && touch "$t/dk/down"
{ ! td 2>"$t/err" && grep -q 'start Docker and re-run for odyssey_client-dev' "$t/err" && gone "$c" && gone "$t2" &&
[ -s "$st/projects" ] && [ ! -s "$t/dk/log" ]; } || fail "teardown with Docker stopped: $(cat "$t/err")"
rm "$t/dk/down" && (sleep 300 >/dev/null 2>&1 & echo $! >"$st/x.pid") && c=$(cat "$st/x.pid") && td in 5 >/dev/null && t3=$(cat "$st/timer.pid")
{ out=$(td) && gone "$c" && gone "$t3" && [ ! -e "$st" ] && echo "$out" | grep -qx 'removed odyssey_client-dev' &&
echo "$out" | grep -qx 'kept image postgres:17.2 (another container uses it)' && echo "$out" | grep -qx 'freed 1.50GB' &&
[ "$(cat "$t/dk/log")" = "$(printf '%s\n' 'docker rm -f c1' 'docker rm -f c2' 'docker volume rm odyssey_client-dev_db-data' \
'docker network rm odyssey_client-dev_default' 'docker image rm odyssey_client-dev-scylla-server' 'docker image rm postgres:17.2')" ]; } ||
fail "teardown: $out $(cat "$t/dk/log")"
ok "teardown-storage removes only what run-local recorded, now or on a replaceable timer, and stores the workspace's auto minutes"


# --- 14. shellcheck, if installed
if command -v shellcheck >/dev/null; then
Expand Down
Loading