Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use environment variables to check for terminal #2330

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mchisolm0
Copy link

@mchisolm0 mchisolm0 commented Feb 24, 2025

Issue #2278 finds CLibrary.isatty gives an error when any maestro command is run unless both the --no-color and --no-ansi flags are given. This fix switches to environment variables because on CachyOS Linux and Fedora Linux users consistently got those errors.

Proposed changes

I switched from using the CLibrary.isatty to using environment variables to check if the call is from a terminal.

Based on the issue, it seems this may be a Linux specific problem. If the team would rather solve this another way, I am happy to help if you would like to direct me how you want it solved. Otherwise, if the team would prefer to go another direction without my help, that is also understandable.

Testing

I ran the ./maestro-cli/build/install/maestro/bin/maestro command with no flags and got expected output.
I also got the demo_app in the e2e/ directory installed on an Android Emulator and ran the tests provided. The output is below.
Ran the ./maestro-cli/build/install/maestro/bin/maestro --device emulator-5554 test e2e/workspaces/demo_app command.

Output from tests
Maestro on  fix-cli [!?]./maestro-cli/build/install/maestro/bin/maestro --device emulator-5554 test e2e/workspaces/demo_app

Waiting for flows to complete...
[Passed] ai_complex (4s)
[Passed] ai_simple (0s)
[Passed] commands_optional_tournee (40s)
[Failed] commands_tour (1m 8s) (Assertion is false: id: com.google.android.inputmethod.latin:id/key_pos_shift is visible)
[Failed] fail_fast (1s) (Assertion is false: false is true)
[Failed] fail_launchApp (0s) (Unable to launch app com.nonexistent: Package com.nonexistent is not installed)
[Failed] fail_launchApp_nonDefault (0s) (Unable to launch app com.nonexistent: Package com.nonexistent is not installed)
[Failed] fail_not_found (18s) (Element not found: Id matching regex: non-existent-id)
[Failed] fail_visible (18s) (Assertion is false: id: non-existent-id is visible)
[Failed] fail_visible_extended (2s) (Assertion is false: id: non-existent-id is visible)
[Passed] fill_form (16s)
[Passed] long_input_text (49s)
[Passed] relatives (20s)
[Passed] scrollUntilVisible_timeout (3s)
[Passed] swipe (8s)

7/15 Flows Failed

Issues fixed

Possible fix for Issue #2278

Feedback welcome

I am new to Maestro, so I would appreciate any feedback on how I solved the issue, if I should delete the comments in the code, and anything else that would help the team or project better.

Issue mobile-dev-inc#2278 finds CLibrary.isatty gives an error unless both the
--no-color and --no-ansi flags are given. This fix switches to
environment variables because on CachyOS Linux and Fedora Linux users
consistently got those errors.
val stdoutIsTTY = CLibrary.isatty(CLibrary.STDOUT_FILENO) != 0
// Instead of using CLibrary.isatty, use environment variables to detect terminal
val forceDisable = System.getenv("MAESTRO_DISABLE_ANSI")?.toBoolean() ?: false
val isTTY = !forceDisable && System.getenv("TERM") != null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I absolutely love the idea of dropping a dependency and simplifying the solution.

This will work on a Mac, but will this work on Windows?

Copy link
Author

@mchisolm0 mchisolm0 Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my research, it looks like the answer is no, it does not. I have added a few more checks specific for windows based on my research, but the only one I have actually been able to verify returns a boolean is ($PSVersionTable -ne $null). I ran into issues building on my first Windows machine (seemed to be a problem with Java, somehow, but I could not figure it out).

I am working on getting my other Windows machine ready to build it and see if I can verify any of it works.

Update: Will have to continue later or someone else can try to get my fix-cli branch working on a Windows machine. I did find I had to specifically install Java 11. For later reference, I have included the error from my most recent build.

Output from failed build
> Task :maestro-ai:compileKotlin
w: file:///C:/Users/mcgen/Maestro/maestro-ai/src/main/java/maestro/ai/DemoApp.kt:106:13 Variable 'aiClient' is never used
w: file:///C:/Users/mcgen/Maestro/maestro-ai/src/main/java/maestro/ai/anthropic/Client.kt:54:13 Variable 'actualImageDetail' is never used

> Task :maestro-studio:web:deps FAILED

> Task :maestro-utils:compileKotlin
w: file:///C:/Users/mcgen/Maestro/maestro-utils/src/main/kotlin/Metrics.kt:27:28 Type mismatch: inferred type is String? but String was expected

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':maestro-studio:web:deps'.
> A problem occurred starting process 'command 'npm.cmd''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants