Ariver
2026-06-20 1fea9bfc8a7639bb3573a7cf2a449ab55065ab9e
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
#!/bin/bash
# Round01 window index progressive filter fixture QA. It verifies that the
# first Option window-index key dims only non-target Waterfall cards, and that
# the second key commits immediately while preserving the pre-commit snapshot.
 
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"
DOMAIN="com.ar.Aligner"
THEME_KEY="com.ar.Aligner.preferences.appearance.theme"
REPORT_WAIT="${ALIGNER_ROUND1_WINDOW_INDEX_FILTER_REPORT_WAIT:-8.0}"
FIXTURE_APP_COUNT="${ALIGNER_ROUND1_WINDOW_INDEX_FILTER_APP_COUNT:-8}"
FIXTURE_WINDOWS_PER_APP="${ALIGNER_ROUND1_WINDOW_INDEX_FILTER_WINDOWS_PER_APP:-6}"
TARGET_APP_INDEX="${ALIGNER_ROUND1_WINDOW_INDEX_FILTER_TARGET_APP_INDEX:-2}"
TARGET_WINDOW_INDEX="${ALIGNER_ROUND1_WINDOW_INDEX_FILTER_TARGET_WINDOW_INDEX:-5}"
APP_SYMBOL="${ALIGNER_ROUND1_WINDOW_INDEX_FILTER_APP_SYMBOL:-3}"
WINDOW_SYMBOL="${ALIGNER_ROUND1_WINDOW_INDEX_FILTER_WINDOW_SYMBOL:-6}"
TARGET_CODE="${APP_SYMBOL}${WINDOW_SYMBOL}"
 
REPORT_HORIZONTAL_LIGHT="$BUILD_REPORT_ROOT/round01-window-index-progressive-filter-horizontal-light-report.json"
REPORT_VERTICAL_LIGHT="$BUILD_REPORT_ROOT/round01-window-index-progressive-filter-vertical-light-report.json"
REPORT_HORIZONTAL_DARK="$BUILD_REPORT_ROOT/round01-window-index-progressive-filter-horizontal-dark-report.json"
REPORT_COMMIT="$BUILD_REPORT_ROOT/round01-window-index-progressive-filter-commit-report.json"
REPORT_INVALID="$BUILD_REPORT_ROOT/round01-window-index-progressive-filter-invalid-report.json"
REPORT_SINGLE_WINDOW="$BUILD_REPORT_ROOT/round01-window-index-progressive-filter-single-window-report.json"
SUMMARY_DIR="$BUILD_TMP_ROOT/round01-window-index-progressive-filter-fixture-qa"
 
APP_PID=""
OLD_THEME_SET=0
OLD_THEME=""
SUMMARY_FILES=()
 
fail() {
  echo "Round01 window index progressive filter fixture 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"
}
 
stop_current_aligner_safely() {
  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
 
  echo "warning: current Aligner app did not exit during cleanup" >&2
}
 
preserve_user_theme() {
  if OLD_THEME="$(/usr/bin/defaults read "$DOMAIN" "$THEME_KEY" 2>/dev/null)"; then
    OLD_THEME_SET=1
  else
    OLD_THEME_SET=0
    OLD_THEME=""
  fi
}
 
restore_user_theme() {
  if [ "$OLD_THEME_SET" -eq 1 ]; then
    /usr/bin/defaults write "$DOMAIN" "$THEME_KEY" -string "$OLD_THEME"
  else
    /usr/bin/defaults delete "$DOMAIN" "$THEME_KEY" >/dev/null 2>&1 || true
  fi
}
 
cleanup() {
  if [ -n "${APP_PID:-}" ]; then
    kill "$APP_PID" 2>/dev/null || true
    wait "$APP_PID" 2>/dev/null || true
    APP_PID=""
  fi
  stop_current_aligner_safely
  restore_user_theme
}
 
set_theme() {
  local theme="$1"
  /usr/bin/defaults write "$DOMAIN" "$THEME_KEY" -string "$theme"
}
 
mode_report_value() {
  local mode="$1"
  case "$mode" in
    horizontal) echo "horizontalMasonry" ;;
    vertical) echo "verticalColumns" ;;
    *) fail "unsupported waterfall mode $mode" ;;
  esac
}
 
pending_key_sequence() {
  echo "physical-index:$APP_SYMBOL"
}
 
commit_key_sequence() {
  echo "physical-index:$APP_SYMBOL,physical-index:$WINDOW_SYMBOL"
}
 
pending_expected_sequence() {
  echo "app:$APP_SYMBOL"
}
 
commit_expected_sequence() {
  echo "app:$APP_SYMBOL,window:$TARGET_CODE"
}
 
invalid_key_sequence() {
  echo "physical-index:$APP_SYMBOL,physical-index:Z"
}
 
invalid_expected_sequence() {
  echo "app:$APP_SYMBOL,windowInvalid:${APP_SYMBOL}Z"
}
 
single_window_expected_sequence() {
  echo "app:$APP_SYMBOL,windowSingle:$APP_SYMBOL"
}
 
run_fixture() {
  local report="$1"
  local theme="$2"
  local mode="$3"
  local key_sequence="$4"
  local windows_per_app="${5:-$FIXTURE_WINDOWS_PER_APP}"
 
  stop_current_aligner
  set_theme "$theme"
  rm -f "$report"
 
  "$APP/Contents/MacOS/Aligner" \
    --round0-skip-permissions \
    --round01-open-quick-switch \
    --round01-fixture-app-count="$FIXTURE_APP_COUNT" \
    --round01-fixture-windows-per-app="$windows_per_app" \
    --round01-disable-screenshot-refresh \
    --round01-waterfall-view-mode="$mode" \
    --round01-debug-key-sequence="$key_sequence" \
    --round01-quick-switch-report="$report" >/dev/null 2>&1 &
 
  APP_PID=$!
}
 
finish_case() {
  if [ -n "${APP_PID:-}" ]; then
    kill "$APP_PID" 2>/dev/null || true
    wait "$APP_PID" 2>/dev/null || true
    APP_PID=""
  fi
  stop_current_aligner
}
 
wait_for_pending_report() {
  local report="$1"
  local expected_mode="$2"
  local expected_sequence="$3"
  local case_name="$4"
 
  /usr/bin/python3 - "$report" "$REPORT_WAIT" "$expected_mode" "$expected_sequence" "$case_name" <<'PY'
import json
import sys
import time
 
path = sys.argv[1]
timeout = float(sys.argv[2])
expected_mode = sys.argv[3]
expected_sequence = [part for part in sys.argv[4].split(",") if part]
case_name = sys.argv[5]
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
        root = report.get("rootView", {})
        if (
            report.get("snapshotLoaded") is True
            and report.get("quickSwitchVisible") is True
            and root.get("waterfallViewMode") == expected_mode
            and root.get("keyboardCommandsApplied") == expected_sequence
            and root.get("windowShortcutFilterPhase") == "appPending"
        ):
            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"{case_name}: pending filter report did not reach appPending within {timeout:.1f}s", file=sys.stderr)
sys.exit(1)
PY
}
 
wait_for_commit_report() {
  local report="$1"
  local expected_mode="$2"
  local expected_sequence="$3"
 
  /usr/bin/python3 - "$report" "$REPORT_WAIT" "$expected_mode" "$expected_sequence" "$TARGET_CODE" <<'PY'
import json
import sys
import time
 
path = sys.argv[1]
timeout = float(sys.argv[2])
expected_mode = sys.argv[3]
expected_sequence = [part for part in sys.argv[4].split(",") if part]
target_code = sys.argv[5]
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
        root = report.get("rootView", {})
        snapshot = root.get("lastWindowShortcutPreCommitFilterSnapshot")
        if (
            report.get("snapshotLoaded") is True
            and root.get("waterfallViewMode") == expected_mode
            and root.get("keyboardCommandsApplied") == expected_sequence
            and root.get("lastWindowIndexKeyCommitCode") == target_code
            and isinstance(snapshot, dict)
        ):
            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"commit report did not reach pre-commit snapshot within {timeout:.1f}s", file=sys.stderr)
sys.exit(1)
PY
}
 
wait_for_invalid_report() {
  local report="$1"
  local expected_mode="$2"
  local expected_sequence="$3"
 
  /usr/bin/python3 - "$report" "$REPORT_WAIT" "$expected_mode" "$expected_sequence" "${APP_SYMBOL}Z" <<'PY'
import json
import sys
import time
 
path = sys.argv[1]
timeout = float(sys.argv[2])
expected_mode = sys.argv[3]
expected_sequence = [part for part in sys.argv[4].split(",") if part]
invalid_code = sys.argv[5]
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
        root = report.get("rootView", {})
        if (
            report.get("snapshotLoaded") is True
            and report.get("quickSwitchVisible") is True
            and root.get("waterfallViewMode") == expected_mode
            and root.get("keyboardCommandsApplied") == expected_sequence
            and root.get("lastWindowIndexKeyCommand") == f"windowInvalid:{invalid_code}"
            and root.get("windowShortcutFilterPhase") == "invalid"
        ):
            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"invalid report did not reach invalid state within {timeout:.1f}s", file=sys.stderr)
sys.exit(1)
PY
}
 
wait_for_single_window_report() {
  local report="$1"
  local expected_mode="$2"
  local expected_sequence="$3"
 
  /usr/bin/python3 - "$report" "$REPORT_WAIT" "$expected_mode" "$expected_sequence" "$APP_SYMBOL" <<'PY'
import json
import sys
import time
 
path = sys.argv[1]
timeout = float(sys.argv[2])
expected_mode = sys.argv[3]
expected_sequence = [part for part in sys.argv[4].split(",") if part]
app_symbol = sys.argv[5]
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
        root = report.get("rootView", {})
        if (
            report.get("snapshotLoaded") is True
            and root.get("waterfallViewMode") == expected_mode
            and root.get("keyboardCommandsApplied") == expected_sequence
            and root.get("lastWindowIndexKeyCommand") == f"windowSingle:{app_symbol}"
            and root.get("lastCommitSource") == "keyboard"
        ):
            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"single-window report did not reach direct commit within {timeout:.1f}s", file=sys.stderr)
sys.exit(1)
PY
}
 
assert_pending_report() {
  local report="$1"
  local case_name="$2"
  local theme="$3"
  local expected_mode="$4"
  local summary_file="$SUMMARY_DIR/$case_name.json"
 
  /usr/bin/python3 - \
    "$report" \
    "$case_name" \
    "$theme" \
    "$expected_mode" \
    "$(pending_expected_sequence)" \
    "$FIXTURE_APP_COUNT" \
    "$FIXTURE_WINDOWS_PER_APP" \
    "$TARGET_APP_INDEX" \
    "$APP_SYMBOL" \
    "$summary_file" <<'PY'
import json
import numbers
import sys
 
path = sys.argv[1]
case_name = sys.argv[2]
theme = sys.argv[3]
expected_mode = sys.argv[4]
expected_sequence = [part for part in sys.argv[5].split(",") if part]
fixture_app_count = int(sys.argv[6])
fixture_windows_per_app = int(sys.argv[7])
target_app_index = int(sys.argv[8])
app_symbol = sys.argv[9]
summary_file = sys.argv[10]
 
with open(path, "r", encoding="utf-8") as file:
    report = json.load(file)
 
def require(condition, message):
    if not condition:
        print(f"{case_name}: {message}", file=sys.stderr)
        print(json.dumps(report, indent=2, ensure_ascii=False), file=sys.stderr)
        sys.exit(1)
 
def sorted_ints(values):
    require(isinstance(values, list), "window ID field must be a list")
    return sorted(int(value) for value in values)
 
def is_number(value):
    return isinstance(value, numbers.Real) and not isinstance(value, bool)
 
root = report.get("rootView", {})
columns = root.get("waterfallColumns", [])
cards = [card for column in columns for card in column.get("cards", [])]
target_column = next((column for column in columns if column.get("appGroupIndex") == target_app_index), None)
 
require(report.get("snapshotLoaded") is True, "snapshotLoaded must be true")
require(report.get("quickSwitchVisible") is True, "pending filter must keep Quick Switch visible")
require(report.get("appCount") == fixture_app_count, "fixture appCount must match")
require(report.get("windowCount") == fixture_app_count * fixture_windows_per_app, "fixture windowCount must match")
require(root.get("waterfallViewMode") == expected_mode, "Waterfall view mode must match case")
require(root.get("keyboardCommandsApplied") == expected_sequence, "pending key sequence must be applied")
require(root.get("appShelfIndexKeyDownCount") == 1, "pending filter must exercise one physical keyDown")
require(root.get("lastAppShelfIndexKeySymbol") == app_symbol, "pending physical symbol must be reported")
require(root.get("lastCommitSource") is None, "pending filter must not commit")
require(root.get("lastCommittedWindowID") is None, "pending filter must not commit a window")
require(root.get("lastWindowIndexKeyCommitCode") is None, "pending filter must not expose a commit code")
 
require(root.get("windowShortcutFilterActive") is True, "windowShortcutFilterActive must be true")
require(root.get("windowShortcutFilterPhase") == "appPending", "filter phase must be appPending")
require(root.get("windowShortcutFilterPendingAppGroupIndex") == target_app_index, "pending App group must match first key")
require(root.get("windowShortcutFilterPrefix") == app_symbol, "filter prefix must match first physical key")
require(root.get("lastWindowShortcutPreCommitFilterSnapshot") is None, "pending run must not expose a pre-commit snapshot")
 
require(target_column is not None, "target App column must exist")
target_cards = target_column.get("cards", [])
target_ids = sorted(int(card.get("windowID")) for card in target_cards)
dimmed_cards = [card for card in cards if int(card.get("windowID")) not in set(target_ids)]
dimmed_ids = sorted(int(card.get("windowID")) for card in dimmed_cards)
 
require(len(target_cards) == fixture_windows_per_app, "target App must keep all fixture windows")
require(root.get("windowShortcutFilterMatchedCount") == len(target_ids), "matched count must equal target App window count")
require(root.get("windowShortcutFilterDimmedCount") == len(dimmed_ids), "dimmed count must equal non-target Waterfall cards")
require(sorted_ints(root.get("windowShortcutFilterMatchedWindowIDs")) == target_ids, "matched window IDs must be exactly target App windows")
require(sorted_ints(root.get("windowShortcutFilterDimmedWindowIDs")) == dimmed_ids, "dimmed window IDs must be exactly non-target Waterfall windows")
 
matched_opacities = []
dimmed_opacities = []
for card in target_cards:
    states = card.get("visualStates", [])
    opacity = card.get("windowShortcutFilterOpacity")
    require(card.get("windowShortcutFilterState") == "matched", "target App cards must report matched filter state")
    require(is_number(opacity), "matched cards must expose numeric filter opacity")
    require(0 <= opacity <= 1.01, "matched card opacity must be normalized")
    require("shortcutMatched" in states, "matched cards must expose shortcutMatched visual state")
    require("shortcutDimmed" not in states, "matched cards must not expose shortcutDimmed")
    require("shortcutTarget" not in states, "pending matched cards must not expose shortcutTarget")
    matched_opacities.append(float(opacity))
 
for card in dimmed_cards:
    states = card.get("visualStates", [])
    opacity = card.get("windowShortcutFilterOpacity")
    require(card.get("windowShortcutFilterState") == "dimmed", "non-target Waterfall cards must report dimmed filter state")
    require(is_number(opacity), "dimmed cards must expose numeric filter opacity")
    require(0 <= opacity <= 1.01, "dimmed card opacity must be normalized")
    require("shortcutDimmed" in states, "dimmed cards must expose shortcutDimmed visual state")
    require("shortcutMatched" not in states, "dimmed cards must not expose shortcutMatched")
    require("shortcutTarget" not in states, "pending dimmed cards must not expose shortcutTarget")
    dimmed_opacities.append(float(opacity))
 
require(matched_opacities, "fixture must have matched cards")
require(dimmed_opacities, "fixture must have dimmed cards")
require(min(matched_opacities) > max(dimmed_opacities), "matched cards must stay visually brighter than dimmed cards")
 
for node in root.get("appShelfItems", []) + root.get("spaceLaneSegments", []):
    states = node.get("visualStates", [])
    require("shortcutDimmed" not in states, "shortcut dim visual state must not leak to Space Lane or App Shelf")
    if "windowShortcutFilterState" in node:
        require(node.get("windowShortcutFilterState") != "dimmed", "Space Lane/App Shelf must not report dimmed filter state")
    if "windowShortcutFilterOpacity" in node:
        opacity = node.get("windowShortcutFilterOpacity")
        require(is_number(opacity), "Space Lane/App Shelf filter opacity must be numeric if present")
        require(opacity >= 0.99, "Space Lane/App Shelf must not be dimmed by window shortcut filter")
 
summary = {
    "case": case_name,
    "status": "passed",
    "theme": theme,
    "mode": root.get("waterfallViewMode"),
    "report": path,
    "phase": root.get("windowShortcutFilterPhase"),
    "prefix": root.get("windowShortcutFilterPrefix"),
    "pendingAppGroupIndex": root.get("windowShortcutFilterPendingAppGroupIndex"),
    "matchedCount": root.get("windowShortcutFilterMatchedCount"),
    "dimmedCount": root.get("windowShortcutFilterDimmedCount"),
    "matchedWindowIDs": target_ids,
    "dimmedWindowIDs": dimmed_ids,
    "matchedOpacityMin": min(matched_opacities),
    "dimmedOpacityMax": max(dimmed_opacities),
    "quickSwitchVisible": report.get("quickSwitchVisible"),
    "commitSource": root.get("lastCommitSource"),
}
with open(summary_file, "w", encoding="utf-8") as file:
    json.dump(summary, file, indent=2, ensure_ascii=False)
PY
 
  SUMMARY_FILES+=("$summary_file")
}
 
assert_commit_report() {
  local report="$1"
  local case_name="valid-commit-horizontal"
  local summary_file="$SUMMARY_DIR/$case_name.json"
 
  /usr/bin/python3 - \
    "$report" \
    "$case_name" \
    "light" \
    "horizontalMasonry" \
    "$(commit_expected_sequence)" \
    "$FIXTURE_APP_COUNT" \
    "$FIXTURE_WINDOWS_PER_APP" \
    "$TARGET_APP_INDEX" \
    "$TARGET_WINDOW_INDEX" \
    "$APP_SYMBOL" \
    "$WINDOW_SYMBOL" \
    "$TARGET_CODE" \
    "$summary_file" <<'PY'
import json
import numbers
import sys
 
path = sys.argv[1]
case_name = sys.argv[2]
theme = sys.argv[3]
expected_mode = sys.argv[4]
expected_sequence = [part for part in sys.argv[5].split(",") if part]
fixture_app_count = int(sys.argv[6])
fixture_windows_per_app = int(sys.argv[7])
target_app_index = int(sys.argv[8])
target_window_index = int(sys.argv[9])
app_symbol = sys.argv[10]
window_symbol = sys.argv[11]
target_code = sys.argv[12]
summary_file = sys.argv[13]
 
with open(path, "r", encoding="utf-8") as file:
    report = json.load(file)
 
def require(condition, message):
    if not condition:
        print(f"{case_name}: {message}", file=sys.stderr)
        print(json.dumps(report, indent=2, ensure_ascii=False), file=sys.stderr)
        sys.exit(1)
 
def sorted_ints(values):
    require(isinstance(values, list), "window ID field must be a list")
    return sorted(int(value) for value in values)
 
def is_number(value):
    return isinstance(value, numbers.Real) and not isinstance(value, bool)
 
root = report.get("rootView", {})
columns = root.get("waterfallColumns", [])
cards = [card for column in columns for card in column.get("cards", [])]
target_column = next((column for column in columns if column.get("appGroupIndex") == target_app_index), None)
 
require(report.get("snapshotLoaded") is True, "snapshotLoaded must be true")
require(report.get("appCount") == fixture_app_count, "fixture appCount must match")
require(report.get("windowCount") == fixture_app_count * fixture_windows_per_app, "fixture windowCount must match")
require(root.get("waterfallViewMode") == expected_mode, "commit run must use horizontal Waterfall")
require(root.get("keyboardCommandsApplied") == expected_sequence, "commit key sequence must be applied")
require(root.get("appShelfIndexKeyDownCount") == 2, "commit must exercise two physical keyDown events")
require(root.get("lastAppShelfIndexKeySymbol") == window_symbol, "last physical symbol must be the window key")
require(root.get("lastWindowIndexKeyCommand") == f"window:{target_code}", "last window shortcut command must be reported")
require(root.get("lastWindowIndexKeyCommitCode") == target_code, "last window shortcut commit code must be reported")
require(root.get("windowIndexKeyPendingAppGroupIndex") is None, "commit must clear legacy pending App group")
require(root.get("windowIndexKeyPendingAppSymbol") is None, "commit must clear legacy pending App symbol")
require(root.get("lastCommitSource") == "keyboard", "valid shortcut commit must be keyboard sourced")
 
require(target_column is not None, "target App column must exist")
target_cards = target_column.get("cards", [])
require(target_window_index < len(target_cards), "target window index must exist")
target_card = target_cards[target_window_index]
target_window_id = int(target_card.get("windowID"))
all_window_ids = sorted(int(card.get("windowID")) for card in cards)
dimmed_ids = sorted(window_id for window_id in all_window_ids if window_id != target_window_id)
 
require(target_card.get("windowShortcutCode") == target_code, "target card shortcut code must match committed code")
require(root.get("lastCommittedAppGroupIndex") == target_app_index, "commit must target expected App")
require(root.get("lastCommittedWindowIndex") == target_window_index, "commit must target expected window index")
require(root.get("lastCommittedWindowID") == target_window_id, "commit must target expected window ID")
require(root.get("selectedAppGroupIndex") == target_app_index, "selection must land on target App")
require(root.get("selectedWindowIndex") == target_window_index, "selection must land on target window")
require(root.get("selectedWindowID") == target_window_id, "selectedWindowID must match target window")
 
snapshot = root.get("lastWindowShortcutPreCommitFilterSnapshot")
require(isinstance(snapshot, dict), "pre-commit filter snapshot must be an object")
require(snapshot.get("phase") == "targetPreCommit", "pre-commit snapshot phase must be targetPreCommit")
require(snapshot.get("targetCode") == target_code, "pre-commit snapshot targetCode must match committed shortcut")
require(int(snapshot.get("targetWindowID")) == target_window_id, "pre-commit snapshot targetWindowID must match target card")
require(sorted_ints(snapshot.get("matchedWindowIDs")) == [target_window_id], "pre-commit snapshot must match only the target window")
require(sorted_ints(snapshot.get("dimmedWindowIDs")) == dimmed_ids, "pre-commit snapshot must dim all non-target Waterfall windows")
 
states = target_card.get("visualStates", [])
opacity = target_card.get("windowShortcutFilterOpacity")
require(target_card.get("windowShortcutFilterState") == "target", "target card must report target filter state")
require(is_number(opacity), "target card must expose numeric filter opacity")
require(0 <= opacity <= 1.01, "target card opacity must be normalized")
require("shortcutTarget" in states, "target card must expose shortcutTarget visual state")
 
for card in cards:
    if int(card.get("windowID")) == target_window_id:
        continue
    card_states = card.get("visualStates", [])
    card_opacity = card.get("windowShortcutFilterOpacity")
    require(card.get("windowShortcutFilterState") == "dimmed", "non-target cards must remain dimmed in target pre-commit state")
    require(is_number(card_opacity), "non-target cards must expose numeric filter opacity")
    require("shortcutDimmed" in card_states, "non-target cards must expose shortcutDimmed in target pre-commit state")
    require("shortcutTarget" not in card_states, "non-target cards must not expose shortcutTarget")
 
for node in root.get("appShelfItems", []) + root.get("spaceLaneSegments", []):
    states = node.get("visualStates", [])
    require("shortcutDimmed" not in states, "shortcut dim visual state must not leak to Space Lane or App Shelf during commit")
    if "windowShortcutFilterState" in node:
        require(node.get("windowShortcutFilterState") != "dimmed", "Space Lane/App Shelf must not report dimmed filter state during commit")
 
summary = {
    "case": case_name,
    "status": "passed",
    "theme": theme,
    "mode": root.get("waterfallViewMode"),
    "report": path,
    "commands": root.get("keyboardCommandsApplied"),
    "targetCode": target_code,
    "targetWindowID": target_window_id,
    "matchedWindowIDs": snapshot.get("matchedWindowIDs"),
    "dimmedCount": len(snapshot.get("dimmedWindowIDs", [])),
    "lastCommitSource": root.get("lastCommitSource"),
    "lastWindowIndexKeyCommitCode": root.get("lastWindowIndexKeyCommitCode"),
    "targetCardState": target_card.get("windowShortcutFilterState"),
}
with open(summary_file, "w", encoding="utf-8") as file:
    json.dump(summary, file, indent=2, ensure_ascii=False)
PY
 
  SUMMARY_FILES+=("$summary_file")
}
 
assert_invalid_report() {
  local report="$1"
  local case_name="invalid-second-key-horizontal"
  local summary_file="$SUMMARY_DIR/$case_name.json"
 
  /usr/bin/python3 - \
    "$report" \
    "$case_name" \
    "horizontalMasonry" \
    "$(invalid_expected_sequence)" \
    "$APP_SYMBOL" \
    "${APP_SYMBOL}Z" \
    "$summary_file" <<'PY'
import json
import numbers
import sys
 
path = sys.argv[1]
case_name = sys.argv[2]
expected_mode = sys.argv[3]
expected_sequence = [part for part in sys.argv[4].split(",") if part]
app_symbol = sys.argv[5]
invalid_code = sys.argv[6]
summary_file = sys.argv[7]
 
with open(path, "r", encoding="utf-8") as file:
    report = json.load(file)
 
def require(condition, message):
    if not condition:
        print(f"{case_name}: {message}", file=sys.stderr)
        print(json.dumps(report, indent=2, ensure_ascii=False), file=sys.stderr)
        sys.exit(1)
 
def is_number(value):
    return isinstance(value, numbers.Real) and not isinstance(value, bool)
 
root = report.get("rootView", {})
columns = root.get("waterfallColumns", [])
cards = [card for column in columns for card in column.get("cards", [])]
 
require(report.get("snapshotLoaded") is True, "snapshotLoaded must be true")
require(report.get("quickSwitchVisible") is True, "invalid shortcut must keep Quick Switch visible")
require(root.get("waterfallViewMode") == expected_mode, "invalid run must use horizontal Waterfall")
require(root.get("keyboardCommandsApplied") == expected_sequence, "invalid key sequence must be applied")
require(root.get("appShelfIndexKeyDownCount") == 2, "invalid shortcut must exercise two physical keyDown events")
require(root.get("lastAppShelfIndexKeySymbol") == "Z", "last physical symbol must be invalid window key")
require(root.get("lastWindowIndexKeyCommand") == f"windowInvalid:{invalid_code}", "invalid command must be reported")
require(root.get("lastWindowIndexKeyCommitCode") is None, "invalid shortcut must not expose commit code")
require(root.get("lastCommitSource") is None, "invalid shortcut must not commit")
require(root.get("lastCommittedWindowID") is None, "invalid shortcut must not commit a window")
require(root.get("windowIndexKeyPendingAppGroupIndex") is None, "invalid shortcut must clear legacy pending App group")
require(root.get("windowIndexKeyPendingAppSymbol") is None, "invalid shortcut must clear legacy pending App symbol")
require(root.get("windowShortcutFilterActive") is False, "invalid shortcut must not leave active filter")
require(root.get("windowShortcutFilterPhase") == "invalid", "invalid shortcut must report invalid phase")
require(root.get("windowShortcutFilterPendingAppGroupIndex") is None, "invalid shortcut must clear pending App group")
require(root.get("windowShortcutFilterPrefix") is None, "invalid shortcut must clear filter prefix")
require(root.get("windowShortcutFilterMatchedCount") == 0, "invalid shortcut must clear matched count")
require(root.get("windowShortcutFilterDimmedCount") == 0, "invalid shortcut must clear dimmed count")
require(root.get("windowShortcutFilterMatchedWindowIDs") == [], "invalid shortcut must clear matched IDs")
require(root.get("windowShortcutFilterDimmedWindowIDs") == [], "invalid shortcut must clear dimmed IDs")
require(root.get("lastWindowShortcutPreCommitFilterSnapshot") is None, "invalid shortcut must not expose pre-commit snapshot")
 
for card in cards:
    opacity = card.get("windowShortcutFilterOpacity")
    states = card.get("visualStates", [])
    require(card.get("windowShortcutFilterState") == "none", "invalid shortcut must restore card filter state")
    require(is_number(opacity), "cards must expose numeric filter opacity")
    require(float(opacity) >= 0.99, "invalid shortcut must restore card opacity")
    require("shortcutDimmed" not in states, "invalid shortcut must not leave shortcutDimmed state")
    require("shortcutMatched" not in states, "invalid shortcut must not leave shortcutMatched state")
    require("shortcutTarget" not in states, "invalid shortcut must not leave shortcutTarget state")
 
summary = {
    "case": case_name,
    "status": "passed",
    "mode": root.get("waterfallViewMode"),
    "report": path,
    "commands": root.get("keyboardCommandsApplied"),
    "firstSymbol": app_symbol,
    "invalidCode": invalid_code,
    "phase": root.get("windowShortcutFilterPhase"),
    "quickSwitchVisible": report.get("quickSwitchVisible"),
    "cardCount": len(cards)
}
with open(summary_file, "w", encoding="utf-8") as file:
    json.dump(summary, file, indent=2, ensure_ascii=False)
PY
 
  SUMMARY_FILES+=("$summary_file")
}
 
assert_single_window_report() {
  local report="$1"
  local case_name="single-window-first-key-commit-horizontal"
  local summary_file="$SUMMARY_DIR/$case_name.json"
 
  /usr/bin/python3 - \
    "$report" \
    "$case_name" \
    "horizontalMasonry" \
    "$(single_window_expected_sequence)" \
    "$FIXTURE_APP_COUNT" \
    "$TARGET_APP_INDEX" \
    "$APP_SYMBOL" \
    "$summary_file" <<'PY'
import json
import numbers
import sys
 
path = sys.argv[1]
case_name = sys.argv[2]
expected_mode = sys.argv[3]
expected_sequence = [part for part in sys.argv[4].split(",") if part]
fixture_app_count = int(sys.argv[5])
target_app_index = int(sys.argv[6])
app_symbol = sys.argv[7]
summary_file = sys.argv[8]
 
with open(path, "r", encoding="utf-8") as file:
    report = json.load(file)
 
def require(condition, message):
    if not condition:
        print(f"{case_name}: {message}", file=sys.stderr)
        print(json.dumps(report, indent=2, ensure_ascii=False), file=sys.stderr)
        sys.exit(1)
 
def is_number(value):
    return isinstance(value, numbers.Real) and not isinstance(value, bool)
 
root = report.get("rootView", {})
columns = root.get("waterfallColumns", [])
cards = [card for column in columns for card in column.get("cards", [])]
target_column = next((column for column in columns if column.get("appGroupIndex") == target_app_index), None)
 
require(report.get("snapshotLoaded") is True, "snapshotLoaded must be true")
require(report.get("appCount") == fixture_app_count, "fixture appCount must match")
require(report.get("windowCount") == fixture_app_count, "single-window fixture must have one window per App")
require(root.get("waterfallViewMode") == expected_mode, "single-window run must use horizontal Waterfall")
require(root.get("keyboardCommandsApplied") == expected_sequence, "single-window key sequence must direct-commit")
require(root.get("appShelfIndexKeyDownCount") == 1, "single-window direct commit must use one physical keyDown")
require(root.get("lastAppShelfIndexKeySymbol") == app_symbol, "last physical symbol must be the App key")
require(root.get("lastWindowIndexKeyCommand") == f"windowSingle:{app_symbol}", "single-window direct command must be reported")
require(root.get("lastWindowIndexKeyCommitCode") == app_symbol, "single-window commit code must be the one-key shortcut")
require(root.get("lastCommitSource") == "keyboard", "single-window direct commit must be keyboard sourced")
require(root.get("windowIndexKeyPendingAppGroupIndex") is None, "single-window direct commit must not leave pending App group")
require(root.get("windowIndexKeyPendingAppSymbol") is None, "single-window direct commit must not leave pending App symbol")
require(root.get("windowShortcutFilterActive") is False, "single-window direct commit must not enter progressive filter")
require(root.get("windowShortcutFilterPhase") == "none", "single-window direct commit must keep filter phase none")
require(root.get("windowShortcutFilterMatchedCount") == 0, "single-window direct commit must not leave matched filter count")
require(root.get("windowShortcutFilterDimmedCount") == 0, "single-window direct commit must not leave dimmed filter count")
require(root.get("lastWindowShortcutPreCommitFilterSnapshot") is None, "single-window direct commit must not expose two-key pre-commit snapshot")
 
require(target_column is not None, "target App column must exist")
target_cards = target_column.get("cards", [])
require(len(target_cards) == 1, "target App must have exactly one visible window")
target_card = target_cards[0]
target_window_id = int(target_card.get("windowID"))
require(root.get("lastCommittedAppGroupIndex") == target_app_index, "direct commit must target expected App")
require(root.get("lastCommittedWindowIndex") == 0, "direct commit must target the only window")
require(root.get("lastCommittedWindowID") == target_window_id, "direct commit must target expected window ID")
require(root.get("selectedAppGroupIndex") == target_app_index, "selection must land on target App")
require(root.get("selectedWindowIndex") == 0, "selection must land on the only window")
require(root.get("selectedWindowID") == target_window_id, "selectedWindowID must match target window")
 
for card in cards:
    opacity = card.get("windowShortcutFilterOpacity")
    states = card.get("visualStates", [])
    require(card.get("windowShortcutFilterState") == "none", "single-window direct commit must not leave card filter state")
    require(is_number(opacity), "cards must expose numeric filter opacity")
    require(float(opacity) >= 0.99, "single-window direct commit must not dim cards")
    require("shortcutDimmed" not in states, "single-window direct commit must not leave shortcutDimmed state")
    require("shortcutMatched" not in states, "single-window direct commit must not leave shortcutMatched state")
    require("shortcutTarget" not in states, "single-window direct commit must not leave shortcutTarget state")
 
summary = {
    "case": case_name,
    "status": "passed",
    "mode": root.get("waterfallViewMode"),
    "report": path,
    "commands": root.get("keyboardCommandsApplied"),
    "targetWindowID": target_window_id,
    "lastCommitSource": root.get("lastCommitSource"),
    "lastWindowIndexKeyCommitCode": root.get("lastWindowIndexKeyCommitCode"),
    "cardCount": len(cards)
}
with open(summary_file, "w", encoding="utf-8") as file:
    json.dump(summary, file, indent=2, ensure_ascii=False)
PY
 
  SUMMARY_FILES+=("$summary_file")
}
 
assert_pending_summaries_consistent() {
  local baseline="$1"
  local candidate="$2"
  local label="$3"
 
  /usr/bin/python3 - "$baseline" "$candidate" "$label" <<'PY'
import json
import sys
 
baseline_path = sys.argv[1]
candidate_path = sys.argv[2]
label = sys.argv[3]
 
with open(baseline_path, "r", encoding="utf-8") as file:
    baseline = json.load(file)
with open(candidate_path, "r", encoding="utf-8") as file:
    candidate = json.load(file)
 
fields = [
    "phase",
    "prefix",
    "pendingAppGroupIndex",
    "matchedCount",
    "dimmedCount",
    "matchedWindowIDs",
    "dimmedWindowIDs",
]
 
for field in fields:
    if baseline.get(field) != candidate.get(field):
        print(f"{label}: pending field {field} differs between baseline and candidate", file=sys.stderr)
        print(json.dumps({"baseline": baseline, "candidate": candidate}, indent=2, ensure_ascii=False), file=sys.stderr)
        sys.exit(1)
PY
}
 
emit_summary() {
  /usr/bin/python3 - "$APP" "$FIXTURE_APP_COUNT" "$FIXTURE_WINDOWS_PER_APP" "${SUMMARY_FILES[@]}" <<'PY'
import json
import sys
 
app = sys.argv[1]
fixture_app_count = int(sys.argv[2])
fixture_windows_per_app = int(sys.argv[3])
case_paths = sys.argv[4:]
cases = []
for path in case_paths:
    with open(path, "r", encoding="utf-8") as file:
        cases.append(json.load(file))
 
print(json.dumps({
    "status": "passed",
    "script": "round1-window-index-progressive-filter-fixture-qa.sh",
    "app": app,
    "fixture": {
        "appCount": fixture_app_count,
        "windowsPerApp": fixture_windows_per_app
    },
    "cases": cases,
    "timeoutCleanup": {
        "status": "skipped",
        "reason": "Current --round01-debug-key-sequence has no stable wait token for the 0.9s expiry path; no sleep injection was added."
    }
}, indent=2, ensure_ascii=False))
PY
}
 
if [ ! -x "$APP/Contents/MacOS/Aligner" ]; then
  fail "current build app executable not found at $APP/Contents/MacOS/Aligner"
fi
if [ "$FIXTURE_APP_COUNT" -le "$TARGET_APP_INDEX" ]; then
  fail "fixture app count must include target App index $TARGET_APP_INDEX"
fi
if [ "$FIXTURE_WINDOWS_PER_APP" -le "$TARGET_WINDOW_INDEX" ]; then
  fail "fixture windows per App must include target window index $TARGET_WINDOW_INDEX"
fi
 
mkdir -p "$SUMMARY_DIR"
rm -f "$SUMMARY_DIR"/*.json
 
stop_current_aligner
"$SCRIPT_DIR/package-app.sh" >&2
preserve_user_theme
trap cleanup EXIT
stop_current_aligner
 
run_fixture "$REPORT_SINGLE_WINDOW" "light" "horizontal" "$(pending_key_sequence)" 1
wait_for_single_window_report "$REPORT_SINGLE_WINDOW" "$(mode_report_value horizontal)" "$(single_window_expected_sequence)"
assert_single_window_report "$REPORT_SINGLE_WINDOW"
finish_case
 
run_fixture "$REPORT_HORIZONTAL_LIGHT" "light" "horizontal" "$(pending_key_sequence)"
wait_for_pending_report "$REPORT_HORIZONTAL_LIGHT" "$(mode_report_value horizontal)" "$(pending_expected_sequence)" "pending-horizontal-light"
assert_pending_report "$REPORT_HORIZONTAL_LIGHT" "pending-horizontal-light" "light" "$(mode_report_value horizontal)"
finish_case
 
run_fixture "$REPORT_VERTICAL_LIGHT" "light" "vertical" "$(pending_key_sequence)"
wait_for_pending_report "$REPORT_VERTICAL_LIGHT" "$(mode_report_value vertical)" "$(pending_expected_sequence)" "pending-vertical-light"
assert_pending_report "$REPORT_VERTICAL_LIGHT" "pending-vertical-light" "light" "$(mode_report_value vertical)"
finish_case
 
run_fixture "$REPORT_HORIZONTAL_DARK" "dark" "horizontal" "$(pending_key_sequence)"
wait_for_pending_report "$REPORT_HORIZONTAL_DARK" "$(mode_report_value horizontal)" "$(pending_expected_sequence)" "pending-horizontal-dark"
assert_pending_report "$REPORT_HORIZONTAL_DARK" "pending-horizontal-dark" "dark" "$(mode_report_value horizontal)"
assert_pending_summaries_consistent \
  "$SUMMARY_DIR/pending-horizontal-light.json" \
  "$SUMMARY_DIR/pending-horizontal-dark.json" \
  "pending-horizontal-dark"
finish_case
 
run_fixture "$REPORT_COMMIT" "light" "horizontal" "$(commit_key_sequence)"
wait_for_commit_report "$REPORT_COMMIT" "$(mode_report_value horizontal)" "$(commit_expected_sequence)"
assert_commit_report "$REPORT_COMMIT"
finish_case
 
run_fixture "$REPORT_INVALID" "light" "horizontal" "$(invalid_key_sequence)"
wait_for_invalid_report "$REPORT_INVALID" "$(mode_report_value horizontal)" "$(invalid_expected_sequence)"
assert_invalid_report "$REPORT_INVALID"
finish_case
 
cleanup
trap - EXIT
emit_summary