123set -euo pipefail45script_dir="$(CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"6repo_dir="$(CDPATH='' cd -- "$script_dir/../.." && pwd -P)"7source_dir="$repo_dir/portal"8dist_dir="$repo_dir/portal-dist"9manifest="$source_dir/runtime-files.txt"10fixture_name="unlisted-runtime-payload-fixture.mjs"11fixture_source="$source_dir/$fixture_name"12fixture_dist="$dist_dir/$fixture_name"13fixture_dir="$dist_dir/unlisted-runtime-payload-fixture"14temp_parent="${TMPDIR:-/tmp}"15temp_parent="${temp_parent%/}"16temp_root="$(mktemp -d "$temp_parent/goq-portal-runtime-payload.XXXXXX")"1718cleanup() {19 local exit_status=$?20 trap - EXIT INT TERM HUP21 rm -f -- "$fixture_source" "$fixture_dist"22 case "$fixture_dir" in23 "$dist_dir"/unlisted-runtime-payload-fixture)24 rm -rf -- "$fixture_dir"25 ;;26 esac27 case "$temp_root" in28 "$temp_parent"/goq-portal-runtime-payload.??????)29 rm -rf -- "$temp_root"30 ;;31 esac32 exit "$exit_status"33}34trap cleanup EXIT INT TERM HUP3536if [[ -L "$manifest" || ! -f "$manifest" ]]; then37 printf 'portal runtime payload manifest must be a regular file: %s\n' "$manifest" >&238 exit 139fi4041printf 'export const shouldNotShip = true;\n' >"$fixture_source"42mkdir -p "$fixture_dir"43printf 'stale\n' >"$fixture_dist"44printf 'stale\n' >"$fixture_dir/stale.test.mjs"4546if [[ -f "${HOME}/.cargo/env" ]]; then47 # shellcheck source=/dev/null48 source "${HOME}/.cargo/env"49fi50cargo check --locked -p portal --quiet5152if [[ -e "$fixture_dist" || -e "$fixture_dir" ]]; then53 printf 'portal build retained an unallowlisted generated payload entry\n' >&254 exit 155fi5657sed -e '/^[[:space:]]*#/d' -e '/^[[:space:]]*$/d' "$manifest" \58 | LC_ALL=C sort >"$temp_root/expected"59find "$dist_dir" -mindepth 1 -maxdepth 1 -type f -exec basename {} \; \60 | LC_ALL=C sort >"$temp_root/actual"61cmp "$temp_root/expected" "$temp_root/actual"6263while IFS= read -r -d '' entry; do64 if [[ -L "$entry" || ! -f "$entry" ]]; then65 printf 'portal-dist contains a non-regular entry: %s\n' "$entry" >&266 exit 167 fi68done < <(find "$dist_dir" -mindepth 1 -maxdepth 1 -print0)6970if find "$dist_dir" -type f -name '*.test.mjs' -print -quit | grep -q .; then71 printf 'portal-dist contains a test suite\n' >&272 exit 173fi7475printf 'portal_runtime_payload_tests=ok\n'