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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/native/ios_startup_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down
82 changes: 69 additions & 13 deletions .github/native/startup_diagnosis.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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']:
Expand All @@ -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))
Expand All @@ -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
76 changes: 76 additions & 0 deletions .github/tests/test_ios_startup_diagnostics.py
Original file line number Diff line number Diff line change
@@ -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()
Loading
Loading