Skip to content

Comments

feat: added "apps foreground" command, improved tested coverage for iOS simulators.#165

Merged
gmegidish merged 7 commits intomainfrom
fix-improving-tests
Feb 2, 2026
Merged

feat: added "apps foreground" command, improved tested coverage for iOS simulators.#165
gmegidish merged 7 commits intomainfrom
fix-improving-tests

Conversation

@gmegidish
Copy link
Member

@gmegidish gmegidish commented Feb 2, 2026

Summary by CodeRabbit

  • New Features

    • Added apps foreground command and device APIs to report the currently foreground app (package, name, version).
    • New Makefile targets to build/run tests with coverage and an end-to-end test target.
  • Documentation

    • Expanded App Management docs with usage examples and updated agent capability descriptions.
  • Tests

    • Expanded end-to-end simulator tests, coverage collection, helper utilities, and new test script for simulator runs.
  • Chores

    • Ignore test/coverage directory in VCS.

@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

Warning

Rate limit exceeded

@gmegidish has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

Adds foreground-app retrieval across CLI, command layer, and device implementations; extends tests and tooling to run coverage-instrumented e2e simulator tests and documents new app-management commands. (44 words)

Changes

Cohort / File(s) Summary
CLI & Command Layer
cli/apps.go, cli/root.go, commands/apps.go
New apps foreground --device CLI command; adds ForegroundAppRequest and ForegroundAppCommand; registers command and updates help text. Verify CLI flag parsing and error handling paths.
Device Interface & Implementations
devices/common.go, devices/android.go, devices/ios.go, devices/simulator.go
Introduces ForegroundAppInfo type and GetForegroundApp() (*ForegroundAppInfo, error) on ControllableDevice; implements Android (adb dumpsys parsing), iOS (WDA + installed apps lookup), and Simulator versions. Review parsing robustness and platform-specific edge cases.
Tests — Types & Infrastructure
test/types.ts, test/server.ts, test/package.json
Adds TS response interfaces (UIDumpResponse, DeviceInfoResponse, ForegroundAppResponse); test server now spawns binary with GOCOVERDIR and creates unique coverage dirs; adds test-simulator npm script. Check coverage dir lifecycle and child-process cleanup.
Tests — Simulator & Emulator Helpers
test/simctl.ts, test/avdctl.ts, test/simulator.ts
Refactors emulator/simulator helpers (formatting, timeouts), narrows active iOS runtime list, and expands simulator e2e tests to exercise listing, launch/terminate cycles, foreground checks, UI dumps, and coverage wiring. Validate flakiness risk and timeouts.
Build & Repo
Makefile, .gitignore
Adds build-cover, updates test-cover dependency to build-cover, adds test-e2e target; .gitignore excludes test/coverage. Ensure Make targets and environment (GOCOVERDIR) align with CI.
Documentation
README.md
Adds App Management section and examples; updates feature list to include list and foreground-app commands. Confirm examples reflect actual CLI output format.

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main changes: adding a new 'apps foreground' CLI command and expanding test coverage for iOS simulators with comprehensive new tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-improving-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@README.md`:
- Line 78: In the README line that reads "`mobilecli` will automatically install
an agent on the device that is required for functions such as tapping on
elements, pressing buttons buttons and streaming screen capture.", remove the
duplicated word so it reads "pressing buttons" (i.e., change "pressing buttons
buttons" to "pressing buttons").

In `@test/server.ts`:
- Around line 25-29: The createCoverageDirectory function currently always makes
a random dir; change it to first check process.env.GOCOVERDIR and return that
path (creating it if needed) and only fall back to generating the random dir
(using path.join(__dirname, "cover-"+randomUUID())) when GOCOVERDIR is not set;
ensure you call mkdirSync on the chosen path (with recursive if required) before
returning. Update the identical pattern in test/simulator.ts (the function
at/around the coverage-dir creation) so both files respect GOCOVERDIR and create
the directory if missing.

In `@test/simctl.ts`:
- Around line 114-120: The cleanupSimulators function mutates createdSimulators
during forEach because deleteSimulator removes entries, which can skip items;
fix by iterating over a stable snapshot (e.g., use a shallow copy of
createdSimulators or iterate from the end) so each simulatorId is guaranteed to
be processed, calling shutdownSimulator(simulatorId) and
deleteSimulator(simulatorId) for every id, then clear createdSimulators.length =
0 as before; reference functions/variables: cleanupSimulators,
createdSimulators, shutdownSimulator, deleteSimulator.
🧹 Nitpick comments (2)
test/simulator.ts (2)

24-24: Consider making the iOS versions configurable.

Hard-coding only '26' risks skipping tests on most dev/CI hosts. Consider deriving from available runtimes or using an env var to keep coverage broad without editing the file.


78-148: Reduce flakiness by replacing fixed sleeps with polling.

Multiple tests rely on fixed delays (e.g., 10s/3s) which can be flaky across CI loads and device states. Consider polling foreground-app/UI state until ready or timeout.

Comment on lines +25 to +29
const createCoverageDirectory = (): string => {
const dir = path.join(__dirname, "cover-" + randomUUID());
mkdirSync(dir);
return dir;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, find and examine the test/server.ts file
fd "server.ts" test/

Repository: mobile-next/mobilecli

Length of output: 79


🏁 Script executed:

# Check if test/server.ts exists and examine the relevant lines
if [ -f "test/server.ts" ]; then
  wc -l "test/server.ts"
  echo "--- Lines 20-35 ---"
  sed -n '20,35p' "test/server.ts"
fi

Repository: mobile-next/mobilecli

Length of output: 506


🏁 Script executed:

# Search for startTestServer function to see if it sets GOCOVERDIR
rg "startTestServer" -A 10 -B 2

Repository: mobile-next/mobilecli

Length of output: 1201


🏁 Script executed:

# Look for GOCOVERDIR usage in the codebase
rg "GOCOVERDIR" -n

Repository: mobile-next/mobilecli

Length of output: 163


🏁 Script executed:

# Check for Makefile and coverage-related targets
fd "Makefile" . && echo "Found Makefile"

Repository: mobile-next/mobilecli

Length of output: 90


🏁 Script executed:

# Examine the Makefile for coverage-related targets
cat Makefile

Repository: mobile-next/mobilecli

Length of output: 763


🏁 Script executed:

# Check test/simulator.ts to see the similar GOCOVERDIR override pattern
sed -n '160,180p' "test/simulator.ts"

Repository: mobile-next/mobilecli

Length of output: 633


🏁 Script executed:

# Search for any coverage aggregation scripts or setup
rg "coverage" -n --type-list | grep -E "Makefile|\.sh|package.json"
fd "\.(sh|json)$" . | xargs grep -l "coverage" 2>/dev/null | head -20

Repository: mobile-next/mobilecli

Length of output: 454


🏁 Script executed:

# Check package.json to see how test-simulator is defined
fd "package.json" test/
cat test/package.json | grep -A 5 "test-simulator"

Repository: mobile-next/mobilecli

Length of output: 224


🏁 Script executed:

# Search for any scripts that might set GOCOVERDIR before running tests
rg "GOCOVERDIR" -B 5 -A 5

Repository: mobile-next/mobilecli

Length of output: 1032


🏁 Script executed:

# Check if there's any setup that pre-sets GOCOVERDIR in the e2e flow
grep -r "GOCOVERDIR" . --include="*.sh" --include="*.json" --include="*.ts" --include="*.js" --include="Makefile" 2>/dev/null | head -20

Repository: mobile-next/mobilecli

Length of output: 159


Respect a pre-set GOCOVERDIR environment variable for proper coverage aggregation.

The createCoverageDirectory function always generates a new random directory, which prevents the e2e coverage flow from working correctly. The Makefile's test-e2e target expects coverage data in test/coverage and uses go tool covdata textfmt -i=test/coverage to aggregate it, but coverage is instead written to random directories (e.g., test/cover-<UUID>). Check for a pre-set GOCOVERDIR environment variable first and use it if available; only generate a random directory as a fallback.

Note: This same pattern exists in test/simulator.ts at line 170 and should be updated consistently.

Proposed fix
-const createCoverageDirectory = (): string => {
-	const dir = path.join(__dirname, "cover-" + randomUUID());
-	mkdirSync(dir);
-	return dir;
-}
+const createCoverageDirectory = (): string => {
+	const envDir = process.env.GOCOVERDIR;
+	if (envDir) {
+		mkdirSync(envDir, {recursive: true});
+		return envDir;
+	}
+	const dir = path.join(__dirname, "cover-" + randomUUID());
+	mkdirSync(dir, {recursive: true});
+	return dir;
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const createCoverageDirectory = (): string => {
const dir = path.join(__dirname, "cover-" + randomUUID());
mkdirSync(dir);
return dir;
}
const createCoverageDirectory = (): string => {
const envDir = process.env.GOCOVERDIR;
if (envDir) {
mkdirSync(envDir, {recursive: true});
return envDir;
}
const dir = path.join(__dirname, "cover-" + randomUUID());
mkdirSync(dir, {recursive: true});
return dir;
}
🤖 Prompt for AI Agents
In `@test/server.ts` around lines 25 - 29, The createCoverageDirectory function
currently always makes a random dir; change it to first check
process.env.GOCOVERDIR and return that path (creating it if needed) and only
fall back to generating the random dir (using path.join(__dirname,
"cover-"+randomUUID())) when GOCOVERDIR is not set; ensure you call mkdirSync on
the chosen path (with recursive if required) before returning. Update the
identical pattern in test/simulator.ts (the function at/around the coverage-dir
creation) so both files respect GOCOVERDIR and create the directory if missing.

gmegidish and others added 4 commits February 2, 2026 15:56
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@gmegidish gmegidish merged commit ce49c3b into main Feb 2, 2026
15 checks passed
@gmegidish gmegidish deleted the fix-improving-tests branch February 2, 2026 19:50
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.

1 participant