Skip to content

Commit

Permalink
remove all initFlow-related code
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Aug 23, 2024
1 parent c2ef61b commit 975788b
Show file tree
Hide file tree
Showing 23 changed files with 21 additions and 377 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import maestro.orchestra.ApplyConfigurationCommand
import maestro.orchestra.CompositeCommand
import maestro.orchestra.MaestroCommand
import maestro.orchestra.Orchestra
import maestro.orchestra.OrchestraAppState
import maestro.orchestra.yaml.YamlCommandReader
import maestro.utils.Insight
import org.slf4j.LoggerFactory
Expand All @@ -48,9 +47,8 @@ object MaestroCommandRunner {
view: ResultView,
commands: List<MaestroCommand>,
debug: FlowDebugMetadata
): Result {
): Boolean {
val config = YamlCommandReader.getConfig(commands)
val initFlow = config?.initFlow
val onFlowComplete = config?.onFlowComplete
val onFlowStart = config?.onFlowStart

Expand Down Expand Up @@ -90,11 +88,6 @@ object MaestroCommandRunner {
view.setState(
UiState.Running(
device = device,
initCommands = toCommandStates(
initFlow?.commands ?: emptyList(),
commandStatuses,
commandMetadata
),
onFlowStartCommands = toCommandStates(
onFlowStart?.commands ?: emptyList(),
commandStatuses,
Expand Down Expand Up @@ -181,8 +174,7 @@ object MaestroCommandRunner {
)

val flowSuccess = orchestra.runFlow(commands)

return Result(flowSuccess = flowSuccess, cachedAppState = null)
return flowSuccess
}

private fun toCommandStates(
Expand Down Expand Up @@ -214,9 +206,4 @@ object MaestroCommandRunner {
)
}
}

data class Result(
val flowSuccess: Boolean,
val cachedAppState: OrchestraAppState?
)
}
15 changes: 4 additions & 11 deletions maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import maestro.cli.runner.resultview.UiState
import maestro.cli.util.PrintUtils
import maestro.cli.view.ErrorViewUtils
import maestro.orchestra.MaestroCommand
import maestro.orchestra.MaestroInitFlow
import maestro.orchestra.util.Env.withEnv
import maestro.orchestra.yaml.YamlCommandReader
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -55,7 +54,7 @@ object TestRunner {
TestDebugReporter.saveFlow(flowFile.name, debug, debugOutputPath)
if (debug.exception != null) PrintUtils.err("${debug.exception?.message}")

return if (result.get()?.flowSuccess == true) 0 else 1
return if (result.get() == true) 0 else 1
}

fun runContinuous(
Expand All @@ -69,7 +68,6 @@ object TestRunner {
val fileWatcher = FileWatcher()

var previousCommands: List<MaestroCommand>? = null
var previousInitFlow: MaestroInitFlow? = null

var ongoingTest: Thread? = null
do {
Expand All @@ -79,15 +77,14 @@ object TestRunner {
join()
}

val commands = YamlCommandReader.readCommands(flowFile.toPath())
val commands = YamlCommandReader
.readCommands(flowFile.toPath())
.withEnv(env)
val initFlow = getInitFlow(commands)

// Restart the flow if anything has changed
if (commands != previousCommands || initFlow != previousInitFlow) {
if (commands != previousCommands) {
ongoingTest = thread {
previousCommands = commands
previousInitFlow = initFlow

runCatching(resultView, maestro) {
MaestroCommandRunner.runCommands(
Expand Down Expand Up @@ -115,10 +112,6 @@ object TestRunner {
} while (true)
}

private fun getInitFlow(commands: List<MaestroCommand>): MaestroInitFlow? {
return YamlCommandReader.getConfig(commands)?.initFlow
}

private fun <T> runCatching(
view: ResultView,
maestro: Maestro,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import io.ktor.util.encodeBase64
import maestro.cli.runner.CommandState
import maestro.cli.runner.CommandStatus
import maestro.utils.Insight
import maestro.utils.Insights
import maestro.utils.chunkStringByWordCount
import org.fusesource.jansi.Ansi

Expand Down Expand Up @@ -66,12 +65,6 @@ class AnsiResultView(
render("Running on ${state.device.description}\n")
}
render("\n")
if (state.initCommands.isNotEmpty()) {
render("\n")
render(" ║ > Init Flow\n")
render("\n")
renderCommands(state.initCommands)
}
if (state.onFlowStartCommands.isNotEmpty()) {
render("\n")
render(" ║ > On Flow Start\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ class PlainTextResultView: ResultView {
}
}

if (state.initCommands.isNotEmpty()) {
if (shouldPrintStep()) {
println(" > Init Flow")
}

renderCommandsPlainText(state.initCommands)
}

if (state.onFlowStartCommands.isNotEmpty()) {
if (shouldPrintStep()) {
println(" > On Flow Start")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ sealed class UiState {

data class Running(
val device: Device? = null,
@Deprecated("Obsolete API. See #1921") val initCommands: List<CommandState> = emptyList(),
val onFlowStartCommands: List<CommandState> = emptyList(),
val onFlowCompleteCommands: List<CommandState> = emptyList(),
val commands: List<CommandState>,
Expand Down
4 changes: 1 addition & 3 deletions maestro-cli/src/main/java/maestro/cli/view/ErrorViewUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package maestro.cli.view

import maestro.MaestroException
import maestro.orchestra.error.InvalidFlowFile
import maestro.orchestra.error.InvalidInitFlowFile
import maestro.orchestra.error.NoInputException
import maestro.orchestra.error.UnicodeNotSupportedError
import maestro.orchestra.error.ValidationError
Expand All @@ -14,7 +13,6 @@ object ErrorViewUtils {
return when (e) {
is ValidationError -> e.message
is NoInputException -> "No commands found in Flow file"
is InvalidInitFlowFile -> "initFlow file is invalid: ${e.initFlowPath}"
is InvalidFlowFile -> "Flow file is invalid: ${e.flowPath}"
is UnicodeNotSupportedError -> "Unicode character input is not supported: ${e.text}. Please use ASCII characters. Follow the issue: https://github.com/mobile-dev-inc/maestro/issues/146"
is InterruptedException -> "Interrupted"
Expand All @@ -24,4 +22,4 @@ object ErrorViewUtils {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ data class MaestroConfig(
val appId: String? = null,
val name: String? = null,
val tags: List<String>? = emptyList(),
@Deprecated("Obsolete API. See #1921") val initFlow: MaestroInitFlow? = null,
val ext: Map<String, Any?> = emptyMap(),
val onFlowStart: MaestroOnFlowStart? = null,
val onFlowComplete: MaestroOnFlowComplete? = null,
Expand All @@ -19,28 +18,13 @@ data class MaestroConfig(
return copy(
appId = appId?.evaluateScripts(jsEngine),
name = name?.evaluateScripts(jsEngine),
initFlow = initFlow?.evaluateScripts(jsEngine),
onFlowComplete = onFlowComplete?.evaluateScripts(jsEngine),
onFlowStart = onFlowStart?.evaluateScripts(jsEngine),
)
}

}

@Deprecated("Obsolete API. See issue #1921")
data class MaestroInitFlow(
val appId: String,
val commands: List<MaestroCommand>,
) {

fun evaluateScripts(jsEngine: JsEngine): MaestroInitFlow {
return copy(
appId = appId.evaluateScripts(jsEngine),
)
}

}

data class MaestroOnFlowComplete(val commands: List<MaestroCommand>) {
fun evaluateScripts(jsEngine: JsEngine): MaestroOnFlowComplete {
return this
Expand Down
61 changes: 10 additions & 51 deletions maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@

package maestro.orchestra

import maestro.*
import maestro.DeviceInfo
import maestro.ElementFilter
import maestro.Filters
import maestro.Filters.asFilter
import maestro.FindElementResult
import maestro.Maestro
import maestro.MaestroException
import maestro.ScreenRecording
import maestro.ViewHierarchy
import maestro.js.GraalJsEngine
import maestro.js.JsEngine
import maestro.js.RhinoJsEngine
Expand All @@ -30,6 +37,7 @@ import maestro.orchestra.filter.TraitFilters
import maestro.orchestra.geo.Traveller
import maestro.orchestra.util.Env.evaluateScripts
import maestro.orchestra.yaml.YamlCommandReader
import maestro.toSwipeDirection
import maestro.utils.Insight
import maestro.utils.Insights
import maestro.utils.MaestroTimer
Expand All @@ -39,7 +47,6 @@ import okio.buffer
import okio.sink
import java.io.File
import java.lang.Long.max
import java.nio.file.Files

class Orchestra(
private val maestro: Maestro,
Expand Down Expand Up @@ -68,28 +75,13 @@ class Orchestra(

private val rawCommandToMetadata = mutableMapOf<MaestroCommand, CommandMetadata>()

/**
* If initState is provided, initialize app disk state with the provided OrchestraAppState and skip
* any initFlow execution. Otherwise, initialize app state with initFlow if defined.
*/
fun runFlow(
commands: List<MaestroCommand>,
initState: OrchestraAppState? = null,
): Boolean {
fun runFlow(commands: List<MaestroCommand>): Boolean {
timeMsOfLastInteraction = System.currentTimeMillis()

val config = YamlCommandReader.getConfig(commands)

initJsEngine(config)

val state = initState ?: config?.initFlow?.let {
runInitFlow(it) ?: return false
}

if (state != null) {
maestro.clearAppState(state.appId)
}

onFlowStart(commands)

executeDefineVariablesCommands(commands, config)
Expand Down Expand Up @@ -134,33 +126,6 @@ class Orchestra(
}
}

/**
* Run the initFlow and return the resulting app OrchestraAppState which can be used to initialize
* app disk state when past into Orchestra.runFlow.
*/
@Deprecated("Obsolete API. See issue #1921")
fun runInitFlow(
initFlow: MaestroInitFlow,
): OrchestraAppState? {
val success = runFlow(
initFlow.commands,
)
if (!success) return null

maestro.stopApp(initFlow.appId)

val stateFile = if (stateDir == null) {
Files.createTempFile(null, ".state")
} else {
Files.createTempFile(stateDir.toPath(), null, ".state")
}

return OrchestraAppState(
appId = initFlow.appId,
file = stateFile.toFile(),
)
}

fun executeCommands(
commands: List<MaestroCommand>,
config: MaestroConfig? = null,
Expand Down Expand Up @@ -1153,9 +1118,3 @@ class Orchestra(
private const val MAX_ERASE_CHARACTERS = 50
}
}

@Deprecated("Obsolete API. See issue #1921")
data class OrchestraAppState(
val appId: String,
val file: File,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ object YamlCommandReader {

// Files to watch for changes. Includes any referenced files.
fun getWatchFiles(flowPath: Path): List<Path> = mapParsingErrors(flowPath) {
val (config, commands) = readConfigAndCommands(flowPath)
val configWatchFiles = config.getWatchFiles(flowPath)
val (_, commands) = readConfigAndCommands(flowPath)
val commandWatchFiles = commands.flatMap { it.getWatchFiles(flowPath) }
(listOf(flowPath) + configWatchFiles + commandWatchFiles)
(listOf(flowPath) + commandWatchFiles)
.filter { it.absolute().parent?.isDirectory() ?: false }
}

Expand Down
Loading

0 comments on commit 975788b

Please sign in to comment.