#!/bin/bash
|
# Round01 Dock reopen QA. It exercises the AppKit reopen path used by the Dock
|
# icon and verifies that the same Quick Switch overlay path opens.
|
|
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"
|
REPORT="$BUILD_REPORT_ROOT/round01-dock-reopen-report.json"
|
SIMULATE_AFTER="${ALIGNER_ROUND1_DOCK_REOPEN_SIMULATE_AFTER:-0.35}"
|
OPEN_TIMEOUT="${ALIGNER_ROUND1_DOCK_REOPEN_OPEN_TIMEOUT:-4.0}"
|
HIDE_AFTER="${ALIGNER_ROUND1_DOCK_REOPEN_HIDE_AFTER:-3.0}"
|
QUIT_AFTER="${ALIGNER_ROUND1_DOCK_REOPEN_QUIT_AFTER:-4.5}"
|
QUIT_TIMEOUT="${ALIGNER_ROUND1_DOCK_REOPEN_QUIT_TIMEOUT:-5.0}"
|
|
fail() {
|
echo "Round01 Dock reopen QA failed: $*" >&2
|
exit 1
|
}
|
|
aligner_pids_for_current_app() {
|
ps -axo pid=,args= | while read -r pid command; do
|
if [[ "$command" == "$APP/Contents/MacOS/Aligner"* ]] \
|
|| [[ "$command" == "/Applications/Aligner.app/Contents/MacOS/Aligner"* ]] \
|
|| [[ "$command" == "$HOME/Applications/Aligner.app/Contents/MacOS/Aligner"* ]]; then
|
echo "$pid"
|
fi
|
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_quick_switch() {
|
local timeout="$1"
|
/usr/bin/python3 - "$SCRIPT_DIR" "$timeout" <<'PY'
|
import subprocess
|
import sys
|
import time
|
|
script_dir = sys.argv[1]
|
timeout = float(sys.argv[2])
|
deadline = time.monotonic() + timeout
|
last_output = ""
|
|
while time.monotonic() < deadline:
|
result = subprocess.run(
|
[
|
"swift",
|
f"{script_dir}/window-logic-qa.swift",
|
"--expect-quick-switch",
|
"--expect-single-aligner-overlay",
|
"--expect-overlay-on-mouse-screen",
|
"--expect-overlay-uses-screen-frame",
|
],
|
text=True,
|
stdout=subprocess.PIPE,
|
stderr=subprocess.STDOUT,
|
)
|
last_output = result.stdout
|
if result.returncode == 0:
|
print(last_output, end="")
|
sys.exit(0)
|
time.sleep(0.2)
|
|
print(last_output, end="")
|
sys.exit(1)
|
PY
|
}
|
|
wait_for_dock_reopen_report() {
|
local timeout="$1"
|
/usr/bin/python3 - "$REPORT" "$timeout" <<'PY'
|
import json
|
import sys
|
import time
|
|
path = sys.argv[1]
|
timeout = float(sys.argv[2])
|
deadline = time.monotonic() + timeout
|
last_report = None
|
|
while time.monotonic() < deadline:
|
try:
|
with open(path, "r", encoding="utf-8") as file:
|
report = json.load(file)
|
last_report = report
|
if (
|
report.get("lastQuickSwitchOpenRequestSource") == "dockReopen"
|
and report.get("quickSwitchVisible") is True
|
):
|
print(json.dumps({
|
"quickSwitchVisible": report.get("quickSwitchVisible"),
|
"lastQuickSwitchOpenRequestSource": report.get("lastQuickSwitchOpenRequestSource"),
|
"resolvedWaterfallViewMode": report.get("resolvedWaterfallViewMode"),
|
"resolvedQuickSwitchTheme": report.get("resolvedQuickSwitchTheme"),
|
}, indent=2, ensure_ascii=False))
|
sys.exit(0)
|
except FileNotFoundError:
|
pass
|
except json.JSONDecodeError:
|
pass
|
time.sleep(0.1)
|
|
if last_report is not None:
|
print(json.dumps(last_report, indent=2, ensure_ascii=False), file=sys.stderr)
|
print(f"Dock reopen report did not become ready within {timeout:.1f}s", file=sys.stderr)
|
sys.exit(1)
|
PY
|
}
|
|
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
|
rm -f "$REPORT"
|
|
"$APP/Contents/MacOS/Aligner" \
|
--round0-skip-permissions \
|
--round01-fixture-app-count=2 \
|
--round01-fixture-windows-per-app=1 \
|
--round01-disable-screenshot-refresh \
|
--round01-simulate-dock-reopen-after="$SIMULATE_AFTER" \
|
--round01-quick-switch-report="$REPORT" \
|
--round01-quick-switch-auto-hide-after="$HIDE_AFTER" \
|
--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
|
|
wait_for_quick_switch "$OPEN_TIMEOUT"
|
wait_for_dock_reopen_report "$OPEN_TIMEOUT"
|
wait_for_app_exit "$QUIT_TIMEOUT"
|
wait "$APP_PID"
|
trap - EXIT
|
|
swift "$SCRIPT_DIR/window-logic-qa.swift" --expect-no-quick-switch
|