From 5bb9c8edb65cdd34257f67653f09354fb5a0d672 Mon Sep 17 00:00:00 2001 From: Antuz tap Date: Sat, 24 Oct 2026 09:27:34 +0000 Subject: [PATCH 1/2] ci: inspect current simulator bundle after failed clear-state launch --- .github/native/hosted_native.py | 31 ++- .github/native/ios_replacement_observation.py | 127 ++++++++++ .../native/ios_startup_command_observation.py | 39 ++- .../tests/test_ios_replacement_observation.py | 228 ++++++++++++++++++ .../SIMULATOR-POST-CLEARSTATE-OBSERVATIONS.md | 48 ++++ 5 files changed, 465 insertions(+), 8 deletions(-) create mode 100644 .github/native/ios_replacement_observation.py create mode 100644 .github/tests/test_ios_replacement_observation.py create mode 100644 docs/r5/SIMULATOR-POST-CLEARSTATE-OBSERVATIONS.md diff --git a/.github/native/hosted_native.py b/.github/native/hosted_native.py index 314a979ef..5fcaaf242 100644 --- a/.github/native/hosted_native.py +++ b/.github/native/hosted_native.py @@ -377,6 +377,15 @@ def ios_command_observation(): spec.loader.exec_module(observer) return observer.collect(PRIVATE, device) collect('command_observation', ios_command_observation) + def ios_replacement_observation(): + spec = importlib.util.spec_from_file_location('ios_replacement_observation', + Path(__file__).with_name('ios_replacement_observation.py')) + observer = importlib.util.module_from_spec(spec) + spec.loader.exec_module(observer) + return observer.collect(SimpleNamespace(PRIVATE=PRIVATE, PLATFORM=PLATFORM, + read=read, artifact_identity=artifact_identity, + _bundle_inventory=_bundle_inventory, owned_ios_bundle_path=owned_ios_bundle_path), device) + collect('replacement_observation', ios_replacement_observation) if PLATFORM == 'ANDROID' and device: def android_details(): args = ['adb', '-s', device, 'logcat', '-d', '-t', '300', '-v', 'brief', @@ -720,6 +729,21 @@ def _bundle_inventory(bundle): return tree, executable +def owned_ios_bundle_path(installed, device, built): + """The same exact owned container policy for acceptance and observations.""" + uuid = r'[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}' + if not re.fullmatch(uuid, device): + raise ValueError('Expected owned simulator UUID.') + installed = Path(installed) + base = Path.home() / 'Library/Developer/CoreSimulator/Devices' / device / 'data/Containers/Bundle/Application' + if (not installed.is_absolute() or installed.name != built.name or + not re.fullmatch(uuid, installed.parent.name) or + installed.parent.parent.resolve() != base.resolve() or + installed.resolve(strict=True).parent.parent != base.resolve()): + raise ValueError('Unexpected installed app container.') + return installed + + def verify_installed_artifact(device): """Attest owned installed bytes, never installation argv or app assertions.""" data = read() @@ -738,12 +762,7 @@ def verify_installed_artifact(device): original, executable = _bundle_inventory(built) installed = Path(command(['xcrun', 'simctl', 'get_app_container', device, APP_IDS['IOS'], 'app'], 'Locate owned installed app bundle', capture=True, error_details=False)) - base = Path.home() / 'Library/Developer/CoreSimulator/Devices' / device / 'data/Containers/Bundle/Application' - if (not installed.is_absolute() or installed.name != built.name or - not re.fullmatch(uuid, installed.parent.name) or - installed.parent.parent.resolve() != base.resolve() or - installed.resolve(strict=True).parent.parent != base.resolve()): - raise ValueError('Unexpected installed app container.') + installed = owned_ios_bundle_path(installed, device, built) actual, installed_executable = _bundle_inventory(installed) if original != actual or executable != installed_executable: raise ValueError('Installed bundle differs; no installer normalization is accepted.') diff --git a/.github/native/ios_replacement_observation.py b/.github/native/ios_replacement_observation.py new file mode 100644 index 000000000..5c913b799 --- /dev/null +++ b/.github/native/ios_replacement_observation.py @@ -0,0 +1,127 @@ +"""Read-only post-failure bundle observations; never repair or acceptance. + +Maestro clearState replaces the first installed instance. Inspect the remaining +owned instance after failure without a launch, retry or metadata promotion. +""" +import importlib.util +from pathlib import Path +import plistlib +import re +import subprocess +import tempfile + +APP = 'io.hexawallet.hexakeeper.dev' +LIMIT = 1024 * 1024 +UUID = r'[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}' + + +def query(private, args): + """Keep output in an unnamed private file; retain no command or raw text.""" + try: + with tempfile.TemporaryFile(dir=private) as output: + process = subprocess.run(args, stdout=output, stderr=subprocess.STDOUT, + timeout=20, check=False) + output.seek(0) + payload = output.read(LIMIT + 1) + if len(payload) > LIMIT: + return 'OVERSIZED', None + if process.returncode != 0: + return 'NONZERO_EXIT', None + return 'EXIT_ZERO', payload + except subprocess.TimeoutExpired: + return 'TIMEOUT', None + except OSError: + return 'UNAVAILABLE', None + + +def entitlement_state(payload): + """Compare types and complete effective values to the fixed signing policy.""" + try: + if type(payload) is not bytes or len(payload) > LIMIT: + return 'UNKNOWN' + begin, end = payload.find(b'') + if (begin < 0 or end < begin or payload.count(b'') != 1): + return 'UNKNOWN' + effective = plistlib.loads(payload[begin:end + len(b'')]) + spec = importlib.util.spec_from_file_location('observed_simulator_policy', + Path(__file__).with_name('simulator_signing.py')) + policy = importlib.util.module_from_spec(spec) + spec.loader.exec_module(policy) + if type(effective) is not dict: + return 'UNKNOWN' + return ('MATCH' if plistlib.dumps(effective, sort_keys=True) == + plistlib.dumps(policy.ENTITLEMENTS, sort_keys=True) else 'MISMATCH') + except Exception: + return 'UNKNOWN' + + +def unknown(stage='NOT_RUN'): + return {'schema': 1, 'state': 'UNKNOWN', 'stage': stage, + 'bytes': 'UNKNOWN', 'signature': 'UNKNOWN', 'identity': 'UNKNOWN', + 'entitlements': 'UNKNOWN', 'built_internal_links': None, + 'installed_internal_links': None, 'queries': {}, + 'scope': 'POST_FAILURE_CURRENT_INSTANCE_NOT_LAUNCH_CAUSE_OR_ACCEPTANCE'} + + +def collect(native, device): + result = unknown() + stage = 'DEVICE_POLICY' + try: + if (native.PLATFORM != 'IOS' or type(device) is not str or + not re.fullmatch(UUID, device)): + return unknown(stage) + stage = 'BUILT_ARTIFACT_STABILITY' + expected = native.read()['built_artifact'] + if native.artifact_identity() != expected: + return unknown(stage) + built = native.PRIVATE / 'DerivedData/Build/Products/Debug-iphonesimulator/hexa_keeper_dev.app' + stage = 'BUILT_INVENTORY' + original, executable = native._bundle_inventory(built) + get_container = ['xcrun', 'simctl', 'get_app_container', device, APP, 'app'] + stage = 'INSTALLED_CONTAINER_QUERY' + status, payload = query(native.PRIVATE, get_container) + result['queries']['container'] = status + if status != 'EXIT_ZERO': + return {**result, 'stage': stage} + stage = 'INSTALLED_CONTAINER_POLICY' + installed = native.owned_ios_bundle_path(payload.decode('utf-8').strip(), device, built) + stage = 'INSTALLED_INVENTORY' + actual, actual_executable = native._bundle_inventory(installed) + result['bytes'] = 'MATCH' if (original, executable) == (actual, actual_executable) else 'MISMATCH' + result['built_internal_links'] = sum(value[0] == 'link' for value in original.values()) + result['installed_internal_links'] = sum(value[0] == 'link' for value in actual.values()) + stage = 'SIGNATURE_QUERIES' + status, _ = query(native.PRIVATE, ['codesign', '--verify', '--deep', '--strict', str(installed)]) + result['queries']['signature'] = status + result['signature'] = ('VERIFIED' if status == 'EXIT_ZERO' else + 'NOT_VERIFIED' if status == 'NONZERO_EXIT' else 'UNKNOWN') + status, payload = query(native.PRIVATE, ['codesign', '--display', '--verbose=4', str(installed)]) + result['queries']['identity'] = status + if status == 'EXIT_ZERO': + lines = payload.decode('utf-8').splitlines() + result['identity'] = ('ADHOC' if 'Signature=adhoc' in lines and + not any(line.startswith('Authority=') for line in lines) else 'OTHER') + status, payload = query(native.PRIVATE, ['codesign', '--display', '--entitlements', ':-', str(installed)]) + result['queries']['entitlements'] = status + if status == 'EXIT_ZERO': + result['entitlements'] = entitlement_state(payload) + # All conclusions refer to one unchanged current instance and built input. + stage = 'FINAL_CONTAINER_QUERY' + status, payload = query(native.PRIVATE, get_container) + result['queries']['final_container'] = status + if status != 'EXIT_ZERO': + return unknown(stage) + final = native.owned_ios_bundle_path(payload.decode('utf-8').strip(), device, built) + stage = 'INSTALLED_STABILITY' + if final != installed or native._bundle_inventory(final) != (actual, actual_executable): + return unknown(stage) + stage = 'BUILT_ARTIFACT_STABILITY' + if native.artifact_identity() != expected: + return unknown(stage) + result.update(state='OBSERVED', stage='COMPLETE') + return result + except Exception: + # Unsupported/missing bundles and failed collectors supply no pass and + # never replace the original startup exception or export its message. + return unknown(stage) diff --git a/.github/native/ios_startup_command_observation.py b/.github/native/ios_startup_command_observation.py index eae0a650f..38ab7a559 100644 --- a/.github/native/ios_startup_command_observation.py +++ b/.github/native/ios_startup_command_observation.py @@ -31,6 +31,38 @@ 'SIMCTL_OPERATION_TEXT': r'An error was encountered processing the command', 'ASSERTION_TEXT': r'Assertion is false:|Element not found:', } +ERROR_DOMAINS = frozenset(('FBSOpenApplicationServiceErrorDomain', 'FBSOpenApplicationErrorDomain', + 'RBSRequestErrorDomain', 'RBSErrorDomain', 'NSPOSIXErrorDomain', 'NSCocoaErrorDomain', + 'NSOSStatusErrorDomain', 'NSMachErrorDomain')) + + +def launch_error_codes(error): + """Project exact simctl header pairs, without descriptions or interpretation.""" + result = {'state': 'UNKNOWN', 'pairs': [], 'scope': 'RECORDED_CODES_NOT_INTERPRETED_CAUSE'} + pairs = [] + if (type(error) is not dict or not set(error) <= {'message', 'debugMessage'} or + any(type(value) is not str or len(value) > 65536 for value in error.values())): + return result + pattern = (r'(?:An error was encountered processing the command|Underlying error) ' + r'\(domain=([A-Za-z][A-Za-z0-9.]{0,95}), code=(-?(?:0|[1-9][0-9]{0,9}))\):') + for text in error.values(): + for line in text.splitlines(): + if 'domain=' not in line and 'Error Domain=' not in line: + continue + match = re.fullmatch(pattern, line.strip(' \t')) + if not match or match[1] not in ERROR_DOMAINS: + return result + code = int(match[2]) + if not -(2 ** 31) <= code < 2 ** 31: + return result + pair = {'domain': match[1], 'code': code} + if pair not in pairs: + pairs.append(pair) + if len(pairs) > 8: + return result + if pairs: + result.update(state='RECORDED', pairs=pairs) + return result def unknown(): @@ -87,10 +119,13 @@ def commands(directory): if (type(evaluated) is not dict or set(evaluated) != {key} or type(evaluated[key]) is not dict or evaluated[key].get('appId') != APP): return result - rows.append({'sequence': sequence, 'kind': kind, + row = {'sequence': sequence, 'kind': kind, 'status': metadata['status'], 'error_markers': [label for label, pattern in ERROR_MARKERS.items() - if re.search(pattern, text, re.IGNORECASE)]}) + if re.search(pattern, text, re.IGNORECASE)]} + if kind == 'LAUNCH_APP' and metadata['status'] == 'FAILED': + row['launch_error_codes'] = launch_error_codes(error) + rows.append(row) result.update(state='RECORDED', rows=rows) except (OSError, ValueError, TypeError, RecursionError): pass diff --git a/.github/tests/test_ios_replacement_observation.py b/.github/tests/test_ios_replacement_observation.py new file mode 100644 index 000000000..657d19749 --- /dev/null +++ b/.github/tests/test_ios_replacement_observation.py @@ -0,0 +1,228 @@ +"""Real private-tree comparisons and fake read-only tools; no native credit.""" +import copy +import importlib.util +import json +from pathlib import Path +import plistlib +import shutil +import subprocess +import tempfile +from types import SimpleNamespace +import unittest +from unittest import mock + +NATIVE = Path(__file__).parents[1] / 'native' + + +def load(name): + spec = importlib.util.spec_from_file_location(name, NATIVE / (name + '.py')) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +observe = load('ios_replacement_observation') +hosted = load('hosted_native') +policy = load('simulator_signing') +commands = load('ios_startup_command_observation') +DEVICE = '12345678-1234-1234-1234-123456789ABC' +CONTAINER = 'ABCDEF12-1234-1234-1234-123456789ABC' + + +class ReplacementObservation(unittest.TestCase): + def setUp(self): + temporary = tempfile.TemporaryDirectory() + self.addCleanup(temporary.cleanup) + self.private = Path(temporary.name) + self.home = self.private / 'home' + self.built = self.private / 'DerivedData/Build/Products/Debug-iphonesimulator/hexa_keeper_dev.app' + self.built.mkdir(parents=True) + (self.built / 'Info.plist').write_bytes(plistlib.dumps({ + 'CFBundleIdentifier': observe.APP, 'CFBundleExecutable': 'hexa_keeper_dev'})) + (self.built / 'hexa_keeper_dev').write_bytes(b'PRIVATE_SENTINEL_EXECUTABLE') + (self.built / 'resource').write_text('PRIVATE_SENTINEL_RESOURCE') + (self.built / 'internal-link').symlink_to('resource') + self.installed = (self.home / 'Library/Developer/CoreSimulator/Devices' / DEVICE / + 'data/Containers/Bundle/Application' / CONTAINER / self.built.name) + shutil.copytree(self.built, self.installed, symlinks=True) + self.state = {'smoke': 'FAIL', 'installed_artifact_verified': True, + 'built_artifact': {'PRIVATE_SENTINEL': 'immutable'}} + self.original = copy.deepcopy(self.state) + self.native = SimpleNamespace(PLATFORM='IOS', PRIVATE=self.private, + read=lambda: self.state, artifact_identity=mock.Mock(return_value=self.state['built_artifact']), + _bundle_inventory=hosted._bundle_inventory, owned_ios_bundle_path=hosted.owned_ios_bundle_path) + + def tool(self, private, args): + self.assertEqual(private, self.private) + if args[:4] == ['xcrun', 'simctl', 'get_app_container', DEVICE]: + self.assertEqual(args[4:], [observe.APP, 'app']) + return 'EXIT_ZERO', str(self.installed).encode() + self.assertEqual(args[0], 'codesign') + self.assertEqual(args[-1], str(self.installed)) + if args[1:4] == ['--verify', '--deep', '--strict']: + return 'EXIT_ZERO', b'' + if args[1:3] == ['--display', '--verbose=4']: + return 'EXIT_ZERO', b'PRIVATE_SENTINEL\nSignature=adhoc\n' + self.assertEqual(args[1:4], ['--display', '--entitlements', ':-']) + return 'EXIT_ZERO', b'PRIVATE_SENTINEL\n' + plistlib.dumps(policy.ENTITLEMENTS) + + def collect(self, tool=None): + with mock.patch.object(hosted.Path, 'home', return_value=self.home), \ + mock.patch.object(observe, 'query', side_effect=tool or self.tool): + result = observe.collect(self.native, DEVICE) + self.assertEqual(self.state, self.original) + encoded = json.dumps(result) + for secret in ('PRIVATE_SENTINEL', str(self.private), observe.APP, DEVICE, 'KEEPERCI00'): + self.assertNotIn(secret, encoded) + return result + + def test_exact_current_instance_bytes_signature_entitlements_are_observed_without_promotion(self): + result = self.collect() + self.assertEqual((result['state'], result['stage']), ('OBSERVED', 'COMPLETE')) + self.assertEqual((result['bytes'], result['signature'], result['identity'], result['entitlements']), + ('MATCH', 'VERIFIED', 'ADHOC', 'MATCH')) + self.assertEqual((result['built_internal_links'], result['installed_internal_links']), (1, 1)) + self.assertIn('NOT_LAUNCH_CAUSE_OR_ACCEPTANCE', result['scope']) + + def test_real_link_and_file_mutation_remain_mismatch_with_no_equivalence_allowance(self): + (self.installed / 'internal-link').unlink() + (self.installed / 'internal-link').write_bytes(b'PRIVATE_SENTINEL_RESOURCE') + (self.installed / 'resource').write_text('changed') + result = self.collect() + self.assertEqual(result['bytes'], 'MISMATCH') + self.assertEqual((result['built_internal_links'], result['installed_internal_links']), (1, 0)) + + def test_missing_foreign_and_aliased_containers_are_unknown_and_not_inspected(self): + for target in (self.private / self.built.name, self.installed.parent / 'Foreign.app'): + with self.subTest(target=target.name): + def tool(private, args): + self.assertEqual(args[0], 'xcrun') + return 'EXIT_ZERO', str(target).encode() + result = self.collect(tool) + self.assertEqual((result['state'], result['stage']), ('UNKNOWN', 'INSTALLED_CONTAINER_POLICY')) + self.assertEqual(result['bytes'], 'UNKNOWN') + shutil.rmtree(self.installed) + self.assertEqual(self.collect()['stage'], 'INSTALLED_CONTAINER_POLICY') + + def test_built_drift_and_installed_drift_discard_all_conclusions(self): + self.native.artifact_identity.side_effect = [self.state['built_artifact'], {'changed': True}] + result = self.collect() + self.assertEqual((result['stage'], result['bytes']), ('BUILT_ARTIFACT_STABILITY', 'UNKNOWN')) + self.native.artifact_identity.side_effect = None + def changing(private, args): + answer = self.tool(private, args) + if args[1:3] == ['--display', '--entitlements']: + (self.installed / 'resource').write_text('changed during signature read') + return answer + result = self.collect(changing) + self.assertEqual((result['stage'], result['bytes'], result['signature']), + ('INSTALLED_STABILITY', 'UNKNOWN', 'UNKNOWN')) + + def test_replaced_container_or_failed_final_query_discards_all_conclusions(self): + replacement = self.installed.parent.parent / '11111111-1111-1111-1111-111111111111' / self.built.name + shutil.copytree(self.built, replacement, symlinks=True) + for status, payload in (('EXIT_ZERO', str(replacement).encode()), ('TIMEOUT', None)): + count = 0 + def changing(private, args): + nonlocal count + if args[0] == 'xcrun': + count += 1 + if count == 2: + return status, payload + return self.tool(private, args) + result = self.collect(changing) + self.assertEqual(result['state'], 'UNKNOWN') + self.assertEqual(result['bytes'], 'UNKNOWN') + self.assertEqual(result['stage'], 'INSTALLED_STABILITY' if status == 'EXIT_ZERO' else 'FINAL_CONTAINER_QUERY') + + def test_signature_tool_rejection_and_unavailable_entitlements_stay_explicit(self): + def rejected(private, args): + if args[:2] == ['codesign', '--verify']: + return 'NONZERO_EXIT', None + if args[1:3] == ['--display', '--entitlements']: + return 'TIMEOUT', None + return self.tool(private, args) + result = self.collect(rejected) + self.assertEqual((result['bytes'], result['signature'], result['entitlements']), + ('MATCH', 'NOT_VERIFIED', 'UNKNOWN')) + self.assertEqual(result['queries']['entitlements'], 'TIMEOUT') + + def test_effective_entitlements_require_complete_typed_policy_and_parseable_xml(self): + self.assertEqual(observe.entitlement_state(plistlib.dumps(policy.ENTITLEMENTS)), 'MATCH') + for changed in ({**policy.ENTITLEMENTS, 'get-task-allow': 1}, + {**policy.ENTITLEMENTS, 'private-extra': 'PRIVATE_SENTINEL'}, + {**policy.ENTITLEMENTS, 'keychain-access-groups': []}): + self.assertEqual(observe.entitlement_state(plistlib.dumps(changed)), 'MISMATCH') + for payload in (b'PRIVATE_SENTINEL', b'', b'x' * (observe.LIMIT + 1), + plistlib.dumps(policy.ENTITLEMENTS) * 2): + self.assertEqual(observe.entitlement_state(payload), 'UNKNOWN') + + def test_private_queries_are_read_only_bounded_timed_and_always_close_output(self): + captured = [] + def run(args, **kwargs): + self.assertEqual(args, ['codesign', '--verify', '--deep', '--strict', str(self.installed)]) + self.assertEqual(kwargs['timeout'], 20) + self.assertEqual(kwargs['stderr'], subprocess.STDOUT) + captured.append(kwargs['stdout']) + kwargs['stdout'].write(b'PRIVATE_SENTINEL') + return SimpleNamespace(returncode=0) + args = ['codesign', '--verify', '--deep', '--strict', str(self.installed)] + with mock.patch.object(observe.subprocess, 'run', side_effect=run): + self.assertEqual(observe.query(self.private, args), ('EXIT_ZERO', b'PRIVATE_SENTINEL')) + self.assertTrue(captured[0].closed) + for failure, state in ((subprocess.TimeoutExpired(args, 20), 'TIMEOUT'), + (OSError('PRIVATE_SENTINEL'), 'UNAVAILABLE')): + with mock.patch.object(observe.subprocess, 'run', side_effect=failure): + self.assertEqual(observe.query(self.private, args), (state, None)) + def oversized(args, **kwargs): + kwargs['stdout'].write(b'x' * (observe.LIMIT + 1)) + return SimpleNamespace(returncode=0) + with mock.patch.object(observe.subprocess, 'run', side_effect=oversized): + self.assertEqual(observe.query(self.private, args), ('OVERSIZED', None)) + self.assertEqual(sorted(path.name for path in self.private.iterdir()), ['DerivedData', 'home']) + + +class LaunchCodes(unittest.TestCase): + def test_exact_top_and_underlying_headers_export_only_allowlisted_pairs(self): + result = commands.launch_error_codes({'message': + 'An error was encountered processing the command (domain=FBSOpenApplicationServiceErrorDomain, code=1):\n' + 'PRIVATE_SENTINEL description\nUnderlying error (domain=NSOSStatusErrorDomain, code=-10814):\n' + 'PRIVATE_SENTINEL path'}) + self.assertEqual(result['state'], 'RECORDED') + self.assertEqual(result['pairs'], [{'domain': 'FBSOpenApplicationServiceErrorDomain', 'code': 1}, + {'domain': 'NSOSStatusErrorDomain', 'code': -10814}]) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(result)) + + def test_unsupported_ambiguous_overflow_and_excess_pairs_are_unknown_without_partial_values(self): + top = 'An error was encountered processing the command (domain=%s, code=%s):' + for message in (top % ('PRIVATE_SENTINEL', 1), top % ('NSPOSIXErrorDomain', '01'), + top % ('NSPOSIXErrorDomain', '2147483648'), top % ('NSPOSIXErrorDomain', '1.0'), + top % ('NSPOSIXErrorDomain', 1) + ' PRIVATE_SENTINEL', + '\u00a0' + top % ('NSPOSIXErrorDomain', 1), + 'Error Domain=NSPOSIXErrorDomain Code=1 PRIVATE_SENTINEL', + '\n'.join(top % ('NSPOSIXErrorDomain', number) for number in range(9))): + result = commands.launch_error_codes({'message': message}) + self.assertEqual((result['state'], result['pairs']), ('UNKNOWN', [])) + + def test_code_projection_only_attaches_to_recorded_failed_owned_launch(self): + with tempfile.TemporaryDirectory() as directory: + output = Path(directory) + flow = output / commands.FLOW + flow.mkdir() + message = 'Underlying error (domain=NSPOSIXErrorDomain, code=3):' + row = {'command': {'launchAppCommand': {'appId': commands.APP}}, + 'metadata': {'status': 'FAILED', 'sequenceNumber': 0, 'error': {'message': message}}} + path = flow / 'commands.json' + path.write_text(json.dumps([row])) + self.assertEqual(commands.commands(output)['rows'][0]['launch_error_codes']['state'], 'RECORDED') + row['metadata']['status'] = 'RUNNING' + path.write_text(json.dumps([row])) + self.assertNotIn('launch_error_codes', commands.commands(output)['rows'][0]) + row['metadata']['status'] = 'FAILED' + row['command']['launchAppCommand']['appId'] = 'PRIVATE_SENTINEL' + path.write_text(json.dumps([row])) + self.assertNotIn('launch_error_codes', commands.commands(output)['rows'][0]) + + +if __name__ == '__main__': + unittest.main() diff --git a/docs/r5/SIMULATOR-POST-CLEARSTATE-OBSERVATIONS.md b/docs/r5/SIMULATOR-POST-CLEARSTATE-OBSERVATIONS.md new file mode 100644 index 000000000..9934265fe --- /dev/null +++ b/docs/r5/SIMULATOR-POST-CLEARSTATE-OBSERVATIONS.md @@ -0,0 +1,48 @@ +# Post-clearState failure observations + +Frozen diagnostic source `bea6056724dd75d1db99f4ce394ba4896edd10bf` +observed an iOS `LAUNCH_APP` failure after Maestro's clear-state/reinstall, +permission-return and owned `simctl launch` invocation markers. The retained +FBS/operation flags do not identify an underlying error code or rejection cause. +The build/signature and initial installed-byte checks preceded Maestro's +clear-state replacement. They do not prove the replacement's integrity. + +This continuation adds only read-only failure observations. Before simulator +cleanup, it queries the exact owned current app container, reuses the existing +strict typed bundle inventory and compares every entry and executable to the +built app. It checks the current instance with `codesign --verify --deep +--strict`, observes ad-hoc identity, and compares complete typed effective +entitlements to the unchanged simulator signing policy. It also counts internal +links without exporting their targets. No bundle transformation is accepted as +equivalent. The existing container admission policy is extracted unchanged and +used by both the original acceptance comparison and this observer. + +The final container path and inventory must still match the inspected instance, +and the built artifact must still match the recorded input. A changed container, +inventory or built artifact discards conclusions. Missing, rejected, unsupported, +timed-out and unavailable inputs remain explicit unknown/query states. A +nonzero signature command means `NOT_VERIFIED`, not a diagnosed signing cause. +All tool output stays in unnamed private files with bounded reads and 20-second +query deadlines; the files close on success and failure. Paths, identifiers, +PIDs, plist values, signature text and error messages are not exported. + +The existing bound command reader additionally projects up to eight distinct +domain/integer pairs from exact simctl top/underlying error headers in a recorded +failed owned `LAUNCH_APP`. Only the reviewed Apple/OS domain vocabulary and +signed 32-bit integer codes leave the runner. Descriptions are discarded; +unsupported domains, syntax, conflicting shapes or overflow supply `UNKNOWN` +without partial pairs. These codes are observations, not interpreted causes. + +Pinned Maestro's Java copy algorithm does not preserve symlink identity in all +cases. Whether this actual app contained affected links, whether its replacement +changed, and why launch was rejected remain unknown until measured. This source +does not change signing, app code, the startup flow or timeouts; it performs no +retry or extra launch. The original failed smoke remains failed even if every +new observation succeeds or the observer itself fails. Initial installed-byte +metadata is not promoted or overwritten by this collector. + +Host-side controls use real temporary trees and fake read-only tools. Native +execution on this continuation is **NOT RUN**. The coordinator owns candidate +selection and the next isolated cloud-native window. No protected-base trust, +physical-device result, signing/distribution permission or release authority is +provided by these diagnostics. From c85b19213c0aacdcae43e47fd7dfea4dbe4ef57f Mon Sep 17 00:00:00 2001 From: Antuz tap Date: Sat, 24 Oct 2026 09:29:07 +0000 Subject: [PATCH 2/2] ci: fence typed built bundle across replacement observations --- .github/native/ios_replacement_observation.py | 3 ++- .github/tests/test_ios_replacement_observation.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/native/ios_replacement_observation.py b/.github/native/ios_replacement_observation.py index 5c913b799..d7b62088e 100644 --- a/.github/native/ios_replacement_observation.py +++ b/.github/native/ios_replacement_observation.py @@ -117,7 +117,8 @@ def collect(native, device): if final != installed or native._bundle_inventory(final) != (actual, actual_executable): return unknown(stage) stage = 'BUILT_ARTIFACT_STABILITY' - if native.artifact_identity() != expected: + if (native._bundle_inventory(built) != (original, executable) or + native.artifact_identity() != expected): return unknown(stage) result.update(state='OBSERVED', stage='COMPLETE') return result diff --git a/.github/tests/test_ios_replacement_observation.py b/.github/tests/test_ios_replacement_observation.py index 657d19749..7e0edf900 100644 --- a/.github/tests/test_ios_replacement_observation.py +++ b/.github/tests/test_ios_replacement_observation.py @@ -135,6 +135,19 @@ def changing(private, args): self.assertEqual(result['bytes'], 'UNKNOWN') self.assertEqual(result['stage'], 'INSTALLED_STABILITY' if status == 'EXIT_ZERO' else 'FINAL_CONTAINER_QUERY') + def test_same_byte_built_link_replacement_is_detected_by_final_typed_inventory(self): + def changing(private, args): + answer = self.tool(private, args) + if args[1:3] == ['--display', '--entitlements']: + link = self.built / 'internal-link' + content = link.read_bytes() + link.unlink() + link.write_bytes(content) + return answer + result = self.collect(changing) + self.assertEqual((result['state'], result['stage'], result['bytes']), + ('UNKNOWN', 'BUILT_ARTIFACT_STABILITY', 'UNKNOWN')) + def test_signature_tool_rejection_and_unavailable_entitlements_stay_explicit(self): def rejected(private, args): if args[:2] == ['codesign', '--verify']: