maestro icon indicating copy to clipboard operation
maestro copied to clipboard

A slash in flow name causes Maestro to crash with FileNotFoundException

Open jonathanj opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and didn't find mine.

Steps to reproduce

Create a flow with a name that includes a / (on an operating system that uses / as a path separator, such as macOS), for example:

appId: your.app.id
name: foo / bar
---
- launchApp

Actual results

The flow appears to run, but maestro errors with an exception as soon as the flow finishes:

❌ Error: BlockingCoroutine is cancelling
kotlinx.coroutines.JobCancellationException: BlockingCoroutine is cancelling; job=BlockingCoroutine{Cancelling}@1ef0ac30
Caused by: java.io.FileNotFoundException: /Users/jonathan/.maestro/tests/2024-09-05_085603/ai-report-foo / bar.html (No such file or directory)
	at java.base/java.io.FileOutputStream.open0(Native Method)
	at java.base/java.io.FileOutputStream.open(FileOutputStream.java:293)
	at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:235)
	at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:184)
	at kotlin.io.FilesKt__FileReadWriteKt.writeBytes(FileReadWrite.kt:108)
	at kotlin.io.FilesKt__FileReadWriteKt.writeText(FileReadWrite.kt:134)
	at kotlin.io.FilesKt__FileReadWriteKt.writeText$default(FileReadWrite.kt:134)
	at maestro.cli.report.HtmlAITestSuiteReporter.report(HtmlAITestSuiteReporter.kt:47)
	at maestro.cli.report.TestDebugReporter.saveSuggestions(TestDebugReporter.kt:64)
	at maestro.cli.runner.TestRunner.runSingle(TestRunner.kt:76)
	at maestro.cli.command.TestCommand$handleSessions$1$1$results$1$1$1.invoke(TestCommand.kt:306)
	at maestro.cli.command.TestCommand$handleSessions$1$1$results$1$1$1.invoke(TestCommand.kt:258)
	at maestro.cli.session.MaestroSessionManager.newSession(MaestroSessionManager.kt:102)
	at maestro.cli.session.MaestroSessionManager.newSession$default(MaestroSessionManager.kt:54)
	at maestro.cli.command.TestCommand$handleSessions$1$1$results$1$1.invokeSuspend(TestCommand.kt:258)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:111)
	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:99)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:585)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:802)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:706)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:693)

The caused by error contains the hint:

Caused by: java.io.FileNotFoundException: /Users/jonathan/.maestro/tests/2024-09-05_085603/ai-report-foo / bar.html 

So it seems to be trying to write to ai-report-${FLOW_NAME}.html which ends up trying to write to a file called bar.html in a directory that doesn't exist.

Expected results

Operations that write to files with user-given input (such as the flow name) should escape/replace characters that have special meaning in filenames, such as the path separator and .. too.

About app

N/A

About environment

  • openjdk version "17.0.12" 2024-07-16 LTS
  • macOS 14.5
  • arm64

Logs

Logs
<!-- Replace this line with your logs. *DO NOT* remove the backticks! -->

Maestro version

1.38.1

How did you install Maestro?

install script (https://get.maestro.mobile.dev)

Anything else?

No response

jonathanj avatar Sep 05 '24 07:09 jonathanj