#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" tmp_dir="$(mktemp -d)" trap 'rm -rf "$tmp_dir"' EXIT assert_gate() { local expected="$1" local name="$2" local paths_file="${tmp_dir}/${name}.paths" local output_file="${tmp_dir}/${name}.output" shift 2 printf '%s\n' "$@" > "$paths_file" GITHUB_OUTPUT="$output_file" "${ROOT_DIR}/Scripts/ci_macos_test_gate.sh" "$paths_file" >/dev/null local actual actual="$(sed -n 's/^macos-tests=//p' "$output_file")" if [[ "$actual" != "$expected" ]]; then printf '%s: expected macos-tests=%s, got %s\n' "$name" "$expected" "${actual:-}" >&2 exit 1 fi } assert_gate false docs-only $'M\tdocs/providers.md' $'M\tREADME.md' assert_gate true configuration-doc $'M\tdocs/configuration.md' assert_gate true rename-to-configuration-doc $'R100\tdocs/old.md\tdocs/configuration.md' assert_gate true rename-from-configuration-doc $'R100\tdocs/configuration.md\tdocs/new.md' assert_gate true agents-contract $'M\tAGENTS.md' assert_gate true rename-to-agents-contract $'R100\tdocs/old.md\tAGENTS.md' assert_gate true rename-from-agents-contract $'R100\tAGENTS.md\tdocs/new.md' assert_gate true source $'M\tSources/CodexBar/App.swift' assert_gate true docs-code $'M\tdocs/site.js' assert_gate true empty assert_gate true source-to-docs $'R100\tSources/CodexBar/App.swift\tdocs/App.md' assert_gate true docs-to-source $'R100\tdocs/App.md\tSources/CodexBar/App.swift' assert_gate_fails() { local name="$1" local paths_file="${tmp_dir}/${name}.paths" local output_file="${tmp_dir}/${name}.output" shift printf '%s\n' "$@" > "$paths_file" if GITHUB_OUTPUT="$output_file" "${ROOT_DIR}/Scripts/ci_macos_test_gate.sh" "$paths_file" >/dev/null 2>&1; then printf '%s: malformed gate input unexpectedly succeeded\n' "$name" >&2 exit 1 fi if [[ -s "$output_file" ]]; then printf '%s: malformed gate input emitted an output\n' "$name" >&2 exit 1 fi } assert_gate_fails missing-rename-target $'R100\tREADME.md' assert_gate_fails extra-modified-path $'M\tREADME.md\tdocs/configuration.md' assert_gate_fails missing-rename-score $'R\tREADME.md\tdocs/README.md' assert_gate_fails invalid-rename-score $'Rfoo\tREADME.md\tdocs/README.md' assert_gate_fails out-of-range-rename-score $'R101\tREADME.md\tdocs/README.md' unterminated_paths="${tmp_dir}/unterminated.paths" unterminated_output="${tmp_dir}/unterminated.output" printf '%s' $'M\tREADME.md\tdocs/configuration.md' > "$unterminated_paths" if GITHUB_OUTPUT="$unterminated_output" \ "${ROOT_DIR}/Scripts/ci_macos_test_gate.sh" "$unterminated_paths" >/dev/null 2>&1 then printf 'unterminated malformed gate input unexpectedly succeeded\n' >&2 exit 1 fi if [[ -s "$unterminated_output" ]]; then printf 'unterminated malformed gate input emitted an output\n' >&2 exit 1 fi verify="${ROOT_DIR}/Scripts/ci_verify_test_jobs.sh" "$verify" success success true success >/dev/null "$verify" success success false skipped >/dev/null assert_verify_fails() { if "$verify" "$@" >/dev/null 2>&1; then printf 'unexpected aggregate success: %s\n' "$*" >&2 exit 1 fi } assert_verify_fails success success true skipped assert_verify_fails success success false success assert_verify_fails success success "" skipped assert_verify_fails failure success true success assert_verify_fails success failure true success printf 'CI macOS path gate tests passed.\n'