Ariver
2026-06-06 5c054407508d90811f2498522d4511c520b10c4c
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
#!/bin/bash
# Round01 performance gate. Runs the interactive-cost PoC metrics and the
# 100-cycle overlay lifecycle leak check as one QA entry point.
 
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"
POC_REPORT="$BUILD_REPORT_ROOT/round01-performance-poc-report.json"
LIFECYCLE_REPORT="$BUILD_REPORT_ROOT/round01-performance-lifecycle-report.json"
LIFECYCLE_CYCLES="${ALIGNER_ROUND1_POC_LIFECYCLE_CYCLES:-100}"
LIFECYCLE_INTERVAL="${ALIGNER_ROUND1_POC_LIFECYCLE_INTERVAL:-0.01}"
LIFECYCLE_VISIBLE_DURATION="${ALIGNER_ROUND1_POC_LIFECYCLE_VISIBLE_DURATION:-0.24}"
 
validate_positive_integer() {
  local name="$1"
  local value="$2"
  if ! [[ "$value" =~ ^[1-9][0-9]*$ ]]; then
    echo "$name must be a positive integer, got: $value" >&2
    exit 1
  fi
}
 
validate_nonnegative_number() {
  local name="$1"
  local value="$2"
  if ! /usr/bin/python3 - "$name" "$value" <<'PY'
import sys
 
name, value = sys.argv[1:3]
try:
    parsed = float(value)
except ValueError:
    print(f"{name} must be a non-negative number, got: {value}", file=sys.stderr)
    sys.exit(1)
 
if parsed < 0:
    print(f"{name} must be a non-negative number, got: {value}", file=sys.stderr)
    sys.exit(1)
PY
  then
    exit 1
  fi
}
 
validate_positive_integer "ALIGNER_ROUND1_POC_LIFECYCLE_CYCLES" "$LIFECYCLE_CYCLES"
validate_nonnegative_number "ALIGNER_ROUND1_POC_LIFECYCLE_INTERVAL" "$LIFECYCLE_INTERVAL"
validate_nonnegative_number "ALIGNER_ROUND1_POC_LIFECYCLE_VISIBLE_DURATION" "$LIFECYCLE_VISIBLE_DURATION"
 
require_json_value() {
  local report="$1"
  local key="$2"
  local expected="$3"
  if ! /usr/bin/python3 - "$report" "$key" "$expected" <<'PY'
import json
import sys
 
path, key, expected = sys.argv[1:4]
with open(path, "r", encoding="utf-8") as handle:
    data = json.load(handle)
 
actual = data.get(key)
if expected == "true":
    ok = actual is True
elif expected == "false":
    ok = actual is False
else:
    ok = str(actual) == expected
 
if not ok:
    print(f"{path}: {key}: expected {expected}, got {actual}", file=sys.stderr)
    sys.exit(1)
PY
  then
    exit 1
  fi
}
 
require_json_number_at_most() {
  local report="$1"
  local key="$2"
  local maximum="$3"
  if ! /usr/bin/python3 - "$report" "$key" "$maximum" <<'PY'
import json
import sys
 
path, key, maximum = sys.argv[1:4]
with open(path, "r", encoding="utf-8") as handle:
    data = json.load(handle)
 
actual = data.get(key)
if actual is None or float(actual) > float(maximum):
    print(f"{path}: {key}: expected <= {maximum}, got {actual}", file=sys.stderr)
    sys.exit(1)
PY
  then
    exit 1
  fi
}
 
"$SCRIPT_DIR/round1-performance-poc.sh" >&2
 
cd "$SOURCE_ROOT"
swift build >&2
"$SCRIPT_DIR/package-app.sh" >&2
 
rm -f "$LIFECYCLE_REPORT"
 
"$APP/Contents/MacOS/Aligner" \
  --round0-skip-permissions \
  --round01-performance-poc \
  --round01-poc-lifecycle-cycles="$LIFECYCLE_CYCLES" \
  --round01-poc-lifecycle-interval="$LIFECYCLE_INTERVAL" \
  --round01-poc-lifecycle-visible-duration="$LIFECYCLE_VISIBLE_DURATION" \
  --round01-poc-report="$LIFECYCLE_REPORT"
 
if [[ ! -f "$LIFECYCLE_REPORT" ]]; then
  echo "Round01 performance lifecycle report was not created: $LIFECYCLE_REPORT" >&2
  exit 1
fi
 
require_json_value "$LIFECYCLE_REPORT" lifecycleTargetCycles "$LIFECYCLE_CYCLES"
require_json_value "$LIFECYCLE_REPORT" lifecycleCompletedCycles "$LIFECYCLE_CYCLES"
require_json_value "$LIFECYCLE_REPORT" lifecycleGatePassed true
require_json_value "$LIFECYCLE_REPORT" firstFrameLatencySampleCount "$LIFECYCLE_CYCLES"
require_json_number_at_most "$LIFECYCLE_REPORT" firstFrameLatencyP95Milliseconds 150
require_json_number_at_most "$LIFECYCLE_REPORT" lifecycleMaximumOverlayWindows 1
require_json_value "$LIFECYCLE_REPORT" lifecycleResidualVisibleOverlayWindows 0
require_json_number_at_most "$LIFECYCLE_REPORT" lifecycleResidualOverlayWindows 1
require_json_number_at_most "$LIFECYCLE_REPORT" lifecycleMaximumVisibleOverlayWindows 1
require_json_value "$LIFECYCLE_REPORT" overlayVisible false
require_json_value "$LIFECYCLE_REPORT" visibleOverlayWindowCount 0
require_json_number_at_most "$LIFECYCLE_REPORT" overlayWindowCount 1
require_json_value "$LIFECYCLE_REPORT" cardLayerCount 200
require_json_value "$LIFECYCLE_REPORT" appLayerCount 20
require_json_value "$LIFECYCLE_REPORT" thumbnailLayerCount 200
require_json_value "$LIFECYCLE_REPORT" simulatedScreenshotRefillCount 200
 
cat <<EOF
{
  "pocReport": "$POC_REPORT",
  "lifecycleReport": "$LIFECYCLE_REPORT",
  "lifecycleCycles": $LIFECYCLE_CYCLES
}
EOF