Repository navigation
Expand file tree
/
Copy pathtest-ios-device-scripts.sh
More file actions
executable file
·359 lines (303 loc) · 11.9 KB
/
Copy pathtest-ios-device-scripts.sh
File metadata and controls
executable file
·359 lines (303 loc) · 11.9 KB
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
#!/usr/bin/env bash
set -euo pipefail
repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
# Keep developer signing defaults out of checks that intentionally omit them.
export LOGSEQ_IOS_CONFIG=/tmp/logseq-device-script-check-no-config
export LOGSEQ_IOS_BUNDLE_ID=com.logseq.logseq.script-check
unset LOGSEQ_IOS_ALLOW_PRODUCTION_REPLACE LOGSEQ_IOS_PROFILE LOGSEQ_IOS_BUILD_CONFIGURATION
failures=0
python3 "$repo_root/scripts/test-ios-simulator-build-arguments.py"
python3 "$repo_root/scripts/test-ios-native-link-manifest.py"
python3 "$repo_root/scripts/test-ios-launch-screen.py"
python3 - "$repo_root/apple" <<'PYTHON'
import json
import os
import subprocess
import sys
for enabled in ("0", "1"):
manifest = json.loads(subprocess.check_output(
["swift", "package", "--package-path", sys.argv[1], "dump-package"],
env=dict(os.environ, LOGSEQ_ENABLE_SENTRY=enabled),
))
packages = {package["identity"] for dependency in manifest["dependencies"]
for package in dependency.get("sourceControl", [])}
assert ("sentry-cocoa" in packages) == (enabled == "1"), f"Unexpected Sentry dependency in mode {enabled}"
print("ok - SwiftPM only resolves Sentry for opted-in builds")
PYTHON
if ! grep -Fq 'scripts/build-mobile-ocaml.sh' \
"$repo_root/scripts/build-mobile-ios-device.sh"; then
echo "not ok - device build does not delegate OCaml compilation to Dune" >&2
failures=$((failures + 1))
fi
if ! grep -q 'LOGSEQ_IOS_KEYCHAIN' \
"$repo_root/scripts/build-mobile-ios-device.sh"; then
echo "not ok - device build cannot select an isolated signing keychain" >&2
failures=$((failures + 1))
fi
if ! grep -q 'restore_keychain_search_list' \
"$repo_root/scripts/build-mobile-ios-device.sh"; then
echo "not ok - device build does not restore the signing keychain search list" >&2
failures=$((failures + 1))
fi
if ! grep -q 'security list-keychains -d user -s' \
"$repo_root/scripts/build-mobile-ios-device.sh"; then
echo "not ok - device build does not add its signing keychain to the search list" >&2
failures=$((failures + 1))
fi
if ! grep -q 'NSAllowsLocalNetworking' \
"$repo_root/scripts/configure-ios-info-plist.sh"; then
echo "not ok - iOS app does not allow an explicitly configured local API" >&2
failures=$((failures + 1))
fi
if ! grep -q 'NSLocalNetworkUsageDescription' \
"$repo_root/scripts/configure-ios-info-plist.sh"; then
echo "not ok - iOS app does not explain local network access" >&2
failures=$((failures + 1))
fi
ios_e2e_script="$repo_root/scripts/test-ios-e2e.sh"
ios_e2e_suite_script="$repo_root/scripts/test-ios-e2e-suite.sh"
simulator_build_script="$repo_root/scripts/build-mobile-ios-simulator.sh"
if ! grep -q 'swift_scratch_dir=' "$simulator_build_script"; then
echo "not ok - simulator build does not define its Swift scratch directory" >&2
failures=$((failures + 1))
fi
for build_script in "$repo_root/scripts/build-mobile-ios-device.sh" "$simulator_build_script"; do
if ! grep -q 'prune_stale_swift_resource_bundles' "$build_script"; then
echo "not ok - iOS build does not prune stale SwiftPM resource bundles: $build_script" >&2
failures=$((failures + 1))
fi
done
for extension in LogseqShareExtension LogseqWidgets; do
if ! grep -Fq "$extension.appex" "$simulator_build_script"; then
echo "not ok - simulator build does not embed $extension" >&2
failures=$((failures + 1))
fi
done
if ! grep -Fq 'PlugIns' "$simulator_build_script"; then
echo "not ok - simulator build does not create the app extension directory" >&2
failures=$((failures + 1))
fi
if ! grep -Fq \
'base_url=${LOGSEQ_E2E_BASE_URL:-http://127.0.0.1:8787}' \
"$ios_e2e_script"; then
echo "not ok - iOS Simulator E2E does not default to the local API" >&2
failures=$((failures + 1))
fi
if grep -Fq 'api-staging.logseq.io' "$ios_e2e_script"; then
echo "not ok - iOS Simulator E2E embeds the staging API" >&2
failures=$((failures + 1))
fi
for required_flow in \
'tests/e2e/ios-outliner-editor-toolbar.yaml' \
'tests/e2e/ios-outliner-continuous-editing.yaml' \
'tests/e2e/ios-outliner-selection-toolbar.yaml' \
'tests/e2e/ios-outliner-hierarchy-navigation.yaml' \
'tests/e2e/ios-graphs-lifecycle.yaml'; do
if ! grep -Fq "$required_flow" "$ios_e2e_suite_script"; then
echo "error: iOS E2E suite is missing $required_flow" >&2
exit 1
fi
done
for marker in \
'tests/e2e/ios-local-graph-setup.yaml' \
'__LOGSEQ_E2E_SETUP_FLOW__' \
'sync.checkpoint' \
'waiting for the graph snapshot import to finish'; do
if ! grep -Fq "$marker" "$ios_e2e_script"; then
echo "not ok - iOS Simulator E2E omits local graph setup: $marker" >&2
failures=$((failures + 1))
fi
done
device_build_script="$repo_root/scripts/build-mobile-ios-device.sh"
if grep -q 'rm -f "$swift_build_dir/LogseqShell"' "$device_build_script"; then
echo "not ok - device build unconditionally discards the incremental Swift link" >&2
failures=$((failures + 1))
fi
for marker in \
'publish-ios-native-link-inputs.py' \
'swift_scratch_dir=${LOGSEQ_IOS_SWIFT_SCRATCH_PATH:-$repo_root/apple/.build}' \
'--scratch-path "$swift_scratch_dir"'; do
if ! grep -Fq -- "$marker" "$device_build_script"; then
echo "not ok - device build is missing: $marker" >&2
failures=$((failures + 1))
fi
done
check_rejects() {
local name=$1
local expected=$2
shift 2
set +e
local output
output=$("$@" 2>&1)
local status=$?
set -e
if [[ $status -eq 0 ]]; then
echo "not ok - $name: command succeeded" >&2
failures=$((failures + 1))
return
fi
if [[ $output != *"$expected"* ]]; then
echo "not ok - $name: expected '$expected'" >&2
echo "$output" >&2
failures=$((failures + 1))
return
fi
echo "ok - $name"
}
check_succeeds() {
local name=$1
local expected=$2
shift 2
set +e
local output
output=$("$@" 2>&1)
local status=$?
set -e
if [[ $status -ne 0 ]]; then
echo "not ok - $name: command failed" >&2
echo "$output" >&2
failures=$((failures + 1))
return
fi
if [[ $output != *"$expected"* ]]; then
echo "not ok - $name: expected '$expected'" >&2
echo "$output" >&2
failures=$((failures + 1))
return
fi
echo "ok - $name"
}
check_succeeds \
"device build defaults to optimized release configuration" \
"configuration=release swift-build-dir=$repo_root/apple/.build/arm64-apple-ios/release" \
env LOGSEQ_IOS_BUNDLE_ID=com.logseq.logseq \
LOGSEQ_IOS_PRINT_BUILD_SETTINGS=1 \
"$repo_root/scripts/build-mobile-ios-device.sh"
check_rejects \
"device install refuses production Logseq bundle id" \
"refusing to install over the production Logseq bundle id" \
env LOGSEQ_IOS_BUNDLE_ID=com.logseq.logseq \
"$repo_root/scripts/install-mobile-ios-device.sh"
check_rejects \
"device build requires a provisioning profile" \
"set LOGSEQ_IOS_PROFILE to a development provisioning profile for com.logseq.logseq" \
env -u LOGSEQ_IOS_PROFILE \
LOGSEQ_IOS_CONFIG=/tmp/logseq-missing-device-config \
"$repo_root/scripts/build-mobile-ios-device.sh"
fake_device_config=$(mktemp /tmp/logseq-ios-device-config.XXXXXX)
cat >"$fake_device_config" <<'CONFIG'
LOGSEQ_IOS_PROFILE=/tmp/logseq-development.mobileprovision
LOGSEQ_IOS_SIGNING_IDENTITY="Apple Development: Tiansheng Qin (T6PA4U4765)"
CONFIG
check_succeeds \
"device build remembers local signing defaults" \
"profile=/tmp/logseq-development.mobileprovision signing-identity=Apple Development: Tiansheng Qin (T6PA4U4765)" \
env -u LOGSEQ_IOS_PROFILE \
-u LOGSEQ_IOS_SIGNING_IDENTITY \
LOGSEQ_IOS_CONFIG="$fake_device_config" \
LOGSEQ_IOS_PRINT_BUILD_SETTINGS=1 \
"$repo_root/scripts/build-mobile-ios-device.sh"
check_succeeds \
"device build selects release configuration" \
"configuration=release swift-build-dir=$repo_root/apple/.build/arm64-apple-ios/release" \
env LOGSEQ_IOS_BUILD_CONFIGURATION=release \
LOGSEQ_IOS_PRINT_BUILD_SETTINGS=1 \
"$repo_root/scripts/build-mobile-ios-device.sh"
check_succeeds \
"device build keeps debug configuration available" \
"configuration=debug swift-build-dir=$repo_root/apple/.build/arm64-apple-ios/debug" \
env LOGSEQ_IOS_BUILD_CONFIGURATION=debug \
LOGSEQ_IOS_PRINT_BUILD_SETTINGS=1 \
"$repo_root/scripts/build-mobile-ios-device.sh"
check_rejects \
"device build rejects unsupported configuration" \
"unsupported iOS build configuration: profile" \
env LOGSEQ_IOS_BUILD_CONFIGURATION=profile \
LOGSEQ_IOS_PRINT_BUILD_SETTINGS=1 \
"$repo_root/scripts/build-mobile-ios-device.sh"
check_rejects \
"device install requires a provisioning profile" \
"set LOGSEQ_IOS_PROFILE to a development provisioning profile for com.logseq.logseq" \
env -u LOGSEQ_IOS_PROFILE \
LOGSEQ_IOS_CONFIG=/tmp/logseq-missing-device-config \
"$repo_root/scripts/install-mobile-ios-device.sh"
fake_profile=$(mktemp /tmp/logseq-fake-mobileprovision.XXXXXX)
fake_bin=$(mktemp -d /tmp/logseq-fake-bin.XXXXXX)
cat >"$fake_bin/xcrun" <<'SH'
#!/usr/bin/env bash
if [[ "$*" == "devicectl list devices" ]]; then
device_state=${FAKE_DEVICE_STATE:-unavailable}
cat <<'DEVICES'
Name Hostname Identifier State Model
--------- -------------------------------- ------------------------------------ ------------------ ---------------------------
DEVICES
printf 'iPhone iPhone.coredevice.local ACC1F5DA-71E4-560F-9818-FC6B1517D6A0 %s iPhone 15 (iPhone15,4)\n' "$device_state"
exit 0
fi
echo "unexpected xcrun invocation: $*" >&2
exit 42
SH
chmod +x "$fake_bin/xcrun"
check_rejects \
"device install reports unavailable target before build" \
"target iOS device 'iPhone' is unavailable" \
env PATH="$fake_bin:$PATH" \
LOGSEQ_IOS_PROFILE="$fake_profile" \
LOGSEQ_IOS_DEVICE=iPhone \
"$repo_root/scripts/install-mobile-ios-device.sh"
check_rejects \
"device install accepts connected target" \
"unexpected xcrun invocation: --sdk iphoneos --show-sdk-path" \
env PATH="$fake_bin:$PATH" \
FAKE_DEVICE_STATE=connected \
LOGSEQ_IOS_PROFILE="$fake_profile" \
LOGSEQ_IOS_DEVICE=iPhone \
"$repo_root/scripts/install-mobile-ios-device.sh"
check_rejects \
"device install accepts available target" \
"unexpected xcrun invocation: --sdk iphoneos --show-sdk-path" \
env PATH="$fake_bin:$PATH" \
FAKE_DEVICE_STATE=available \
LOGSEQ_IOS_PROFILE="$fake_profile" \
LOGSEQ_IOS_DEVICE=iPhone \
"$repo_root/scripts/install-mobile-ios-device.sh"
check_rejects \
"profile creation refuses production Logseq bundle id" \
"refusing to create a profile for the production Logseq bundle id" \
env LOGSEQ_IOS_BUNDLE_ID=com.logseq.logseq \
"$repo_root/scripts/create-mobile-ios-profile.sh"
check_rejects \
"profile creation requires API key id" \
"set APP_STORE_CONNECT_API_KEY_ID" \
env -u APP_STORE_CONNECT_API_KEY_ID \
"$repo_root/scripts/create-mobile-ios-profile.sh"
check_rejects \
"profile creation requires API issuer id" \
"set APP_STORE_CONNECT_ISSUER_ID" \
env -u APP_STORE_CONNECT_ISSUER_ID \
APP_STORE_CONNECT_API_KEY_ID=fake-key-id \
"$repo_root/scripts/create-mobile-ios-profile.sh"
check_rejects \
"profile creation requires API private key file" \
"App Store Connect API key file was not found" \
env APP_STORE_CONNECT_API_KEY_PATH=/tmp/logseq-missing-auth-key.p8 \
APP_STORE_CONNECT_API_KEY_ID=fake-key-id \
APP_STORE_CONNECT_ISSUER_ID=fake-issuer-id \
"$repo_root/scripts/create-mobile-ios-profile.sh"
fake_key=$(mktemp /tmp/logseq-fake-auth-key.XXXXXX)
cat >"$fake_key" <<'KEY'
-----BEGIN PRIVATE KEY-----
fake
-----END PRIVATE KEY-----
KEY
check_succeeds \
"profile creation dry run ensures bundle id before profile" \
"Would ensure bundle id com.logseq.logseq.script-check" \
env LOGSEQ_IOS_DRY_RUN=1 \
APP_STORE_CONNECT_API_KEY_ID=fake-key-id \
APP_STORE_CONNECT_ISSUER_ID=fake-issuer-id \
APP_STORE_CONNECT_API_KEY_PATH="$fake_key" \
"$repo_root/scripts/create-mobile-ios-profile.sh"
if [[ $failures -ne 0 ]]; then
exit 1
fi