Skip to content

feat(cli): compute product commands - #555

Merged
lutz-grex merged 38 commits into
developfrom
feat/cli-scripts
Dec 4, 2026
Merged

lutz-grex merged 38 commits into
developfrom
feat/cli-scripts

Conversation

@lutz-grex

@lutz-grex lutz-grex commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The CLI manages Serverless Functions, routines, and sandboxes through the published SDK, including creation, execution, inspection, and cleanup flows.

Changes

  • Add cloud function runs, versions, and log downloads using SDK 6.3.2 Run.wait_logs(). Configure completion waits with --timeout; missing logs preserve finished run results and exit codes.
  • Ignore inherited device settings for cloud function runs and require explicit version selection or --all when deleting a function by name.
  • Add YAML 1.2 routine documents, JSON export, execution history, and enable/disable commands. Reject duplicate document keys and YAML anchors/aliases.
  • Add sandbox execution with remote exit codes and retry-safe binary file transfers. Pending commands identify themselves and explain that execution may still finish.
  • Share pagination, metadata rendering, timestamp formatting, and destructive confirmation with --yes/--no-input across the compute commands.
  • Require mobilerun-sdk>=6.3.2,<7, tested with the PyPI 6.3.2 release. Advertise sandbox delete and retain stop as a hidden alias of the same command.
  • Return exit code 124 for execution/completion-wait timeouts, preserving IDs and JSON output; ordinary failures retain their remote exit code. Function creation uses waitS=0 so server-side waiting cannot bypass the CLI completion timeout.
  • Provide consistent JSON output, actionable errors, and command examples.
  • Quality-pass simplifications (split function run, shared list rendering, named timeout constants); output formats unchanged.
  • Three small behaviour changes: routine pull/schema refuse an existing file before downloading; function delete resolves the name before confirming; function list rejects --name with --search.
  • Env hint now names MOBILERUN_BASE_URL and MOBILERUN_API_BASE_URL.

Testing

  • uv run pytest tests -q -k cli: 1,316 passed, 4 failed (2,032 deselected); the same four failures also fail on develop: test_android_device_selection.py::test_device_command_with_multiple_devices_raises_click_error, test_cloud_cli.py::test_cloud_listing_errors_are_failures, test_cloud_cli.py::test_devices_cloud_missing_key_exits_nonzero, test_cloud_cli.py::test_local_listing_uses_local_scope.
  • Scoped Ruff and mypy passed (untyped third-party imports excluded). Black passed across the repository.
  • Regression coverage includes inherited device settings, explicit delete guards, absent/slow logs, SDK upload replay after HTTP 502, confirmations, document parsing, and ISO timestamps. Mutation checks failed as expected and passed after restoration.
  • Repository-wide Ruff and mypy retain existing baseline findings outside the scoped checks.

Runtime

Verified against the API on 2026-11-24: cloud runs succeeded with inherited device environment settings and a custom wait timeout. A quiet function completed with empty stdout/stderr; the API still published a small runtime log, so logs=none is covered with generated SDK responses. Unsafe delete commands exited 2; selected version deletion was explicit. Sandbox stdout/stderr, exit code 7, and exact binary transfer were verified. D2–D4 checks on SDK 6.3.2 verified both timeout paths return 124, normal commands return 0/7, and the hidden alias behaves like delete. Created functions and routines were deleted and all sandboxes stopped.

🤖 Generated with Claude Code

lutz-grex and others added 30 commits November 12, 2026 20:13
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@lutz-grex
lutz-grex requested a review from RasulOs November 24, 2026 15:01
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@lutz-grex
lutz-grex requested a review from Cyro292 November 24, 2026 15:20

@Cyro292 Cyro292 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review: changes requested. All SDK calls match 6.3.2, and the 215 new tests pass. The problems are in edge-case handling, grouped below.

1. API URL precedence 🔴

  • options.py:600: MOBILERUN_BASE_URL now wins over MOBILERUN_API_BASE_URL for every existing command. On base, the legacy variable won. mobilerun env still reports only the legacy one, so it can show a different endpoint than the one actually used.
  • function.py:233: run --local with a cloud device sets only MOBILERUN_API_BASE_URL for the child process. mobilerun_functions reads MOBILERUN_BASE_URL first, so the API key can go to an inherited host instead of --api-url. Fix: set both variables.

2. Wait and poll failures lose state 🔴

  • function.py:373: if the completion poll fails after the run was created, the run ID is dropped. Callers may then start a duplicate run.
  • sandbox.py:164: if a status request times out, the command exits 1 with "Request timed out". It should take the pending path, which keeps the command ID and exits 124.
  • function.py:532: _poll_until treats any APIError as "still pending" and exits 0. A 403 is hidden.
  • function.py:599: push polls latest_version, not the version it just created. If another push lands in between, a rejected v2 can exit 0.
  • function.py:373: --wait polls even when the create response is already terminal. If that poll times out, a finished run is reported as "still running" with exit 124.
  • function.py:385: --timeout doesn't bound the command. The log wait adds up to 60s after it.

3. Output fidelity 🟠

  • routine.py:165: pull -o routine.json writes YAML, then check and push reject the file. Fix: infer the format from the suffix.
  • sandbox.py:170: rstrip + emit rewrites remote stdout: X and X\n\n both become X\n. This breaks pipes.
  • options.py:262: redaction collapses whitespace in --json error details, so keys like "a b" and "a b" merge.
  • routine.py:57: a 422 with non-dict details exits 3 with no output.
  • function.py:72: check -j prints no JSON when mobilerun-functions is missing.
  • function.py:662: show --version crashes on data: null, which the SDK allows.

4. Local device selection 🟠

  • function.py:213: -P ios without -d selects no device, but README.md:379 says it does. Either make it select a device or fix the docs.

5. Files 🟡

  • options.py:748: the no---force path publishes with os.link, which should fail on filesystems without hard links, such as exFAT or some network mounts. Written files also end up with mode 0600. (Derived from the code, not run.)
  • sandbox.py:212,239: uploads and downloads buffer the whole file in memory.

6. YAML 🟡

  • documents.py:117: explicit tags bypass the YAML 1.2 rules: !!float 1:30 becomes 90.0.
  • PyYAML is imported but not declared; it only arrives through llama-index-core. It also now loads on every CLI startup via tree.py.

Nits and open questions

  • routine.py:237: the enqueue-failure message prints a literal ID.
  • routine.py:227: ❓ keyed runs may record queue failures on the execution instead of setting enqueueFailed, so a failed enqueue may still exit 0. Not checked against the live API.

Verification: 215/215 new tests pass on SDK 6.3.2. Ruff and Black are clean. I couldn't reproduce the "1,281 passed" claim: the full -k cli run gave 1,276 passed, 8 failed, and all 8 also fail on base. The PR has no test job in CI.

@lutz-grex

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. I checked every point against the code. Fixes are in 024b5bd and c59f8a0 (develop merged in 72a42d5); status per point:

1. API URL precedence

  • options.py:600: this order is intended. MOBILERUN_BASE_URL is the name the SDK reads (mobilerun_sdk/_client.py), and mobilerun-core (connection/cloud.py) and mobilerun-functions (device.py) use the same rule: new name first, MOBILERUN_API_BASE_URL only as a fallback. Before this PR the CLI read only the legacy name, so nothing took priority before. The CLI now follows the same rule as the rest of the stack.
  • You're right about the two consequences, both fixed:
    • run --local with a cloud device now sets MOBILERUN_BASE_URL (and the legacy name, same value) for the child, so --api-url always wins over an inherited shell value.
    • mobilerun env now shows MOBILERUN_BASE_URL and resolves it with the same order as the commands.

2. Wait and poll failures

All fixed:

  • function run --wait: an error while waiting no longer drops the run ID. The ID and the function logs hint go to stderr, and the exit code is non-zero.
  • sandbox exec: a timeout or connection error while polling takes the pending path (command ID kept, exit 124).
  • _poll_until: an API error is no longer treated as pending. A 403 now shows the error and exits 1. A request timeout or connection error while polling stays pending. Pending at the end of the wait now exits 124 for check --remote and push, the same as run. Note: a pending result used to exit 0 here.
  • push now polls the version it created, not latest_version.
  • A create response that is already terminal skips the wait.
  • --timeout now bounds the whole command. The log wait only gets the time that is left.

3. Output fidelity

All fixed: pull -o takes the format from the file suffix (an explicit --format that contradicts it is a usage error); sandbox exec writes remote stdout byte for byte; detail keys keep their whitespace; non-dict 422 details are printed; check -j prints a JSON error when mobilerun-functions is missing; show --version handles data: null.

4. Local device selection

I fixed the code to match the README: -P ios without -d now selects a local iOS device.

5. Files

  • os.link now falls back to an exclusive create on filesystems without hard links. Written files get the normal umask mode instead of 0600.
  • Buffering of uploads and downloads: I'm leaving that as is for now, since sandbox files are small today.

6. YAML

  • Explicit !!float/!!int tags now follow the YAML 1.2 rules, so !!float 1:30 no longer becomes 90.0.
  • PyYAML is now a direct dependency and is imported only when a routine command needs it.

Nits and open questions

  • The enqueue-failure message now names the routine ID.
  • Keyed runs: I checked this in triggers-api. A failed enqueue cannot return a successful response there. enqueue-execution.ts:26-38 writes the pending execution and the workflow.run.queued outbox event in one transaction with the request (run-flow.ts:123-125, flows.route.ts:382-397), so if either write fails the whole request fails. This holds for keyed and keyless runs. Later dispatch failures are execution outcomes, not a failed enqueue. So the CLI needs no extra execution read. It still handles enqueueFailed for older API responses.

Verification

You're right about the count. This round: uv run pytest tests -q -k cli → 1,314 passed, 4 failed (1,985 deselected). The same 4 tests fail on develop as well, and the PR description now lists them. Every fix has a regression test that fails without it.

Could you take another look?

@lutz-grex
lutz-grex requested a review from Cyro292 November 29, 2026 18:32

@Cyro292 Cyro292 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, the happy path looks good and the offline tests pass (799/799 on SDK 6.3.2). A few things to fix before merge:

Important

push crashes on a data: null version response (mobilerun/cli/function.py:639)
SDK 6.3.2 allows data: null when the version is read back. Right now that becomes an AttributeError, so the user never sees the function ID and version that were already created. They will likely push again and create a duplicate.
Fix: handle the missing record explicitly, and print both the function ID and the version ID so the user can inspect the upload instead of re-pushing.

Minor

Sandbox output loses ANSI sequences when redirected (mobilerun/cli/sandbox.py:180)
click.echo strips ANSI codes when stdout/stderr isn't a TTY, so mobilerun sandbox exec ... > out.log doesn't contain the exact remote output. The existing regression test covers trailing newlines, not exact stream content.
Fix: pass color=True for both remote streams, and add a test with escape sequences.

Misleading pending-validation hint (mobilerun/cli/function.py:173)
The hint tells users to rerun check --remote, but that starts a new validation instead of checking the printed ID.
Fix: drop the retry instruction, or point to a way to retrieve that validation ID. Please also update README.md:403 and :417 to distinguish pending --no-wait from exit 124, and describe the shared completion/log budget.

Structure

  • mobilerun/cli/options.py:742: file publishing and filesystem fallback logic (refuse_existing, write_file) now live in the Click options module. Please move them together into a small, focused CLI file utility.
  • mobilerun/cli/function.py:507: _print_function has one caller. Use the existing print_models with a single item instead.

@Cyro292 Cyro292 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Correction to my earlier review: I'm withdrawing the data: null point on push (mobilerun/cli/function.py:639). The server contract requires data, and a missing version returns 404, not 200 with data: null. Only the generated SDK type allows None, so the crash can't happen in practice.

Small remaining ask on that path: when polling the new version fails (404, network error), the SDK error path (function.py:552) prints the function ID but not the version number. Printing both would let users inspect the upload instead of pushing again.

The other minor points from my earlier review (ANSI output with color=True, the pending-validation hint plus the README, and moving the file helpers / replacing _print_function) are non-blocking. Approving.

lutz-grex and others added 2 commits December 4, 2026 09:47
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@lutz-grex
lutz-grex merged commit 8f35cb2 into develop Dec 4, 2026
9 checks passed
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.

3 participants