53 lines
2.9 KiB
Python
53 lines
2.9 KiB
Python
"""Single entry point for regression tests and explicit app probes."""
|
|
import argparse
|
|
import importlib
|
|
import sys
|
|
|
|
COMMANDS = {
|
|
'inventory': ('exports', 'List local Desktop storage files'),
|
|
'stats': ('exports', 'Summarize a saved JSON/JSONL export'),
|
|
'search': ('exports', 'Search a saved export'),
|
|
'desktop-search': ('exports', 'Search the running Desktop app'),
|
|
'live': ('live', 'Run fixed Desktop math/capability/data probes'),
|
|
'webview-test': ('webview', 'Run an isolated WebView2 host test'),
|
|
'analyze': ('analyzer', 'Inspect storage and optionally an existing CDP session'),
|
|
'history-export': ('history', 'Export history through an existing Desktop CDP endpoint'),
|
|
'export-zip': ('zip_export', 'Export all local messages via JavaScript in WebView; no CDP or UI automation'),
|
|
'send-self': ('self_message', 'Send one test text to your own WhatsApp account via JavaScript'),
|
|
'contacts-export': ('contacts_export', 'Export all locally stored contacts via JavaScript without CDP'),
|
|
'ram-read': ('ram', 'Recover loaded message objects from process RAM'),
|
|
'ram-search': ('ram_search', 'Search verified loaded message objects'),
|
|
'native-search': ('injected_search', 'Experimental native SQLite search/index export'),
|
|
'qr-memory': ('qr_memory', 'Find Desktop pairing QR candidates in RAM'),
|
|
'qr-window': ('qr_window', 'Capture an already displayed Desktop pairing QR'),
|
|
'pairing': ('pairing', 'Request a linking QR in an isolated browser'),
|
|
}
|
|
|
|
|
|
def main(argv=None):
|
|
argv = list(sys.argv[1:] if argv is None else argv)
|
|
if not argv:
|
|
argv = ['test']
|
|
parser = argparse.ArgumentParser(description='WhatsApp tools and test suite. Default: offline regression tests.')
|
|
commands = parser.add_subparsers(dest='command', required=True)
|
|
commands.add_parser('test', help='Run offline regression tests; optionally add live checks', add_help=False)
|
|
for name, (_, description) in COMMANDS.items():
|
|
commands.add_parser(name, help=description, add_help=False)
|
|
args, remaining = parser.parse_known_args(argv)
|
|
try:
|
|
if args.command == 'test':
|
|
from .runner import main as run_tests
|
|
return run_tests(remaining)
|
|
module = importlib.import_module('.' + COMMANDS[args.command][0], __package__)
|
|
if args.command in ('inventory', 'stats', 'search', 'desktop-search'):
|
|
command = 'whatsapp-search' if args.command == 'desktop-search' else args.command
|
|
return module.main([command] + remaining)
|
|
if args.command == 'webview-test':
|
|
help_parser = argparse.ArgumentParser(description=COMMANDS[args.command][1])
|
|
help_parser.parse_args(remaining)
|
|
return module.run_webview_test()
|
|
return module.main(remaining)
|
|
except (OSError, ValueError, RuntimeError, ImportError) as error:
|
|
print(f'{args.command}: {error}', file=sys.stderr)
|
|
return 1
|