Skip to content

fix(cli): stop AI commands losing the API key in suite runs - #3692

Open
Mohanad49 wants to merge 2 commits into
mobile-dev-inc:mainfrom
Mohanad49:fix/ai-commands-api-key-suite
Open

Mohanad49 wants to merge 2 commits into
mobile-dev-inc:mainfrom
Mohanad49:fix/ai-commands-api-key-suite

Conversation

@Mohanad49

Copy link
Copy Markdown
Contributor

Why

AI commands (assertWithAI, assertNoDefectsWithAI, extractTextWithAI) fail with "MAESTRO_CLOUD_API_KEY is not available" whenever maestro test runs more than one flow, or a single flow with --format junit/html or --shard-all, which covers most CI setups. Separately, --api-key never reached AI commands at all, so the key came from MAESTRO_CLOUD_API_KEY or the stored login instead, even in a single-flow run. Fixes #3051.

Approach

  • TestSuiteInteractor now takes the API key and passes it to Orchestra, the same way MaestroCommandRunner does for a single flow. That covers all three suite-path triggers listed on the issue.
  • TestCommand.authToken was computed in the constructor, before picocli sets --api-key. It's lazy now.

One commit per fix. I also added maestro-test as a test dependency of maestro-cli so the suite runner can be tested against FakeDriver.

Not covered: the MCP run tool builds its own Orchestra without a key too (McpViewerOrchestra). Happy to do that separately if it should have one.

Verification

  • New TestSuiteInteractorTest runs a flow with assertWithAI through the suite runner against FakeDriver, with the AI endpoint stubbed by MockWebServer, and checks the request carries Bearer <key>. On main it fails with the missing-key error.
  • Two new TestCommandTest cases: --api-key wins over MAESTRO_CLOUD_API_KEY, and the env var is used when the flag isn't passed. The first fails on main.
  • :maestro-cli:test passes (168), and each commit passes on its own.
  • Ran the built CLI before and after on two headless web flows, with MAESTRO_CLOUD_API_URL pointed at a local stub and dummy keys:
maestro test … main this branch
one flow key sent key sent
a directory key missing key sent
one flow, --format junit key missing key sent
a directory, --api-key key missing --api-key value sent
one flow, --api-key env key sent instead --api-key value sent

--shard-all goes through the same TestSuiteInteractor call, but I didn't run it.

TestSuiteInteractor built its Orchestra without the API key, so every AI
command failed with "MAESTRO_CLOUD_API_KEY is not available" whenever
maestro test took the suite path: a directory or several flows, a single
flow with --format junit/html, or --shard-all. The single-flow path
already passed it.

The test runs a suite against FakeDriver with the AI endpoint stubbed,
and checks the request carries the key.
authToken was computed when TestCommand was constructed, before picocli
sets --api-key, so the flag never reached AI commands and the key came
from MAESTRO_CLOUD_API_KEY or the stored login instead. It's computed
lazily now.
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.

AI commands lose the API key whenever a run takes the suite path (multiple flows, --format, or --shard-all)

1 participant