blob: 5b75192ecb9e71d8fe9ac0d7a6392d75a3cbd5e7 [file] [edit]
#!/bin/bash
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
JQ_BIN=""
while [[ $# -gt 0 ]]; do
case "$1" in
--jq) JQ_BIN="$2"; shift 2 ;;
--) shift; break ;;
*) echo "Unknown option: $1"; exit 1 ;;
esac
done
if [[ -z "${JQ_BIN}" ]]; then
echo "Error: --jq is required." >&2
exit 1
fi
export BUILDMINDER_CHECKPOINT_PATH="${TEST_TMPDIR}/buildminder_checkpoint.json"
readonly CHECKPOINT="${BUILDMINDER_CHECKPOINT_PATH}"
# Execute the wrapped command.
"$@"
echo "Verifying buildminder checkpoint (FAILED): ${CHECKPOINT}"
# 1. Check that all invocations are in StateDone (status "DONE").
non_done=$("${JQ_BIN}" '[.invocations[] | select(.timing.status != "DONE")] | length' "${CHECKPOINT}")
if [[ "${non_done}" -gt 0 ]]; then
echo "Error: Found ${non_done} invocations that are not in StateDone." >&2
exit 1
fi
# 2. Check that at least one invocation has "FAILED" status.
num_failed=$("${JQ_BIN}" '[.invocations[] | select(.status == "FAILED")] | length' "${CHECKPOINT}")
if [[ "${num_failed}" -eq 0 ]]; then
echo "Error: Found 0 invocations with FAILED status." >&2
"${JQ_BIN}" '.invocations[] | .status' "${CHECKPOINT}" >&2
exit 1
fi
echo "Verification successful: Found ${num_failed} failed invocations."