Skip to content

Commit 5af9438

Browse files
committed
Add a native sign-in screen, the sign-in hand-off, a native tab bar and an offline lock to the iOS shell, with UI tests against mock stacks and my.open.bot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012xYtaUjbkB1hwLtK4TEzhq
1 parent b21ea5a commit 5af9438

24 files changed

Lines changed: 2727 additions & 188 deletions

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

Lines changed: 106 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
name: iOS shell
22

3-
# Builds the experimental iOS web view shell in ios-shell/ for the simulator and runs its UI tests:
4-
# against the local probe site (ios-shell/Probe) and against the hosted web app at my.open.bot.
5-
# Uploads screenshots, the app's diagnostics log and a SUMMARY.md. Simulator only: no signing,
6-
# no secrets.
3+
# Builds the experimental iOS shell in ios-shell/ for the simulator and runs its UI tests: against
4+
# the local probe site (ios-shell/Probe), against two mock stacks of the real built web app
5+
# (app/workbench/mock-server.ts), and against the hosted web app at my.open.bot.
6+
#
7+
# Artifacts: ios-shell-<run id> (everything that is not a real account's), ios-shell-shots-<run id>
8+
# (downscaled screenshots, SUMMARY.md, diagnostics.jsonl) and, only when a test used a real account,
9+
# ios-shell-private-<run id>. Simulator only: no signing.
10+
#
11+
# Optional repository secrets for the tests against a real account (skipped when empty):
12+
# OPENBOT_SHELL_TEST_SESSION, OPENBOT_SHELL_GOOGLE_EMAIL, OPENBOT_SHELL_GOOGLE_PASSWORD,
13+
# OPENBOT_SHELL_GOOGLE_TOTP_SECRET.
714
on:
815
push:
916
branches:
@@ -12,6 +19,8 @@ on:
1219
paths:
1320
- ios-shell/**
1421
- .github/workflows/ios-shell.yml
22+
- app/src/lib/native-shell/**
23+
- app/workbench/mock-server.ts
1524
workflow_dispatch:
1625

1726
permissions: {}
@@ -25,7 +34,7 @@ jobs:
2534
name: Build and test on the iOS simulator
2635
if: github.repository == 'CopilotKit/OpenBot'
2736
runs-on: macos-latest
28-
timeout-minutes: 60
37+
timeout-minutes: 90
2938
permissions:
3039
contents: read
3140
steps:
@@ -42,12 +51,40 @@ jobs:
4251
mkdir -p artifacts
4352
echo "XCODE_VERSION=$(xcodebuild -version | tr '\n' ' ')" >> "$GITHUB_ENV"
4453
45-
- name: Install XcodeGen
46-
run: brew install xcodegen
54+
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
55+
with:
56+
bun-version: 1.4.3
4757

48-
- name: Generate the Xcode project
49-
working-directory: ios-shell
50-
run: xcodegen generate
58+
- name: Install dependencies and build the web app
59+
timeout-minutes: 15
60+
run: |
61+
bun install --frozen-lockfile
62+
cp .env.example .env
63+
cd app && bun run build
64+
65+
- name: Start the mock stacks
66+
run: |
67+
# A: signed out unless the mock's cookie is sent, with the sign-in hand-off.
68+
MOCK_SIGNED_OUT=1 SERVER_PORT=3001 nohup bun app/workbench/mock-server.ts > artifacts/mock-a.log 2>&1 &
69+
APP_PORT=3010 SERVER_PORT=3001 nohup bun app/serve.ts > artifacts/app-a.log 2>&1 &
70+
# B: the same without the hand-off.
71+
MOCK_NO_HANDOFF=1 MOCK_SIGNED_OUT=1 SERVER_PORT=3002 nohup bun app/workbench/mock-server.ts > artifacts/mock-b.log 2>&1 &
72+
APP_PORT=3011 SERVER_PORT=3002 nohup bun app/serve.ts > artifacts/app-b.log 2>&1 &
73+
challenge="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
74+
for _ in $(seq 1 60); do
75+
a_page="$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3010/ || true)"
76+
b_page="$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3011/ || true)"
77+
a_handoff="$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:3010/api/auth/shell/handoff?challenge=$challenge" || true)"
78+
b_handoff="$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:3011/api/auth/shell/handoff?challenge=$challenge" || true)"
79+
if [ "$a_page" = 200 ] && [ "$b_page" = 200 ] && [ "$a_handoff" = 200 ] && [ "$b_handoff" = 404 ]; then
80+
echo "mock stacks are up (A hand-off $a_handoff, B hand-off $b_handoff)"
81+
exit 0
82+
fi
83+
sleep 1
84+
done
85+
echo "mock stacks did not start: A $a_page/$a_handoff, B $b_page/$b_handoff"
86+
tail -n 40 artifacts/mock-a.log artifacts/app-a.log artifacts/mock-b.log artifacts/app-b.log
87+
exit 1
5188
5289
- name: Start the probe server
5390
run: |
@@ -63,6 +100,13 @@ jobs:
63100
cat artifacts/probe-server.log
64101
exit 1
65102
103+
- name: Install XcodeGen
104+
run: brew install xcodegen
105+
106+
- name: Generate the Xcode project
107+
working-directory: ios-shell
108+
run: xcodegen generate
109+
66110
- name: Pick and boot a simulator
67111
run: |
68112
picked="$(python3 ios-shell/ci/pick_simulator.py)"
@@ -78,14 +122,34 @@ jobs:
78122
xcrun simctl boot "$udid" || true
79123
xcrun simctl bootstatus "$udid" -b
80124
81-
- name: Build and run the UI tests
82-
timeout-minutes: 40
125+
- name: Build for testing
126+
timeout-minutes: 20
127+
run: |
128+
set -o pipefail
129+
xcodebuild build-for-testing \
130+
-project ios-shell/OpenBotShell.xcodeproj \
131+
-scheme OpenBotShell \
132+
-destination "platform=iOS Simulator,id=$SIM_UDID" \
133+
-derivedDataPath DerivedData \
134+
CODE_SIGNING_ALLOWED=NO \
135+
2>&1 | tee xcodebuild-build.log | grep -E "error:|warning: .*(OpenBotShell|ios-shell)|BUILD (SUCCEEDED|FAILED)" || true
136+
grep -q "TEST BUILD SUCCEEDED\|BUILD SUCCEEDED" xcodebuild-build.log
137+
138+
- name: Run the UI tests
139+
timeout-minutes: 50
140+
env:
141+
# xcodebuild hands TEST_RUNNER_* to the test runner without the prefix. Empty: those tests skip.
142+
TEST_RUNNER_OPENBOT_SHELL_TEST_SESSION: ${{ secrets.OPENBOT_SHELL_TEST_SESSION }}
143+
TEST_RUNNER_OPENBOT_SHELL_GOOGLE_EMAIL: ${{ secrets.OPENBOT_SHELL_GOOGLE_EMAIL }}
144+
TEST_RUNNER_OPENBOT_SHELL_GOOGLE_PASSWORD: ${{ secrets.OPENBOT_SHELL_GOOGLE_PASSWORD }}
145+
TEST_RUNNER_OPENBOT_SHELL_GOOGLE_TOTP_SECRET: ${{ secrets.OPENBOT_SHELL_GOOGLE_TOTP_SECRET }}
83146
run: |
84147
set -o pipefail
85-
xcodebuild test \
148+
xcodebuild test-without-building \
86149
-project ios-shell/OpenBotShell.xcodeproj \
87150
-scheme OpenBotShell \
88151
-destination "platform=iOS Simulator,id=$SIM_UDID" \
152+
-derivedDataPath DerivedData \
89153
-resultBundlePath TestResults.xcresult \
90154
-parallel-testing-enabled NO \
91155
CODE_SIGNING_ALLOWED=NO \
@@ -109,30 +173,54 @@ jobs:
109173
container="$(xcrun simctl get_app_container "$SIM_UDID" ai.openbot.shell data 2>/dev/null || true)"
110174
if [ -n "$container" ] && [ -f "$container/Documents/diagnostics.jsonl" ]; then
111175
cp "$container/Documents/diagnostics.jsonl" artifacts/diagnostics.jsonl
112-
echo "::group::diagnostics.jsonl"
113-
cat artifacts/diagnostics.jsonl
114-
echo "::endgroup::"
115176
else
116177
echo "no diagnostics.jsonl in the app container ($container)"
117178
fi
118-
xcrun simctl spawn "$SIM_UDID" log show --last 15m --style compact \
179+
xcrun simctl spawn "$SIM_UDID" log show --last 90m --style compact \
119180
--predicate 'process == "OpenBotShell"' > artifacts/simulator-app.log 2>&1 || true
120181
fi
121182
122-
- name: Write the summary
183+
- name: Write the summary and collect the screenshots
123184
if: always()
124185
run: |
125186
python3 ios-shell/ci/summarize.py artifacts TestResults.xcresult xcodebuild.log || true
187+
python3 ios-shell/ci/collect_shots.py artifacts || true
126188
if [ -f artifacts/SUMMARY.md ]; then
127189
cat artifacts/SUMMARY.md >> "$GITHUB_STEP_SUMMARY"
128190
fi
191+
if [ -f artifacts/diagnostics.jsonl ]; then
192+
echo "::group::diagnostics.jsonl (tests with a real account left out)"
193+
cat artifacts/diagnostics.jsonl
194+
echo "::endgroup::"
195+
fi
196+
if [ -d private-artifacts ] && [ -n "$(ls -A private-artifacts/shots 2>/dev/null)" ]; then
197+
echo "HAS_PRIVATE=1" >> "$GITHUB_ENV"
198+
fi
199+
200+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
201+
if: always()
202+
with:
203+
name: ios-shell-shots-${{ github.run_id }}
204+
path: artifacts/shots/
205+
retention-days: 14
206+
if-no-files-found: warn
129207

130208
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
131209
if: always()
132210
with:
133211
name: ios-shell-${{ github.run_id }}
134212
path: |
135213
artifacts/
214+
!artifacts/shots/
136215
xcodebuild.log
216+
xcodebuild-build.log
137217
retention-days: 14
138218
if-no-files-found: warn
219+
220+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
221+
if: always() && env.HAS_PRIVATE == '1'
222+
with:
223+
name: ios-shell-private-${{ github.run_id }}
224+
path: private-artifacts/
225+
retention-days: 7
226+
if-no-files-found: ignore
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import SwiftUI
2+
import UIKit
3+
4+
/// Where the app is: deciding at launch, on the native sign-in screen, or signed in with the tabs.
5+
/// `plain` is the DEBUG probe mode: step 1's bare full-screen web view.
6+
enum Phase: String {
7+
case launching, signedOut, signedIn, plain
8+
}
9+
10+
/// The sign-in in progress while signed out.
11+
enum SignInStep: String {
12+
case idle
13+
/// Asking the server whether it has the sign-in hand-off.
14+
case probing
15+
/// The system sign-in sheet is up.
16+
case sheet
17+
/// The web view is loading the hand-off's enter URL; waiting for the page to say signed in.
18+
case entering
19+
/// No hand-off on this server: the web app's own sign-in, full screen in the web view.
20+
case webFallback
21+
}
22+
23+
/// The native tab bar's tabs, left to right.
24+
enum ShellTab: String, CaseIterable {
25+
case conversations, home, bots
26+
27+
var path: String {
28+
switch self {
29+
case .conversations: return "/conversations"
30+
case .home: return "/"
31+
case .bots: return "/bots"
32+
}
33+
}
34+
35+
var title: String {
36+
switch self {
37+
case .conversations: return "Conversations"
38+
case .home: return "Home"
39+
case .bots: return "Bots"
40+
}
41+
}
42+
43+
/// The web app's own icons for these are Tabler's messages, home and bolt.
44+
var symbol: String {
45+
switch self {
46+
case .conversations: return "bubble.left.and.bubble.right"
47+
case .home: return "house"
48+
case .bots: return "bolt"
49+
}
50+
}
51+
52+
var selectedSymbol: String { symbol + ".fill" }
53+
}
54+
55+
/// The one observable model the views draw from. Changes are logged to diagnostics.
56+
final class AppModel: ObservableObject {
57+
private let diagnostics: Diagnostics
58+
59+
init(diagnostics: Diagnostics) {
60+
self.diagnostics = diagnostics
61+
}
62+
63+
@Published var phase: Phase = .launching {
64+
didSet { if phase != oldValue { diagnostics.log("state", ["phase": phase.rawValue, "from": oldValue.rawValue]) } }
65+
}
66+
@Published var signIn: SignInStep = .idle {
67+
didSet { if signIn != oldValue { diagnostics.log("sign-in-phase", ["step": signIn.rawValue, "from": oldValue.rawValue]) } }
68+
}
69+
/// The short line under the Sign in button after a sign-in that did not finish.
70+
@Published var signInMessage: String?
71+
/// Wins over everything: the offline lock covers the whole app.
72+
@Published var offline = false {
73+
didSet { if offline != oldValue { diagnostics.log("offline", ["offline": offline]) } }
74+
}
75+
@Published var selectedTab: ShellTab = .home {
76+
didSet { if selectedTab != oldValue { diagnostics.log("tab-selected", ["tab": selectedTab.rawValue]) } }
77+
}
78+
/// The page's body background, painted behind the status bar and the tab bar.
79+
@Published var pageBackground: UIColor?
80+
/// Whether the page is in dark mode; nil until the page has said.
81+
@Published var pageIsDark: Bool?
82+
@Published var keyboardVisible = false
83+
/// "Connected, but OpenBot did not answer": the overlay with Try again.
84+
@Published var loadError: String?
85+
/// How the last tab tap reached the page: "event" (openbot:open) or "load".
86+
@Published var lastNavigation = "none"
87+
@Published var mainFrameCommits = 0
88+
89+
var showsSignInScreen: Bool {
90+
phase == .launching || (phase == .signedOut && signIn != .webFallback)
91+
}
92+
93+
var webVisible: Bool {
94+
switch phase {
95+
case .signedIn, .plain: return true
96+
case .signedOut: return signIn == .webFallback || signIn == .entering
97+
case .launching: return false
98+
}
99+
}
100+
101+
var showsTabBar: Bool { phase == .signedIn && !keyboardVisible }
102+
var showsWebSignInBar: Bool { phase == .signedOut && signIn == .webFallback }
103+
104+
/// Whether the status bar and tab bar should be drawn for a dark page; nil: follow the system.
105+
var chromeIsDark: Bool? {
106+
if offline || showsSignInScreen { return nil }
107+
return pageIsDark
108+
}
109+
110+
var chromeBackground: UIColor {
111+
if offline || showsSignInScreen { return .systemBackground }
112+
return pageBackground ?? .systemBackground
113+
}
114+
115+
/// For UI tests (DEBUG only on screen).
116+
var debugState: String {
117+
"phase=\(phase.rawValue) signIn=\(signIn.rawValue) tab=\(selectedTab.rawValue) nav=\(lastNavigation) commits=\(mainFrameCommits) offline=\(offline ? 1 : 0) keyboard=\(keyboardVisible ? 1 : 0) dark=\(pageIsDark.map { $0 ? "1" : "0" } ?? "-")"
118+
}
119+
}

‎ios-shell/OpenBotShell/Diagnostics.swift‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ import Foundation
22
import os
33
import WebKit
44

5-
/// Records what happens inside the web view, as JSON lines in Documents/diagnostics.jsonl and in
5+
/// Records what the shell and the web view do, as JSON lines in Documents/diagnostics.jsonl and in
66
/// the log with the prefix "OPENBOT_DIAG ". Compiled in always, on only when the launch
77
/// environment has OPENBOT_SHELL_DIAGNOSTICS=1. Never records cookie values, tokens, query string
88
/// values or request and response bodies.
99
final class Diagnostics: NSObject, WKScriptMessageHandler {
1010
static let handlerName = "openbotShellDiagnostics"
1111

1212
let enabled: Bool
13+
/// OPENBOT_SHELL_TEST_NAME, put on every line so CI can tell tests apart (and keep the lines of
14+
/// tests that use a real account out of public logs).
15+
private let testName: String
1316
private let fileURL: URL?
1417
private let logger = Logger(subsystem: "ai.openbot.shell", category: "diagnostics")
1518
private let formatter = ISO8601DateFormatter()
1619

17-
init(enabled: Bool) {
20+
init(enabled: Bool, testName: String = "") {
1821
self.enabled = enabled
22+
self.testName = testName
1923
if enabled,
2024
let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
2125
fileURL = documents.appendingPathComponent("diagnostics.jsonl")
@@ -30,6 +34,7 @@ final class Diagnostics: NSObject, WKScriptMessageHandler {
3034
guard enabled else { return }
3135
var entry = fields
3236
entry["kind"] = kind
37+
if !testName.isEmpty { entry["test"] = testName }
3338
entry["ts"] = formatter.string(from: Date())
3439
var data: Data
3540
if JSONSerialization.isValidJSONObject(entry),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import SwiftUI
2+
3+
/// Connected, but OpenBot did not answer: says so, with Try again.
4+
struct LoadErrorOverlay: View {
5+
let message: String
6+
let retry: () -> Void
7+
8+
var body: some View {
9+
VStack(spacing: 16) {
10+
Image(systemName: "exclamationmark.icloud")
11+
.font(.system(size: 40))
12+
.foregroundStyle(.secondary)
13+
.accessibilityHidden(true)
14+
Text("OpenBot couldn't load")
15+
.font(.headline)
16+
Text(message)
17+
.font(.subheadline)
18+
.foregroundStyle(.secondary)
19+
.multilineTextAlignment(.center)
20+
Button("Try again", action: retry)
21+
.buttonStyle(.borderedProminent)
22+
.tint(Color(uiColor: .label))
23+
.foregroundColor(Color(uiColor: .systemBackground))
24+
.accessibilityIdentifier("retry-button")
25+
}
26+
.padding(32)
27+
.frame(maxWidth: .infinity, maxHeight: .infinity)
28+
.background(Color(uiColor: .systemBackground))
29+
}
30+
}

0 commit comments

Comments
 (0)