Ariver
2026-06-29 cea8745cfadb698774cb7b4f930c6f10b7cbdf3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
# Round01 window activation fixture QA. It verifies that Enter and mouse
# commits call the activation service, close Quick Switch, and distinguish
# normal activation from minimized-window restore.
 
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"
SOURCE_ROOT="$OUTPUT_ROOT/C1.source"
APP="$BUILD_CURRENT_APP"
MINIMIZED_REPORT="$BUILD_REPORT_ROOT/round01-window-activation-minimized-report.json"
NORMAL_REPORT="$BUILD_REPORT_ROOT/round01-window-activation-normal-report.json"
APP_ONLY_REPORT="$BUILD_REPORT_ROOT/round01-window-activation-app-only-report.json"
FAILURE_REPORT="$BUILD_REPORT_ROOT/round01-window-activation-failure-report.json"
REPORT_WAIT="${ALIGNER_ROUND1_ACTIVATION_REPORT_WAIT:-6.0}"
 
fail() {
  echo "Round01 window activation fixture 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"
}
 
assert_activation_budget_source() {
  /usr/bin/python3 - "$SOURCE_ROOT/Sources/Aligner/Infrastructure/Windows/CGWindowAXWindowService.swift" "$SOURCE_ROOT/Sources/Aligner/QuickSwitchSessionController.swift" <<'PY'
import re
import sys
 
window_service_path, session_path = sys.argv[1:3]
window_service = open(window_service_path, "r", encoding="utf-8").read()
session = open(session_path, "r", encoding="utf-8").read()
 
def fail(message):
    print(message, file=sys.stderr)
    sys.exit(1)
 
cycle_match = re.search(r"finderTabCycleMaximumAttempts\s*=\s*(\d+)", window_service)
if not cycle_match:
    fail("Finder tab cycling attempt limit is missing")
if int(cycle_match.group(1)) != 5:
    fail(f"Finder tab cycling attempt limit must be 5, got {cycle_match.group(1)}")
 
budget_match = re.search(r"finderTabActivationBudgetLimit:\s*TimeInterval\s*=\s*([0-9.]+)", window_service)
if not budget_match:
    fail("Finder tab activation budget limit is missing")
if float(budget_match.group(1)) > 1.5:
    fail(f"Finder tab activation budget must stay at or below 1.5s, got {budget_match.group(1)}")
 
if "lastActivationDurationMilliseconds" not in session:
    fail("Quick Switch activation report must expose lastActivationDurationMilliseconds")
 
print("Finder activation source guardrails passed")
PY
}
 
wait_for_activation_report() {
  local report="$1"
  /usr/bin/python3 - "$report" "$REPORT_WAIT" <<'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("snapshotLoaded") is True
            and report.get("quickSwitchVisible") is False
            and report.get("lastActivationResult") is not None
        ):
            sys.exit(0)
    except FileNotFoundError:
        pass
    except json.JSONDecodeError:
        pass
    time.sleep(0.2)
 
if last_report is not None:
    print(json.dumps(last_report, indent=2, ensure_ascii=False), file=sys.stderr)
print(f"activation report did not become hidden+activated within {timeout:.1f}s", file=sys.stderr)
sys.exit(1)
PY
}
 
assert_activation_report() {
  local report="$1"
  local expected_source="$2"
  local expected_result="$3"
  local expected_app_group_index="$4"
  local expected_window_id="$5"
  local expected_minimized="$6"
 
  /usr/bin/python3 - "$report" "$expected_source" "$expected_result" "$expected_app_group_index" "$expected_window_id" "$expected_minimized" <<'PY'
import json
import sys
 
path = sys.argv[1]
expected_source = sys.argv[2]
expected_result = sys.argv[3]
expected_app_group_index = int(sys.argv[4])
expected_window_id = int(sys.argv[5])
expected_minimized = sys.argv[6] == "true"
 
with open(path, "r", encoding="utf-8") as file:
    report = json.load(file)
 
def require(condition, message):
    if not condition:
        print(message, file=sys.stderr)
        print(json.dumps(report, indent=2, ensure_ascii=False), file=sys.stderr)
        sys.exit(1)
 
root = report.get("rootView", {})
cards = [
    card
    for column in root.get("waterfallColumns", [])
    for card in column.get("cards", [])
]
selected_cards = [card for card in cards if card.get("isSelected") is True]
 
require(report.get("snapshotLoaded") is True, "activation snapshotLoaded must be true")
require(report.get("quickSwitchVisible") is False, "activation commit must close Quick Switch")
require(report.get("appCount") == 2, "activation fixture must expose two Apps")
require(report.get("windowCount") == 3, "activation fixture must expose three windows")
require(root.get("selectedAppGroupIndex") == expected_app_group_index, "selected App group must match activation target")
require(root.get("selectedWindowID") == expected_window_id, "selectedWindowID must match activation target")
require(report.get("lastCommittedWindowID") == expected_window_id, "commit window must match activation target")
require(report.get("lastCommitSource") == expected_source, "commit source must match expected path")
require(report.get("lastActivationWindowID") == expected_window_id, "activation window must match selected target")
require(report.get("lastActivationResult") == expected_result, "activation result must match expected path")
require(report.get("lastActivationError") is None, "debug activation should not record an error")
duration = report.get("lastActivationDurationMilliseconds")
require(isinstance(duration, (int, float)) and duration >= 0, "activation report must include non-negative duration")
require(len(selected_cards) == 1, "activation fixture must expose exactly one selected card")
require(selected_cards[0].get("windowID") == expected_window_id, "selected card must match activation target")
require(selected_cards[0].get("isMinimized") is expected_minimized, "selected card minimized flag must match activation target")
 
print(json.dumps({
    "commitSource": report.get("lastCommitSource"),
    "activationResult": report.get("lastActivationResult"),
    "activationDurationMilliseconds": report.get("lastActivationDurationMilliseconds"),
    "selectedWindowID": root.get("selectedWindowID"),
    "quickSwitchVisible": report.get("quickSwitchVisible"),
    "selectedIsMinimized": selected_cards[0].get("isMinimized")
}, indent=2, ensure_ascii=False))
PY
}
 
assert_activation_failure_suppression_report() {
  /usr/bin/python3 - "$FAILURE_REPORT" <<'PY'
import json
import sys
 
path = sys.argv[1]
 
with open(path, "r", encoding="utf-8") as file:
    report = json.load(file)
 
def require(condition, message):
    if not condition:
        print(message, file=sys.stderr)
        print(json.dumps(report, indent=2, ensure_ascii=False), file=sys.stderr)
        sys.exit(1)
 
root = report.get("rootView", {})
cards = [
    card
    for column in root.get("waterfallColumns", [])
    for card in column.get("cards", [])
]
visible_window_ids = [card.get("windowID") for card in cards]
 
require(report.get("snapshotLoaded") is True, "activation failure snapshotLoaded must be true")
require(report.get("quickSwitchVisible") is False, "activation failure still hides Quick Switch after commit")
require(report.get("lastActivationResult") == "activationFailed", "forced activation failure must be reported")
require(report.get("lastActivationWindowID") == 40100, "forced activation failure must target the clicked window")
require(report.get("suppressedActivationWindowCount") == 1, "activation failure must suppress exactly one target")
require(40100 in report.get("suppressedActivationWindowIDs", []), "failed windowID must be recorded as suppressed")
require(40100 not in visible_window_ids, "failed activation target must be removed from the projected Waterfall")
require(report.get("windowCount") == 2, "projected view must keep remaining windows only")
require(report.get("suppressedCloseTargetCount") == 0, "activation suppression must not use close suppression")
 
print(json.dumps({
    "activationResult": report.get("lastActivationResult"),
    "lastActivationWindowID": report.get("lastActivationWindowID"),
    "suppressedActivationWindowIDs": report.get("suppressedActivationWindowIDs"),
    "visibleWindowIDs": visible_window_ids
}, indent=2, ensure_ascii=False))
PY
}
 
assert_activation_budget_source
stop_current_aligner
"$SCRIPT_DIR/package-app.sh" >&2
rm -f "$MINIMIZED_REPORT" "$NORMAL_REPORT" "$APP_ONLY_REPORT" "$FAILURE_REPORT"
 
"$APP/Contents/MacOS/Aligner" \
  --round0-skip-permissions \
  --round01-open-quick-switch \
  --round01-waterfall-view-mode=vertical \
  --round01-fixture-window-activation \
  --round01-disable-screenshot-refresh \
  --round01-debug-window-activation \
  --round01-debug-key-sequence="2,down,enter" \
  --round01-quick-switch-report="$MINIMIZED_REPORT" &
 
APP_PID=$!
 
cleanup() {
  kill "$APP_PID" 2>/dev/null || true
  wait "$APP_PID" 2>/dev/null || true
  stop_current_aligner
}
trap cleanup EXIT
 
wait_for_activation_report "$MINIMIZED_REPORT"
swift "$SCRIPT_DIR/window-logic-qa.swift" --expect-no-quick-switch >&2
assert_activation_report "$MINIMIZED_REPORT" "keyboard" "restored" 1 40200 true
kill "$APP_PID" 2>/dev/null || true
wait "$APP_PID" 2>/dev/null || true
stop_current_aligner
 
"$APP/Contents/MacOS/Aligner" \
  --round0-skip-permissions \
  --round01-open-quick-switch \
  --round01-waterfall-view-mode=vertical \
  --round01-fixture-window-activation \
  --round01-disable-screenshot-refresh \
  --round01-debug-window-activation \
  --round01-debug-mouse-sequence="click-card:0:1" \
  --round01-quick-switch-report="$NORMAL_REPORT" &
 
APP_PID=$!
wait_for_activation_report "$NORMAL_REPORT"
swift "$SCRIPT_DIR/window-logic-qa.swift" --expect-no-quick-switch >&2
assert_activation_report "$NORMAL_REPORT" "mouse" "activated" 0 40100 false
kill "$APP_PID" 2>/dev/null || true
wait "$APP_PID" 2>/dev/null || true
stop_current_aligner
 
"$APP/Contents/MacOS/Aligner" \
  --round0-skip-permissions \
  --round01-open-quick-switch \
  --round01-waterfall-view-mode=vertical \
  --round01-fixture-window-activation \
  --round01-disable-screenshot-refresh \
  --round01-debug-window-activation \
  --round01-debug-mouse-sequence="click-card:0:0" \
  --round01-quick-switch-report="$APP_ONLY_REPORT" &
 
APP_PID=$!
wait_for_activation_report "$APP_ONLY_REPORT"
swift "$SCRIPT_DIR/window-logic-qa.swift" --expect-no-quick-switch >&2
assert_activation_report "$APP_ONLY_REPORT" "mouse" "appActivatedOnly" 0 40110 false
 
kill "$APP_PID" 2>/dev/null || true
wait "$APP_PID" 2>/dev/null || true
stop_current_aligner
 
ALIGNER_DEBUG_WINDOW_ACTIVATION_RESULT=activationFailed "$APP/Contents/MacOS/Aligner" \
  --round0-skip-permissions \
  --round01-open-quick-switch \
  --round01-waterfall-view-mode=vertical \
  --round01-fixture-window-activation \
  --round01-disable-screenshot-refresh \
  --round01-debug-window-activation \
  --round01-debug-mouse-sequence="click-card:0:1" \
  --round01-quick-switch-report="$FAILURE_REPORT" &
 
APP_PID=$!
wait_for_activation_report "$FAILURE_REPORT"
swift "$SCRIPT_DIR/window-logic-qa.swift" --expect-no-quick-switch >&2
assert_activation_failure_suppression_report
 
kill "$APP_PID" 2>/dev/null || true
wait "$APP_PID" 2>/dev/null || true
trap - EXIT
stop_current_aligner