From 2eb0b22bbeb24ffa7b39c39af5537b4eff3e16f9 Mon Sep 17 00:00:00 2001 From: Tarek Belkahia Date: Tue, 17 Sep 2024 00:56:39 +0200 Subject: [PATCH 1/3] Log js console --- maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt b/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt index a5fec61b36..a0d793196d 100644 --- a/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt +++ b/maestro-orchestra/src/main/java/maestro/orchestra/Orchestra.kt @@ -173,6 +173,7 @@ class Orchestra( command, metadata.copy(logMessages = metadata.logMessages + msg) ) + jsLogger.info(msg) } val evaluatedCommand = command.evaluateScripts(jsEngine) @@ -1386,5 +1387,6 @@ class Orchestra( private const val MAX_ERASE_CHARACTERS = 50 private const val MAX_RETRIES_ALLOWED = 3 private val logger = LoggerFactory.getLogger(Orchestra::class.java) + private val jsLogger = LoggerFactory.getLogger("maestro.js.JsEngine.console.log") } } From ff99a94b5867a11f6f9abc4473716db07991a3e5 Mon Sep 17 00:00:00 2001 From: Tarek Belkahia Date: Tue, 17 Sep 2024 00:56:51 +0200 Subject: [PATCH 2/3] Add log level config env var --- maestro-client/src/main/java/maestro/debuglog/LogConfig.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt b/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt index 6a38e93b7e..9a54ab1d15 100644 --- a/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt +++ b/maestro-client/src/main/java/maestro/debuglog/LogConfig.kt @@ -13,9 +13,11 @@ object LogConfig { private const val DEFAULT_FILE_LOG_PATTERN = "%d{HH:mm:ss.SSS} [%5level] %logger.%method: %msg%n" private const val DEFAULT_CONSOLE_LOG_PATTERN = "%highlight([%5level]) %msg%n" + private const val DEFAULT_LOG_LEVEL = "ALL" private val FILE_LOG_PATTERN: String = System.getenv("MAESTRO_CLI_LOG_PATTERN_FILE") ?: DEFAULT_FILE_LOG_PATTERN private val CONSOLE_LOG_PATTERN: String = System.getenv("MAESTRO_CLI_LOG_PATTERN_CONSOLE") ?: DEFAULT_CONSOLE_LOG_PATTERN + private val LOG_LEVEL: String = System.getenv("MAESTRO_CLI_LOG_LEVEL") ?: DEFAULT_LOG_LEVEL fun configure(logFileName: String, printToConsole: Boolean) { val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext @@ -27,7 +29,7 @@ object LogConfig { createAndAddConsoleAppender(loggerContext) } - loggerContext.getLogger("ROOT").level = Level.ALL + loggerContext.getLogger("ROOT").level = Level.toLevel(LOG_LEVEL, Level.ALL) } private fun createAndAddConsoleAppender(loggerContext: LoggerContext) { From 743044c6e7b3ca90715d00672b0924cbbb049b86 Mon Sep 17 00:00:00 2001 From: Tarek Belkahia Date: Tue, 17 Sep 2024 01:29:24 +0200 Subject: [PATCH 3/3] Fix script detection regexes --- .../main/java/maestro/orchestra/util/Env.kt | 4 ++-- .../kotlin/maestro/orchestra/util/EnvTest.kt | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/maestro-orchestra-models/src/main/java/maestro/orchestra/util/Env.kt b/maestro-orchestra-models/src/main/java/maestro/orchestra/util/Env.kt index 36562697af..44fbe1d4da 100644 --- a/maestro-orchestra-models/src/main/java/maestro/orchestra/util/Env.kt +++ b/maestro-orchestra-models/src/main/java/maestro/orchestra/util/Env.kt @@ -8,7 +8,7 @@ import maestro.orchestra.MaestroCommand object Env { fun String.evaluateScripts(jsEngine: JsEngine): String { - val result = "(? val script = match.groups[1]?.value ?: "" @@ -20,7 +20,7 @@ object Env { } return result - .replace("\\\\\\\$\\{([^\$]*)}".toRegex()) { match -> + .replace("\\\\\\\$\\{(.*?)}".toRegex()) { match -> match.value.substringAfter('\\') } } diff --git a/maestro-orchestra-models/src/test/kotlin/maestro/orchestra/util/EnvTest.kt b/maestro-orchestra-models/src/test/kotlin/maestro/orchestra/util/EnvTest.kt index 80b4fee6da..27dd79dfb1 100644 --- a/maestro-orchestra-models/src/test/kotlin/maestro/orchestra/util/EnvTest.kt +++ b/maestro-orchestra-models/src/test/kotlin/maestro/orchestra/util/EnvTest.kt @@ -3,10 +3,12 @@ package maestro.orchestra.util import com.google.common.truth.Truth.assertThat import java.io.File import kotlin.random.Random +import maestro.js.GraalJsEngine import maestro.orchestra.ApplyConfigurationCommand import maestro.orchestra.DefineVariablesCommand import maestro.orchestra.MaestroCommand import maestro.orchestra.MaestroConfig +import maestro.orchestra.util.Env.evaluateScripts import maestro.orchestra.util.Env.withDefaultEnvVars import maestro.orchestra.util.Env.withEnv import maestro.orchestra.util.Env.withInjectedShellEnvVars @@ -60,4 +62,20 @@ class EnvTest { assertThat(withEnv).containsExactly(defineVariables, applyConfig) } + + @Test + fun `evaluateScripts regex`() { + val engine = GraalJsEngine() + val inputs = listOf( + "${'$'}{console.log('Hello!')}", + "${'$'}{console.log('Hello Money! $')}", + "${'$'}{console.log('$')}", + ) + + val evaluated = inputs.map { it.evaluateScripts(engine) } + + // "undefined" is the expected output when evaluating console.log successfully + assertThat(evaluated).containsExactly("undefined", "undefined", "undefined") + } + }