feat(usable): package gui-host validation snapshot
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
168
scripts/qa/test-failure-path-evidence-sidecar.sh
Executable file
168
scripts/qa/test-failure-path-evidence-sidecar.sh
Executable file
@@ -0,0 +1,168 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
tmp_dir="$(mktemp -d)"
|
||||
state_dir="$tmp_dir/state"
|
||||
fake_bin_dir="$tmp_dir/bin"
|
||||
output_dir="$tmp_dir/out"
|
||||
mkdir -p "$state_dir/container_fs" "$fake_bin_dir" "$output_dir"
|
||||
|
||||
cleanup() {
|
||||
rm -rf "$tmp_dir"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
cat >"$tmp_dir/fake-dbtool" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
if [ "${1:-}" = "--version" ]; then
|
||||
echo "fake-dbtool 0.1.0"
|
||||
exit 0
|
||||
fi
|
||||
printf '{"status":"error","state":"error","error":{"kind":"authentication"}}\n'
|
||||
exit 2
|
||||
EOF
|
||||
chmod +x "$tmp_dir/fake-dbtool"
|
||||
|
||||
cat >"$fake_bin_dir/docker" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
state_dir="${MOCK_DOCKER_STATE_DIR:?}"
|
||||
container_fs="$state_dir/container_fs"
|
||||
|
||||
cmd="${1:?}"
|
||||
shift
|
||||
|
||||
copy_into_container() {
|
||||
local src="$1"
|
||||
local dest="$2"
|
||||
mkdir -p "$(dirname "$dest")"
|
||||
cp "$src" "$dest"
|
||||
}
|
||||
|
||||
copy_from_container() {
|
||||
local src="$1"
|
||||
local dest="$2"
|
||||
mkdir -p "$dest"
|
||||
cp -R "$src"/. "$dest"/
|
||||
}
|
||||
|
||||
case "$cmd" in
|
||||
image)
|
||||
[ "${1:-}" = "inspect" ] || exit 90
|
||||
exit 0
|
||||
;;
|
||||
create)
|
||||
echo "mock-sidecar-id"
|
||||
exit 0
|
||||
;;
|
||||
start)
|
||||
exit 0
|
||||
;;
|
||||
rm)
|
||||
exit 0
|
||||
;;
|
||||
cp)
|
||||
src="${1:?}"
|
||||
dest="${2:?}"
|
||||
if [[ "$src" == *:* ]]; then
|
||||
container_src="${src#*:}"
|
||||
container_src="${container_src%/.}"
|
||||
copy_from_container "$container_fs$container_src" "$dest"
|
||||
else
|
||||
container_dest="${dest#*:}"
|
||||
copy_into_container "$src" "$container_fs$container_dest"
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
exec)
|
||||
env_pairs=()
|
||||
while [ "${1:-}" = "-e" ]; do
|
||||
env_pairs+=("${2:?}")
|
||||
shift 2
|
||||
done
|
||||
|
||||
if [ "${1:-}" = "-i" ]; then
|
||||
shift
|
||||
shift
|
||||
cat >/dev/null
|
||||
exit 0
|
||||
fi
|
||||
|
||||
target="${1:?}"
|
||||
shift
|
||||
|
||||
case "${1:-}" in
|
||||
mkdir)
|
||||
shift
|
||||
[ "${1:-}" = "-p" ] || exit 91
|
||||
shift
|
||||
for path in "$@"; do
|
||||
mkdir -p "$container_fs$path"
|
||||
done
|
||||
exit 0
|
||||
;;
|
||||
chmod)
|
||||
exit 0
|
||||
;;
|
||||
bash)
|
||||
[ "${2:-}" = "-lc" ] || exit 92
|
||||
for pair in "${env_pairs[@]}"; do
|
||||
export "$pair"
|
||||
done
|
||||
out_dir="$container_fs/tmp/work/out"
|
||||
mkdir -p "$out_dir"
|
||||
cat >"$out_dir/PG-CONN-AUTH-001.md" <<EOM
|
||||
### PG-CONN-AUTH-001
|
||||
|
||||
- Host: \`${QA_HOST_LABEL:-missing-host}\`
|
||||
- Execution Path: \`${QA_EXECUTION_PATH:-missing-execution-path}\`
|
||||
- Binary Path: \`${QA_BINARY_PATH_LABEL:-missing-binary-path}\`
|
||||
- Binary Version: \`${QA_BINARY_VERSION:-missing-binary-version}\`
|
||||
- Commit SHA: \`${QA_COMMIT_SHA:-missing-commit}\`
|
||||
- Branch: \`${QA_BRANCH_NAME:-missing-branch}\`
|
||||
- Result: \`pass\`
|
||||
EOM
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "unsupported docker exec target command: $*" >&2
|
||||
exit 93
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo "unsupported docker command: $cmd" >&2
|
||||
exit 94
|
||||
;;
|
||||
esac
|
||||
EOF
|
||||
chmod +x "$fake_bin_dir/docker"
|
||||
|
||||
export PATH="$fake_bin_dir:$PATH"
|
||||
export MOCK_DOCKER_STATE_DIR="$state_dir"
|
||||
export QA_HOST_LABEL="runner-host-01"
|
||||
export QA_BINARY_PATH_LABEL="./target/release/dbtool"
|
||||
export QA_BINARY_VERSION="dbtool 0.1.0"
|
||||
|
||||
"$root_dir/scripts/qa/run-failure-path-evidence-sidecar.sh" \
|
||||
"$tmp_dir/fake-dbtool" \
|
||||
"$output_dir" >/dev/null
|
||||
|
||||
evidence_file="$output_dir/PG-CONN-AUTH-001.md"
|
||||
[ -f "$evidence_file" ] || {
|
||||
echo "expected evidence file not copied back: $evidence_file" >&2
|
||||
exit 95
|
||||
}
|
||||
|
||||
grep -Fq 'Host: `runner-host-01`' "$evidence_file"
|
||||
grep -Fq 'Execution Path: `sidecar`' "$evidence_file"
|
||||
grep -Fq 'Binary Path: `./target/release/dbtool`' "$evidence_file"
|
||||
grep -Fq 'Binary Version: `dbtool 0.1.0`' "$evidence_file"
|
||||
grep -Fq 'Commit SHA: `' "$evidence_file"
|
||||
grep -Fq 'Branch: `' "$evidence_file"
|
||||
grep -Fq 'Result: `pass`' "$evidence_file"
|
||||
|
||||
echo "sidecar helper fixture passed"
|
||||
Reference in New Issue
Block a user