Ariver
2026-06-11 3d8d37306e39db5c8eb41fafd95a13112d573f62
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
#!/bin/bash
# Round01 minimized-window QA. It launches a temporary AppKit helper, lets that
# helper miniaturize its own window, then verifies the real snapshot sees it.
 
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"
REPORT="$BUILD_REPORT_ROOT/round01-minimized-window-qa-snapshot.json"
SAMPLE_TITLE="Aligner Round01 Minimized QA Sample"
HELPER_HOLD_SECONDS="${ALIGNER_ROUND1_MINIMIZED_HELPER_HOLD_SECONDS:-20.0}"
READY_ATTEMPTS="${ALIGNER_ROUND1_MINIMIZED_READY_ATTEMPTS:-16}"
READY_INTERVAL="${ALIGNER_ROUND1_MINIMIZED_READY_INTERVAL:-0.5}"
 
HELPER_PID=""
 
cleanup() {
  if [[ -n "$HELPER_PID" ]] && kill -0 "$HELPER_PID" 2>/dev/null; then
    kill "$HELPER_PID" 2>/dev/null || true
    wait "$HELPER_PID" 2>/dev/null || true
  fi
}
trap cleanup EXIT
 
cd "$SOURCE_ROOT"
swift build >&2
"$SCRIPT_DIR/package-app.sh" >&2
 
swift "$SCRIPT_DIR/round1-minimized-window-helper.swift" "$HELPER_HOLD_SECONDS" &
HELPER_PID=$!
 
snapshot() {
  "$APP/Contents/MacOS/Aligner" \
    --round0-skip-permissions \
    --round01-dump-window-snapshot \
    --round01-dump-window-snapshot-pretty > "$REPORT"
}
 
snapshot_has_minimized_sample() {
  /usr/bin/python3 - "$REPORT" "$SAMPLE_TITLE" <<'PY'
import json
import sys
 
report_path, sample_title = sys.argv[1:3]
def stable_fingerprint(value):
    hash_value = 0xCBF29CE484222325
    for byte in (value or "").encode("utf-8"):
        hash_value ^= byte
        hash_value = (hash_value * 0x100000001B3) & 0xFFFFFFFFFFFFFFFF
    return f"{hash_value:016x}"
 
sample_title_hash = stable_fingerprint(sample_title)
try:
    with open(report_path, "r", encoding="utf-8") as handle:
        data = json.load(handle)
except Exception:
    sys.exit(1)
 
windows = data.get("windows", [])
sample = [
    window for window in windows
    if window.get("titleHash") == sample_title_hash
    and window.get("isMinimized") is True
]
sys.exit(0 if sample else 1)
PY
}
 
for _ in $(seq 1 "$READY_ATTEMPTS"); do
  snapshot
  if snapshot_has_minimized_sample; then
    break
  fi
  sleep "$READY_INTERVAL"
done
 
/usr/bin/python3 - "$REPORT" "$SAMPLE_TITLE" <<'PY'
import json
import sys
 
report_path, sample_title = sys.argv[1:3]
def stable_fingerprint(value):
    hash_value = 0xCBF29CE484222325
    for byte in (value or "").encode("utf-8"):
        hash_value ^= byte
        hash_value = (hash_value * 0x100000001B3) & 0xFFFFFFFFFFFFFFFF
    return f"{hash_value:016x}"
 
sample_title_hash = stable_fingerprint(sample_title)
with open(report_path, "r", encoding="utf-8") as handle:
    data = json.load(handle)
 
windows = data.get("windows", [])
minimized = [window for window in windows if window.get("isMinimized") is True]
sample_minimized = [
    window for window in minimized
    if window.get("titleHash") == sample_title_hash
]
sample_synthetic = [
    window for window in sample_minimized
    if window.get("identifierSource") == "syntheticAX"
    and window.get("isSyntheticWindowID") is True
]
sample_cg = [
    window for window in sample_minimized
    if window.get("identifierSource") == "cgWindow"
    and window.get("isSyntheticWindowID") is False
]
synthetic = [
    window for window in minimized
    if window.get("identifierSource") == "syntheticAX"
    or window.get("isSyntheticWindowID") is True
]
missing_identifier_source = [window.get("id") for window in windows if "identifierSource" not in window]
 
if missing_identifier_source:
    print(f"Missing identifierSource on windows: {missing_identifier_source}", file=sys.stderr)
    sys.exit(1)
 
if not sample_minimized:
    print(
        f"Expected minimized helper window '{sample_title}' in snapshot; "
        f"minimizedWindowCount={len(minimized)}",
        file=sys.stderr,
    )
    sys.exit(1)
 
if not sample_synthetic and not sample_cg:
    print(
        f"Expected minimized helper window '{sample_title}' to use cgWindow or syntheticAX; "
        f"sampleMinimized={sample_minimized}",
        file=sys.stderr,
    )
    sys.exit(1)
 
summary = {
    "windowCount": len(windows),
    "minimizedWindowCount": len(minimized),
    "sampleMinimizedCount": len(sample_minimized),
    "syntheticAXCount": len(synthetic),
    "sampleWindows": [
        {
            "id": window.get("id"),
            "titleHash": window.get("titleHash"),
            "titleLength": window.get("titleLength"),
            "identifierSource": window.get("identifierSource"),
            "isSyntheticWindowID": window.get("isSyntheticWindowID"),
        }
        for window in sample_minimized
    ],
}
print(json.dumps(summary, ensure_ascii=False, indent=2, sort_keys=True))
PY