Skip to content

Commit

Permalink
Replace input text with redacted version in TestDebugReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
tokou committed Aug 24, 2024
1 parent 60a15ab commit 2726206
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import maestro.debuglog.DebugLogStore
import maestro.debuglog.LogConfig
import maestro.orchestra.MaestroCommand
import org.slf4j.LoggerFactory
import com.fasterxml.jackson.databind.module.SimpleModule
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
Expand All @@ -28,6 +29,7 @@ import java.util.IdentityHashMap
import java.util.Properties
import kotlin.io.path.absolutePathString
import kotlin.io.path.exists
import maestro.orchestra.InputTextCommand

object TestDebugReporter {

Expand All @@ -43,6 +45,8 @@ object TestDebugReporter {
// json
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
val module = SimpleModule().addSerializer(InputTextCommand.Serializer())
mapper.registerModule(module)
}

fun saveFlow(flowName: String, data: FlowDebugMetadata, path: Path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

package maestro.orchestra

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import maestro.KeyCode
import maestro.Point
import maestro.ScrollDirection
Expand Down Expand Up @@ -385,6 +388,20 @@ data class InputTextCommand(
override fun toString(): String {
return "InputTextCommand(text=$redacted,label=$label)"
}

class Serializer : StdSerializer<InputTextCommand> {

constructor() : super(InputTextCommand::class.java)
constructor(item: Class<InputTextCommand>) : super(item)

override fun serialize(value: InputTextCommand, gen: JsonGenerator, provider: SerializerProvider) = with (gen) {
writeStartObject()
writeStringField("text", value.redacted)
if (value.label != null) writeStringField("label", value.label)
if (value.redact) writeBooleanField("redact", true)
writeEndObject()
}
}
}

data class LaunchAppCommand(
Expand Down

0 comments on commit 2726206

Please sign in to comment.