Skip to content

Commit 034bf6b

Browse files
committed
Speed up the video workflow: boot the simulator in the background, a cached XcodeGen, stream-copied cuts, shorter tours; count only visible text as drawn; check the shell offers no browser notifications
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012xYtaUjbkB1hwLtK4TEzhq
1 parent ce01f9c commit 034bf6b

8 files changed

Lines changed: 157 additions & 44 deletions

File tree

‎.github/workflows/ios-shell-video.yml‎

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,37 @@ jobs:
5757
- name: Start the clock
5858
run: echo "$(date +%s) start" > "$RUNNER_TEMP/timing"
5959

60-
- name: Generate the Xcode project and boot a simulator
60+
- name: Boot a simulator in the background
6161
run: |
62-
echo "$(date +%s) project-and-simulator" >> "$RUNNER_TEMP/timing"
63-
HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install xcodegen
64-
(cd ios-shell && xcodegen generate)
6562
picked="$(python3 ios-shell/ci/pick_simulator.py)"
6663
udid="$(printf '%s' "$picked" | cut -f1)"
6764
echo "SIM_UDID=$udid" >> "$GITHUB_ENV"
6865
defaults write com.apple.iphonesimulator ConnectHardwareKeyboard -bool false
69-
xcrun simctl boot "$udid" || true
70-
xcrun simctl bootstatus "$udid" -b
71-
xcrun simctl spawn "$udid" defaults write com.apple.Preferences DidShowContinuousPathIntroduction -bool true || true
72-
xcrun simctl spawn "$udid" defaults write com.apple.keyboard.preferences DidShowContinuousPathIntroduction -bool true || true
66+
# Booting takes minutes on a fresh runner: it runs while the rest of the job does.
67+
nohup bash -c 'xcrun simctl boot "$1" || true; xcrun simctl bootstatus "$1" -b \
68+
&& xcrun simctl spawn "$1" defaults write com.apple.Preferences DidShowContinuousPathIntroduction -bool true; \
69+
xcrun simctl spawn "$1" defaults write com.apple.keyboard.preferences DidShowContinuousPathIntroduction -bool true; \
70+
touch "$2"' boot "$udid" "$RUNNER_TEMP/simulator.ready" > "$RUNNER_TEMP/boot.log" 2>&1 &
71+
72+
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
73+
with:
74+
path: ~/xcodegen-dist
75+
key: ios-shell-video-xcodegen-v1
76+
77+
- name: Generate the Xcode project
78+
run: |
79+
echo "$(date +%s) project" >> "$RUNNER_TEMP/timing"
80+
if [ ! -x ~/xcodegen-dist/xcodegen/bin/xcodegen ]; then
81+
mkdir -p ~/xcodegen-dist
82+
curl -fsSL -o "$RUNNER_TEMP/xcodegen.zip" https://github.com/yonaskolb/XcodeGen/releases/latest/download/xcodegen.zip \
83+
&& unzip -q -o "$RUNNER_TEMP/xcodegen.zip" -d ~/xcodegen-dist || true
84+
fi
85+
if [ -x ~/xcodegen-dist/xcodegen/bin/xcodegen ]; then
86+
(cd ios-shell && ~/xcodegen-dist/xcodegen/bin/xcodegen generate)
87+
else
88+
HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install xcodegen
89+
(cd ios-shell && xcodegen generate)
90+
fi
7391
7492
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
7593
with:
@@ -130,6 +148,8 @@ jobs:
130148
env:
131149
TEST_RUNNER_OPENBOT_SHELL_VIDEO_MODE: "1"
132150
run: |
151+
for _ in $(seq 1 300); do [ -f "$RUNNER_TEMP/simulator.ready" ] && break; sleep 1; done
152+
[ -f "$RUNNER_TEMP/simulator.ready" ] || { cat "$RUNNER_TEMP/boot.log"; exit 1; }
133153
echo "$(date +%s) record" >> "$RUNNER_TEMP/timing"
134154
started="$(python3 -c 'import time; print(time.time())')"
135155
echo "STARTED=$started" >> "$GITHUB_ENV"
@@ -190,19 +210,37 @@ jobs:
190210
- name: Start the clock
191211
run: echo "$(date +%s) start" > "$RUNNER_TEMP/timing"
192212

193-
- name: Generate the Xcode project and boot a simulator
213+
- name: Boot a simulator in the background
194214
run: |
195-
echo "$(date +%s) project-and-simulator" >> "$RUNNER_TEMP/timing"
196-
HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install xcodegen
197-
(cd ios-shell && xcodegen generate)
198215
picked="$(python3 ios-shell/ci/pick_simulator.py)"
199216
udid="$(printf '%s' "$picked" | cut -f1)"
200217
echo "SIM_UDID=$udid" >> "$GITHUB_ENV"
201218
defaults write com.apple.iphonesimulator ConnectHardwareKeyboard -bool false
202-
xcrun simctl boot "$udid" || true
203-
xcrun simctl bootstatus "$udid" -b
204-
xcrun simctl spawn "$udid" defaults write com.apple.Preferences DidShowContinuousPathIntroduction -bool true || true
205-
xcrun simctl spawn "$udid" defaults write com.apple.keyboard.preferences DidShowContinuousPathIntroduction -bool true || true
219+
# Booting takes minutes on a fresh runner: it runs while the rest of the job does.
220+
nohup bash -c 'xcrun simctl boot "$1" || true; xcrun simctl bootstatus "$1" -b \
221+
&& xcrun simctl spawn "$1" defaults write com.apple.Preferences DidShowContinuousPathIntroduction -bool true; \
222+
xcrun simctl spawn "$1" defaults write com.apple.keyboard.preferences DidShowContinuousPathIntroduction -bool true; \
223+
touch "$2"' boot "$udid" "$RUNNER_TEMP/simulator.ready" > "$RUNNER_TEMP/boot.log" 2>&1 &
224+
225+
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
226+
with:
227+
path: ~/xcodegen-dist
228+
key: ios-shell-video-xcodegen-v1
229+
230+
- name: Generate the Xcode project
231+
run: |
232+
echo "$(date +%s) project" >> "$RUNNER_TEMP/timing"
233+
if [ ! -x ~/xcodegen-dist/xcodegen/bin/xcodegen ]; then
234+
mkdir -p ~/xcodegen-dist
235+
curl -fsSL -o "$RUNNER_TEMP/xcodegen.zip" https://github.com/yonaskolb/XcodeGen/releases/latest/download/xcodegen.zip \
236+
&& unzip -q -o "$RUNNER_TEMP/xcodegen.zip" -d ~/xcodegen-dist || true
237+
fi
238+
if [ -x ~/xcodegen-dist/xcodegen/bin/xcodegen ]; then
239+
(cd ios-shell && ~/xcodegen-dist/xcodegen/bin/xcodegen generate)
240+
else
241+
HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_INSTALL_CLEANUP=1 brew install xcodegen
242+
(cd ios-shell && xcodegen generate)
243+
fi
206244
207245
- name: Decide the build
208246
env:
@@ -238,6 +276,8 @@ jobs:
238276
TEST_RUNNER_OPENBOT_SHELL_GOOGLE_TOTP_SECRET: ${{ secrets.OPENBOT_SHELL_GOOGLE_TOTP_SECRET }}
239277
REAL_SIGN_OUT: ${{ inputs.real_sign_out }}
240278
run: |
279+
for _ in $(seq 1 300); do [ -f "$RUNNER_TEMP/simulator.ready" ] && break; sleep 1; done
280+
[ -f "$RUNNER_TEMP/simulator.ready" ] || { cat "$RUNNER_TEMP/boot.log"; exit 1; }
241281
echo "$(date +%s) record" >> "$RUNNER_TEMP/timing"
242282
if [ "$REAL_SIGN_OUT" = "true" ]; then export TEST_RUNNER_OPENBOT_SHELL_REAL_SIGN_OUT=1; fi
243283
if [ "$CONFIGURATION" = "Release" ]; then

‎app/workbench/mock-server.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ function mockDataHandlers(): RequestHandler[] {
264264
},
265265
});
266266
}),
267+
// Push is set up here, as on a server that offers it: the phone app's tests check that the
268+
// page still offers no browser notifications inside the native shell.
269+
http.get(`${API}/notification-transports`, () =>
270+
HttpResponse.json({
271+
notificationTransports: [{ id: "push", title: "Push notifications" }],
272+
nextCursor: null,
273+
}),
274+
),
267275
http.get(`${API}/conversations/:conversationId/refused-turns`, () =>
268276
HttpResponse.json({ refusedTurns: [], nextCursor: null }),
269277
),

‎ios-shell/OpenBotShell/ShellController.swift‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ final class ShellController: NSObject, WebControllerDelegate {
198198
/// complete and the body has something in it, checking a few times.
199199
private func checkPageDrawn(attempt: Int = 0) {
200200
guard model.pageLoading else { return }
201-
// Drawn: the document is complete and at least three pieces of text are really on screen
202-
// (screen-reader-only text measures 1 px and does not count).
201+
// Drawn: the document is complete and at least three pieces of text are really on screen:
202+
// inside the viewport, not hidden, not faded out, more than 4 px (screen-reader-only text
203+
// measures 1 px).
203204
let script = """
204205
(function () {
205206
if (document.readyState !== 'complete' || !document.body) return false;
@@ -209,7 +210,16 @@ final class ShellController: NSObject, WebControllerDelegate {
209210
if (!node.textContent.trim()) continue;
210211
range.selectNodeContents(node);
211212
var r = range.getBoundingClientRect();
212-
if (r.width > 4 && r.height > 4 && r.bottom > 0 && r.top < innerHeight) seen++;
213+
if (!(r.width > 4 && r.height > 4 && r.bottom > 0 && r.top < innerHeight && r.right > 0 && r.left < innerWidth)) continue;
214+
// Not faded out (a page's intro animation starts at opacity 0) and not hidden.
215+
var el = node.parentElement, visible = true, opacity = 1;
216+
while (el && el !== document.documentElement) {
217+
var cs = getComputedStyle(el);
218+
if (cs.visibility === 'hidden' || cs.display === 'none') { visible = false; break; }
219+
opacity *= parseFloat(cs.opacity || '1');
220+
el = el.parentElement;
221+
}
222+
if (visible && opacity > 0.5) seen++;
213223
}
214224
return seen >= 3;
215225
})()

‎ios-shell/OpenBotShellUITests/DemoTourUITests.swift‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ final class DemoTourUITests: ShellTestCase {
3333
var app = launch(base: ShellTestCase.mockA, moment: "tour", ephemeral: false)
3434
let signIn = app.buttons["sign-in-button"]
3535
XCTAssertTrue(signIn.waitForExistence(timeout: 20))
36-
pause(1.5)
36+
pause(1)
3737
signIn.tap()
38+
// Whichever comes first: the consent alert (then the sheet), or the sheet.
3839
let consent = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts.buttons["Continue"]
39-
if consent.waitForExistence(timeout: 6) {
40-
pause(2)
40+
let link = app.webViews.links["Sign in as test person"]
41+
if let first = firstExisting([consent, link], timeout: 20), first == consent {
42+
pause(1.5)
4143
consent.tap()
4244
} else {
4345
note("demo: no consent alert this time")
4446
}
45-
let link = app.webViews.links["Sign in as test person"]
4647
if link.waitForExistence(timeout: 15) {
4748
pause(1.2)
4849
link.tap()
@@ -96,7 +97,7 @@ final class DemoTourUITests: ShellTestCase {
9697

9798
// The lock screen, then the connection comes back.
9899
app = launch(base: ShellTestCase.mockA, moment: "tour-offline", reset: false,
99-
extra: ["OPENBOT_SHELL_FORCE_OFFLINE_SECONDS": "6"])
100+
extra: ["OPENBOT_SHELL_FORCE_OFFLINE_SECONDS": "4"])
100101
XCTAssertTrue(lockScreen(app).waitForExistence(timeout: 8), "demo: no lock screen")
101102
XCTAssertTrue(lockScreen(app).waitForNonExistence(timeout: 15), "demo: the lock did not lift")
102103
pause(1.5)

‎ios-shell/OpenBotShellUITests/RealBackendUITests.swift‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class RealBackendTestCase: ShellTestCase {
2828
}
2929
}
3030

31+
/// A pause for a person to see a screen: short in the video workflow, as briefed in the tests.
32+
func hold(_ seconds: UInt32) {
33+
sleep(videoMode ? min(seconds, 2) : seconds)
34+
}
35+
3136
func secret(_ name: String) -> String? {
3237
let value = ProcessInfo.processInfo.environment[name] ?? ""
3338
return value.isEmpty ? nil : value
@@ -278,14 +283,14 @@ class RealBackendTestCase: ShellTestCase {
278283
XCTAssertTrue(tab(app, .home).waitForExistence(timeout: 30), "no tabs")
279284
let composer = app.webViews.textViews.firstMatch
280285
XCTAssertTrue(composer.waitForExistence(timeout: 30), "no message box on Home")
281-
sleep(3)
286+
hold(3)
282287
screenshot("j1-home")
283288

284289
// One real message, and the reply streaming in.
285290
composer.tap()
286291
_ = app.keyboards.firstMatch.waitForExistence(timeout: 8)
287292
composer.typeText(RealBackendTestCase.prompt)
288-
sleep(1)
293+
hold(1)
289294
screenshot("j2-message-typed")
290295
let before = Set(labels(in: app.webViews.firstMatch, limit: 400))
291296
if let send = firstExisting([webElement(app, label: "Send message")], timeout: 5) {
@@ -295,66 +300,66 @@ class RealBackendTestCase: ShellTestCase {
295300
}
296301
var lengths: [Int] = []
297302
let started = Date()
298-
while Date().timeIntervalSince(started) < 60 {
299-
sleep(3)
303+
while Date().timeIntervalSince(started) < (videoMode ? 30 : 60) {
304+
hold(videoMode ? 1 : 3)
300305
let now = labels(in: app.webViews.firstMatch, limit: 400)
301306
let fresh = now.filter { !before.contains($0) && !$0.contains(RealBackendTestCase.prompt) && $0.hasPrefix("StaticText") }
302307
lengths.append(fresh.map { $0.count }.max() ?? 0)
303308
if lengths.count == 2 { screenshot("j3-reply-streaming") }
304-
if lengths.count >= 4, lengths.suffix(3).allSatisfy({ $0 == lengths.last! }), (lengths.last ?? 0) > 0 { break }
309+
if lengths.count >= 3, lengths.suffix(2).allSatisfy({ $0 == lengths.last! }), (lengths.last ?? 0) > 0 { break }
305310
}
306311
let grew = zip(lengths, lengths.dropFirst()).contains { $0 < $1 && $0 > 0 }
307312
note("reply: longest new text by 3 s step \(lengths); grew while shown (streaming) \(grew); after \(Int(Date().timeIntervalSince(started))) s")
308-
sleep(3)
313+
hold(3)
309314
screenshot("j4-reply")
310315
dismissKeyboardIfUp(app, tapping: webText(app, RealBackendTestCase.prompt))
311316
XCTAssertTrue(tab(app, .bots).waitForExistence(timeout: 5), "the tab bar did not come back after the reply")
312317
note("after sending: \(debugState(app))")
313318

314319
// Bots, a Bot.
315320
tab(app, .bots).tap()
316-
sleep(5)
321+
hold(5)
317322
screenshot("j5-bots")
318323
if let bot = firstExisting([webText(app, "General Assistant")], timeout: 10) {
319324
bot.tap()
320-
sleep(5)
325+
hold(5)
321326
dismissKeyboardIfUp(app)
322327
screenshot("j6-a-bot")
323328
}
324329
note("bots: \(debugState(app))")
325330

326331
// Conversations: production has no /conversations yet.
327332
tab(app, .conversations).tap()
328-
sleep(6)
333+
hold(6)
329334
screenshot("j7-conversations-tab")
330335
note("conversations tab: \(debugState(app)); web app's sidebar button \(webElement(app, label: "Show sidebar").exists)")
331336
if webElement(app, label: "Show sidebar").exists {
332337
webElement(app, label: "Show sidebar").tap()
333-
sleep(2)
338+
hold(2)
334339
screenshot("j8-web-sidebar")
335340
if webElement(app, label: "Hide sidebar").exists { webElement(app, label: "Hide sidebar").tap() }
336-
sleep(1)
341+
hold(1)
337342
}
338343

339344
tab(app, .home).tap()
340-
sleep(2)
345+
hold(2)
341346
// Background for 40 s (6 s in the video), then back.
342347
XCUIDevice.shared.press(.home)
343348
sleep(videoMode ? 6 : 40)
344349
app.activate()
345-
sleep(3)
350+
hold(3)
346351
screenshot("j9-back-from-background")
347352
tab(app, .home).tap()
348353
XCTAssertTrue(app.webViews.textViews.firstMatch.waitForExistence(timeout: 20), "Home did not come back after the background")
349354
note("after background: \(debugState(app))")
350355

351356
// Killed and opened again: straight to the tabs.
352-
sleep(4)
357+
hold(4)
353358
app.terminate()
354359
app = relaunch()
355360
XCTAssertTrue(tab(app, .home).waitForExistence(timeout: 20), "a relaunch did not go straight to the tabs")
356361
XCTAssertFalse(app.buttons["sign-in-button"].exists)
357-
sleep(6)
362+
hold(6)
358363
screenshot("j10-relaunched")
359364

360365
guard signOut else {
@@ -365,7 +370,7 @@ class RealBackendTestCase: ShellTestCase {
365370
// the account button at the drawer's bottom, then Sign out. The app notices the URL on /sign.
366371
if webElement(app, label: "Show sidebar").waitForExistence(timeout: 5) {
367372
webElement(app, label: "Show sidebar").tap()
368-
sleep(2)
373+
hold(2)
369374
}
370375
// Production's account button is not exposed as a button: look at anything in the drawer's
371376
// bottom-left corner, and failing that tap where its avatar sits.
@@ -525,7 +530,7 @@ final class RealBackendDebugUITests: RealBackendTestCase {
525530
XCTFail("the session cookie did not reach the tabs; state \(debugState(app))")
526531
return
527532
}
528-
sleep(6)
533+
hold(6)
529534
if app.buttons["sign-in-button"].exists || webText(app, "Sign in to OpenBot Cloud").exists {
530535
screenshot("session-rejected")
531536
XCTFail("production rejected the session cookie (it may be stale or copied wrong)")

‎ios-shell/OpenBotShellUITests/ShellFlowUITests.swift‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,48 @@ final class ShellFlowUITests: ShellTestCase {
420420
note("after background: \(debugState(app))")
421421
}
422422

423+
// Inside the shell the page offers no browser notifications, even where the server has push:
424+
// not after the first message, and not in Settings, Notifications.
425+
func testNoBrowserNotificationOffersInTheShell() throws {
426+
let app = launchSignedIn()
427+
let composer = app.webViews.textViews.firstMatch
428+
XCTAssertTrue(composer.waitForExistence(timeout: 30))
429+
composer.tap()
430+
_ = app.keyboards.firstMatch.waitForExistence(timeout: 6)
431+
composer.typeText("Hello there")
432+
guard let send = firstExisting([webElement(app, label: "Send message")], timeout: 5) else {
433+
XCTFail("no Send button")
434+
return
435+
}
436+
send.tap()
437+
sleep(4)
438+
dismissKeyboardIfUp(app)
439+
screenshot("1-after-first-message")
440+
let offer = app.webViews.descendants(matching: .any)
441+
.matching(NSPredicate(format: "label CONTAINS[c] 'Enable notifications'")).firstMatch
442+
XCTAssertFalse(offer.exists, "the page offers browser notifications inside the shell")
443+
// Settings, Notifications, through the web app's Account menu.
444+
tab(app, .home).tap()
445+
let account = webElement(app, label: "Account")
446+
XCTAssertTrue(account.waitForExistence(timeout: 10))
447+
account.tap()
448+
guard let settings = firstExisting([webElement(app, label: "Settings")], timeout: 5) else {
449+
XCTFail("no Settings in the Account menu")
450+
return
451+
}
452+
settings.tap()
453+
guard let notifications = firstExisting([webText(app, "Notifications")], timeout: 10) else {
454+
XCTFail("no Notifications row in Settings")
455+
return
456+
}
457+
notifications.tap()
458+
sleep(3)
459+
screenshot("2-settings-notifications")
460+
let row = app.webViews.descendants(matching: .any)
461+
.matching(NSPredicate(format: "label CONTAINS[c] 'Notifications in this browser'")).firstMatch
462+
XCTAssertFalse(row.exists, "Settings offers notifications in this browser inside the shell")
463+
}
464+
423465
// The native skeleton while the first page loads (the first load is held back 3 s here).
424466
func testLoadingSkeleton() throws {
425467
var app = launchSignedIn(moment: "sign-in")

‎ios-shell/ci/trim_video.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ def run(cmd):
4444
shrink = [ffmpeg, "-loglevel", "error", "-y", "-i", tmp, "-vf", "scale=600:-2", "-c:v", "libx264", "-crf", "28",
4545
"-pix_fmt", "yuv420p", "-movflags", "+faststart", "-an", small]
4646
else:
47-
cut = ["xcrun", "swift", tool, video, tmp, f"{begin:.2f}", f"{length or 0:.2f}", "0"]
48-
shrink = ["xcrun", "swift", tool, tmp, small, "0", "0", "600"]
47+
# Compiled once (about 10 s) and run twice, rather than interpreted twice.
48+
binary = os.path.join(os.environ.get("RUNNER_TEMP", "/tmp"), "video_tool")
49+
if not os.path.exists(binary):
50+
subprocess.run(["xcrun", "swiftc", "-O", tool, "-o", binary], check=False)
51+
runner = [binary] if os.path.exists(binary) else ["xcrun", "swift", tool]
52+
cut = runner + [video, tmp, f"{begin:.2f}", f"{length or 0:.2f}", "0"]
53+
shrink = runner + [tmp, small, "0", "0", "600"]
4954
ok, error = run(cut)
5055
if ok and os.path.exists(tmp) and os.path.getsize(tmp) > 10000:
5156
ok2, error2 = run(shrink)

‎ios-shell/ci/video_tool.swift‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ guard args.count == 6, let start = Double(args[3]), let length = Double(args[4])
1313
let asset = AVURLAsset(url: URL(fileURLWithPath: args[1]))
1414
let output = URL(fileURLWithPath: args[2])
1515
try? FileManager.default.removeItem(at: output)
16-
guard let export = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetHighestQuality) else {
16+
// Cutting alone copies the stream (no re-encode); scaling needs one encode.
17+
let preset = width > 0 ? AVAssetExportPresetMediumQuality : AVAssetExportPresetPassthrough
18+
guard let export = AVAssetExportSession(asset: asset, presetName: preset) else {
1719
FileHandle.standardError.write("no export session\n".data(using: .utf8)!)
1820
exit(1)
1921
}

0 commit comments

Comments
 (0)