#!/bin/bash
|
# Round01 permission gate QA. It simulates an Accessibility-denied launch path
|
# and verifies Quick Switch does not open while the permissions window is shown.
|
|
set -euo pipefail
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
OUTPUT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
# shellcheck source=build-output-paths.sh
|
source "$SCRIPT_DIR/build-output-paths.sh"
|
APP="$BUILD_CURRENT_APP"
|
OPEN_WAIT="${ALIGNER_ROUND1_PERMISSION_GATE_OPEN_WAIT:-2.5}"
|
QUIT_AFTER="${ALIGNER_ROUND1_PERMISSION_GATE_QUIT_AFTER:-4.0}"
|
QUIT_TIMEOUT="${ALIGNER_ROUND1_PERMISSION_GATE_QUIT_TIMEOUT:-5.0}"
|
|
fail() {
|
echo "Round01 permission gate QA failed: $*" >&2
|
exit 1
|
}
|
|
aligner_pids_for_current_app() {
|
ps -axo pid=,args= | while read -r pid command; do
|
case "$command" in
|
"$APP/Contents/MacOS/Aligner"*) echo "$pid" ;;
|
esac
|
done
|
}
|
|
stop_current_aligner() {
|
for pid in $(aligner_pids_for_current_app); do
|
kill "$pid" 2>/dev/null || true
|
done
|
|
for _ in {1..30}; do
|
[ -z "$(aligner_pids_for_current_app)" ] && return
|
sleep 0.1
|
done
|
|
fail "current Aligner app did not exit before QA"
|
}
|
|
wait_for_app_exit() {
|
local timeout="$1"
|
/usr/bin/python3 - "$APP_PID" "$timeout" <<'PY'
|
import os
|
import sys
|
import time
|
|
pid = int(sys.argv[1])
|
timeout = float(sys.argv[2])
|
deadline = time.monotonic() + timeout
|
|
while time.monotonic() < deadline:
|
stat = os.popen(f"ps -p {pid} -o stat=").read().strip()
|
if not stat or "Z" in stat:
|
sys.exit(0)
|
time.sleep(0.1)
|
|
print(f"Aligner app did not quit within {timeout:.1f}s", file=sys.stderr)
|
sys.exit(1)
|
PY
|
}
|
|
stop_current_aligner
|
"$SCRIPT_DIR/package-app.sh" >&2
|
|
"$APP/Contents/MacOS/Aligner" \
|
--round0-skip-permissions \
|
--round01-simulate-accessibility-denied \
|
--round01-open-quick-switch \
|
--round01-quick-switch-quit-after="$QUIT_AFTER" &
|
|
APP_PID=$!
|
|
cleanup() {
|
if kill -0 "$APP_PID" 2>/dev/null; then
|
kill "$APP_PID" 2>/dev/null || true
|
wait "$APP_PID" 2>/dev/null || true
|
fi
|
}
|
trap cleanup EXIT
|
|
sleep "$OPEN_WAIT"
|
|
swift "$SCRIPT_DIR/window-logic-qa.swift" \
|
--expect-permissions \
|
--expect-no-quick-switch
|
|
wait_for_app_exit "$QUIT_TIMEOUT" || fail "app did not quit after permission gate check"
|
wait "$APP_PID"
|
trap - EXIT
|
|
swift "$SCRIPT_DIR/window-logic-qa.swift" \
|
--expect-no-permissions \
|
--expect-no-quick-switch
|
|
"$APP/Contents/MacOS/Aligner" \
|
--round01-simulate-screen-recording-denied &
|
|
APP_PID=$!
|
trap cleanup EXIT
|
|
sleep "$OPEN_WAIT"
|
|
swift "$SCRIPT_DIR/window-logic-qa.swift" \
|
--expect-permissions \
|
--expect-no-quick-switch
|
|
kill "$APP_PID" 2>/dev/null || true
|
wait "$APP_PID" 2>/dev/null || true
|
trap - EXIT
|
|
swift "$SCRIPT_DIR/window-logic-qa.swift" \
|
--expect-no-permissions \
|
--expect-no-quick-switch
|