Skip to content

Commit

Permalink
fix screenshots taken by assertVisualAI being empty
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Aug 16, 2024
1 parent fc57417 commit d23a25f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
39 changes: 24 additions & 15 deletions maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package maestro.cli.report

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.core.util.DefaultIndenter
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
Expand Down Expand Up @@ -35,16 +37,17 @@ object TestDebugReporter {

private val logger = LoggerFactory.getLogger(TestDebugReporter::class.java)
private val mapper = jacksonObjectMapper()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.writerWithDefaultPrettyPrinter()
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
.writerWithDefaultPrettyPrinter()

private var debugOutputPath: Path? = null
private var debugOutputPathAsString: String? = null
private var flattenDebugOutput: Boolean = false

fun saveFlow(flowName: String, debugOutput: FlowDebugOutput, aiOutput: FlowAIOutput?, path: Path) {
// TODO(bartekpacia): Potentially accept a single "FlowPersistentOutput object
// TODO(bartekpacia): Potentially accept a single "FlowPersistentOutput" object
// TODO(bartekpacia: Build output incrementally, instead of single-shot on flow completion

println("TestDebugReporter.saveFlow: saving flow metadata to $path")

Expand Down Expand Up @@ -75,18 +78,22 @@ object TestDebugReporter {
it.screenshot.copyTo(file)
}

// AI screenshots
aiOutput?.outputs?.forEach { output ->
val screenshotFilename = output.screenshotPath.name
val screenshotFile = File(path.absolutePathString(), screenshotFilename)
output.screenshotPath.copyTo(screenshotFile)
}
aiOutput?.run {
// Write AI screenshots. Paths need to be changed to the final ones.
val updatedOutputs = outputs.map { output ->
val screenshotFilename = output.screenshotPath.name
val screenshotFile = File(path.absolutePathString(), screenshotFilename)
output.screenshotPath.copyTo(screenshotFile)
output.copy(screenshotPath = screenshotFile)
}

outputs.clear()
outputs.addAll(updatedOutputs)

// AI JSON output
aiOutput?.let { flowAiOutput ->
// Write AI JSON output
val filename = "ai-(${flowName.replace("/", "_")}).json"
val file = File(path.absolutePathString(), filename)
mapper.writeValue(file, flowAiOutput)
mapper.writeValue(file, this)
}
}

Expand Down Expand Up @@ -140,8 +147,10 @@ object TestDebugReporter {
fun getDebugOutputPath(): Path {
if (debugOutputPath != null) return debugOutputPath as Path

val debugRootPath = if(debugOutputPathAsString != null) debugOutputPathAsString!! else System.getProperty("user.home")
val debugOutput = if(flattenDebugOutput) Paths.get(debugRootPath) else buildDefaultDebugOutputPath(debugRootPath)
val debugRootPath =
if (debugOutputPathAsString != null) debugOutputPathAsString!! else System.getProperty("user.home")
val debugOutput =
if (flattenDebugOutput) Paths.get(debugRootPath) else buildDefaultDebugOutputPath(debugRootPath)

if (!debugOutput.exists()) {
Files.createDirectories(debugOutput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,11 @@ class Orchestra(

val imageData = Buffer()
maestro.takeScreenshot(imageData, compressed = false)
val imageDataBytes = imageData.readByteArray()

val defects = Prediction.findDefects(
aiClient = ai,
assertion = null,
screen = imageDataBytes,
screen = imageData.copy().readByteArray(),
previousFalsePositives = listOf(), // TODO: take it from WorkspaceConfig (or MaestroConfig?)
)

Expand Down

0 comments on commit d23a25f

Please sign in to comment.