| #!/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 |
| # to verify that it contains the raw action IDs in passthrough mode. |
| |
| DUMP_FILE="" |
| JQ_BIN="" |
| EXPECTED_ACTION_ID="raw action/with spaces" |
| |
| while [[ "$#" -gt 0 ]]; do |
| case $1 in |
| --dump_file) DUMP_FILE="$2"; shift ;; |
| --jq) JQ_BIN="$2"; shift ;; |
| *) echo "Unknown parameter passed: $1"; exit 1 ;; |
| esac |
| shift |
| done |
| |
| if [[ -z "${DUMP_FILE}" || -z "${JQ_BIN}" ]]; then |
| echo "Usage: $0 --jq <path> --dump_file <path>" |
| exit 1 |
| fi |
| |
| # Check if the dump file exists and is not empty. |
| if [ ! -s "${DUMP_FILE}" ]; then |
| echo "FAIL: Dump file '${DUMP_FILE}' does not exist or is empty." >&2 |
| exit 1 |
| fi |
| |
| # Search for the action_id in the flattened UploadRequests. |
| # In passthrough mode, the raw IDs from fakebuild's prototext should be preserved. |
| echo "Searching for action_id: ${EXPECTED_ACTION_ID}" |
| found_action=$("${JQ_BIN}" -r --arg id "${EXPECTED_ACTION_ID}" ' |
| .UploadRequests[] | .. | .action_id? | select(. == $id) |
| ' "${DUMP_FILE}") |
| |
| if [[ -z "${found_action}" ]]; then |
| echo "FAIL: Expected action_id '${EXPECTED_ACTION_ID}' not found in logical UploadRequests." >&2 |
| echo "Full dump content:" >&2 |
| cat "${DUMP_FILE}" >&2 |
| exit 1 |
| fi |
| |
| echo "PASS: Found expected action_id '${EXPECTED_ACTION_ID}' in passthrough stream." |
| exit 0 |