Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ python scripts/build_and_test.py --get-warnings xcresult-20251018-143052
python scripts/build_and_test.py --get-log xcresult-20251018-143052
```

Add `--run` to build, install and launch in one call (`Launched: com.example.MyApp on iPhone 17 Pro (pid 4410)`). If Xcode's parallel test clones can't boot, `--test` reports `Tests: NOT RUN` instead of a misleading FAIL; `--no-parallel` runs tests on one simulator.

This keeps agent conversations focused — no walls of build output unless you ask for them.

### Simulator Navigation via Accessibility
Expand Down Expand Up @@ -234,7 +236,7 @@ Every script supports `--help` and `--json`. See **SKILL.md** for the complete r

| Script | What it does | Key flags |
|--------|-------------|-----------|
| `build_and_test.py` | Build Xcode projects, run tests, parse xcresult bundles | `--project`, `--scheme`, `--test`, `--get-errors`, `--get-warnings` |
| `build_and_test.py` | Build Xcode projects, run tests, parse xcresult bundles | `--project`, `--scheme`, `--test`, `--run`, `--no-parallel`, `--get-errors`, `--get-warnings` |
| `log_monitor.py` | Real-time log monitoring with severity filtering | `--app`, `--severity`, `--follow`, `--duration` |

#### Device State
Expand Down
2 changes: 1 addition & 1 deletion ios-simulator-skill/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ios-simulator-skill",
"version": "1.7.2",
"version": "1.8.0",
"description": "30 scripts for iOS app building, testing, and simulator automation. Semantic UI navigation via the accessibility tree, xcodebuild with progressive error disclosure, accessibility audits, hang detection, and simulator lifecycle management.",
"author": {
"name": "Conor Luddy"
Expand Down
2 changes: 1 addition & 1 deletion ios-simulator-skill/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ios-simulator-skill",
"version": "1.7.2",
"version": "1.8.0",
"description": "30 scripts for iOS app building, testing, and simulator automation. Semantic UI navigation via the accessibility tree, xcodebuild with progressive error disclosure, accessibility audits, hang detection, and simulator lifecycle management.",
"author": {
"name": "Conor Luddy",
Expand Down
6 changes: 4 additions & 2 deletions ios-simulator-skill/skills/ios-simulator-skill/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: ios-simulator-skill
version: 1.7.2
version: 1.8.0
description: Build, test, and drive iOS apps in the Simulator with 30 token-efficient scripts. Use when asked to build or test an Xcode project, launch an app on a simulator, tap/type/swipe through its UI by accessibility label, take screenshots or visual diffs, audit accessibility, read logs or diagnose hangs, or manage simulators (boot, erase, permissions, location, push, appearance). macOS only; needs Xcode, Python 3.12+ and idb.
---

Expand Down Expand Up @@ -52,7 +52,9 @@ Screenshots cost 1,600–6,300 tokens depending on size. The accessibility tree
- Build with live result streaming
- Parse errors and warnings from xcresult bundles
- Retrieve detailed build logs on demand
- Options: `--project`, `--scheme`, `--clean`, `--test`, `--verbose`, `--json`
- `--run` builds, installs and launches the app in one call: `Launched: <bundle> on <device> (pid N)`
- Tests that never started (parallel clone failed to boot) report `Tests: NOT RUN`, not FAIL; retry with `--no-parallel`
- Options: `--project`, `--scheme`, `--clean`, `--test`, `--run`, `--no-parallel`, `--verbose`, `--json`

2. **log_monitor.py** - Real-time log monitoring with intelligent filtering
- Stream logs or capture by duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,62 @@

import argparse
import sys
import time
from pathlib import Path

from app_launcher import AppLauncher

# Import our modular components
from common.env_config import env_int
from simctl_boot import SimulatorBooter

from xcode import BuildRunner, OutputFormatter, XCResultCache, XCResultParser
from xcode.reporter import is_runner_failure

BUILD_LOG_PREVIEW_CHARS = env_int("IOS_SIM_BUILD_LOG_PREVIEW", 4000)
BUILD_JSON_CAP = env_int("IOS_SIM_BUILD_JSON_CAP", 50)
LAUNCH_RETRY_DELAY_S = 1.0


def run_built_app(builder: BuildRunner) -> tuple[dict | None, str]:
"""Install and launch the app a successful build produced.

Returns (run info, message): info is None on failure and the message is one line
naming the failed step and what to do next.
"""
built_app = builder.get_built_app()
if not built_app:
return None, f"Run failed: no .app target in scheme {builder.scheme} (is it a framework?)"
app_path, bundle_id = built_app

udid = builder.get_destination_udid()
if not udid:
return (
None,
"Run failed: no simulator to run on; pass --simulator '<name>' (see sim_list.py)",
)

booted, boot_message = SimulatorBooter(udid).boot(wait_ready=True)
if not booted and "Booted" not in boot_message:
return None, f"Run failed: could not boot {udid}: {boot_message}"

launcher = AppLauncher(udid)
if not launcher.install(app_path):
return None, f"Run failed: could not install {app_path}; retry or try --clean"
launched, pid = launcher.launch(bundle_id)
if not launched:
# Seen once right after a fresh install; a second attempt succeeded.
time.sleep(LAUNCH_RETRY_DELAY_S)
launched, pid = launcher.launch(bundle_id)
if not launched:
return None, f"Run failed: installed {bundle_id} but launch failed; check log_monitor.py"

device_name = builder._extract_simulator_name_from_destination(
builder.get_simulator_destination()
)
pid_text = f"pid {pid}" if pid else "pid unknown"
info = {"bundle_id": bundle_id, "app_path": app_path, "udid": udid, "pid": pid}
return info, f"Launched: {bundle_id} on {device_name} ({pid_text})"


def main():
Expand Down Expand Up @@ -92,6 +139,14 @@ def main():
build_group.add_argument("--clean", action="store_true", help="Clean before building")
build_group.add_argument("--test", action="store_true", help="Run tests")
build_group.add_argument("--suite", help="Specific test suite to run")
build_group.add_argument(
"--run", action="store_true", help="After a successful build, install and launch the app"
)
build_group.add_argument(
"--no-parallel",
action="store_true",
help="Run tests on one simulator (no parallel clones)",
)

# Progressive disclosure arguments
disclosure_group = parser.add_argument_group("Progressive Disclosure Options")
Expand All @@ -117,6 +172,9 @@ def main():
output_group.add_argument("--json", action="store_true", help="Output as JSON")

args = parser.parse_args()
if args.run and args.test:
print("Error: --run builds and launches the app; it can't be combined with --test")
return 1

# Initialize cache
cache = XCResultCache()
Expand Down Expand Up @@ -248,7 +306,9 @@ def main():

# Execute build or test
if args.test:
success, xcresult_id, stderr = builder.test(test_suite=args.suite)
success, xcresult_id, stderr = builder.test(
test_suite=args.suite, parallel=not args.no_parallel
)
else:
success, xcresult_id, stderr = builder.build(clean=args.clean)

Expand Down Expand Up @@ -297,6 +357,14 @@ def main():
if not success:
failed_tests = parser.get_failed_tests()

runner_failed = args.test and not success and is_runner_failure(errors, test_info)

run_info = None
run_message = None
if args.run and success:
run_info, run_message = run_built_app(builder)
success = run_info is not None

if args.verbose:
# Verbose mode with error/warning details
verbose_errors = errors if error_count > 0 else None
Expand Down Expand Up @@ -327,6 +395,12 @@ def main():
data["errors"] = errors[:BUILD_JSON_CAP]
if failed_tests:
data["failed_tests"] = failed_tests[:BUILD_JSON_CAP]
if runner_failed:
data["status"] = "not_run"
if run_info:
data["run"] = run_info
elif run_message:
data["run_error"] = run_message
if hints:
data["hints"] = hints
import json
Expand All @@ -343,8 +417,11 @@ def main():
hints=hints,
errors=errors,
failed_tests=failed_tests,
runner_failed=runner_failed,
)
print(output)
if run_message and not args.json:
print(run_message)

# Exit with appropriate code
return 0 if success else 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,32 +167,68 @@ def _find_simulator_os(self, name: str, os_version: str | None = None) -> str |

With os_version, only that runtime counts. None when no device matches.
"""
device = self._find_simulator(name, os_version)
return device[0] if device else None

def _find_simulator(self, name: str, os_version: str | None = None) -> tuple[str, str] | None:
"""Return (iOS version, udid) of the newest available device named exactly `name`."""
matches = [
(version, device.get("udid", ""))
for version, device in _available_ios_devices()
if device.get("name") == name and (not os_version or version == os_version)
]
if not matches:
return None
return max(matches, key=lambda match: _version_key(match[0]))

def get_destination_udid(self) -> str | None:
"""Return the UDID of the simulator the destination names, or None if generic/unknown."""
destination = self.get_simulator_destination()
name = self._extract_simulator_name_from_destination(destination)
if not name:
return None
os_match = re.search(r"OS=([^,]+)", destination)
device = self._find_simulator(name, os_match.group(1).strip() if os_match else None)
return device[1] if device and device[1] else None

def get_built_app(self) -> tuple[str, str] | None:
"""Return (app path, bundle ID) of the scheme's .app product, or None if there isn't one."""
cmd = ["xcodebuild", "-showBuildSettings", "-json", *self._project_args()]
cmd.extend(
[
"-scheme",
self.scheme or "",
"-configuration",
self.configuration,
"-destination",
self.get_simulator_destination(),
]
)
try:
result = subprocess.run(
["xcrun", "simctl", "list", "devices", "available", "-j"],
capture_output=True,
text=True,
check=True,
timeout=INTROSPECT_TIMEOUT,
cmd, capture_output=True, text=True, check=True, timeout=INTROSPECT_TIMEOUT
)
runtimes = json.loads(result.stdout).get("devices", {})
targets = json.loads(result.stdout)
except (subprocess.SubprocessError, OSError, json.JSONDecodeError):
return None

matching_versions = []
for runtime_id, devices in runtimes.items():
version_match = re.search(r"SimRuntime\.iOS-([\d-]+)$", runtime_id)
if not version_match:
continue
version = version_match.group(1).replace("-", ".")
if os_version and version != os_version:
for target in targets:
settings = target.get("buildSettings", {})
if settings.get("WRAPPER_EXTENSION") != "app":
continue
if any(device.get("name") == name for device in devices):
matching_versions.append(version)
build_dir = settings.get("TARGET_BUILD_DIR")
product = settings.get("FULL_PRODUCT_NAME")
bundle_id = settings.get("PRODUCT_BUNDLE_IDENTIFIER")
if build_dir and product and bundle_id:
return (str(Path(build_dir) / product), bundle_id)
return None

if not matching_versions:
return None
return max(matching_versions, key=lambda v: tuple(int(part) for part in v.split(".")))
def _project_args(self) -> list[str]:
if self.workspace_path:
return ["-workspace", self.workspace_path]
if self.project_path:
return ["-project", self.project_path]
return []

def _extract_simulator_name_from_destination(self, destination: str) -> str | None:
"""
Expand Down Expand Up @@ -351,12 +387,13 @@ def build(self, clean: bool = False) -> tuple[bool, str, str]:
print(f"Error executing build: {e}", file=sys.stderr)
return (False, "", str(e))

def test(self, test_suite: str | None = None) -> tuple[bool, str, str]:
def test(self, test_suite: str | None = None, parallel: bool = True) -> tuple[bool, str, str]:
"""
Run tests.

Args:
test_suite: Specific test suite to run
parallel: False runs tests on one simulator (-parallel-testing-enabled NO)

Returns:
Tuple of (success: bool, xcresult_id: str, stderr: str)
Expand Down Expand Up @@ -396,6 +433,8 @@ def test(self, test_suite: str | None = None) -> tuple[bool, str, str]:

if test_suite:
cmd.extend(["-only-testing", test_suite])
if not parallel:
cmd.extend(["-parallel-testing-enabled", "NO"])

# Execute tests
try:
Expand Down Expand Up @@ -437,3 +476,33 @@ def test(self, test_suite: str | None = None) -> tuple[bool, str, str]:
except Exception as e:
print(f"Error executing tests: {e}", file=sys.stderr)
return (False, "", str(e))


# === HELPERS ===


def _available_ios_devices() -> list[tuple[str, dict]]:
"""Return (iOS version, device) for every available simulator; empty if simctl fails."""
try:
result = subprocess.run(
["xcrun", "simctl", "list", "devices", "available", "-j"],
capture_output=True,
text=True,
check=True,
timeout=INTROSPECT_TIMEOUT,
)
runtimes = json.loads(result.stdout).get("devices", {})
except (subprocess.SubprocessError, OSError, json.JSONDecodeError):
return []

devices = []
for runtime_id, runtime_devices in runtimes.items():
version_match = re.search(r"SimRuntime\.iOS-([\d-]+)$", runtime_id)
if version_match:
version = version_match.group(1).replace("-", ".")
devices.extend((version, device) for device in runtime_devices)
return devices


def _version_key(version: str) -> tuple[int, ...]:
return tuple(int(part) for part in version.split("."))
Loading
Loading