| #!/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 |
| |
| # This script checks the content of a fake_resultstore dump file (JSON or JSONL) |
| # to verify that it contains the BES requests generated by Bazel. |
| |
| BES_LOG="" |
| JQ_BIN="" |
| |
| while [[ "$#" -gt 0 ]]; do |
| case $1 in |
| --bes_log) BES_LOG="$2"; shift ;; |
| --dump_file) BES_LOG="$2"; shift ;; |
| --jq) JQ_BIN="$2"; shift ;; |
| *) shift ;; |
| esac |
| shift |
| done |
| |
| if [[ -z "${BES_LOG}" || -z "${JQ_BIN}" ]]; then |
| echo "Usage: $0 --bes_log <path> --jq <path>" |
| exit 1 |
| fi |
| |
| if [ ! -s "${BES_LOG}" ]; then |
| echo "FAIL: BES dump file '${BES_LOG}' does not exist or is empty." >&2 |
| exit 1 |
| fi |
| |
| echo "Verifying BES traffic in ${BES_LOG}..." |
| |
| # We use jq -s to handle both single JSON objects (old format) and JSONL streams (new format). |
| # The query extracts the array of events regardless of the wrapper structure. |
| EXTRACT_QUERY='if .[0] | type == "array" then .[0] elif .[0].bes_requests then .[0].bes_requests else . end | map(.payload? // .)' |
| |
| # 1. Verify BES PublishBuildToolEventStream messages exist. |
| NUM_BES_REQS=$("${JQ_BIN}" -s "${EXTRACT_QUERY} | map(select(.ordered_build_event != null)) | length" "${BES_LOG}") |
| |
| if [[ "${NUM_BES_REQS}" -eq 0 ]]; then |
| echo "FAIL: No BES requests (PublishBuildToolEventStream) found in dump." >&2 |
| exit 1 |
| fi |
| echo "Found ${NUM_BES_REQS} raw BES requests." |
| |
| # 2. Verify that at least one 'Started' event was seen in the stream. |
| # We use a recursive search (..) for the 'started' key to handle various nesting levels (Bazel vs raw BES). |
| HAS_STARTED=$("${JQ_BIN}" -s "${EXTRACT_QUERY} | any(.. | .started? != null)" "${BES_LOG}") |
| if [[ "${HAS_STARTED}" != "true" ]]; then |
| echo "FAIL: No 'Started' event found in the BES stream." >&2 |
| exit 1 |
| fi |
| echo "Confirmed 'Started' event exists in BES stream." |
| |
| # 3. Verify that at least one 'Finished' event was seen. |
| HAS_FINISHED=$("${JQ_BIN}" -s "${EXTRACT_QUERY} | any(.. | .finished? != null)" "${BES_LOG}") |
| if [[ "${HAS_FINISHED}" != "true" ]]; then |
| echo "FAIL: No 'Finished' event found in the BES stream." >&2 |
| exit 1 |
| fi |
| echo "Confirmed 'Finished' event exists in BES stream." |
| |
| echo "PASS: Bazel BES dump validation successful." |
| exit 0 |