Skip to content

Commit e8a3902

Browse files
committed
Reapply "feat(desktop): route beta channel to dev backend" (#7230)
This reverts commit d44b4a3, reversing changes made to 34265a0.
1 parent 8feefc9 commit e8a3902

2 files changed

Lines changed: 62 additions & 12 deletions

File tree

desktop/Desktop/Sources/DesktopBackendEnvironment.swift

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,34 @@ enum DesktopBackendEnvironment {
88
static var shouldUseDevelopmentBackends: Bool {
99
shouldUseDevelopmentBackends(
1010
bundleIdentifier: AppBuild.bundleIdentifier,
11-
updateChannel: AppBuild.currentUpdateChannel
11+
updateChannel: AppBuild.currentUpdateChannel,
12+
forceOverride: currentEnvironmentValue("OMI_FORCE_DEV_BACKENDS")
1213
)
1314
}
1415

1516
static func shouldUseDevelopmentBackends(
1617
bundleIdentifier: String,
17-
updateChannel: String
18+
updateChannel: String,
19+
forceOverride: String? = nil
1820
) -> Bool {
19-
// Beta-to-dev routing disabled: signed-in users were landing in fresh empty
20-
// Firebase accounts (e.g. caLCFj7… instead of viUv7Gtdo… for kodjima33),
21-
// because the dev backend's auth path mints custom tokens for new UIDs
22-
// instead of linking to the existing prod user. Keep beta on prod backends
23-
// until the auth flow is fixed.
24-
return false
21+
// Beta channel of the production bundle routes to the dev backend
22+
// (api.omiapi.com + dev Cloud Run desktop-backend). The dev backend is
23+
// configured to use prod Firebase (project_id=based-hardware, prod service
24+
// account, prod FIREBASE_API_KEY), so custom tokens it mints resolve to the
25+
// same UID a user has on prod — and reads/writes hit prod Firestore. Same
26+
// pattern as mobile TestFlight → staging.
27+
//
28+
// PR #7014 (April 2026) was reverted because at that time the dev backend
29+
// was wired to the based-hardware-dev Firebase project, so beta users
30+
// ended up signed in as fresh empty UIDs. The infra has since been moved
31+
// onto prod Firebase. Verify before any future revert: dev backend
32+
// /v1/auth/token must mint custom tokens whose UID matches prod.
33+
if isAffirmative(forceOverride) {
34+
return true
35+
}
36+
37+
return bundleIdentifier == AppBuild.productionBundleIdentifier
38+
&& normalizedChannel(updateChannel) == "beta"
2539
}
2640

2741
static func pythonBaseURL(
@@ -102,4 +116,10 @@ enum DesktopBackendEnvironment {
102116
}
103117
return string
104118
}
119+
120+
private static func isAffirmative(_ value: String?) -> Bool {
121+
guard let value else { return false }
122+
let normalized = value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
123+
return normalized == "1" || normalized == "true" || normalized == "yes"
124+
}
105125
}

desktop/Desktop/Tests/APIClientRoutingTests.swift

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,54 @@ final class APIClientRoutingTests: XCTestCase {
154154
XCTAssertEqual(url, "https://desktop-backend-hhibjajaja-uc.a.run.app/")
155155
}
156156

157-
func testDevelopmentBackendRoutingDisabled() {
158-
// Beta-to-dev routing disabled — see DesktopBackendEnvironment for context.
159-
XCTAssertFalse(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
157+
func testBetaProductionBundleRoutesToDevelopmentBackends() {
158+
XCTAssertTrue(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
160159
bundleIdentifier: "com.omi.computer-macos",
161160
updateChannel: "beta"
162161
))
163-
XCTAssertFalse(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
162+
// "staging" is normalized to "beta" — same routing.
163+
XCTAssertTrue(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
164164
bundleIdentifier: "com.omi.computer-macos",
165165
updateChannel: "staging"
166166
))
167+
}
168+
169+
func testStableProductionBundleKeepsProductionBackends() {
167170
XCTAssertFalse(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
168171
bundleIdentifier: "com.omi.computer-macos",
169172
updateChannel: "stable"
170173
))
174+
}
175+
176+
func testNonProductionBundleSkipsAutomaticBetaRouting() {
177+
// Dev bundle and named test bundles never trigger beta-to-dev routing
178+
// automatically. They must opt in via OMI_FORCE_DEV_BACKENDS or env URLs.
171179
XCTAssertFalse(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
172180
bundleIdentifier: "com.omi.desktop-dev",
173181
updateChannel: "beta"
174182
))
183+
XCTAssertFalse(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
184+
bundleIdentifier: "com.omi.omi-beta-dev-test",
185+
updateChannel: "beta"
186+
))
187+
}
188+
189+
func testForceOverrideEnablesDevelopmentBackendsForAnyBundle() {
190+
XCTAssertTrue(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
191+
bundleIdentifier: "com.omi.desktop-dev",
192+
updateChannel: "stable",
193+
forceOverride: "1"
194+
))
195+
XCTAssertTrue(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
196+
bundleIdentifier: "com.omi.omi-beta-dev-test",
197+
updateChannel: "stable",
198+
forceOverride: "true"
199+
))
200+
XCTAssertFalse(DesktopBackendEnvironment.shouldUseDevelopmentBackends(
201+
bundleIdentifier: "com.omi.computer-macos",
202+
updateChannel: "stable",
203+
forceOverride: "0"
204+
))
175205
}
176206

177207
func testBaseURLReadsFromPythonEnvVar() async {

0 commit comments

Comments
 (0)