From 76d1c949d91c5d885fc002f689a9ec321c16eafb Mon Sep 17 00:00:00 2001 From: antuz123 <43998049+antuz123@users.noreply.github.com> Date: Fri, 23 Oct 2026 02:29:03 +0530 Subject: [PATCH] Observe iOS startup without changing app execution --- .github/native/hosted_native.py | 35 +++- .github/native/startup_diagnosis.py | 95 +++++++++-- .github/native/startup_observer.cjs | 3 +- .github/tests/startup-observer.test.cjs | 19 +++ .github/tests/test_ios_startup_diagnostics.py | 79 ++++++++++ .github/tests/test_startup_diagnosis.py | 149 ++++++++++++++++++ .github/tests/test_startup_integration.py | 34 +++- docs/r5-ios-startup-observation.md | 76 +++++++++ 8 files changed, 465 insertions(+), 25 deletions(-) create mode 100644 .github/tests/test_ios_startup_diagnostics.py create mode 100644 docs/r5-ios-startup-observation.md diff --git a/.github/native/hosted_native.py b/.github/native/hosted_native.py index dd537e829..593eea0db 100644 --- a/.github/native/hosted_native.py +++ b/.github/native/hosted_native.py @@ -174,8 +174,21 @@ def ios_startup_diagnostics(payload, executable): pattern = re.compile(r'^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d+)?' r'(?:[+-]\d{2}:?\d{2}|Z)?\s+(\S+)\s+' r'([A-Za-z0-9_.-]+)\[\d+:[A-Fa-f0-9x]+\]\s+(.*)$') - selected = [] - matched = 0 + patterns = { + 'JS_TYPE': r'\bTypeError\b', 'JS_REFERENCE': r'\bReferenceError\b', + 'JS_SYNTAX': r'\bSyntaxError\b', 'JS_RANGE': r'\bRangeError\b', + 'JS_INVARIANT': r'Invariant Violation|has not been registered', + 'REACT_FATAL': r'\bRCTFatal\b|Unhandled JS Exception|\bRCTExceptionsManager\b|Exception in HostFunction', + 'OBJC_EXCEPTION': r'\bNS(?:InvalidArgument|InternalInconsistency|Range|Generic|Malloc)?Exception\b|terminating app due to uncaught exception', + 'NATIVE_MODULE': r'TurboModuleRegistry.*could not be found|Native module cannot be null|Cannot find native module', + 'NATIVE_LIBRARY': r'Library not loaded|Symbol not found|dyld.*(?:not found|failed|error)', + 'HERMES_EXCEPTION': r'hermes.*(?:exception|fatal|error|failed)|(?:exception|fatal|error).*hermes', + 'BUNDLE_LOAD': r'No script URL provided|No bundle URL present|Unable to load script|(?:Could not|Failed to) load bundle|Could not connect to development server', + 'ATS_BLOCKED': r'App Transport Security.*(?:blocked|requires)|NSURLErrorDomain.*-1022\b', + 'CONNECTION': r'ECONNREFUSED|Connection refused|NSURLErrorDomain.*-(?:1001|1003|1004|1009)\b|The Internet connection appears to be offline', + } + selected, counts = [], {name: 0 for name in patterns} + matched, errors, classified = 0, 0, 0 for line in payload.splitlines(): match = pattern.match(line) if not match: @@ -184,13 +197,23 @@ def ios_startup_diagnostics(payload, executable): if process != executable: continue matched += 1 - if severity.lower() in ['e', 'f', 'er', 'ft', 'error', 'fault'] or re.search( + found = [name for name, regex in patterns.items() if re.search(regex, message, re.IGNORECASE)] + if found or severity.lower() in ['e', 'f', 'er', 'ft', 'error', 'fault'] or re.search( r'(?:\b(?:error|exception|fatal)\b|\b[\w.$]*(?:Exception|Error)\b)', message, re.IGNORECASE): if not selected: selected.append('IOS_STARTUP_ERROR') + errors += 1 + classified += bool(found) + for name in found: + counts[name] += 1 return {'format': 'compact', 'matching_process_records': matched, - 'errors': selected} + 'errors': selected, 'observation_state': 'OWN_RECORDS_OBSERVED' if matched else 'UNKNOWN', + 'error_records': errors, 'classified_error_records': classified, + 'unclassified_error_records': errors - classified, + 'categories': [name for name, count in counts.items() if count], + 'category_record_counts': counts, + 'scope': 'Fixed markers in prefixed own-process records; marker presence is not failure-cause or crash proof.'} def startup_hierarchy_signals(directory): @@ -405,7 +428,7 @@ def ios_details(): code = result.returncode except subprocess.TimeoutExpired: code = 124 - result = {'command': args, 'exit_code': code, 'errors': []} + result = {'command': args, 'exit_code': code, 'errors': [], 'observation_state': 'UNKNOWN'} if code == 0: try: payload, truncated = private_log_prefix(path) @@ -1004,7 +1027,7 @@ def smoke(suite='startup'): try: if is_probe or is_features: metro_args += ['--config', str(ROOT / ('.github/native/r5_metro.cjs' if is_features else '.github/native/release_metro.cjs'))] - elif PLATFORM == 'ANDROID': + elif PLATFORM in ['ANDROID', 'IOS']: # Observation retains the normal entrypoint/resolver/transformer and # response body. Only fixed facts leave the disposable launch window. spec = importlib.util.spec_from_file_location('startup_diagnosis', Path(__file__).with_name('startup_diagnosis.py')) diff --git a/.github/native/startup_diagnosis.py b/.github/native/startup_diagnosis.py index ac90ebd45..6acf3f48f 100644 --- a/.github/native/startup_diagnosis.py +++ b/.github/native/startup_diagnosis.py @@ -1,5 +1,6 @@ -"""Private launch-window capture and fixed Android startup facts only.""" +"""Private startup observations; no raw device or application text escapes.""" import json +from itertools import islice import os import re import subprocess @@ -27,8 +28,10 @@ def categories(text): def _device(native, device): - if native.PLATFORM != 'ANDROID' or not re.fullmatch(r'emulator-\d+', device): - raise ValueError('Expected owned Android emulator.') + patterns = {'ANDROID': r'emulator-\d+', + 'IOS': r'[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}'} + if native.PLATFORM not in patterns or not re.fullmatch(patterns[native.PLATFORM], device): + raise ValueError('Expected owned disposable device selector.') def _read(native, path): @@ -52,6 +55,10 @@ def start(native, device): _device(native, device) native.PRIVATE.mkdir(parents=True, exist_ok=True) started_ms = int(time.time() * 1000) + if native.PLATFORM == 'IOS': + # Timestamp only. The original Maestro command owns app launch; no new + # native process, launch, PID query or log-capture lifecycle is added. + return Capture(None, None, started_ms) output = (native.PRIVATE / 'startup-logcat.log').open('wb') tags = ['AndroidRuntime:V', 'ReactNativeJS:V', 'ReactNative:V', 'ReactHost:V', 'unknown:ReactHost:V', 'unknown:ReactNative:V', 'unknown:BridgelessReact:V', @@ -67,7 +74,7 @@ def start(native, device): def stop(handle): - if handle is None: + if handle is None or handle.process is None: return try: if handle.process.poll() is None: @@ -84,9 +91,18 @@ def stop(handle): def hierarchy(native, directory): flags = {'credential_error': False, 'retry': False, 'logbox_controls': False, 'redbox_resource': False, 'loading': False, 'snapshot_count': 0} - for path in list(directory.glob('**/screen-hierarchy/step-*.json'))[:8]: + if native.PLATFORM == 'IOS': + flags.update(login=False, welcome_back=False, logbox_error_header=False, + logbox_warning_header=False, logbox_syntax_footer=False, logbox_counter=False) + paths = (list(islice(directory.glob('**/screen-hierarchy/step-*.json'), 9)) if native.PLATFORM == 'IOS' + else list(directory.glob('**/screen-hierarchy/step-*.json'))[:8]) + if native.PLATFORM == 'IOS' and len(paths) > 8: + raise ValueError('Hierarchy snapshot count exceeded limit.') + for path in paths: text, truncated = _read(native, path) if truncated: + if native.PLATFORM == 'IOS': + raise ValueError('Incomplete bounded hierarchy snapshot.') continue pending = [json.loads(text)] count, dismiss, minimize = 0, False, False @@ -95,8 +111,9 @@ def hierarchy(native, directory): count += 1 if count > 10000 or not isinstance(node, dict): raise ValueError('Invalid bounded hierarchy.') - attrs = node.get('attributes') or {} - if not isinstance(attrs, dict) or not isinstance(node.get('children', []), list): + attrs = node.get('attributes', {}) if native.PLATFORM == 'IOS' else node.get('attributes') or {} + children = node.get('children', []) + if not isinstance(attrs, dict) or not isinstance(children, list): raise ValueError('Invalid hierarchy shape.') resource = attrs.get('resource-id', '') flags['redbox_resource'] |= isinstance(resource, str) and resource.rsplit(':id/', 1)[-1] in LOGBOX_IDS @@ -107,7 +124,20 @@ def hierarchy(native, directory): flags['loading'] |= value in ['please wait', 'loading'] dismiss |= value == 'Dismiss' minimize |= value == 'Minimize' - pending.extend(node.get('children', [])) + if native.PLATFORM == 'IOS' and isinstance(value, str): + value = value.strip() + flags['credential_error'] |= value == 'Unable to check your passcode. Please try again.' + flags['retry'] |= value == 'Retry' + flags['loading'] |= value in ['please wait', 'loading'] + dismiss |= value == 'Dismiss' + minimize |= value == 'Minimize' + flags['login'] |= value == 'Enter your passcode' + flags['welcome_back'] |= value == 'Welcome Back' + flags['logbox_error_header'] |= value in ['Console Error', 'Uncaught Error', 'Syntax Error', 'Render Error', 'Failed to compile'] + flags['logbox_warning_header'] |= value == 'Console Warning' + flags['logbox_syntax_footer'] |= value == 'This error cannot be dismissed.' + flags['logbox_counter'] |= bool(re.fullmatch(r'Log [1-9]\d* of [1-9]\d*', value)) + pending.extend(children) flags['snapshot_count'] += 1 flags['logbox_controls'] |= dismiss and minimize return flags @@ -116,7 +146,9 @@ def hierarchy(native, directory): def collect(native, device, handle=None): _device(native, device) started_ms = handle.started_ms if handle is not None else None - facts = {'scope': 'Owned emulator launch window; fixed facts only.', 'collection_errors': []} + facts = {'scope': ('Owned simulator startup window; fixed observations, not app-process or cause proof.' + if native.PLATFORM == 'IOS' else 'Owned emulator launch window; fixed facts only.'), + 'collection_errors': []} def collect_one(name, action): try: facts[name] = action() @@ -130,7 +162,8 @@ def observer(): # Fixed rows are regenerated, never forwarded from a writable JSON file. text, truncated = _read(native, native.PRIVATE / 'startup-observer.jsonl') rows, invalid = [], 0 - for line in text.splitlines()[:1024]: + lines = text.splitlines() + for line in lines[:1024]: if not line.strip(): continue try: @@ -143,7 +176,11 @@ def observer(): if (kind == 'BUILD' and row.get('event') in ['bundle_build_started', 'bundle_build_done', 'bundle_build_failed']) or (kind == 'ERROR' and row.get('event') in ['bundling_error', 'initialize_failed', 'transformer_load_failed', 'hmr_client_error', 'cache_read_error', 'cache_write_error', 'worker_stderr_chunk']): result.update(kind=kind, event=row['event']) result['error_type'] = row.get('error_type') if row.get('error_type') in ['SyntaxError', 'TypeError', 'ReferenceError', 'RangeError', 'TransformError', 'UnableToResolveError', 'ResolutionError', 'AmbiguousModuleResolutionError', 'NotFoundError', 'ResourceNotFoundError', 'GraphNotFoundError', 'RevisionNotFoundError', 'OTHER', None] else 'OTHER' - result['categories'] = [item for item in ['MODULE_RESOLUTION', 'SYNTAX', 'TYPE', 'REFERENCE', 'MEMORY', 'TRANSFORM', 'CONNECTION'] if item in row.get('categories', [])] + categories = row.get('categories', []) + if native.PLATFORM == 'IOS' and (type(categories) is not list or + any(type(item) is not str for item in categories)): + raise ValueError('Invalid observation categories.') + result['categories'] = [item for item in ['MODULE_RESOLUTION', 'SYNTAX', 'TYPE', 'REFERENCE', 'MEMORY', 'TRANSFORM', 'CONNECTION'] if item in categories] elif kind in ['REQUEST', 'RESPONSE'] and row.get('request') in ['ENTRY_BUNDLE', 'SPLIT_BUNDLE', 'SYMBOLICATE']: result.update(kind=kind, request=row['request']) if kind == 'REQUEST': @@ -159,8 +196,19 @@ def observer(): rows.append(result) except Exception: invalid += 1 - return {'rows': rows[:512], 'input_truncated': truncated, 'invalid_rows': invalid, - 'scope': 'Outer HTTP status only; multipart terminal status is not observed.'} + result = {'rows': rows[:512], 'input_truncated': truncated, 'invalid_rows': invalid, + 'scope': 'Outer HTTP status only; multipart terminal status is not observed.'} + if native.PLATFORM == 'IOS': + result['observation_state'] = 'ROWS_OBSERVED' if rows else 'UNKNOWN' + result.update(producer_row_limit=512, export_row_limit=512, line_scan_limit=1024, + lines_scanned=min(len(lines), 1024), valid_rows_in_scanned_input=len(rows), + exported_rows=min(len(rows), 512), + producer_limit_may_be_reached=len(rows) >= 512, + export_truncated=len(rows) > 512, line_scan_truncated=len(lines) > 1024, + coverage=('UNKNOWN' if not rows else 'PARTIAL_OR_CAPPED' + if truncated or len(rows) >= 512 or len(lines) > 1024 + else 'BOUNDED_INPUT_ONLY')) + return result def process(): proc = subprocess.run(['adb', '-s', device, 'shell', 'pidof', APP], capture_output=True, timeout=10) present = proc.returncode == 0 and bool(re.fullmatch(rb'\s*\d+(?:\s+\d+)*\s*', proc.stdout)) @@ -177,6 +225,25 @@ def foreground(): match[1] == APP for line in text.splitlines()) return {'exit_code': proc.returncode, 'own_app_resumed': True if present else None, 'input_truncated': truncated, 'scope': 'Positive observation only; absence is not inferred.'} - for name, action in [('logcat', logcat), ('metro', observer), ('hierarchy', lambda: hierarchy(native, native.PRIVATE / 'maestro-output')), ('process', process), ('foreground', foreground)]: + if native.PLATFORM == 'IOS': + facts['metro'] = {'observation_state': 'UNKNOWN', 'rows': [], 'coverage': 'UNKNOWN', + 'producer_row_limit': 512, 'export_row_limit': 512, 'line_scan_limit': 1024, + 'valid_rows_in_scanned_input': None, 'exported_rows': 0} + # A missing/invalid snapshot cannot establish that a public UI is absent. + facts['hierarchy'] = {name: None for name in ['credential_error', 'retry', 'logbox_controls', + 'redbox_resource', 'loading', 'login', 'welcome_back', 'logbox_error_header', + 'logbox_warning_header', 'logbox_syntax_footer', 'logbox_counter']} + facts['hierarchy'].update(observation_state='UNKNOWN', snapshot_count=0) + def ios_hierarchy(): + result = hierarchy(native, native.PRIVATE / 'maestro-output') + if result['snapshot_count']: + result['observation_state'] = 'SNAPSHOTS_PARSED' + return result + return facts['hierarchy'] + facts['process'] = {'state': 'UNKNOWN', 'scope': 'Not queried; Metro and hierarchy do not establish process state.'} + actions = [('metro', observer), ('hierarchy', ios_hierarchy)] + else: + actions = [('logcat', logcat), ('metro', observer), ('hierarchy', lambda: hierarchy(native, native.PRIVATE / 'maestro-output')), ('process', process), ('foreground', foreground)] + for name, action in actions: collect_one(name, action) return facts diff --git a/.github/native/startup_observer.cjs b/.github/native/startup_observer.cjs index 5f428e51f..b84f89b7f 100644 --- a/.github/native/startup_observer.cjs +++ b/.github/native/startup_observer.cjs @@ -19,7 +19,8 @@ function enhanceMiddleware(middleware, server) { options.platform = enumeration(query.get('platform'), ['android', 'ios']); options.sourcePaths = enumeration(query.get('sourcePaths'), ['url-server', 'absolute']); options.engine = enumeration(query.get('transform.engine'), ['hermes', 'jsc']); - options.app = query.has('app') ? query.get('app') === 'io.hexawallet.keeper.development' ? 'EXPECTED' : 'OTHER' : null; + const expectedApp = { android: 'io.hexawallet.keeper.development', ios: 'io.hexawallet.hexakeeper.dev' }[query.get('platform')]; + options.app = query.has('app') ? expectedApp && query.get('app') === expectedApp ? 'EXPECTED' : 'OTHER' : null; const started = Date.now(); emit({ kind: 'REQUEST', request: kind, options }); res.once('finish', () => { diff --git a/.github/tests/startup-observer.test.cjs b/.github/tests/startup-observer.test.cjs index 9e2e2d891..7181b9efd 100644 --- a/.github/tests/startup-observer.test.cjs +++ b/.github/tests/startup-observer.test.cjs @@ -106,3 +106,22 @@ test('emits only fixed error/query categories and caps rows', () => { assert.equal(new disabled.Reporter({}).update({ type: 'bundle_build_done' }), 31); assert.equal(disabled.rows.length, 0); }); + +test('expected app enums bind each platform without exporting either identifier or arbitrary query data', () => { + for (const [platform, app, expected] of [ + ['ios', 'io.hexawallet.hexakeeper.dev', 'EXPECTED'], + ['android', 'io.hexawallet.keeper.development', 'EXPECTED'], + ['ios', 'io.hexawallet.keeper.development', 'OTHER'], + ['android', 'io.hexawallet.hexakeeper.dev', 'OTHER'], + ['PRIVATE_SENTINEL', 'io.hexawallet.hexakeeper.dev', 'OTHER'], + ['ios', 'PRIVATE_SENTINEL', 'OTHER'], + ]) { + const loaded = load({}); + const handler = loaded.config.server.enhanceMiddleware(() => 23, {}); + const request = { url: `/index.bundle?platform=${platform}&app=${app}&PRIVATE_SENTINEL=private` }; + assert.equal(handler(request, new EventEmitter(), () => {}), 23); + assert.equal(loaded.rows[0].options.app, expected); + assert(!JSON.stringify(loaded.rows).includes('PRIVATE_SENTINEL')); + assert(!JSON.stringify(loaded.rows).includes('io.hexawallet')); + } +}); diff --git a/.github/tests/test_ios_startup_diagnostics.py b/.github/tests/test_ios_startup_diagnostics.py new file mode 100644 index 000000000..8c9f9e732 --- /dev/null +++ b/.github/tests/test_ios_startup_diagnostics.py @@ -0,0 +1,79 @@ +"""Fixed own-process log classification controls; no native execution.""" +import importlib.util +import json +from pathlib import Path +import unittest + +spec = importlib.util.spec_from_file_location('ios_log_controls', + Path(__file__).resolve().parents[1] / 'native/hosted_native.py') +native = importlib.util.module_from_spec(spec) +spec.loader.exec_module(native) + + +class IOSStartupDiagnosticsTests(unittest.TestCase): + def record(self, message, process='hexa_keeper_dev', severity='Df'): + return '2026-10-22 20:00:00.123+0000 %s %s[123:abc] %s' % (severity, process, message) + + def test_known_js_native_bundle_and_network_markers_are_fixed_not_error_excerpts(self): + cases = { + 'JS_TYPE': 'TypeError: private value', + 'JS_REFERENCE': 'ReferenceError: private identifier', + 'JS_SYNTAX': 'SyntaxError: private source', + 'JS_RANGE': 'RangeError: private value', + 'JS_INVARIANT': 'Invariant Violation: private details', + 'REACT_FATAL': 'Unhandled JS Exception: private details', + 'OBJC_EXCEPTION': 'NSInvalidArgumentException: private details', + 'NATIVE_MODULE': 'TurboModuleRegistry: module could not be found', + 'NATIVE_LIBRARY': 'dyld: Library not loaded: private path', + 'HERMES_EXCEPTION': 'Hermes fatal error: private details', + 'BUNDLE_LOAD': 'No bundle URL present: private URL', + 'ATS_BLOCKED': 'NSURLErrorDomain Code=-1022 private URL', + 'CONNECTION': 'NSURLErrorDomain Code=-1004 private URL', + } + for category, message in cases.items(): + with self.subTest(category=category): + result = native.ios_startup_diagnostics( + self.record(message + ' PRIVATE_SENTINEL'), 'hexa_keeper_dev') + self.assertIn(category, result['categories']) + self.assertEqual(result['category_record_counts'][category], 1) + self.assertEqual(result['error_records'], 1) + self.assertEqual(result['classified_error_records'], 1) + self.assertEqual(result['unclassified_error_records'], 0) + self.assertEqual(result['errors'], ['IOS_STARTUP_ERROR']) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(result)) + self.assertNotIn(message, json.dumps(result)) + + def test_foreign_process_continuation_and_ordinary_hermes_records_cannot_become_app_errors(self): + payload = '\n'.join([ + self.record('TypeError PRIVATE_SENTINEL', process='OtherApp', severity='E'), + 'TypeError PRIVATE_SENTINEL unprefixed continuation', + 'hexa_keeper_dev[123:abc] SyntaxError PRIVATE_SENTINEL missing timestamp', + self.record('Hermes engine initialized normally'), + ]) + result = native.ios_startup_diagnostics(payload, 'hexa_keeper_dev') + self.assertEqual(result['matching_process_records'], 1) + self.assertEqual(result['error_records'], 0) + self.assertEqual(result['categories'], []) + self.assertEqual(result['errors'], []) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(result)) + + def test_generic_errors_remain_unclassified_and_missing_records_remain_unknown(self): + result = native.ios_startup_diagnostics('\n'.join([ + self.record('PRIVATE_SENTINEL arbitrary application text', severity='E'), + self.record('ReferenceError PRIVATE_SENTINEL', severity='E'), + self.record('TypeError and ReferenceError PRIVATE_SENTINEL', severity='E'), + ]), 'hexa_keeper_dev') + self.assertEqual(result['error_records'], 3) + self.assertEqual(result['classified_error_records'], 2) + self.assertEqual(result['unclassified_error_records'], 1) + self.assertEqual(result['category_record_counts']['JS_REFERENCE'], 2) + self.assertEqual(result['category_record_counts']['JS_TYPE'], 1) + self.assertEqual(result['observation_state'], 'OWN_RECORDS_OBSERVED') + absent = native.ios_startup_diagnostics('PRIVATE_SENTINEL no compact records', 'hexa_keeper_dev') + self.assertEqual(absent['observation_state'], 'UNKNOWN') + self.assertEqual(absent['categories'], []) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps((result, absent))) + + +if __name__ == '__main__': + unittest.main() diff --git a/.github/tests/test_startup_diagnosis.py b/.github/tests/test_startup_diagnosis.py index dc2958b8b..938a035b9 100644 --- a/.github/tests/test_startup_diagnosis.py +++ b/.github/tests/test_startup_diagnosis.py @@ -67,6 +67,8 @@ def subprocess_result(args, **kwargs): self.assertTrue(facts['hierarchy']['logbox_controls']) self.assertTrue(facts['foreground']['own_app_resumed']) self.assertTrue(facts['process']['alive']) + self.assertNotIn('coverage', facts['metro'], 'Android receipt schema stays unchanged') + self.assertNotIn('producer_row_limit', facts['metro']) def test_failed_malformed_foreign_and_truncated_queries_do_not_claim_absence(self): for code, pid, foreground, oversized in [ @@ -105,6 +107,153 @@ def test_private_size_bounds_and_symlink_rejection(self): self.assertFalse(truncated) self.assertEqual(len(json.loads(payload)['padding']), 600 * 1024) + def test_ios_timestamp_only_start_collects_metro_on_success_without_native_commands(self): + native = SimpleNamespace(PRIVATE=self.root, PLATFORM='IOS') + device = '12345678-1234-1234-1234-123456789ABC' + rows = [ + {'time_ms': 149, 'kind': 'BUILD', 'event': 'bundle_build_done'}, + {'time_ms': 150, 'kind': 'REQUEST', 'request': 'ENTRY_BUNDLE', + 'options': {'platform': 'ios', 'app': 'EXPECTED', 'private': 'PRIVATE_SENTINEL'}}, + {'time_ms': 151, 'kind': 'RESPONSE', 'request': 'ENTRY_BUNDLE', 'outer_http_status': 200}, + ] + (self.root / 'startup-observer.jsonl').write_text('\n'.join(json.dumps(row) for row in rows)) + with mock.patch.object(diagnosis.time, 'time', return_value=0.150), \ + mock.patch.object(diagnosis.subprocess, 'Popen') as popen, \ + mock.patch.object(diagnosis.subprocess, 'run') as run: + handle = diagnosis.start(native, device) + facts = diagnosis.collect(native, device, handle) + diagnosis.stop(handle) + self.assertEqual(handle.started_ms, 150) + self.assertIsNone(handle.process) + self.assertIsNone(handle.output) + popen.assert_not_called() + run.assert_not_called() + self.assertEqual([row['stage'] for row in facts['metro']['rows']], + ['BEFORE_APP', 'APP_WINDOW', 'APP_WINDOW']) + self.assertEqual(facts['metro']['rows'][-1]['outer_http_status'], 200) + self.assertEqual(facts['metro']['observation_state'], 'ROWS_OBSERVED') + self.assertEqual(facts['metro']['coverage'], 'BOUNDED_INPUT_ONLY') + self.assertEqual(facts['metro']['valid_rows_in_scanned_input'], 3) + self.assertEqual(facts['metro']['exported_rows'], 3) + self.assertEqual(facts['process']['state'], 'UNKNOWN') + self.assertEqual(facts['hierarchy']['observation_state'], 'UNKNOWN') + self.assertIsNone(facts['hierarchy']['login']) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(facts)) + + def test_ios_missing_or_malformed_observation_does_not_invent_absence_or_app_stage(self): + native = SimpleNamespace(PRIVATE=self.root, PLATFORM='IOS') + device = '12345678-1234-1234-1234-123456789ABC' + facts = diagnosis.collect(native, device) + self.assertEqual(facts['metro']['observation_state'], 'UNKNOWN') + self.assertEqual(facts['hierarchy']['observation_state'], 'UNKNOWN') + self.assertIn('metro', facts['collection_errors']) + (self.root / 'startup-observer.jsonl').write_text(json.dumps( + {'time_ms': 150, 'kind': 'REQUEST', 'request': 'ENTRY_BUNDLE', 'options': {'platform': 'ios'}})) + folder = self.root / 'maestro-output' / 'screen-hierarchy' + folder.mkdir(parents=True) + (folder / 'step-1.json').write_text('{PRIVATE_SENTINEL') + facts = diagnosis.collect(native, device) + self.assertEqual(facts['metro']['rows'][0]['stage'], 'UNKNOWN') + self.assertEqual(facts['hierarchy']['observation_state'], 'UNKNOWN') + self.assertIsNone(facts['hierarchy']['credential_error']) + self.assertIn('hierarchy', facts['collection_errors']) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(facts)) + for invalid in ['booted', 'emulator-5554', 'physical-PRIVATE_SENTINEL']: + with self.assertRaises(ValueError): + diagnosis.start(native, invalid) + + def test_ios_public_login_and_modern_logbox_text_is_presence_only_and_fixed(self): + native = SimpleNamespace(PRIVATE=self.root, PLATFORM='IOS') + folder = self.root / 'maestro-output' / 'screen-hierarchy' + folder.mkdir(parents=True) + path = folder / 'step-1.json' + def snapshot(values): + path.write_text(json.dumps({'children': [ + {'attributes': {'accessibilityText': value}} for value in values]})) + return diagnosis.hierarchy(native, folder.parent) + public = ['Enter your passcode', 'Welcome Back', + 'Unable to check your passcode. Please try again.', 'Retry', + 'Uncaught Error', 'Console Warning', 'Failed to compile', + 'This error cannot be dismissed.', 'Dismiss', 'Minimize', + 'Log 2 of 11', 'please wait', 'PRIVATE_SENTINEL'] + facts = snapshot(public) + for name in ['login', 'welcome_back', 'credential_error', 'retry', 'loading', + 'logbox_error_header', 'logbox_warning_header', 'logbox_syntax_footer', + 'logbox_controls', 'logbox_counter']: + self.assertTrue(facts[name], name) + self.assertFalse(facts['redbox_resource'], 'modern text need not expose native IDs') + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(facts)) + facts = snapshot(['Retry', 'PRIVATE_SENTINEL Enter your passcode', 'Log 0 of 3']) + self.assertTrue(facts['retry']) + for name in ['login', 'credential_error', 'loading', 'logbox_controls', 'logbox_counter']: + self.assertFalse(facts[name], name) + + def test_ios_incomplete_or_excess_hierarchy_stays_unknown(self): + native = SimpleNamespace(PRIVATE=self.root, PLATFORM='IOS') + device = '12345678-1234-1234-1234-123456789ABC' + folder = self.root / 'maestro-output' / 'screen-hierarchy' + folder.mkdir(parents=True) + path = folder / 'step-1.json' + path.write_bytes(b'PRIVATE_SENTINEL' + b'x' * (1024 * 1024 + 1)) + facts = diagnosis.collect(native, device) + self.assertEqual(facts['hierarchy']['observation_state'], 'UNKNOWN') + self.assertIsNone(facts['hierarchy']['login']) + for index in range(1, 10): + (folder / ('step-%d.json' % index)).write_text('{}') + facts = diagnosis.collect(native, device) + self.assertEqual(facts['hierarchy']['observation_state'], 'UNKNOWN') + self.assertIsNone(facts['hierarchy']['logbox_error_header']) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(facts)) + + def test_ios_malformed_category_shapes_are_invalid_not_substring_or_key_matches(self): + native = SimpleNamespace(PRIVATE=self.root, PLATFORM='IOS') + device = '12345678-1234-1234-1234-123456789ABC' + invalid = ['PRIVATE_SENTINELTYPE', {'TYPE': 'PRIVATE_SENTINEL'}, None, True, [True], [['TYPE']]] + rows = [{'time_ms': 150, 'kind': 'ERROR', 'event': 'bundling_error', + 'categories': value} for value in invalid] + rows.append({'time_ms': 150, 'kind': 'ERROR', 'event': 'bundling_error', + 'categories': ['TYPE', 'PRIVATE_SENTINEL']}) + (self.root / 'startup-observer.jsonl').write_text('\n'.join(json.dumps(row) for row in rows)) + facts = diagnosis.collect(native, device) + self.assertEqual(facts['metro']['invalid_rows'], len(invalid)) + self.assertEqual(len(facts['metro']['rows']), 1) + self.assertEqual(facts['metro']['rows'][0]['categories'], ['TYPE']) + self.assertEqual(facts['metro']['valid_rows_in_scanned_input'], 1) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(facts)) + + def test_ios_row_caps_expose_bounded_counts_and_conservative_coverage(self): + native = SimpleNamespace(PRIVATE=self.root, PLATFORM='IOS') + device = '12345678-1234-1234-1234-123456789ABC' + row = {'time_ms': 150, 'kind': 'BUILD', 'event': 'bundle_build_done'} + for count in [511, 512, 513, 1025]: + with self.subTest(count=count): + (self.root / 'startup-observer.jsonl').write_text('\n'.join(json.dumps(row) for _ in range(count))) + facts = diagnosis.collect(native, device)['metro'] + self.assertEqual((facts['producer_row_limit'], facts['export_row_limit'], facts['line_scan_limit']), + (512, 512, 1024)) + self.assertEqual(facts['valid_rows_in_scanned_input'], min(count, 1024)) + self.assertEqual(facts['exported_rows'], min(count, 512)) + self.assertEqual(len(facts['rows']), min(count, 512)) + self.assertEqual(facts['producer_limit_may_be_reached'], count >= 512) + self.assertEqual(facts['export_truncated'], count > 512) + self.assertEqual(facts['line_scan_truncated'], count > 1024) + self.assertEqual(facts['coverage'], 'BOUNDED_INPUT_ONLY' if count < 512 else 'PARTIAL_OR_CAPPED') + + def test_ios_supplied_falsey_nonobject_attributes_and_nonlist_children_stay_unknown(self): + native = SimpleNamespace(PRIVATE=self.root, PLATFORM='IOS') + device = '12345678-1234-1234-1234-123456789ABC' + folder = self.root / 'maestro-output' / 'screen-hierarchy' + folder.mkdir(parents=True) + for field, values in [('attributes', [[], None, False, 0, '']), + ('children', [{}, None, False, 0, ''])]: + for value in values: + with self.subTest(field=field, value=value): + (folder / 'step-1.json').write_text(json.dumps({field: value})) + facts = diagnosis.collect(native, device) + self.assertEqual(facts['hierarchy']['observation_state'], 'UNKNOWN') + self.assertIsNone(facts['hierarchy']['credential_error']) + self.assertIn('hierarchy', facts['collection_errors']) + if __name__ == '__main__': unittest.main() diff --git a/.github/tests/test_startup_integration.py b/.github/tests/test_startup_integration.py index a9fd30e96..b19b0cda2 100644 --- a/.github/tests/test_startup_integration.py +++ b/.github/tests/test_startup_integration.py @@ -37,7 +37,7 @@ def setUp(self): self.spawn_error = OSError('PRIVATE_SENTINEL Metro spawn failure') def start(self, context, device): - self.assertEqual(context.PLATFORM, 'ANDROID') + self.assertEqual(context.PLATFORM, self.platform) self.assertEqual(context.PRIVATE, self.root) self.assertEqual(device, self.device) self.events.append('capture-start') @@ -58,6 +58,8 @@ def exercise(self, suite='startup', smoke_fails=False, start_fails=False, import_fails=False, popen_fails=False, receipt_fails=None, cleanup_fails=(), diagnostics_fail=False, install_timeout=False, install_fails=False, readiness_fails=False): + self.platform = platform + self.device = ('12345678-1234-1234-1234-123456789ABC' if platform == 'IOS' else 'emulator-5554') captured = {} original_read, original_save, original_unlink = native.read, native.save, Path.unlink original_command = native.command @@ -98,6 +100,7 @@ def command(args, label, **kwargs): if label.startswith('Assert '): self.events.append('maestro') captured['flow'] = args[-1] + captured['maestro_args'], captured['maestro_options'] = args, kwargs if smoke_fails: raise self.original_error @@ -335,6 +338,16 @@ def test_ios_install_success_keeps_exact_bytes_and_default_passcode_flow(self): self.assertEqual(value['flow'], '.github/native/startup.yaml') self.assertEqual(self.events.count('installed-proof'), 2) self.assertEqual(value['metadata']['smoke'], 'PASS') + self.assertEqual(value['metadata']['startup_observation']['scope'], 'startup only') + self.assertEqual(value['maestro_options'], {'timeout': 420, 'error_details': True}) + self.assertEqual(self.events.count('maestro'), 1) + self.assertLess(self.events.index('installed-proof'), self.events.index('capture-start')) + self.assertLess(self.events.index('capture-start'), self.events.index('maestro')) + self.assertLess(self.events.index('maestro'), self.events.index('capture-collect')) + self.assertLess(self.events.index('capture-collect'), self.events.index('device-shutdown')) + self.assertEqual(value['metro_args'][-4:], [ + '--config', str(self.root / '.github/native/startup_observer.cjs'), + '--custom-log-reporter-path', str(self.root / '.github/native/startup_reporter.cjs')]) def test_ios_install_observation_delegates_once_after_readiness_before_proof_and_ui(self): value = self.exercise(platform='IOS') @@ -349,7 +362,7 @@ def test_ios_install_observation_delegates_once_after_readiness_before_proof_and self.assertLess(self.events.index('app-services-ready'), self.events.index('install-observe')) self.assertLess(self.events.index('install-observe'), self.events.index('installed-proof')) self.assertLess(self.events.index('installed-proof'), self.events.index('maestro')) - self.assertNotIn('capture-start', self.events) + self.assertEqual(self.events.count('capture-start'), 1) self.assertIn('device-shutdown', self.events) self.assertIn('device-delete', self.events) @@ -445,10 +458,11 @@ def test_only_observer_raw_files_are_purged_after_collection(self): for name in ['build-artifact', 'maestro.zip']: self.assertTrue((self.root / name).exists()) - def test_probes_and_ios_preserve_their_existing_metro_configuration_without_observation(self): + def test_probes_on_both_platforms_preserve_existing_metro_configuration_without_observation(self): for suite, platform, config in [('probe', 'ANDROID', 'release_metro.cjs'), ('features', 'ANDROID', 'r5_metro.cjs'), - ('startup', 'IOS', None)]: + ('probe', 'IOS', 'release_metro.cjs'), + ('features', 'IOS', 'r5_metro.cjs')]: with self.subTest(suite=suite, platform=platform): self.events.clear() value = self.exercise(suite=suite, platform=platform) @@ -460,6 +474,18 @@ def test_probes_and_ios_preserve_their_existing_metro_configuration_without_obse else: self.assertNotIn('--config', value['metro_args']) + def test_ios_observation_failure_never_masks_the_original_ui_error_or_skips_cleanup(self): + value = self.exercise(platform='IOS', smoke_fails=True, collect_fails=True) + self.assertIs(value['error'], self.original_error) + self.assertEqual(value['metadata']['smoke'], 'FAIL') + self.assertEqual(value['metadata']['startup_observation'], {'collection_errors': ['collector']}) + self.assertEqual(self.events.count('maestro'), 1) + self.assertEqual(value['maestro_options']['timeout'], 420) + for event in ['capture-stop', 'metro-stop', 'device-shutdown', 'device-delete', + 'purge-startup-observer.jsonl']: + self.assertIn(event, self.events) + self.assertNotIn('PRIVATE_SENTINEL', str(value['metadata'])) + if __name__ == '__main__': unittest.main() diff --git a/docs/r5-ios-startup-observation.md b/docs/r5-ios-startup-observation.md new file mode 100644 index 000000000..047639f36 --- /dev/null +++ b/docs/r5-ios-startup-observation.md @@ -0,0 +1,76 @@ +# iOS startup observation preparation + +This isolated preparation starts from exact source +`23f14e01f3437c213f1443c3167d96022f3a43bc`. Its hosted run39846002094 attempt1 +passed driver readiness, unsigned development build, app installation and the +pre-UI installed-byte comparison, then failed to find Create a passcode. Native +persistence, production workers and product checks did not run on iOS. The +retained metadata has36 Metro bundle markers and2446 generic own-process log +records; those facts do not identify the startup failure. The active combined +window and its serialized Android execution remain untouched. + +This changes observation only. Normal iOS startup uses the existing Metro +middleware and CLI reporter observer already used for Android. Resolver, +transformer, serializer, middleware arguments, response streaming and the +original TerminalReporter remain intact. Fixed app enums distinguish the iOS +development bundle ID from Android's. An in-memory timestamp immediately before +the original Maestro command separates warmup rows from the app window. No +extra launch, install, CLI invocation, process sampler or native capture process +is introduced. The420s CLI deadline and startup flow are unchanged. Probe, +production-worker and full-product configurations are unchanged. + +Both successful and failed startup retain regenerated fixed Metro facts and +bounded public hierarchy presence flags. Missing or invalid iOS observations +remain UNKNOWN. Outer HTTP200 does not establish multipart terminal success, +JavaScript execution or visible UI. The existing post-failure iOS log query keeps +its25s deadline and own-process compact-record filter. Its classifier adds fixed +JS, React/Objective-C, module/library, Hermes, bundle and network marker categories +with counts; unclassified errors and the generic fallback remain explicit. +Categories are observations, not failure-cause or crash proof. App PID/crash +state is not queried and remains UNKNOWN. + +The shared reporter can emit at most512 rows per process. The iOS reader scans +at most1024 lines of bounded private input and exports at most512 valid rows. +It reports all three limits, scanned valid-row/export counts, byte/line +truncation and conservative coverage. Reaching512 valid rows means the producer +limit may have been reached; it does not establish how many observations were +lost. No coverage value claims a complete startup trace. Malformed category +containers and supplied non-object hierarchy attributes/non-list children +remain invalid/UNKNOWN rather than producing diagnostic facts. + +The Login flags use exact23f English strings Enter your passcode and Welcome +Back. Credential-error and Retry are separate public flags; Retry alone does not +prove a credential error. Generic please wait/loading text belongs to the +Navigator loading overlay. Pending credential lookup has no dedicated public +loading marker, so its state cannot be inferred from missing flags. + +Modern LogBox strings were read from the exact lock-pinned React Native0.83.9 +npm tarball after SHA1 and SHA512 verification. SHA1 is +`61d2a4ccd89e06b98992c9b9781856ad88a09d39`. Fixed labels come from +`Libraries/LogBox/UI/LogBoxInspectorBody.js`, `LogBoxInspectorHeader.js` and +`LogBoxInspectorFooter.js`: Console Warning, Console Error, Uncaught Error, +Syntax Error, Render Error, Failed to compile, This error cannot be dismissed., +Dismiss/Minimize, and the fixed Log-number-of-number shape. Error titles can be +overridden. React id maps to nativeID separately from testID; no assumption is +made that Maestro exposes modern LogBox IDs. Metro0.83.6 reporter events were +also checked against the lock-pinned tarball, SHA1 +`1b42929143729d854c25a40f0568f955ba70895e`. Runtime client_log data is not added +to the observer. + +Raw request URLs/bodies, UI text, stack traces, logs and credentials are never +exported. The same private observer files are purged by the existing cleanup; +only metadata is uploaded. Collection cannot replace the original UI failure. +Cleanup failures retain the existing fail-closed behavior. No app source, +dependency, selector, timeout, workflow, signing or release operation changes. + +Offline controls verify fixed enum/privacy filtering, original middleware and +reporter forwarding, platform/window separation, missing/invalid data, public +hierarchy positives/negatives, own-process log attribution and classification, +one unchanged Maestro call, probe exclusion, original failure preservation and +cleanup. They provide no native acceptance. Hosted iOS validation of this +preparation is NOT RUN; physical devices and signers are NOT RUN. The original +startup cause remains UNKNOWN. The final offline suites passed 152 Node controls +and 224 Python controls; independent review cleared malformed category shapes, +malformed hierarchy fields and undisclosed row-cap coverage. Those are diagnostic +accuracy checks, not native evidence. No additional native window is selected +by this preparation.