Skip to content

Commit

Permalink
fix: remove cloud upload
Browse files Browse the repository at this point in the history
  • Loading branch information
proksh committed Feb 27, 2025
1 parent 2e18a41 commit abe95f1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 113 deletions.
65 changes: 12 additions & 53 deletions maestro-cli/src/main/java/maestro/cli/api/ApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,8 @@ class ApiClient(
uploadId: String,
projectId: String?,
): UploadStatus {
val baseUrl = if (projectId != null) {
"$baseUrl/v2/project/$projectId/upload/$uploadId"
} else {
"$baseUrl/v2/upload/$uploadId/status?includeErrors=true"
}
val baseUrl = "$baseUrl/v2/project/$projectId/upload/$uploadId"

val request = Request.Builder()
.header("Authorization", "Bearer $authToken")
.url(baseUrl)
Expand Down Expand Up @@ -244,8 +241,8 @@ class ApiClient(
disableNotifications: Boolean,
deviceLocale: String? = null,
progressListener: (totalBytes: Long, bytesWritten: Long) -> Unit = { _, _ -> },
projectId: String? = null,
): UploadResponse {
projectId: String,
): RobinUploadResponse {
if (appBinaryId == null && appFile == null) throw CliError("Missing required parameter for option '--app-file' or '--app-binary-id'")
if (appFile != null && !appFile.exists()) throw CliError("App file does not exist: ${appFile.absolutePathString()}")
if (!workspaceZip.exists()) throw CliError("Workspace zip does not exist: ${workspaceZip.absolutePathString()}")
Expand All @@ -265,7 +262,7 @@ class ApiClient(
iOSVersion?.let { requestPart["iOSVersion"] = it }
appBinaryId?.let { requestPart["appBinaryId"] = it }
deviceLocale?.let { requestPart["deviceLocale"] = it }
projectId?.let { requestPart["projectId"] = it }
requestPart["projectId"] = projectId
if (includeTags.isNotEmpty()) requestPart["includeTags"] = includeTags
if (excludeTags.isNotEmpty()) requestPart["excludeTags"] = excludeTags
if (disableNotifications) requestPart["disableNotifications"] = true
Expand Down Expand Up @@ -297,7 +294,7 @@ class ApiClient(

val body = bodyBuilder.build()

fun retry(message: String, e: Throwable? = null): UploadResponse {
fun retry(message: String, e: Throwable? = null): RobinUploadResponse {
if (completedRetries >= maxRetryCount) {
e?.printStackTrace()
throw CliError(message)
Expand Down Expand Up @@ -332,11 +329,8 @@ class ApiClient(
)
}

val url = if (projectId != null) {
"$baseUrl/v2/project/$projectId/runMaestroTest"
} else {
"$baseUrl/v2/upload"
}
val url = "$baseUrl/v2/project/$projectId/runMaestroTest"

val response = try {
val request = Request.Builder()
.header("Authorization", "Bearer $authToken")
Expand Down Expand Up @@ -388,6 +382,7 @@ class ApiClient(
appBinaryId = appBinaryId,
disableNotifications = disableNotifications,
deviceLocale = deviceLocale,
projectId = projectId
)
} else {
println("\u001B[31;1m[ERROR]\u001B[0m Failed to start trial. Please check your details and try again.")
Expand All @@ -406,11 +401,7 @@ class ApiClient(

val responseBody = JSON.readValue(response.body?.bytes(), Map::class.java)

return if (projectId != null) {
parseRobinUploadResponse(responseBody)
} else {
parseMaestroCloudUpload(responseBody)
}
return parseRobinUploadResponse(responseBody)
}
}

Expand All @@ -436,7 +427,7 @@ class ApiClient(
}
}

private fun parseRobinUploadResponse(responseBody: Map<*, *>): UploadResponse {
private fun parseRobinUploadResponse(responseBody: Map<*, *>): RobinUploadResponse {
@Suppress("UNCHECKED_CAST")
val orgId = responseBody["orgId"] as String
val uploadId = responseBody["uploadId"] as String
Expand All @@ -463,27 +454,6 @@ class ApiClient(
)
}

private fun parseMaestroCloudUpload(responseBody: Map<*, *>): UploadResponse {
@Suppress("UNCHECKED_CAST")
val analysisRequest = responseBody["analysisRequest"] as Map<String, Any>
val uploadId = analysisRequest["id"] as String
val teamId = analysisRequest["teamId"] as String
val appId = responseBody["targetId"] as String
val appBinaryIdResponse = responseBody["appBinaryId"] as? String
val deviceInfoStr = responseBody["deviceInfo"] as? Map<String, Any>

val deviceInfo = deviceInfoStr?.let {
DeviceInfo(
platform = it["platform"] as String,
displayInfo = it["displayInfo"] as String,
isDefaultOsVersion = it["isDefaultOsVersion"] as Boolean,
deviceLocale = responseBody["deviceLocale"] as String
)
}

return MaestroCloudUploadResponse(teamId, appId, uploadId, appBinaryIdResponse, deviceInfo)
}


private inline fun <reified T> post(path: String, body: Any): Result<T, Response> {
val bodyBytes = JSON.writeValueAsBytes(body)
Expand Down Expand Up @@ -564,25 +534,14 @@ class ApiClient(
}
}

sealed class UploadResponse

@JsonIgnoreProperties(ignoreUnknown = true)
data class RobinUploadResponse(
val orgId: String,
val uploadId: String,
val appId: String,
val deviceConfiguration: DeviceConfiguration?,
val appBinaryId: String?,
) : UploadResponse()

@JsonIgnoreProperties(ignoreUnknown = true)
data class MaestroCloudUploadResponse(
val teamId: String,
val appId: String,
val uploadId: String,
val appBinaryId: String?,
val deviceInfo: DeviceInfo?
) : UploadResponse()
)

data class DeviceConfiguration(
val platform: String,
Expand Down
72 changes: 20 additions & 52 deletions maestro-cli/src/main/java/maestro/cli/cloud/CloudInteractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import maestro.cli.CliError
import maestro.cli.api.ApiClient
import maestro.cli.api.DeviceConfiguration
import maestro.cli.api.DeviceInfo
import maestro.cli.api.MaestroCloudUploadResponse
import maestro.cli.api.RobinUploadResponse
import maestro.cli.api.UploadStatus
import maestro.cli.auth.Auth
import maestro.cli.device.Platform
Expand Down Expand Up @@ -77,6 +75,7 @@ class CloudInteractor(
deviceLocale: String? = null,
projectId: String? = null,
): Int {
if (projectId == null) throw CliError("Missing required parameter '--project-id'")
if (appBinaryId == null && appFile == null && !flowFile.isWebFlow()) throw CliError("Missing required parameter for option '--app-file' or '--app-binary-id'")
if (!flowFile.exists()) throw CliError("File does not exist: ${flowFile.absolutePath}")
if (mapping?.exists() == false) throw CliError("File does not exist: ${mapping.absolutePath}")
Expand Down Expand Up @@ -135,55 +134,24 @@ class CloudInteractor(
}
)

when (response) {
is RobinUploadResponse -> {
println()
val project = requireNotNull(projectId)
val appId = response.appId
val uploadUrl = robinUploadUrl(project, appId, response.uploadId, client.domain)
val deviceMessage =
if (response.deviceConfiguration != null) printDeviceInfo(response.deviceConfiguration) else ""
return printMaestroCloudResponse(
async,
authToken,
failOnCancellation,
reportFormat,
reportOutput,
testSuiteName,
uploadUrl,
deviceMessage,
appId,
response.appBinaryId,
response.uploadId,
projectId,
)
}

is MaestroCloudUploadResponse -> {
println()
val deviceInfo = response.deviceInfo
val teamId = response.teamId
val appId = response.appId
val uploadId = response.uploadId
val appBinaryIdResponse = response.appBinaryId
val uploadUrl = uploadUrl(uploadId, teamId, appId, client.domain)
val deviceInfoMessage =
if (deviceInfo != null) printDeviceInfo(deviceInfo, iOSVersion, androidApiLevel) else ""
return printMaestroCloudResponse(
async = async,
authToken = authToken,
failOnCancellation = failOnCancellation,
reportFormat = reportFormat,
reportOutput = reportOutput,
testSuiteName = testSuiteName,
uploadUrl = uploadUrl,
deviceInfoMessage = deviceInfoMessage,
appId = appId,
appBinaryIdResponse = appBinaryIdResponse,
uploadId = uploadId
)
}
}
val project = requireNotNull(projectId)
val appId = response.appId
val uploadUrl = robinUploadUrl(project, appId, response.uploadId, client.domain)
val deviceMessage = if (response.deviceConfiguration != null) printDeviceInfo(response.deviceConfiguration) else ""
return printMaestroCloudResponse(
async,
authToken,
failOnCancellation,
reportFormat,
reportOutput,
testSuiteName,
uploadUrl,
deviceMessage,
appId,
response.appBinaryId,
response.uploadId,
projectId,
)
}
}

Expand All @@ -199,7 +167,7 @@ class CloudInteractor(
appId: String,
appBinaryIdResponse: String?,
uploadId: String,
projectId: String? = null
projectId: String
): Int {
if (async) {
PrintUtils.message("✅ Upload successful!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import java.io.File
import java.util.concurrent.Callable
import java.util.concurrent.TimeUnit
import maestro.orchestra.util.Env.withDefaultEnvVars
import kotlin.io.path.absolutePathString

@CommandLine.Command(
name = "cloud",
Expand Down Expand Up @@ -180,13 +179,7 @@ class CloudCommand : Callable<Int> {
validateWorkSpace()

// Upload
val apiUrl = apiUrl ?: run {
if (projectId != null) {
"https://api.copilot.mobile.dev"
} else {
throw CliError("You need to specify a Robin project with --projectId")
}
}
val apiUrl = apiUrl ?: "https://api.copilot.mobile.dev"

env = env
.withInjectedShellEnvVars()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ final class maestro_driver_iosUITests: XCTestCase {
maestro_driver_iosUITests.logger.info("Will start HTTP server")
try await server.start()
}

func testSomething() async throws {
let s = try! await XCUIApplication(bundleIdentifier: "de.komoot.berlinbikeapp")
let snap = s.snapshot().dictionaryRepresentation

print(snap)
}

override class func tearDown() {
logger.trace("tearDown")
Expand Down

0 comments on commit abe95f1

Please sign in to comment.