Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,18 @@ public struct CloudConfiguration: Sendable, Equatable {
let scheme = value("CMUX_AUTH_CALLBACK_SCHEME").flatMap { URL(string: "\($0)://auth-callback") == nil ? nil : $0 }
?? (isDebugBuild ? (tag.map { "cmux-dev-\($0)" } ?? "cmux-dev") : defaultScheme(bundleID))
let stackBase = value("CMUX_STACK_BASE_URL").flatMap(URL.init(string:)) ?? stackOrigin
// CMUX_NEXT_CLOUD_LINK survives the launch: the app unsets every inherited
// CMUX_* variable but CMUX_NEXT_* (LaunchIdentity.stripInheritedEnvironment);
// CMUX_CLOUD_LINK works only when baked into the bundle's LSEnvironment.
// The app-server link (NEXT Cloud through the owner API) is the default in every
// environment, production included; `legacy` keeps the classic one as the escape hatch.
let linkSource: LinkSource = (value("CMUX_NEXT_CLOUD_LINK") ?? value("CMUX_CLOUD_LINK"))?.lowercased() == "legacy" ? .legacy : .appServer
if production {
return CloudConfiguration(
backend: .production, apiBaseURL: productionOrigin, authWebOrigin: productionOrigin,
stackBaseURL: stackBase, stackProjectID: productionProjectID, stackPublishableClientKey: productionClientKey,
isProductionAuth: true, callbackScheme: scheme, bundleID: bundleID, isDebugBuild: isDebugBuild)
isProductionAuth: true, callbackScheme: scheme, bundleID: bundleID, isDebugBuild: isDebugBuild,
linkSource: linkSource)
}
// Every non-production build (Debug, tagged fleet builds) signs in on staging and uses the
// new cloud with no launch environment. Tagged builds bake loopback origins for a local
Expand All @@ -148,11 +155,7 @@ public struct CloudConfiguration: Sendable, Equatable {
stackProjectID: value("CMUX_STACK_PROJECT_ID") ?? developmentProjectID,
stackPublishableClientKey: value("CMUX_STACK_PUBLISHABLE_CLIENT_KEY") ?? developmentClientKey,
isProductionAuth: false, callbackScheme: scheme, bundleID: bundleID, isDebugBuild: isDebugBuild,
// CMUX_NEXT_CLOUD_LINK survives the launch: the app unsets every inherited
// CMUX_* variable but CMUX_NEXT_* (LaunchIdentity.stripInheritedEnvironment);
// CMUX_CLOUD_LINK works only when baked into the bundle's LSEnvironment.
// The app-server link is the default; `legacy` keeps the classic one.
linkSource: (value("CMUX_NEXT_CLOUD_LINK") ?? value("CMUX_CLOUD_LINK"))?.lowercased() == "legacy" ? .legacy : .appServer)
linkSource: linkSource)
}

/// This process's configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,25 @@ struct CloudConfigurationSignedDEVTests {
@Test(arguments: ["com.cmuxterm.app", "com.cmuxterm.app.nightly", "com.cmuxterm.app.nightly.cmux-next",
"com.cmuxterm.app.rc", "com.cmuxterm.app.debug", "com.cmuxterm.app.debug.next.other", "com.cmuxterm.app.debug.nextx"])
func otherReleaseChannelsKeepProduction(bundleID: String) {
let config = CloudConfiguration.resolve(bundleID: bundleID, bundled: ["CMUX_CLOUD_LINK": "app"], process: [:], isDebugBuild: false)
#expect(config.linkSource == .legacy)
let config = CloudConfiguration.resolve(bundleID: bundleID, bundled: [:], process: [:], isDebugBuild: false)
// Production auth uses NEXT Cloud through the production owner API (cmux-api, which forwards
// Cloud to cmux-platform-production), the same app-server link signed DEV builds use.
#expect(config.linkSource == .appServer)
#expect(config.isProductionAuth)
#expect(config.apiBaseURL.absoluteString == "https://cmux.com")
#expect(config.ownerAPIBaseURL(environment: [:]).absoluteString == "https://cloud-api.cmux.dev")
}

@Test(arguments: [["CMUX_NEXT_CLOUD_LINK": "legacy"], ["CMUX_CLOUD_LINK": "LEGACY"]])
func productionKeepsTheLegacyEscapeHatch(bundled: [String: String]) {
let config = CloudConfiguration.resolve(bundleID: "com.cmuxterm.app.nightly.cmux-next", bundled: bundled, process: [:], isDebugBuild: false)
#expect(config.linkSource == .legacy)
#expect(config.isProductionAuth)
let launched = CloudConfiguration.resolve(bundleID: "com.cmuxterm.app.nightly.cmux-next", bundled: [:],
process: ["CMUX_NEXT_CLOUD_LINK": "legacy"], isDebugBuild: false)
#expect(launched.linkSource == .legacy)
}

@Test func onlyABenchCaptureBuildIsConfiguredAsDebug() {
#expect(CloudConfiguration.isCaptureBuild(bundleID: "com.cmuxterm.app.debug.cap0123456789", benchHooks: true))
#expect(CloudConfiguration.isCaptureBuild(bundleID: "com.cmuxterm.app.debug.capabcdef0123", benchHooks: true))
Expand Down