Skip to content

Commit

Permalink
more wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Aug 15, 2024
1 parent 2b29c53 commit d089f0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
26 changes: 15 additions & 11 deletions maestro-cli/src/main/java/maestro/cli/report/TestDebugReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import maestro.MaestroException
import maestro.TreeNode
import maestro.cli.runner.CommandStatus
Expand Down Expand Up @@ -33,19 +34,15 @@ import kotlin.io.path.exists
object TestDebugReporter {

private val logger = LoggerFactory.getLogger(TestDebugReporter::class.java)
private val mapper = ObjectMapper()
private val mapper = jacksonObjectMapper()
.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

init {

// json
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
}

fun saveFlow(flowName: String, debugOutput: FlowDebugOutput, aiOutput: FlowAIOutput?, path: Path) {
// TODO(bartekpacia): Potentially accept a single "FlowPersistentOutput object

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

// AI output
aiOutput?.let {
// AI screenshots
aiOutput?.outputs?.forEach { output ->
val screenshotFilename = output.screenshotPath.name
val screenshotFile = File(path.absolutePathString(), screenshotFilename)
output.screenshotPath.copyTo(screenshotFile)
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ object MaestroCommandRunner {
}

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

0 comments on commit d089f0c

Please sign in to comment.