prompttest 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CONTRIBUTING.md +80 -0
  2. package/LICENSE +36 -0
  3. package/LICENSES.md +81 -0
  4. package/README.md +402 -0
  5. package/SECURITY.md +56 -0
  6. package/dist/bin/prompttest.d.ts +2 -0
  7. package/dist/bin/prompttest.js +1020 -0
  8. package/dist/constants/commands.d.ts +125 -0
  9. package/dist/index.d.ts +140 -0
  10. package/dist/index.js +862 -0
  11. package/dist/lib/adb.d.ts +394 -0
  12. package/dist/lib/ai/heuristic-resolver.d.ts +19 -0
  13. package/dist/lib/ai/index.d.ts +16 -0
  14. package/dist/lib/ai/llm-provider.d.ts +40 -0
  15. package/dist/lib/ai/types.d.ts +64 -0
  16. package/dist/lib/baseline.d.ts +111 -0
  17. package/dist/lib/benchmark.d.ts +100 -0
  18. package/dist/lib/checkpoint.d.ts +61 -0
  19. package/dist/lib/config-loader.d.ts +87 -0
  20. package/dist/lib/config.d.ts +136 -0
  21. package/dist/lib/crawler.d.ts +335 -0
  22. package/dist/lib/data-loader.d.ts +53 -0
  23. package/dist/lib/dfs-engine.d.ts +106 -0
  24. package/dist/lib/dictionary.d.ts +41 -0
  25. package/dist/lib/doctor.d.ts +45 -0
  26. package/dist/lib/driver-interface.d.ts +50 -0
  27. package/dist/lib/enterprise.d.ts +71 -0
  28. package/dist/lib/errors.d.ts +68 -0
  29. package/dist/lib/explorer.d.ts +121 -0
  30. package/dist/lib/form-filler.d.ts +101 -0
  31. package/dist/lib/ios-driver.d.ts +38 -0
  32. package/dist/lib/live-server.d.ts +47 -0
  33. package/dist/lib/lock.d.ts +30 -0
  34. package/dist/lib/logger.d.ts +68 -0
  35. package/dist/lib/memory.d.ts +259 -0
  36. package/dist/lib/patterns.d.ts +202 -0
  37. package/dist/lib/prompt-runner.d.ts +100 -0
  38. package/dist/lib/recorder.d.ts +115 -0
  39. package/dist/lib/repl.d.ts +29 -0
  40. package/dist/lib/reporter.d.ts +253 -0
  41. package/dist/lib/runner-utils.d.ts +290 -0
  42. package/dist/lib/step-handlers.d.ts +388 -0
  43. package/docs/ARCHITECTURE.md +154 -0
  44. package/docs/USER_MANUAL.md +765 -0
  45. package/package.json +90 -0
@@ -0,0 +1,125 @@
1
+ /**
2
+ * @module commands
3
+ * @description Defines standard ADB (Android Debug Bridge) command arrays used throughout PromptTest.
4
+ * This centralizes all shell syntax, flags, and arguments required to control Android devices,
5
+ * preventing scattered string-building logic in the driver classes.
6
+ */
7
+ /**
8
+ * A collection of constants and factory functions for constructing ADB commands.
9
+ * All commands are represented as string arrays compatible with child_process.spawn.
10
+ */
11
+ export declare const ADB_COMMANDS: {
12
+ /** Command to list all attached devices and emulators. */
13
+ readonly DEVICES: readonly ["devices", "-l"];
14
+ /** Command to capture a raw PNG screenshot directly to standard output. */
15
+ readonly SCREENCAP: readonly ["exec-out", "screencap", "-p"];
16
+ /** Command to dump window manager state (used to extract screen dimensions and density). */
17
+ readonly FOREGROUND_APP: readonly ["shell", "dumpsys", "window"];
18
+ /** Command to dump activity state (used to identify the currently focused app package). */
19
+ readonly CURRENT_FOCUS: readonly ["shell", "dumpsys", "activity", "activities"];
20
+ /**
21
+ * Generates a command to forcefully terminate an application.
22
+ * @param pkg The Android package name to stop.
23
+ * @returns Array of ADB command arguments.
24
+ */
25
+ readonly FORCE_STOP: (pkg: string) => readonly string[];
26
+ /**
27
+ * Generates a command to clear all application data and cache.
28
+ * @param pkg The Android package name to clear.
29
+ * @returns Array of ADB command arguments.
30
+ */
31
+ readonly CLEAR_APP: (pkg: string) => readonly string[];
32
+ /**
33
+ * Generates a command to launch the main launcher activity of an app.
34
+ * @param pkg The Android package name to launch.
35
+ * @returns Array of ADB command arguments.
36
+ */
37
+ readonly LAUNCH_APP: (pkg: string) => readonly string[];
38
+ /** Command to dump the current UI Automator hierarchy as compressed XML to standard output. */
39
+ readonly UIAUTOMATOR_DUMP: readonly ["exec-out", "uiautomator", "dump", "--compressed", "/dev/tty"];
40
+ /**
41
+ * Generates a command to simulate a single tap event.
42
+ * @param x The X coordinate on the screen.
43
+ * @param y The Y coordinate on the screen.
44
+ * @returns Array of ADB command arguments.
45
+ */
46
+ readonly INPUT_TAP: (x: number, y: number) => readonly string[];
47
+ /**
48
+ * Generates a command to input text via the keyboard. Note: spaces and special chars must be escaped.
49
+ * @param escapedText The text to input, properly escaped for the Android shell.
50
+ * @returns Array of ADB command arguments.
51
+ */
52
+ readonly INPUT_TEXT: (escapedText: string) => readonly string[];
53
+ /**
54
+ * Generates a command to simulate a physical or logical key press (e.g., BACK=4, ENTER=66).
55
+ * @param keyCode The Android KeyEvent code number or name.
56
+ * @returns Array of ADB command arguments.
57
+ */
58
+ readonly INPUT_KEY: (keyCode: number | string) => readonly string[];
59
+ /**
60
+ * Generates a command to simulate a swipe gesture across the screen.
61
+ * @param x1 The starting X coordinate.
62
+ * @param y1 The starting Y coordinate.
63
+ * @param x2 The ending X coordinate.
64
+ * @param y2 The ending Y coordinate.
65
+ * @param durationMs The duration of the swipe in milliseconds (default: 300).
66
+ * @returns Array of ADB command arguments.
67
+ */
68
+ readonly INPUT_SWIPE: (x1: number, y1: number, x2: number, y2: number, durationMs?: number) => readonly string[];
69
+ /**
70
+ * Generates a command to extract the most recent AndroidRuntime crash logs for a package.
71
+ * @param pkg The Android package name (used by callers to filter the output if needed).
72
+ * @returns Array of ADB command arguments.
73
+ */
74
+ readonly LOGCAT_CRASH: (_pkg: string) => readonly string[];
75
+ /**
76
+ * Generates a command to clear the AndroidRuntime crash log buffer.
77
+ * @returns Array of ADB command arguments.
78
+ */
79
+ readonly CLEAR_CRASH_LOGS: () => readonly string[];
80
+ /**
81
+ * Generates a command to grant a runtime permission to an application.
82
+ * @param pkg The Android package name.
83
+ * @param perm The permission name (will automatically prepend 'android.permission.' if omitted).
84
+ * @returns Array of ADB command arguments.
85
+ */
86
+ readonly GRANT_PERMISSION: (pkg: string, perm: string) => readonly string[];
87
+ /**
88
+ * Generates a command to install an APK file on the device, replacing any existing version.
89
+ * @param path The path to the APK file on the host machine.
90
+ * @returns Array of ADB command arguments.
91
+ */
92
+ readonly INSTALL_APK: (path: string) => readonly string[];
93
+ /**
94
+ * Generates a command to completely uninstall an application from the device.
95
+ * @param pkg The Android package name to uninstall.
96
+ * @returns Array of ADB command arguments.
97
+ */
98
+ readonly UNINSTALL_APP: (pkg: string) => readonly string[];
99
+ /**
100
+ * Generates a command to trigger a specific URI intent (deep link) on the device.
101
+ * @param uri The deep link URI (e.g., 'myapp://settings').
102
+ * @returns Array of ADB command arguments.
103
+ */
104
+ readonly DEEP_LINK: (uri: string) => readonly string[];
105
+ /**
106
+ * Generates a command to restart the adbd daemon listening on TCP for wireless debugging.
107
+ * @param port The TCP port to listen on (default: 5555).
108
+ * @returns Array of ADB command arguments.
109
+ */
110
+ readonly TCPIP: (port?: number) => readonly string[];
111
+ /**
112
+ * Generates a command to connect to a device over TCP/IP.
113
+ * @param target The target IP and optional port (e.g., '192.168.1.100:5555').
114
+ * @returns Array of ADB command arguments.
115
+ */
116
+ readonly CONNECT: (target: string) => readonly string[];
117
+ /**
118
+ * Generates a command to disconnect from a specific TCP/IP device or all devices.
119
+ * @param target The optional target IP to disconnect from.
120
+ * @returns Array of ADB command arguments.
121
+ */
122
+ readonly DISCONNECT: (target?: string) => readonly string[];
123
+ /** Command to retrieve the device's WLAN IP address. */
124
+ readonly GET_WLAN_IP: readonly ["shell", "ip", "-f", "inet", "addr", "show", "wlan0"];
125
+ };
@@ -0,0 +1,140 @@
1
+ /**
2
+ * PromptTest — Ultra-fast, zero-code autonomous mobile testing & visual QA brain for Android
3
+ *
4
+ * Programmatic SDK & Core Engine Exports
5
+ *
6
+ * Architecture Overview:
7
+ * This module serves as the primary public SDK entry point for the PromptTest framework.
8
+ * It provides the building blocks (classes, types, and factory functions) to embed, extend,
9
+ * or orchestrate the testing engine in a multi-instance, parallelizable manner.
10
+ *
11
+ * NOTE: Singleton instances (promptRunner, androidDriver, etc.) are intentionally
12
+ * NOT exported from the public API. Use the factory functions below to create
13
+ * isolated instances with no shared state, which is required for parallel runs,
14
+ * programmatic embedding, and unit testing.
15
+ */
16
+ import { PromptRunner } from './lib/prompt-runner.js';
17
+ import { AndroidDriver } from './lib/adb.js';
18
+ import { AutonomousExplorer } from './lib/explorer.js';
19
+ import { MemoryEngine } from './lib/memory.js';
20
+ import { QaReporter } from './lib/reporter.js';
21
+ import { AutonomousRecorder } from './lib/recorder.js';
22
+ import { SemanticFormFiller } from './lib/form-filler.js';
23
+ import { BaselineManager } from './lib/baseline.js';
24
+ /** Core engine classes and execution types for test runs. */
25
+ export { PromptRunner, type PromptStep, type RunOptions } from './lib/prompt-runner.js';
26
+ /** ADB wrapper for low-level Android device interaction. */
27
+ export { AndroidDriver, type AndroidDevice } from './lib/adb.js';
28
+ /** Autonomous crawler and UI discovery engine. */
29
+ export { AutonomousExplorer } from './lib/explorer.js';
30
+ /** Dynamic locator learning and UI mapping storage. */
31
+ export { MemoryEngine, type LearnedMapping } from './lib/memory.js';
32
+ /** Audit and visual report generation tools. */
33
+ export { QaReporter, type QaReportData, type AuditStep, type ReportFormat } from './lib/reporter.js';
34
+ /** Interactive test creation via manual recording. */
35
+ export { AutonomousRecorder, type RecordedEvent } from './lib/recorder.js';
36
+ /** AI-powered semantic data generation for form filling. */
37
+ export { SemanticFormFiller, type TestDataPool, type FormFillResult } from './lib/form-filler.js';
38
+ /** Framework logging utilities. */
39
+ export { Logger, logger, type LogLevel } from './lib/logger.js';
40
+ /** Concurrency management for device access. */
41
+ export { acquireDeviceLock, releaseDeviceLock, type DeviceLock } from './lib/lock.js';
42
+ /** Visual regression testing and baseline image management. */
43
+ export { BaselineManager, baselineManager, type BaselineDiffResult, type MaskRegion, type BaselineCompareOptions, } from './lib/baseline.js';
44
+ /** Standard error classes and CLI exit codes. */
45
+ export { ExitCode, PromptTestError, DeviceError, LocatorError, ConfigError, LockError, SpecRecursionError, } from './lib/errors.js';
46
+ /** Additional utility modules and types */
47
+ export * from './lib/crawler.js';
48
+ export * from './lib/patterns.js';
49
+ export * from './lib/dictionary.js';
50
+ export * from './lib/config.js';
51
+ export * from './lib/config-loader.js';
52
+ export * from './lib/step-handlers.js';
53
+ export * from './lib/data-loader.js';
54
+ export * from './lib/live-server.js';
55
+ export * from './lib/runner-utils.js';
56
+ export * from './lib/ai/index.js';
57
+ export * from './lib/benchmark.js';
58
+ export * from './lib/doctor.js';
59
+ export * from './lib/repl.js';
60
+ export * from './lib/driver-interface.js';
61
+ export * from './lib/ios-driver.js';
62
+ export * from './lib/enterprise.js';
63
+ /**
64
+ * Factory functions to create isolated instances with no shared global state.
65
+ */
66
+ /**
67
+ * Creates an isolated PromptRunner instance.
68
+ * @param driver - Optional custom AndroidDriver instance to use.
69
+ * @param memory - Optional MemoryEngine instance for locator resolution.
70
+ * @param reporter - Optional QaReporter instance to log test results.
71
+ * @returns A fresh PromptRunner instance.
72
+ * @example
73
+ * const driver = createAndroidDriver();
74
+ * const runner = createPromptRunner(driver);
75
+ * await runner.runFile('test.txt');
76
+ */
77
+ export declare function createPromptRunner(driver?: AndroidDriver, memory?: MemoryEngine, reporter?: QaReporter): PromptRunner;
78
+ /**
79
+ * Creates an isolated AutonomousExplorer instance.
80
+ * @param driver - Optional custom AndroidDriver to control the device.
81
+ * @param formFiller - Optional SemanticFormFiller for input generation.
82
+ * @param reporter - Optional QaReporter for visual and audit logs.
83
+ * @returns A fresh AutonomousExplorer instance.
84
+ * @example
85
+ * const explorer = createAutonomousExplorer();
86
+ * await explorer.explore('com.example.app');
87
+ */
88
+ export declare function createAutonomousExplorer(driver?: AndroidDriver, formFiller?: SemanticFormFiller, reporter?: QaReporter): AutonomousExplorer;
89
+ /**
90
+ * Creates an isolated AndroidDriver instance.
91
+ * @param serial - Optional device serial number to target a specific device.
92
+ * @returns A fresh AndroidDriver instance.
93
+ * @example
94
+ * const driver = createAndroidDriver('emulator-5554');
95
+ * await driver.init();
96
+ */
97
+ export declare function createAndroidDriver(serial?: string): AndroidDriver;
98
+ /**
99
+ * Creates an isolated MemoryEngine instance.
100
+ * @returns A fresh MemoryEngine instance.
101
+ * @example
102
+ * const memory = createMemoryEngine();
103
+ * await memory.load();
104
+ */
105
+ export declare function createMemoryEngine(): MemoryEngine;
106
+ /**
107
+ * Creates an isolated QaReporter instance.
108
+ * @param outputDir - Optional custom directory path to write reports.
109
+ * @returns A fresh QaReporter instance.
110
+ * @example
111
+ * const reporter = createQaReporter('./reports');
112
+ * reporter.logStep('Started run');
113
+ */
114
+ export declare function createQaReporter(outputDir?: string): QaReporter;
115
+ /**
116
+ * Creates an isolated AutonomousRecorder instance.
117
+ * @param driver - Optional custom AndroidDriver for recording events.
118
+ * @returns A fresh AutonomousRecorder instance.
119
+ * @example
120
+ * const recorder = createAutonomousRecorder();
121
+ * await recorder.start();
122
+ */
123
+ export declare function createAutonomousRecorder(driver?: AndroidDriver): AutonomousRecorder;
124
+ /**
125
+ * Creates an isolated SemanticFormFiller instance.
126
+ * @param customDataPath - Optional path to custom form data definitions.
127
+ * @param driver - Optional AndroidDriver instance.
128
+ * @returns A fresh SemanticFormFiller instance.
129
+ * @example
130
+ * const filler = createFormFiller('./custom-data.json');
131
+ * await filler.fillCurrentScreen();
132
+ */
133
+ export declare function createFormFiller(customDataPath?: string, driver?: AndroidDriver): SemanticFormFiller;
134
+ /**
135
+ * Creates an isolated BaselineManager instance.
136
+ * @param baselineDir - Optional directory path to store baseline images.
137
+ * @param threshold - Optional default threshold ratio.
138
+ * @returns A fresh BaselineManager instance.
139
+ */
140
+ export declare function createBaselineManager(baselineDir?: string, threshold?: number): BaselineManager;