Files
dbtool-cli-v1/scripts/qa/run-failure-path-evidence-sidecar.sh
Paperclip CTO d5f69462b0
Some checks failed
release-smoke / macos-13 / x86_64-apple-darwin (push) Has been cancelled
release-smoke / ubuntu-latest / x86_64-unknown-linux-gnu (push) Has been cancelled
release-smoke / windows-latest / x86_64-pc-windows-msvc (push) Has been cancelled
feat(usable): integrate current dbtool implementation snapshot
Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-02 08:26:18 +00:00

97 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "usage: scripts/qa/run-failure-path-evidence-sidecar.sh <binary-path> [output-dir]" >&2
exit 2
fi
binary_path="$1"
output_dir="${2:-./tmp/failure-path-evidence}"
if [ ! -x "$binary_path" ]; then
echo "error: binary is not executable: $binary_path" >&2
exit 3
fi
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
sidecar_image="${QA_SIDECAR_IMAGE:-paperclip-local-db-codex}"
docker_network="${QA_DOCKER_NETWORK:-dbtool-cli-v1_default}"
postgres_container="${QA_POSTGRES_CONTAINER:-dbtool-cli-v1-postgres-1}"
mysql_container="${QA_MYSQL_CONTAINER:-dbtool-cli-v1-mysql-1}"
postgres_admin_user="${QA_POSTGRES_ADMIN_USER:-postgres}"
postgres_admin_password="${QA_POSTGRES_ADMIN_PASSWORD:-dbtoolroot}"
postgres_db="${QA_POSTGRES_DB:-dbtool_demo}"
mysql_root_password="${QA_MYSQL_ROOT_PASSWORD:-dbtoolroot}"
sidecar_root="/tmp/work"
sidecar_output_dir="$sidecar_root/out"
host_label="${QA_HOST_LABEL:-$(hostname 2>/dev/null || echo unknown-host)}"
binary_label="${QA_BINARY_PATH_LABEL:-$binary_path}"
binary_version="${QA_BINARY_VERSION:-$("$binary_path" --version 2>/dev/null | head -n 1 || echo unknown-version)}"
commit_sha="$(git -C "$root_dir" rev-parse HEAD 2>/dev/null || echo unknown-commit)"
branch_name="$(git -C "$root_dir" branch --show-current 2>/dev/null || echo unknown-branch)"
cid=""
cleanup() {
if [ -n "$cid" ]; then
docker rm -f "$cid" >/dev/null 2>&1 || true
fi
}
trap cleanup EXIT
mkdir -p "$output_dir"
docker image inspect "$sidecar_image" >/dev/null
docker exec -e "PGPASSWORD=$postgres_admin_password" -i "$postgres_container" \
psql -v ON_ERROR_STOP=1 -U "$postgres_admin_user" -d "$postgres_db" \
< "$root_dir/examples/fixtures/postgres/init.sql" >/dev/null
docker exec -i "$mysql_container" \
mysql --default-character-set=utf8mb4 -uroot "-p$mysql_root_password" \
< "$root_dir/examples/fixtures/mysql/init.sql" >/dev/null
cid="$(docker create --network "$docker_network" "$sidecar_image" sleep 300)"
docker start "$cid" >/dev/null
docker exec "$cid" mkdir -p \
"$sidecar_root/examples/sql/postgres" \
"$sidecar_root/examples/sql/mysql" \
"$sidecar_root/scripts/qa"
docker cp "$binary_path" "$cid":"$sidecar_root/dbtool"
docker cp "$root_dir/examples/sql/postgres/failing_query.sql" \
"$cid":"$sidecar_root/examples/sql/postgres/failing_query.sql"
docker cp "$root_dir/examples/sql/mysql/failing_query.sql" \
"$cid":"$sidecar_root/examples/sql/mysql/failing_query.sql"
docker cp "$root_dir/scripts/qa/run-failure-path-evidence.sh" \
"$cid":"$sidecar_root/scripts/qa/run-failure-path-evidence.sh"
docker exec "$cid" chmod +x \
"$sidecar_root/dbtool" \
"$sidecar_root/scripts/qa/run-failure-path-evidence.sh"
docker exec \
-e QA_OPERATOR="${QA_OPERATOR:-qa-engineer}" \
-e QA_HOST_LABEL="$host_label" \
-e QA_BINARY_PATH_LABEL="$binary_label" \
-e QA_BINARY_VERSION="$binary_version" \
-e QA_EXECUTION_PATH=sidecar \
-e QA_COMMIT_SHA="$commit_sha" \
-e QA_BRANCH_NAME="$branch_name" \
-e DBTOOL_POSTGRES_HOST="${DBTOOL_POSTGRES_HOST:-$postgres_container}" \
-e DBTOOL_POSTGRES_PORT=5432 \
-e DBTOOL_POSTGRES_NET_PORT=59999 \
-e DBTOOL_MYSQL_HOST="${DBTOOL_MYSQL_HOST:-$mysql_container}" \
-e DBTOOL_MYSQL_PORT=3306 \
-e DBTOOL_MYSQL_NET_PORT=59998 \
"$cid" \
bash -lc \
"cd '$sidecar_root' && ./scripts/qa/run-failure-path-evidence.sh ./dbtool all '$sidecar_output_dir'"
rm -rf "$output_dir"
mkdir -p "$output_dir"
docker cp "$cid":"$sidecar_output_dir"/. "$output_dir"/
echo "sidecar evidence written to: $output_dir"