spawn/sh/e2e/lib/teardown.sh
A b84adfb74e
refactor: move all shell scripts to /sh directory (#1843)
Reorganizes the project so all shell scripts live under a dedicated
/sh directory, enabling the OpenRouter rewrite URL to point at /sh/
instead of the repository root.

Moves:
- cli/install.sh → sh/cli/install.sh
- shared/*.sh → sh/shared/*.sh
- {cloud}/{agent}.sh → sh/{cloud}/{agent}.sh (48 scripts)
- {cloud}/README.md → sh/{cloud}/README.md
- e2e/*.sh → sh/e2e/*.sh
- test/macos-compat.sh → sh/test/macos-compat.sh
- test/fixtures/**/*.sh → sh/test/fixtures/**/*.sh

Updates all references:
- RAW_BASE path construction in commands.ts, update-check.ts
- GitHub auth URL in agent-setup.ts
- Self-referencing URLs in install.sh, github-auth.sh
- CI workflow paths in lint.yml, cli-release.yml
- Test file paths in install-script-validation, manifest-integrity
- Documentation in README.md, cli/README.md, CLAUDE.md
- QA scripts in .claude/skills/

Co-authored-by: lab <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-02-23 21:14:54 -08:00

62 lines
1.7 KiB
Bash

#!/bin/bash
# e2e/lib/teardown.sh — Tear down a Fly.io app via REST API
set -eo pipefail
# ---------------------------------------------------------------------------
# teardown_agent APP_NAME
#
# 1. List machines in the app
# 2. Stop each machine
# 3. Delete each machine (force)
# 4. Delete the app
# ---------------------------------------------------------------------------
teardown_agent() {
local app="$1"
log_step "Tearing down ${app}..."
# Get machines list
local machines_json
machines_json=$(fly_api GET "/apps/${app}/machines" 2>/dev/null || true)
if [ -z "${machines_json}" ] || [ "${machines_json}" = "null" ]; then
log_warn "No machines response for ${app} — attempting app delete anyway"
fly_api DELETE "/apps/${app}" >/dev/null 2>&1 || true
untrack_app "${app}"
return 0
fi
# Extract machine IDs
local machine_ids
machine_ids=$(printf '%s' "${machines_json}" | jq -r '.[].id // empty' 2>/dev/null || true)
if [ -n "${machine_ids}" ]; then
# Stop each machine
for mid in ${machine_ids}; do
log_step "Stopping machine ${mid}..."
fly_api POST "/apps/${app}/machines/${mid}/stop" '{}' >/dev/null 2>&1 || true
done
# Brief wait for stop to propagate
sleep 2
# Force-delete each machine
for mid in ${machine_ids}; do
log_step "Deleting machine ${mid}..."
fly_api DELETE "/apps/${app}/machines/${mid}?force=true" >/dev/null 2>&1 || true
done
fi
# Delete the app
log_step "Deleting app ${app}..."
fly_api DELETE "/apps/${app}" >/dev/null 2>&1 || true
# Verify deletion
if flyctl status -a "${app}" >/dev/null 2>&1; then
log_warn "App ${app} may still exist (flyctl still reports it)"
else
log_ok "App ${app} torn down"
fi
untrack_app "${app}"
}