Skip to content

Commit

Permalink
make assertVisualAI save screenshots when running many flows at once
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Aug 16, 2024
1 parent d23a25f commit 0f7b418
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ object TestDebugReporter {
if (commandMetadata.isNotEmpty()) {
val commandsFilename = "commands-(${flowName.replace("/", "_")}).json"
val file = File(path.absolutePathString(), commandsFilename)
commandMetadata.map { CommandDebugWrapper(it.key, it.value) }.let {
commandMetadata.map {
CommandDebugWrapper(it.key, it.value) }.let {
mapper.writeValue(file, it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ object MaestroCommandRunner {
refreshUi()
},
onCommandGeneratedOutput = { command, defects, screenshot ->
logger.info("${command.description()} OUTPUTTED")
logger.info("${command.description()} generated output")
val screenshotPath = writeAIscreenshot(screenshot)
aiOutput.outputs.add(
AIOutput(
screenshotPath = screenshotPath,
defects = defects
defects = defects,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import maestro.orchestra.Orchestra
import maestro.orchestra.util.Env.withEnv
import maestro.orchestra.workspace.WorkspaceExecutionPlanner
import maestro.orchestra.yaml.YamlCommandReader
import okio.Buffer
import okio.Sink
import org.slf4j.LoggerFactory
import java.io.File
Expand Down Expand Up @@ -136,9 +137,11 @@ class TestSuiteInteractor(
var flowStatus: FlowStatus
var errorMessage: String? = null

// debug
val debugOutput = FlowDebugOutput()
val aiOutput: FlowAIOutput? = null
val aiOutput = FlowAIOutput(
flowName = flowFile.nameWithoutExtension,
flowFilePath = flowFile.absolutePath,
)

fun takeDebugScreenshot(status: CommandStatus): File? {
val containsFailed = debugOutput.screenshots.any { it.status == CommandStatus.FAILED }
Expand All @@ -165,6 +168,14 @@ class TestSuiteInteractor(
return result.getOrNull()
}

fun writeAIscreenshot(buffer: Buffer): File {
val out = File
.createTempFile("ai-screenshot-${System.currentTimeMillis()}", ".png")
.also { it.deleteOnExit() }
out.outputStream().use { it.write(buffer.readByteArray()) }
return out
}

val flowTimeMillis = measureTimeMillis {
try {
val commands = YamlCommandReader
Expand Down Expand Up @@ -215,10 +226,11 @@ class TestSuiteInteractor(
},
// another name idea: onCommandFoundDefects
onCommandGeneratedOutput = { command, defects, screenshot ->
logger.info("${command.description()} OUTPUTTED")
aiOutput?.outputs?.add(
logger.info("${command.description()} generated output")
val screenshotPath = writeAIscreenshot(screenshot)
aiOutput.outputs.add(
AIOutput(
screenshotPath = File("TODO"), // TODO
screenshotPath = screenshotPath,
defects = defects,
)
)
Expand Down

0 comments on commit 0f7b418

Please sign in to comment.