Skip to content

Commit aeb7bae

Browse files
committed
Prove the self-hosted lock screen with the server really stopped, check the self-hosted path on the release build, and even out the two shards
Mock stack C's front end runs under ci/stack_control.py, which a test asks to stop and start. The release-like build gets its own self-hosted test (no http exception at all), and check_apk fails a release APK without the control's text or with a cleartext exception. The hardening tests move to the lighter shard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012xYtaUjbkB1hwLtK4TEzhq
1 parent a9622dd commit aeb7bae

8 files changed

Lines changed: 191 additions & 23 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ jobs:
212212
else
213213
# C: a self-hosted OpenBot on another origin, with the hand-off.
214214
MOCK_PERSON_NAME="Priya Shah" MOCK_ORG_NAME="Northwind" MOCK_SIGNED_OUT=1 SERVER_PORT=3003 nohup bun app/workbench/mock-server.ts > "$ARTIFACTS/mock-c.log" 2>&1 &
215-
APP_PORT=3013 SERVER_PORT=3003 nohup bun app/serve.ts > "$ARTIFACTS/app-c.log" 2>&1 &
215+
# Its front end runs under a small control server, so a test can stop and start it.
216+
nohup python3 android-shell/ci/stack_control.py "$GITHUB_WORKSPACE" "$ARTIFACTS/app-c.log" > "$ARTIFACTS/stack-control.log" 2>&1 &
216217
second="http://127.0.0.1:3013/api/auth/shell/config?platform=android"; want=200
217218
fi
218219
for _ in $(seq 1 60); do

‎android-shell/PRODUCTION-PARITY.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ https://my.open.bot.
1717
| App Links (the https callback) | Not tested here | Coded (`autoVerify` filter for `https://my.open.bot/api/auth/shell/callback`; used only when `DomainVerificationManager` reports the domain verified, API 31+). Needs a release signed with the real key and `/.well-known/assetlinks.json` on my.open.bot naming its SHA-256 fingerprint (TODO). Test: an internal-testing Play build once the server ships the hand-off. |
1818
| WebView version | Real backend (two versions) | The default emulator (API 35) has Android System WebView 124.0.6367.219, frozen in the image; the `api_level: 36` run (Android 16, run 46126178447, all green) has WebView and Chrome 133.0.6943.137. Phones update it through Play (current is far newer); old or unupdated devices (no Play services, some markets) can be much older. The bridge needs `WEB_MESSAGE_LISTENER` and `DOCUMENT_START_SCRIPT` (WebView 86+, feature-checked; without them the user agent still marks the shell). |
1919
| GPU drawing (the Bots "ghosting") | Emulator only | In recordings the Bots screen sometimes showed a faint second copy of its heading and rows. The page is clean: one `h1`, `scrollHeight` 628 equal to `innerHeight`, nothing duplicated in the DOM. Drawn in software (a canvas capture, and the WebView on a software layer) it is clean; drawn by the GPU compositor it ghosts, the same on API 35 (WebView 124.0.6367.219) and API 36 (WebView 133.0.6943.137). So it is the emulator's guest GPU renderer (`-gpu guest`), not the app or the page. The demo tour draws the Bots scene on a software layer for the recording only (debug hook `openbot.software_layer`); the app itself never does. Check on a real phone. |
20-
| A self-hosted OpenBot | Simulated | Mock stack C on another origin (`http://127.0.0.1:3013`, a development host the debug build may reach over http) stands in for it: the field, each refusal, the hand-off with the custom scheme, relaunch, sign-out, back to Cloud with no session left, a page of the other origin getting no bridge, the lock screen (`SelfHostedTest`). Not tested: a real https self-hosted OpenBot, a private certificate authority (refused, see the README's follow-ups), a server behind a VPN or a captive portal. |
20+
| A self-hosted OpenBot | Simulated | Mock stack C on another origin (`http://127.0.0.1:3013`, a development host the debug build may reach over http) stands in for it: the field, each refusal, the hand-off with the custom scheme, relaunch, sign-out, back to Cloud with no session left, a page of the other origin getting no bridge, the lock screen (`SelfHostedTest`). On the release-like build (no hooks, release's network rules) `RealBackendReleaseTest#testSelfHostedOnTheReleaseBuild` finds the quiet control and the field, sees `http://` refused even for a development host, and an https address checked and refused; `ci/check_apk.sh` fails a release APK without the control's text, with a cleartext exception, or with any hook name in its dex. The lock screen is proved with stack C's front end really stopped and started again (`ci/stack_control.py`). Not tested: a real https self-hosted OpenBot (so the saved address on the release build is the same code, not a separate run), a private certificate authority (refused, see the README's follow-ups), a server behind a VPN or a captive portal. |
2121
| Cloudflare's bot check on my.open.bot | Real backend: seen, often | 403 `cf-mitigated: challenge` in the WebView, never in the Custom Tab. See the section below. |
2222
| OEM differences | Not tested here | One Google emulator image. Samsung, Xiaomi and others ship their own launchers, keyboards, battery killers and sometimes their own WebView provider settings. Test on a Samsung and a Xiaomi device. |
2323
| Edge to edge, insets, keyboard | Simulated | Target 36 forces edge to edge; the shell applies the insets itself, measured in CI on a 720×1600 screen at 320 dpi with gesture navigation (`testTabsRouteTheWebView`, `testKeyboardHidesTabBar`, the skeleton test). Three-button navigation, display cutouts of other shapes and foldables are not tested; a tablet size and rotation are (`HardeningTest`). On the emulator's guest GPU renderer, the resize when the keyboard closes on send leaves the web area blank (the page's background, no skeleton: it is not a new document) for about 0.5 s while the WebView redraws its tiles, and the bar comes back a moment later (demo run 46132747876, 47.6 to 48.2 s). Check on a phone. |

‎android-shell/app/src/androidTest/java/ai/openbot/shell/test/RealBackendReleaseTest.kt‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,45 @@ class RealBackendReleaseTest : ShellTestBase() {
9090
check(exists("offline_lock"), "the lock went away with nothing to reach")
9191
}
9292

93+
/**
94+
* The self-hosted path on the release-like build (no hooks, release's network rules): the quiet
95+
* control, the field, the check, https only with no exception at all (http to a development host
96+
* is refused too), and a refused address keeps OpenBot Cloud. Needs no network: the address
97+
* checks are local or fail on the device itself.
98+
*/
99+
@Test
100+
fun testSelfHostedOnTheReleaseBuild() {
101+
launchPlain("https://unreachable.openbot.invalid", "self-hosted-release")
102+
check(waitFor("sign_in_button", 15_000) != null, "no Sign in button")
103+
check(find("self_hosted_address") == null, "the address field shows before it is asked for")
104+
val toggle = waitFor("self_hosted_toggle", 5_000)
105+
if (!check(toggle != null, "no quiet self-hosted control on the release build")) return
106+
checkEquals(instrumentation.targetContext.getString(ai.openbot.shell.R.string.self_hosted_toggle), toggle!!.text, "the quiet control")
107+
toggle.click()
108+
val field = waitFor("self_hosted_address", 5_000)
109+
if (!check(field != null, "no address field on the release build")) return
110+
screenshot("1-field")
111+
fun attempt(address: String): String {
112+
find("self_hosted_address")?.text = address
113+
sleep(300)
114+
find("self_hosted_continue")?.click()
115+
val error = device.wait(androidx.test.uiautomator.Until.findObject(res("self_hosted_error")), 20_000)
116+
sleep(500)
117+
return find("self_hosted_error")?.text ?: error?.text ?: ""
118+
}
119+
val http = instrumentation.targetContext.getString(ai.openbot.shell.R.string.self_hosted_error_http)
120+
checkEquals(http, attempt("http://127.0.0.1:3013"), "http to a development host on the release build")
121+
checkEquals(http, attempt("http://openbot.example.com"), "http on the release build")
122+
val checked = attempt("https://openbot.invalid")
123+
note("https to a host that does not exist: '$checked'")
124+
check(checked.isNotEmpty() && checked != http, "the release build did not check an https address")
125+
dismissKeyboardIfUp()
126+
screenshot("2-refused")
127+
find("self_hosted_cancel")?.click()
128+
sleep(600)
129+
check(find("server_host") == null, "a refused address changed the server on the release build")
130+
}
131+
93132
/**
94133
* The real sign-in a person does on production today, with no hook: fresh install, native
95134
* sign-in, Sign in, config 404, the real web sign-in in the WebView, OpenBot by CopilotKit's page,

‎android-shell/app/src/androidTest/java/ai/openbot/shell/test/SelfHostedTest.kt‎

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,32 +215,63 @@ class SelfHostedTest : ShellTestBase() {
215215
}
216216
}
217217

218-
// 7. The lock screen names the server; Change address opens the field with the address in it.
218+
/** Stops or starts mock stack C's front end through the CI's control server (ci/stack_control.py). */
219+
private fun stackC(action: String): Boolean = try {
220+
val connection = java.net.URL("http://127.0.0.1:8790/stack-c/$action").openConnection() as java.net.HttpURLConnection
221+
connection.requestMethod = "POST"
222+
connection.connectTimeout = 5_000
223+
connection.readTimeout = 40_000
224+
val ok = connection.responseCode == 200
225+
connection.disconnect()
226+
note("stack C $action: $ok")
227+
ok
228+
} catch (error: java.io.IOException) {
229+
note("stack C $action failed: ${error.javaClass.simpleName}")
230+
false
231+
}
232+
233+
// 7. With the self-hosted OpenBot really stopped: the lock screen names its host, Change address
234+
// opens the field with the address in it, and once it is back Try again returns to the app.
219235
@Test
220236
fun testLockNamesTheServer() {
221237
launch(MOCK_A, "lock-choose")
222238
check(waitFor("sign_in_button", 20_000) != null, "no Sign in button")
223239
if (!chooseSelfHosted("lock")) return
224-
launch(MOCK_A, "lock", reset = false, extras = mapOf("openbot.force_offline" to "1"))
225-
check(waitFor("offline_lock", 15_000) != null, "no lock screen")
226-
checkEquals(string(ai.openbot.shell.R.string.lock_reaching, "127.0.0.1:3013"), find("offline_lock_host")?.text, "the host on the lock screen")
227-
val change = find("lock_change_address")
228-
if (!check(change != null, "no Change address on the lock screen")) return
229-
screenshot("1-lock-self-hosted")
230-
change!!.click()
231-
val field = waitFor("self_hosted_address", 5_000)
232-
checkEquals(MOCK_C, field?.text, "the address field after Change address")
233-
dismissKeyboardIfUp()
234-
sleep(600)
235-
screenshot("2-change-address")
236-
find("self_hosted_cancel")?.click()
237-
check(waitFor("offline_lock", 5_000) != null, "Cancel did not return to the lock screen")
240+
if (!check(signInThroughCustomTab("lock", shots = false), "signing in to the self-hosted server did not reach the tabs")) return
241+
check(waitPageText("Start a conversation", 30_000), "no Home on the self-hosted server")
242+
try {
243+
if (!check(stackC("stop"), "could not stop the self-hosted OpenBot")) return
244+
launch(MOCK_A, "lock", reset = false)
245+
if (!check(waitFor("offline_lock", 40_000) != null, "no lock screen with the self-hosted OpenBot stopped: ${debugState()}")) return
246+
checkEquals(string(ai.openbot.shell.R.string.lock_reaching, "127.0.0.1:3013"), find("offline_lock_host")?.text, "the host on the lock screen")
247+
val change = find("lock_change_address")
248+
if (!check(change != null, "no Change address on the lock screen")) return
249+
screenshot("1-lock-self-hosted")
250+
change!!.click()
251+
val field = waitFor("self_hosted_address", 5_000)
252+
checkEquals(MOCK_C, field?.text, "the address field after Change address")
253+
dismissKeyboardIfUp()
254+
sleep(600)
255+
screenshot("2-change-address")
256+
find("self_hosted_cancel")?.click()
257+
check(waitFor("offline_lock", 5_000) != null, "Cancel did not return to the lock screen")
258+
if (!check(stackC("start"), "could not start the self-hosted OpenBot again")) return
259+
find("retry_button")?.click()
260+
check(waitGone("offline_lock", 30_000), "Try again did not lift the lock once the self-hosted OpenBot was back")
261+
check(waitPageText("Start a conversation", 30_000), "no Home after the self-hosted OpenBot came back")
262+
checkEquals(MOCK_C, pageString("location.origin"), "the page's origin after the lock")
263+
screenshot("3-back-after-lock")
264+
} finally {
265+
stackC("start")
266+
}
238267

239-
launch(MOCK_A, "lock-cloud", extras = mapOf("openbot.force_offline" to "1"))
240-
check(waitFor("offline_lock", 15_000) != null, "no lock screen on OpenBot Cloud")
241-
checkEquals(string(ai.openbot.shell.R.string.lock_reaching, "localhost:3010"), find("offline_lock_host")?.text, "the host on OpenBot Cloud's lock screen")
268+
// OpenBot Cloud that does not answer (a closed port as this build's Cloud): no Change address.
269+
launch("http://127.0.0.1:8799", "lock-cloud")
270+
waitFor("sign_in_button", 20_000)?.click()
271+
check(waitFor("offline_lock", 30_000) != null, "no lock screen when OpenBot Cloud does not answer")
272+
checkEquals(string(ai.openbot.shell.R.string.lock_reaching, "127.0.0.1:8799"), find("offline_lock_host")?.text, "the host on OpenBot Cloud's lock screen")
242273
check(find("lock_change_address") == null, "Change address shows on OpenBot Cloud")
243-
screenshot("3-lock-cloud")
274+
screenshot("4-lock-cloud")
244275
}
245276

246277
companion object {

‎android-shell/ci/check_apk.sh‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ if echo "$manifest" | grep -q 'android:debuggable="true"'; then echo "::error::t
3838
if echo "$manifest" | grep -q 'android:usesCleartextTraffic="true"'; then echo "::error::the release manifest allows cleartext"; exit 1; fi
3939
echo "release manifest: not debuggable, no usesCleartextTraffic"
4040
echo "$manifest" | grep -E 'targetSdkVersion|minSdkVersion|allowBackup|networkSecurityConfig|enableOnBackInvokedCallback|autoVerify|uses-permission' | sed 's/^ */ /'
41+
# The self-hosted path ships in release: its first-screen strings, and no cleartext exception at all.
42+
toggle="$("$analyzer" resources value --config default --name self_hosted_toggle --type string "$release" 2>/dev/null || true)"
43+
if ! echo "$toggle" | grep -q 'Or sign in to a self-hosted OpenBot'; then echo "::error::the release APK lacks the self-hosted control's text (got '$toggle')"; exit 1; fi
44+
nsc="$("$analyzer" resources xml --file res/xml/network_security_config.xml "$release" 2>/dev/null || true)"
45+
if echo "$nsc" | grep -qi 'cleartextTrafficPermitted="true"'; then echo "::error::the release network security config permits cleartext"; exit 1; fi
46+
echo "release: the self-hosted control ships ('$toggle'); no cleartext exception in its network security config"
4147
echo "sizes: $(du -h "$release" | cut -f1) release, $(du -h "$release_test" | cut -f1) releaseTest"

‎android-shell/ci/emulator.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ prepare() {
9090
adb shell am set-debug-app --persistent com.android.chrome || true
9191
adb shell pm grant com.android.chrome android.permission.POST_NOTIFICATIONS > /dev/null 2>&1 || true
9292
# The test servers on the host, as localhost on the emulator (after adb root, which drops these).
93-
for port in 3010 3011 3012 3013 8765 8766 8797; do adb reverse "tcp:$port" "tcp:$port" > /dev/null; done
93+
for port in 3010 3011 3012 3013 8765 8766 8790 8797; do adb reverse "tcp:$port" "tcp:$port" > /dev/null; done
9494
adb reverse --list
9595
# SystemUI that started while the runner was busy (the web build, the mock servers) can keep a
9696
# half-drawn status bar for good: the clock and icons cut off below their first row, on every

‎android-shell/ci/run_tests.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"RealBackendReleaseTest#testRealFirstScreenAndWebSignIn",
5050
"RealBackendReleaseTest#testRealLockScreenWhenBackendUnreachable",
5151
"RealBackendReleaseTest#testRealGoogleSignInInWebViewAndJourney",
52+
"RealBackendReleaseTest#testSelfHostedOnTheReleaseBuild",
5253
]
5354
SUITE1_DEBUG = [
5455
"RealBackendDebugTest#testLoadsHostedWebApp",
@@ -96,6 +97,9 @@
9697
"ShellFlowTest#testLoadingSkeleton",
9798
"ShellFlowTest#testLockLiftsWhenServerComesBack",
9899
"RenderingTest#testBotsPageRendering",
100+
]
101+
# On mock stack A, in the lighter shard ("other") to keep the two shards even.
102+
HARDENING = [
99103
"HardeningTest#testLargestFontScale",
100104
"HardeningTest#testAccessibilityLabels",
101105
"HardeningTest#testTabletSizeAndRotation",
@@ -442,7 +446,7 @@ def main():
442446
plan += SUITE2
443447
if shard in ("", "other"):
444448
if not REAL_ONLY:
445-
plan += PROBE
449+
plan += PROBE + HARDENING
446450
plan += SUITE1_DEBUG + SUITE1_RELEASE
447451
after_release = -1
448452
results, logs = [], []

‎android-shell/ci/stack_control.py‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/usr/bin/env python3
2+
"""Runs mock stack C's front end (app/serve.ts on APP_PORT 3013) and lets a test stop and start it.
3+
4+
The self-hosted lock-screen test needs that OpenBot to really go away and come back. This listens on
5+
127.0.0.1:8790 (reached from the emulator through adb reverse) and answers:
6+
POST /stack-c/stop stops the front end: 3013 refuses connections
7+
POST /stack-c/start starts it again and waits until it answers
8+
GET /stack-c "up" or "down"
9+
Standard-library Python; started by the test workflow's "other" shard only.
10+
"""
11+
12+
import http.server
13+
import os
14+
import subprocess
15+
import sys
16+
import time
17+
import urllib.request
18+
19+
ROOT = sys.argv[1] if len(sys.argv) > 1 else "."
20+
LOG = sys.argv[2] if len(sys.argv) > 2 else os.devnull
21+
ENV = dict(os.environ, APP_PORT="3013", SERVER_PORT="3003")
22+
state = {"process": None}
23+
24+
25+
def up():
26+
try:
27+
with urllib.request.urlopen("http://127.0.0.1:3013/", timeout=2) as answer:
28+
return answer.status == 200
29+
except Exception:
30+
return False
31+
32+
33+
def start():
34+
if state["process"] is None or state["process"].poll() is not None:
35+
log = open(LOG, "ab")
36+
state["process"] = subprocess.Popen(["bun", "app/serve.ts"], cwd=ROOT, env=ENV, stdout=log, stderr=log)
37+
for _ in range(60):
38+
if up():
39+
return True
40+
time.sleep(0.5)
41+
return False
42+
43+
44+
def stop():
45+
process = state["process"]
46+
if process is not None and process.poll() is None:
47+
process.terminate()
48+
try:
49+
process.wait(timeout=10)
50+
except subprocess.TimeoutExpired:
51+
process.kill()
52+
state["process"] = None
53+
for _ in range(20):
54+
if not up():
55+
return True
56+
time.sleep(0.5)
57+
return False
58+
59+
60+
class Handler(http.server.BaseHTTPRequestHandler):
61+
def answer(self, status, text):
62+
body = text.encode()
63+
self.send_response(status)
64+
self.send_header("Content-Type", "text/plain")
65+
self.send_header("Content-Length", str(len(body)))
66+
self.end_headers()
67+
self.wfile.write(body)
68+
69+
def do_GET(self):
70+
if self.path == "/stack-c":
71+
return self.answer(200, "up" if up() else "down")
72+
self.answer(404, "not found")
73+
74+
def do_POST(self):
75+
if self.path == "/stack-c/stop":
76+
return self.answer(200 if stop() else 500, "down")
77+
if self.path == "/stack-c/start":
78+
return self.answer(200 if start() else 500, "up")
79+
self.answer(404, "not found")
80+
81+
def log_message(self, *args):
82+
pass
83+
84+
85+
if __name__ == "__main__":
86+
start()
87+
http.server.ThreadingHTTPServer(("127.0.0.1", 8790), Handler).serve_forever()

0 commit comments

Comments
 (0)