From ba42f60de6309db949ff9fc9f8dfd74b72360079 Mon Sep 17 00:00:00 2001 From: showxu <10173746+showxu@users.noreply.github.com> Date: Fri, 23 Oct 2026 21:14:09 +0800 Subject: [PATCH] fix(apple): download a simulator runtime only when none matches --- README.md | 2 +- scripts/run-validation.py | 13 ++++++++++--- tests/test_config.py | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ce16d53..12e9f5c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ checks are exactly **`policy / policy`** and | `compiler` | Each compiler runs every test configuration and a release build for every declared trait set. Verifies the selected Swift version. | | `format` | Strict recursive Swift formatting using the repository's `.swift-format`, on the last compiler. | | `linux` | Runs tests in each digest-pinned Swift Docker image. | -| `apple` | Builds each generic iOS, tvOS, watchOS or visionOS destination, skipping plugin and macro validation for non-interactive CI. Optional tests download the SDK-matching runtime and create/delete a matching simulator. | +| `apple` | Builds each generic iOS, tvOS, watchOS or visionOS destination, skipping plugin and macro validation for non-interactive CI. Optional tests use the SDK-matching simulator runtime, downloading it only when the runner lacks it, and create/delete a matching simulator. | | `docs` | Builds the whole package once, emitting public symbol graphs with extension blocks, then converts each target's DocC archive with warnings as errors. | | `demo` | Builds the release executable and checks a fresh terminal recording through the presentation action's recording-only mode. | | `commands` | Runs each repository command in its own job in the member checkout. | diff --git a/scripts/run-validation.py b/scripts/run-validation.py index 0e102a1..a95b6dc 100755 --- a/scripts/run-validation.py +++ b/scripts/run-validation.py @@ -34,10 +34,17 @@ def simulator(entry, root, environment): sdk = {'iOS': 'iphonesimulator', 'tvOS': 'appletvsimulator', 'watchOS': 'watchsimulator', 'visionOS': 'xrsimulator'}[platform] expected = run(['xcrun', '--sdk', sdk, '--show-sdk-version'], root, environment, capture=True).strip() - run([*XCODEBUILD, '-downloadPlatform', platform], root, environment) - inventory = json.loads(run(['xcrun', 'simctl', 'list', '-j'], root, environment, capture=True)) - runtimes = [item for item in inventory['runtimes'] if item.get('isAvailable') + + def matching(): + inventory = json.loads(run(['xcrun', 'simctl', 'list', '-j'], root, environment, capture=True)) + return [item for item in inventory['runtimes'] if item.get('isAvailable') and item['name'].startswith(platform + ' ') and item['version'] == expected] + + # Runner images preinstall the runtime that matches their Xcode; download only when it is absent. + runtimes = matching() + if not runtimes: + run([*XCODEBUILD, '-downloadPlatform', platform], root, environment) + runtimes = matching() if not runtimes: raise ValueError('No available simulator runtime matching ' + platform + ' ' + expected) runtime = runtimes[-1] diff --git a/tests/test_config.py b/tests/test_config.py index 3c150df..f4ee692 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -128,6 +128,41 @@ def test_format_rejects_missing_option_and_escaping_paths_before_running(self): runner.execute(self.root, 'format', {}, self.config) run.assert_not_called() + def test_simulator_uses_an_installed_runtime_without_downloading(self): + inventory = json.dumps({'runtimes': [{ + 'isAvailable': True, 'name': 'iOS 26.5', 'version': '26.5', + 'identifier': 'com.apple.CoreSimulator.SimRuntime.iOS-26-5', + 'supportedDeviceTypes': [{'name': 'iPhone 17', 'identifier': 'iPhone-17'}]}]}) + + def respond(command, cwd, environment, capture=False): + if '--show-sdk-version' in command: + return '26.5\n' + if command[:3] == ['xcrun', 'simctl', 'list']: + return inventory + return 'device-id\n' + + with patch.object(runner, 'run', side_effect=respond) as run: + device = runner.simulator({'platform': 'iOS'}, self.root, {}) + self.assertEqual(device, 'device-id') + self.assertFalse(any('-downloadPlatform' in call.args[0] for call in run.call_args_list)) + + def test_simulator_downloads_the_platform_only_when_no_runtime_matches(self): + listings = iter([json.dumps({'runtimes': []}), json.dumps({'runtimes': [{ + 'isAvailable': True, 'name': 'iOS 26.5', 'version': '26.5', 'identifier': 'runtime', + 'supportedDeviceTypes': [{'name': 'iPhone 17', 'identifier': 'iPhone-17'}]}]})]) + + def respond(command, cwd, environment, capture=False): + if '--show-sdk-version' in command: + return '26.5\n' + if command[:3] == ['xcrun', 'simctl', 'list']: + return next(listings) + return 'device-id\n' + + with patch.object(runner, 'run', side_effect=respond) as run: + runner.simulator({'platform': 'iOS'}, self.root, {}) + downloads = [call.args[0] for call in run.call_args_list if '-downloadPlatform' in call.args[0]] + self.assertEqual(len(downloads), 1) + def test_compiler_runs_every_test_configuration_and_builds_every_trait(self): self.config.update(test_configurations=['debug', 'release'], traits=[['default'], ['Feature', 'default'], []], build_system='native', environment={'VALUE': 'declared'}) with patch.object(runner, 'run') as run: @@ -189,7 +224,7 @@ def execute(command, *args, **kwargs): entry = {**self.config['platforms']['apple'][0], 'test': tests} runner.execute(self.root, 'apple', entry, self.config) commands = [call.args[0] for call in run.call_args_list if call.args[0][0] == 'xcodebuild'] - self.assertEqual(len(commands), 3 if tests else 1) + self.assertEqual(len(commands), 2 if tests else 1) self.assertIn('generic/platform=iOS', commands[0]) for command in commands: self.assertIn('-skipPackagePluginValidation', command)