Skip to content

Commit

Permalink
code discovery (add comments, renames)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Aug 22, 2024
1 parent 6ccf1b0 commit ea737c9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import maestro.cli.DisableAnsiMixin
import maestro.cli.ShowHelpMixin
import maestro.cli.api.ApiClient
import maestro.cli.report.TestDebugReporter
import maestro.cli.runner.TestRunner
import maestro.cli.runner.MaestroFlowRunner
import maestro.cli.runner.resultview.AnsiResultView
import maestro.cli.session.MaestroSessionManager
import maestro.cli.view.ProgressBar
Expand Down Expand Up @@ -104,7 +104,7 @@ class RecordCommand : Callable<Int> {
val screenRecording = kotlin.io.path.createTempFile(suffix = ".mp4").toFile()
val exitCode = screenRecording.sink().use { out ->
maestro.startScreenRecording(out).use {
TestRunner.runSingle(maestro, device, flowFile, env, resultView, path)
MaestroFlowRunner.runSingle(maestro, device, flowFile, env, resultView, path)
}
}

Expand Down
7 changes: 4 additions & 3 deletions maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import maestro.cli.model.TestExecutionSummary
import maestro.cli.report.ReportFormat
import maestro.cli.report.ReporterFactory
import maestro.cli.report.TestDebugReporter
import maestro.cli.runner.TestRunner
import maestro.cli.runner.MaestroFlowRunner
import maestro.cli.runner.TestSuiteInteractor
import maestro.cli.runner.resultview.AnsiResultView
import maestro.cli.runner.resultview.PlainTextResultView
Expand Down Expand Up @@ -297,12 +297,13 @@ class TestCommand : Callable<Int> {
if (!flattenDebugOutput) {
TestDebugReporter.deleteOldFiles()
}
TestRunner.runContinuous(maestro, device, flowFile, env)
MaestroFlowRunner.runContinuous(maestro, device, flowFile, env)

} else {
val resultView =
if (DisableAnsiMixin.ansiEnabled) AnsiResultView()
else PlainTextResultView()
val resultSingle = TestRunner.runSingle(
val resultSingle = MaestroFlowRunner.runSingle(
maestro,
device,
flowFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ import org.slf4j.LoggerFactory
import java.io.File
import java.util.IdentityHashMap

/**
* Knows how to run a list of Maestro commands.
*
* Does not know what a "flow" is.
*/
object MaestroCommandRunner {

private val logger = LoggerFactory.getLogger(MaestroCommandRunner::class.java)
Expand Down Expand Up @@ -125,7 +130,7 @@ object MaestroCommandRunner {
refreshUi()

val orchestra = Orchestra(
maestro,
maestro = maestro,
onCommandStart = { _, command ->
logger.info("${command.description()} RUNNING")
commandStatuses[command] = CommandStatus.RUNNING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ import java.io.File
import java.nio.file.Path
import kotlin.concurrent.thread

object TestRunner {
/**
* Knows how to run a single Maestro flow.
*/
object MaestroFlowRunner {

private val logger = LoggerFactory.getLogger(TestRunner::class.java)
private val logger = LoggerFactory.getLogger(MaestroFlowRunner::class.java)

fun runSingle(
maestro: Maestro,
Expand All @@ -53,12 +56,12 @@ object TestRunner {
}

MaestroCommandRunner.runCommands(
maestro,
device,
resultView,
commands,
debugOutput,
aiOutput,
maestro = maestro,
device = device,
view = resultView,
commands = commands,
debugOutput = debugOutput,
aiOutput = aiOutput,
)
}

Expand Down Expand Up @@ -119,13 +122,13 @@ object TestRunner {

previousResult = runCatching(resultView, maestro) {
MaestroCommandRunner.runCommands(
maestro,
device,
resultView,
commands,
FlowDebugOutput(),
// TODO: bartekpacia - make AI outputs work in continuous mode
FlowAIOutput(
maestro = maestro,
device = device,
view = resultView,
commands = commands,
debugOutput = FlowDebugOutput(),
// TODO(bartekpacia): make AI outputs work in continuous mode
aiOutput = FlowAIOutput(
flowName = "TODO",
flowFile = flowFile,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import maestro.cli.report.SingleScreenFlowAIOutput
import maestro.cli.report.CommandDebugMetadata
import maestro.cli.report.FlowAIOutput
import maestro.cli.report.FlowDebugOutput
import maestro.cli.report.HtmlAITestSuiteReporter
import maestro.cli.report.TestDebugReporter
import maestro.cli.report.TestSuiteReporter
import maestro.cli.util.PrintUtils
Expand Down Expand Up @@ -233,7 +232,6 @@ class TestSuiteInteractor(
it.status = CommandStatus.PENDING
}
},
// another name idea: onCommandFoundDefects
onCommandGeneratedOutput = { command, defects, screenshot ->
logger.info("${command.description()} generated output")
val screenshotPath = writeAIscreenshot(screenshot)
Expand Down
13 changes: 10 additions & 3 deletions maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ sealed class CommandOutput {
data class AIDefects(val defects: List<Defect>, val screenshot: Buffer) : CommandOutput()
}

/**
* Orchestra . It's is one of the core classes in the Maestro codebase.s
*
* Orchestra should not know about:
* - File systems. It should instead write to [Sink]s that it requests from the caller.
* -
*/
class Orchestra(
private val maestro: Maestro,
private val stateDir: File? = null,
Expand Down Expand Up @@ -223,7 +230,6 @@ class Orchestra(
onCommandComplete(index, command)
} catch (ignored: CommandSkipped) {
// Swallow exception
println("ignored CommandSkipped")
onCommandSkipped(index, command)
} catch (e: Throwable) {

Expand Down Expand Up @@ -379,16 +385,17 @@ class Orchestra(
aiClient = ai,
assertion = command.assertion,
screen = imageData.copy().readByteArray(),
previousFalsePositives = listOf(), // TODO: take it from WorkspaceConfig (or MaestroConfig?)
previousFalsePositives = listOf(), // TODO(bartekpacia): take it from WorkspaceConfig (or MaestroConfig?)
)

if (defects.isNotEmpty()) {
onCommandGeneratedOutput(command, defects, imageData)

if (command.optional) throw CommandSkipped

val word = if (defects.size == 1) "defect" else "defects"
throw MaestroException.AssertionFailure(
"Visual AI found possible defects:\n ${defects.joinToString("\n ") { "${it.category}: ${it.reasoning}" }}",
"Visual AI found ${defects.size} possible $word. See the report to learn more.",
maestro.viewHierarchy().root,
)
}
Expand Down

0 comments on commit ea737c9

Please sign in to comment.