diff --git a/.github/native/ios_startup_errors.py b/.github/native/ios_startup_errors.py index d1be4d673..dda8d0176 100644 --- a/.github/native/ios_startup_errors.py +++ b/.github/native/ios_startup_errors.py @@ -24,15 +24,17 @@ 'JS_RANGE_ERROR': r'\bRangeError\b', 'JS_EXCEPTION': r'\bUnhandled (?:JS|JavaScript) Exception\b|\bJavaScript exception\b|\bUnhandled promise rejection\b', 'JS_INVARIANT': r'\bInvariant Violation\b|\bhas not been registered\b', - 'SCRIPT_URL_MISSING': r'\bNo script URL provided\b', - 'SCRIPT_LOAD_ERROR': r'\bUnable to load script\b|\bCould not connect to development server\b|\bdevelopment server returned response error\b', + 'SCRIPT_URL_MISSING': r'\bNo script URL provided\b|\bNo bundle URL present\b', + 'SCRIPT_LOAD_ERROR': r'\bUnable to load script\b|\bCould not connect to development server\b|\bdevelopment server returned response error\b|\b(?:Could not|Failed to) load bundle\b', 'MODULE_RESOLUTION_ERROR': r'\bUnable to resolve module\b|\bCannot find module\b|\bUnableToResolveError\b', 'NATIVE_MODULE_UNAVAILABLE': r'\bNative module cannot be null\b|\bCannot find native module\b|\bTurboModuleRegistry(?:\.getEnforcing)?\b.{0,256}\b(?:could not be found|not found|missing|null|unavailable|failed|failure)\b', - 'NATIVE_LIBRARY_LOAD_ERROR': r'\bLibrary not loaded\b|\bSymbol not found\b|\bdlopen(?:\([^\n]{0,256}\))? failed\b|\bincompatible architecture\b', + 'NATIVE_LIBRARY_LOAD_ERROR': r'\bLibrary not loaded\b|\bSymbol not found\b|\bdlopen(?:\([^\n]{0,256}\))? failed\b|\bincompatible architecture\b|\bdyld\b.{0,256}\b(?:not found|failed|error)\b', 'CONNECTION_ERROR': r'\b(?:ECONNREFUSED|ECONNRESET|NSURLErrorDomain)\b|\bConnection refused\b|\bCould not connect\b', - 'NATIVE_EXCEPTION': r'\bNS[A-Za-z0-9_]*Exception\b|\bRCTFatal\b', + 'NATIVE_EXCEPTION': r'\bNS[A-Za-z0-9_]*Exception\b|\bRCTFatal\b|\bRCTExceptionsManager\b|\bException in HostFunction\b', 'EXCEPTION_MARKER': r'\b[A-Za-z_$][A-Za-z0-9_.$]*Exception\b|\buncaught exception\b|\bunhandled exception\b', 'FATAL_MARKER': r'\bfatal(?: error| exception| signal)?\b|\bSIG(?:ABRT|SEGV|BUS|ILL|TRAP)\b', + 'HERMES_ERROR': r'\bhermes\b.{0,256}\b(?:exception|fatal|error|failed)\b|\b(?:exception|fatal|error)\b.{0,256}\bhermes\b', + 'ATS_BLOCKED': r'\bApp Transport Security\b.{0,256}\b(?:blocked|requires)\b|\bNSURLErrorDomain\b.{0,256}-1022\b', } _CATEGORY_PATTERNS = {name: re.compile(pattern, re.IGNORECASE) for name, pattern in CATEGORIES.items()} diff --git a/.github/native/startup_diagnosis.py b/.github/native/startup_diagnosis.py index 6678578f6..e83e7870b 100644 --- a/.github/native/startup_diagnosis.py +++ b/.github/native/startup_diagnosis.py @@ -1,5 +1,6 @@ """Private launch-window capture and fixed startup observation; never acceptance.""" import json +from itertools import islice import os import re import subprocess @@ -93,9 +94,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 @@ -104,8 +114,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 @@ -116,10 +127,25 @@ 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 - flags['observation_state'] = 'OBSERVED' if flags['snapshot_count'] else 'UNKNOWN' + flags['observation_state'] = ('SNAPSHOTS_PARSED' if native.PLATFORM == 'IOS' else 'OBSERVED') if flags['snapshot_count'] else 'UNKNOWN' + if native.PLATFORM == 'IOS': + flags['scope'] = 'ANY_RETAINED_SNAPSHOT_NOT_FINAL_ROUTE_OR_VISIBILITY_PROOF' return flags @@ -162,7 +188,8 @@ def observer(): result.update({key: row.get(key) if type(row.get(key)) is bool else None for key in ['dev', 'minify']}) 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' categories = row.get('categories', []) - if not isinstance(categories, list): + if (not isinstance(categories, list) or (native.PLATFORM == 'IOS' and + any(type(item) is not str for item in categories))): raise ValueError('Invalid fixed category shape.') 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']: @@ -182,10 +209,23 @@ def observer(): rows.append(result) except Exception: invalid += 1 - return {'rows': rows[:512], 'input_truncated': truncated, 'invalid_rows': invalid, - 'row_limit_reached': len(lines) > 1024 or len(rows) > 512, - 'emitter_cap_observed': len(lines) >= 512, - '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': + # Input coverage only: invalid rows or a possibly reached emitter cap + # cannot establish a complete launch window or a successful bundle. + result.update(observation_state='ROWS_OBSERVED' if rows else 'UNKNOWN', + 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(lines) >= 512, + export_truncated=len(rows) > 512, line_scan_truncated=len(lines) > 1024, + coverage=('UNKNOWN' if not rows else 'PARTIAL_OR_CAPPED' + if truncated or invalid or len(lines) >= 512 else 'BOUNDED_INPUT_ONLY')) + else: + result.update(row_limit_reached=len(lines) > 1024 or len(rows) > 512, + emitter_cap_observed=len(lines) >= 512) + 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)) @@ -202,9 +242,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.'} - actions = [('metro', observer), ('hierarchy', lambda: hierarchy(native, native.PRIVATE / 'maestro-output'))] - if native.PLATFORM == 'ANDROID': - actions = [('logcat', logcat), *actions, ('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} + # Missing, invalid or capped input cannot establish that a 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, + scope='ANY_RETAINED_SNAPSHOT_NOT_FINAL_ROUTE_OR_VISIBILITY_PROOF') + def ios_hierarchy(): + result = hierarchy(native, native.PRIVATE / 'maestro-output') + return result if result['snapshot_count'] else 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/tests/test_ios_startup_diagnostics.py b/.github/tests/test_ios_startup_diagnostics.py new file mode 100644 index 000000000..b1cbf7eb4 --- /dev/null +++ b/.github/tests/test_ios_startup_diagnostics.py @@ -0,0 +1,76 @@ +"""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_ERROR': 'TypeError: private value', + 'JS_REFERENCE_ERROR': 'ReferenceError: private identifier', + 'JS_SYNTAX_ERROR': 'SyntaxError: private source', + 'JS_RANGE_ERROR': 'RangeError: private value', + 'JS_INVARIANT': 'Invariant Violation: private details', + 'JS_EXCEPTION': 'Unhandled JS Exception: private details', + 'NATIVE_EXCEPTION': 'NSInvalidArgumentException: private details', + 'NATIVE_MODULE_UNAVAILABLE': 'TurboModuleRegistry: module could not be found', + 'NATIVE_LIBRARY_LOAD_ERROR': 'dyld: Library not loaded: private path', + 'HERMES_ERROR': 'Hermes fatal error: private details', + 'SCRIPT_URL_MISSING': 'No bundle URL present: private URL', + 'ATS_BLOCKED': 'NSURLErrorDomain Code=-1022 private URL', + 'CONNECTION_ERROR': '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.assertEqual(result['category_record_counts'][category], 1) + self.assertEqual(result['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.assertFalse(any(result['category_record_counts'].values())) + 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['unclassified_error_records'], 1) + self.assertEqual(result['category_record_counts']['JS_REFERENCE_ERROR'], 2) + self.assertEqual(result['category_record_counts']['JS_TYPE_ERROR'], 1) + self.assertEqual(result['parse_status'], 'PARSED') + absent = native.ios_startup_diagnostics('PRIVATE_SENTINEL no compact records', 'hexa_keeper_dev') + self.assertEqual(absent['parse_status'], 'UNKNOWN') + self.assertFalse(any(absent['category_record_counts'].values())) + 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 1d8408b28..e5238aaa0 100644 --- a/.github/tests/test_startup_diagnosis.py +++ b/.github/tests/test_startup_diagnosis.py @@ -125,7 +125,8 @@ def test_ios_observation_uses_no_extra_capture_process_or_device_queries(self): self.assertEqual(facts['metro']['rows'][0]['options']['app'], 'EXPECTED') self.assertEqual(facts['metro']['rows'][0]['stage'], 'APP_WINDOW') self.assertEqual(facts['hierarchy']['observation_state'], 'UNKNOWN') - for key in ['logcat', 'process', 'foreground']: + self.assertEqual(facts['process']['state'], 'UNKNOWN') + for key in ['logcat', 'foreground']: self.assertNotIn(key, facts) self.assertNotIn('PRIVATE_SENTINEL', json.dumps(facts)) with self.assertRaises(ValueError): @@ -149,8 +150,9 @@ def test_malformed_future_and_capped_metro_rows_remain_honest_on_ios(self): (self.root / 'startup-observer.jsonl').write_text((json.dumps(row)+'\n')*1100) facts = diagnosis.collect(native, device) self.assertEqual(len(facts['metro']['rows']), 512) - self.assertTrue(facts['metro']['row_limit_reached']) - self.assertTrue(facts['metro']['emitter_cap_observed']) + self.assertTrue(facts['metro']['line_scan_truncated']) + self.assertTrue(facts['metro']['producer_limit_may_be_reached']) + self.assertEqual(facts['metro']['coverage'], 'PARTIAL_OR_CAPPED') self.assertEqual(facts['metro']['rows'][0]['stage'], 'UNKNOWN') def test_ios_missing_or_private_alias_inputs_cannot_create_observation_pass(self): @@ -158,7 +160,8 @@ def test_ios_missing_or_private_alias_inputs_cannot_create_observation_pass(self device = '12345678-1234-1234-1234-123456789ABC' facts = diagnosis.collect(native, device) self.assertIn('metro', facts['collection_errors']) - self.assertNotIn('metro', facts) + self.assertEqual(facts['metro']['coverage'], 'UNKNOWN') + self.assertEqual(facts['metro']['rows'], []) actual = self.root / 'private-actual.jsonl' actual.write_text('PRIVATE_SENTINEL') (self.root / 'startup-observer.jsonl').symlink_to(actual) @@ -167,5 +170,175 @@ def test_ios_missing_or_private_alias_inputs_cannot_create_observation_pass(self self.assertNotIn('PRIVATE_SENTINEL', json.dumps(facts)) + 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', side_effect=[0.150, 0.152]), \ + 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_invalid_rows_and_possible_emitter_cap_cannot_claim_complete_coverage(self): + native = SimpleNamespace(PRIVATE=self.root, PLATFORM='IOS') + device = '12345678-1234-1234-1234-123456789ABC' + row = json.dumps({'time_ms': 150, 'kind': 'BUILD', 'event': 'bundle_build_done'}) + for invalid_count in [1, 500]: + with self.subTest(invalid_count=invalid_count): + (self.root / 'startup-observer.jsonl').write_text( + ('PRIVATE_SENTINEL\n' * invalid_count) + ((row + '\n') * 12)) + facts = diagnosis.collect(native, device)['metro'] + self.assertEqual(facts['invalid_rows'], invalid_count) + self.assertEqual(facts['valid_rows_in_scanned_input'], 12) + self.assertEqual(facts['coverage'], 'PARTIAL_OR_CAPPED') + self.assertEqual(facts['producer_limit_may_be_reached'], invalid_count == 500) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(facts)) + + + 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 11320cb1b..564877419 100644 --- a/.github/tests/test_startup_integration.py +++ b/.github/tests/test_startup_integration.py @@ -100,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 @@ -337,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') diff --git a/docs/r5-ios-startup-observation.md b/docs/r5-ios-startup-observation.md index 824d1dda6..6b86d510b 100644 --- a/docs/r5-ios-startup-observation.md +++ b/docs/r5-ios-startup-observation.md @@ -1,51 +1,77 @@ -# iOS startup observation preparation - -This bounded source package adds observations for a future exact-candidate -hosted startup run. It changes no app source, dependencies, entrypoint, SDK, -UI flow/assertion, timing marker, timeout, build budget or job scheduling. -It grants no native acceptance and arms no execution route. - -On immutable `23f14e01f3437c213f1443c3167d96022f3a43bc`, run39846002094 -attempt1/iOSjob120059314071 passed driver readiness, build, installation and -the full installed-byte comparison **before UI**. Startup then failed at the -Create-a-passcode assertion after232.6s. Artifact12456827499 ZIP SHA256 is -`96617d1fe5680464a841a97416e2b80eed03f88d9c36bb1252293ccd5a26d219`. -The retained receipt has2446 own-app compact records with a generic error -category and no fixed startup hierarchy selector. Its specific cause remains -unknown. The post-UI byte check and later feature/product phases did not run. -No result from that source transfers to this package. - -Normal iOS startup now uses the existing supported CLI custom reporter and -middleware observer already used on Android. The observer requires the normal -Metro configuration and forwards its resolver, transformer, original reporter, -requests, response bodies, streaming and backpressure. It records only fixed -query options, build/error categories and outer HTTP statuses. App matching uses -the request's actual platform and that platform's committed development app ID. -An outer200 response does not establish multipart completion or app execution. - -The existing failure-only compact-log query remains restricted to the built -executable on the fresh owned simulator. Its pure classifier exports fixed -record-category counts, generic and unclassified error counts, explicit bounds -and parse status. It reads at most1MiB,4096 lines/own records and16KiB per record; -incomplete, malformed, oversized, foreign and unprefixed continuation records -cannot supply an own-app error category. Categories are observed text markers, -not exception totals or a causal diagnosis. Empty, failed, missing or truncated -observations establish no pass or absence; cause remains `UNDETERMINED`. - -iOS adds no process inventory, foreground/private SPI, crash dump, provider, -storage hook or additional log stream. Its capture handle supplies only the -host-side launch-window timestamp for Metro rows. No CPU/load value is used to -infer cause. Android's existing capture and device queries remain in place. - -Only reconstructed fixed metadata leaves the ephemeral runner. Raw observer -and iOS error/stderr files are purged after collection. Cleanup attempts Metro -stop/output close, simulator shutdown/delete and each private-file purge even -when collection or receipt I/O fails. A primary UI/native failure stays primary; -unconfirmed cleanup fails the phase. Probe/features keep their existing separate -Metro configurations and acceptance prerequisites. - -Offline privacy, malformed-input, platform/app identity, middleware/reporter, -actual smoke-finalizer and cleanup fault controls validate source behavior. -They are not native results. iOS/Android execution on this new source is -`NOT RUN`; coordinate a fresh exact candidate only after the existing serialized -native window ends. Physical/biometric checks remain separate and unrun. +# Canonical bounded iOS startup observations + +Stage A reconciles the completed [#7115](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7115) +source `eceb5551a430a0e31cff7a32d70181ee55007b69` already included in +`80199f90b3f64869d9998e0984450c1b670c87b4` with the original completed +[#7116](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7116) startup +checkpoint `76d1c949d91c5d885fc002f689a9ec321c16eafb` by ancestry. +[Original #7115 patch](https://github.com/KeeperCommunity/bitcoin-keeper/compare/c8c4e22ffc0137f774e533f167ada81aa673b94a...eceb5551a430a0e31cff7a32d70181ee55007b69) +and [original #7116 startup patch](https://github.com/KeeperCommunity/bitcoin-keeper/compare/23f14e01...76d1c949d91c5d885fc002f689a9ec321c16eafb) +retain their producing sources and receipts. Later product-failure observation +at `1bc34890cb8618b2fffd446a63924974e0fe15b5` is a separate Stage B package. +No original producer or main integration branch is rewritten. + +## Compact-log receipt + +`ios_startup_errors.py` remains the sole pure classifier. The harness delegates +to it; there is no second compact parser or legacy category alias. The canonical +`category_record_counts` keys from #7115 remain, with fixed `HERMES_ERROR` and +`ATS_BLOCKED` markers plus bounded bundle/dyld/React-fatal patterns. Counts mean +records containing text markers, not exception totals or authenticated causes. +`parse_status` is UNKNOWN, PARSED or PARTIAL; `cause` remains UNDETERMINED. + +The classifier retains exact validated executable prefixes, real calendar/time +validation, strict input types, allowed compact severities/PIDs, control-character +rejection, multiline non-attribution, and limits of 1MiB input, 16KiB per record, +4096 scan lines and 4096 own-process records. Malformed, oversized, replacement +or truncated input cannot establish a complete observation. The existing +failure-only query stays restricted to the built executable on the fresh owned +simulator; its command, timeout, query outcome and private stderr separation +remain unchanged. Failed or missing queries remain UNKNOWN. + +## Metro and hierarchy receipts + +The normal Metro configuration, resolver, transformer, supported CLI reporter, +request/response bodies, streaming and backpressure remain intact. The existing +observer uses each request's platform and the actual development app ID. iOS +capture creates only a timestamp handle; it starts no extra native process or +service query. Android command execution and its existing receipt fields remain +unchanged. + +For iOS, Metro facts disclose producer/export limits of 512 rows and a scan limit +of 1024 lines, scanned/valid/exported counts, invalid rows, input/export/scan +truncation and whether the producer limit may have been reached. Valid rows have +only allowlisted fixed fields. Future-dated rows retain UNKNOWN stage. Missing +input gives UNKNOWN coverage and no rows. Invalid rows, truncation or a possibly +reached producer cap give PARTIAL_OR_CAPPED coverage when valid rows exist. +BOUNDED_INPUT_ONLY describes the supplied input; it grants no launch-window, +HTTP multipart terminal-status, JavaScript execution or UI acceptance. + +The bounded iOS hierarchy recognizes fixed Login, Welcome Back, credential-error, +Retry and modern LogBox phrases. At most eight complete private snapshots with +valid node/attribute/children containers and 10000 nodes per snapshot are parsed. +Missing, malformed, oversized, invalid-shape or excess snapshots leave UNKNOWN +with null flags. A parsed snapshot has SNAPSHOTS_PARSED state and fixed boolean +presence flags. The scope is ANY_RETAINED_SNAPSHOT_NOT_FINAL_ROUTE_OR_VISIBILITY_PROOF; +no flag establishes the final route, delivered tap or current UI visibility. +The iOS process-state receipt explicitly remains UNKNOWN because it is not queried. + +## Privacy, cleanup and acceptance + +Only fixed categories, bounded counts and public marker flags leave the runner. +Private log text, UI text, arbitrary attributes, paths, request bodies, credentials +and stacks are never copied into receipts. Existing cleanup attempts every owned +resource and private-file purge and preserves the original smoke failure even +when collection, receipt I/O or cleanup also fails. The startup integration +controls retain those failure/ordering assertions and unchanged UI command and +deadline arguments. + +The preserved 23f native window's first iOS passcode assertion and Android's first +full-product sample failed. Android progress through Skip does not identify the +failed action or a cause. This package supplies source/host diagnostic controls +only. Its own native execution, five startup/first-wallet sample pairs, Retry, +key/PIN, physical and full backend acceptance remain NOT RUN or incomplete. +There is no selector/app fix, performance pass, trusted-gate clearance or release +readiness claim. No native opt-in, scheduling, signing or release operation is +selected here; a later combined candidate needs fresh independent review and +exact-source hosted evidence. Work-package 5.2 remains unidentified and excluded.