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,100 @@
1
+ /**
2
+ * @module benchmark
3
+ * @description
4
+ * Performance benchmarking and diagnostic utilities for PromptTest.
5
+ * Measures latency and timing distributions (min, avg, p50, p95, max) for
6
+ * UI hierarchy dumping, screen captures, and fuzzy/spatial node matching.
7
+ */
8
+ import { AndroidDriver } from './adb.js';
9
+ import { UiNode } from './crawler.js';
10
+ /**
11
+ * Statistical latency metrics computed over a series of benchmark iterations.
12
+ */
13
+ export interface BenchmarkMetrics {
14
+ /** Minimum elapsed time in milliseconds */
15
+ minMs: number;
16
+ /** Maximum elapsed time in milliseconds */
17
+ maxMs: number;
18
+ /** Arithmetic average elapsed time in milliseconds */
19
+ avgMs: number;
20
+ /** 50th percentile (median) elapsed time in milliseconds */
21
+ p50Ms: number;
22
+ /** 95th percentile elapsed time in milliseconds */
23
+ p95Ms: number;
24
+ /** Number of recorded samples */
25
+ iterations: number;
26
+ /** Raw recorded durations in milliseconds */
27
+ durations: number[];
28
+ }
29
+ /**
30
+ * Complete benchmark report covering core device and engine operations.
31
+ */
32
+ export interface BenchmarkReport {
33
+ /** ISO 8601 timestamp when the benchmark was executed */
34
+ timestamp: string;
35
+ /** Device identifier or model tested */
36
+ device: string;
37
+ /** Target package tested, if specified */
38
+ package?: string;
39
+ /** Screen capture latency metrics */
40
+ screencap: BenchmarkMetrics;
41
+ /** UI hierarchy dump and parsing latency metrics */
42
+ uiHierarchy: BenchmarkMetrics;
43
+ /** Natural language node matching latency metrics on 1,000-node layout */
44
+ nodeMatching: BenchmarkMetrics;
45
+ /** Total elapsed time of the benchmark suite in milliseconds */
46
+ totalDurationMs: number;
47
+ }
48
+ /**
49
+ * Configuration options for running performance benchmarks.
50
+ */
51
+ export interface BenchmarkOptions {
52
+ /** Number of benchmark iterations per operation (default: 5) */
53
+ iterations?: number;
54
+ /** Target device serial number */
55
+ serial?: string;
56
+ /** Target application package name */
57
+ packageName?: string;
58
+ /** If true, executes against synthetic mock data even if device is present */
59
+ forceMock?: boolean;
60
+ }
61
+ /**
62
+ * Calculates a specific percentile (e.g. 50 for median, 95 for p95) from raw numbers.
63
+ *
64
+ * @param values - Array of numeric measurements.
65
+ * @param percentile - Target percentile in range [0, 100].
66
+ * @returns The calculated percentile value rounded to two decimal places.
67
+ */
68
+ export declare function calculatePercentile(values: number[], percentile: number): number;
69
+ /**
70
+ * Computes summary statistical metrics from an array of measured durations.
71
+ *
72
+ * @param durations - Array of measured durations in milliseconds.
73
+ * @returns Computed BenchmarkMetrics.
74
+ */
75
+ export declare function summarizeMetrics(durations: number[]): BenchmarkMetrics;
76
+ /**
77
+ * Generates a realistic synthetic 1,000-node UI hierarchy tree for benchmark matching.
78
+ * Models a complex mobile application screen containing headers, nested scroll lists,
79
+ * form inputs, action cards, and navigational tabs.
80
+ *
81
+ * @param nodeCount - Target number of nodes to generate (default: 1000).
82
+ * @returns An array of 1,000 structured UiNode elements.
83
+ */
84
+ export declare function generateSyntheticHierarchy(nodeCount?: number): UiNode[];
85
+ /**
86
+ * Runs the diagnostic benchmark across device screencap, hierarchy retrieval,
87
+ * and natural language node matching algorithms.
88
+ *
89
+ * @param driver - The AndroidDriver instance to benchmark against.
90
+ * @param options - Benchmark configuration options.
91
+ * @returns Completed BenchmarkReport.
92
+ */
93
+ export declare function runBenchmark(driver?: AndroidDriver, options?: BenchmarkOptions): Promise<BenchmarkReport>;
94
+ /**
95
+ * Formats a BenchmarkReport into an attractive CLI terminal summary table.
96
+ *
97
+ * @param report - The BenchmarkReport to format.
98
+ * @returns Multi-line formatted string.
99
+ */
100
+ export declare function formatBenchmarkTable(report: BenchmarkReport): string;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Structure of the saved checkpoint JSON data.
3
+ */
4
+ export interface CheckpointData {
5
+ /** The specification file name or identifier that was being executed. */
6
+ specFile: string;
7
+ /** The Android package name of the app under test. */
8
+ packageName: string;
9
+ /** The 0-based index of the last step that was successfully completed. */
10
+ lastPassedStep: number;
11
+ /** The total number of steps in the specification. */
12
+ totalSteps: number;
13
+ /** ISO 8601 timestamp of when the checkpoint was saved. */
14
+ savedAt: string;
15
+ }
16
+ /**
17
+ * Manages saving, loading, and clearing execution checkpoints for test runs.
18
+ */
19
+ export declare class CheckpointManager {
20
+ private checkpointDir;
21
+ /**
22
+ * Initializes a new CheckpointManager.
23
+ *
24
+ * @param checkpointDir The directory where checkpoint files should be stored. Defaults to './output/checkpoints'.
25
+ */
26
+ constructor(checkpointDir?: string);
27
+ private filePath;
28
+ /**
29
+ * Persists the index of the last successfully completed step (0-based).
30
+ *
31
+ * @param specName The name of the test specification.
32
+ * @param packageName The Android package name.
33
+ * @param lastPassedStep The 0-based index of the step just completed.
34
+ * @param totalSteps The total number of steps in the test.
35
+ */
36
+ save(specName: string, packageName: string, lastPassedStep: number, totalSteps: number): Promise<void>;
37
+ /**
38
+ * Loads an existing checkpoint from disk.
39
+ *
40
+ * @param specName The name of the test specification.
41
+ * @returns A Promise resolving to the parsed CheckpointData, or null if no checkpoint exists or it's invalid.
42
+ */
43
+ load(specName: string): Promise<CheckpointData | null>;
44
+ /**
45
+ * Deletes a checkpoint for a given spec. Should be called after a fully successful run.
46
+ *
47
+ * @param specName The name of the test specification.
48
+ */
49
+ clear(specName: string): Promise<void>;
50
+ /**
51
+ * Returns the 0-based step index to resume from, based on the last saved checkpoint.
52
+ *
53
+ * @param specName The name of the test specification.
54
+ * @returns The 0-based step index to resume from, or 0 if no checkpoint is found.
55
+ */
56
+ getResumeIndex(specName: string): Promise<number>;
57
+ }
58
+ /**
59
+ * A globally accessible singleton instance of CheckpointManager.
60
+ */
61
+ export declare const checkpointManager: CheckpointManager;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @module config-loader
3
+ * @description Discovers, parses, and merges PromptTest configuration from prompttest.config.json
4
+ * and environment variables (PROMPTTEST_*) over CONFIG defaults.
5
+ */
6
+ export interface PromptTestConfig {
7
+ adb: {
8
+ commandTimeoutMs: number;
9
+ binaryTimeoutMs: number;
10
+ retryCount: number;
11
+ retryBaseDelayMs: number;
12
+ };
13
+ polling: {
14
+ intervalMs: number;
15
+ jitterMs: number;
16
+ defaultTimeoutMs: number;
17
+ extendedTimeoutMs: number;
18
+ hierarchyCacheTtlMs: number;
19
+ verifyCacheTtlMs: number;
20
+ };
21
+ settle: {
22
+ tapMs: number;
23
+ backMs: number;
24
+ launchMs: number;
25
+ stopMs: number;
26
+ keyboardDismissMs: number;
27
+ scrollMs: number;
28
+ toggleMs: number;
29
+ selectMs: number;
30
+ inputFocusMs: number;
31
+ inputClearMs: number;
32
+ inputDoneMs: number;
33
+ submitWaitMs: number;
34
+ };
35
+ gestures: {
36
+ swipeDurationMs: number;
37
+ longPressDurationMs: number;
38
+ bottomNavThresholdRatio: number;
39
+ tapTargetYRatio: number;
40
+ };
41
+ recorder: {
42
+ staleTapTimeoutMs: number;
43
+ asyncRefreshDelayMs: number;
44
+ heartbeatIntervalMs: number;
45
+ };
46
+ screen: {
47
+ fallbackWidth: number;
48
+ fallbackHeight: number;
49
+ };
50
+ visual: {
51
+ overlapRatio: number;
52
+ };
53
+ device: {
54
+ maxDeviceRetries: number;
55
+ autoReconnect: boolean;
56
+ };
57
+ flow: {
58
+ maxLoopIterations: number;
59
+ waitUntilTimeoutMs: number;
60
+ defaultRetryCount: number;
61
+ };
62
+ ai: {
63
+ provider: 'heuristic' | 'openai' | 'anthropic' | 'ollama' | 'mock';
64
+ model: string;
65
+ selfHealing: boolean;
66
+ confidenceThreshold: number;
67
+ maxHealingAttempts: number;
68
+ endpoint: string;
69
+ };
70
+ locale: string;
71
+ }
72
+ /**
73
+ * Loads configuration by merging CONFIG defaults, prompttest.config.json (if present),
74
+ * and PROMPTTEST_* environment variables.
75
+ *
76
+ * @param configFilePath - Optional explicit path to configuration JSON file.
77
+ * @returns The resolved PromptTestConfig object.
78
+ */
79
+ export declare function loadConfig(configFilePath?: string): PromptTestConfig;
80
+ /**
81
+ * Returns the currently active configuration, loading it if not yet initialized.
82
+ */
83
+ export declare function getActiveConfig(): PromptTestConfig;
84
+ /**
85
+ * Resets the active configuration cache (useful for testing).
86
+ */
87
+ export declare function resetActiveConfig(): void;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @module config
3
+ * @description Centralized PromptTest Engine Configuration.
4
+ *
5
+ * Consolidates all magic numbers, timeouts, settle durations,
6
+ * gesture thresholds, and polling strategies across the codebase.
7
+ * This guarantees consistent timing and reliable execution behavior
8
+ * during natural language script execution, autonomous crawling,
9
+ * and ADB interactions.
10
+ */
11
+ /**
12
+ * Helper to compute settle scaling factor from PROMPTTEST_SETTLE_FACTOR environment variable.
13
+ */
14
+ export declare function getSettleFactor(): number;
15
+ /**
16
+ * Scales a duration in milliseconds by the global settle factor, clamped to a minimum floor.
17
+ *
18
+ * @param ms - Target duration in milliseconds.
19
+ * @param minFloorMs - Minimum floor duration in milliseconds (default: 50).
20
+ * @returns Scaled millisecond duration.
21
+ */
22
+ export declare function scaleSettle(ms: number, minFloorMs?: number): number;
23
+ /**
24
+ * The global configuration settings for PromptTest.
25
+ */
26
+ export declare const CONFIG: {
27
+ /** Configuration related to ADB command execution and retry behavior. */
28
+ readonly adb: {
29
+ readonly commandTimeoutMs: 20000;
30
+ readonly binaryTimeoutMs: 45000;
31
+ readonly retryCount: 2;
32
+ readonly retryBaseDelayMs: 200;
33
+ };
34
+ /** Configuration for UI hierarchy polling and caching mechanisms. */
35
+ readonly polling: {
36
+ readonly intervalMs: 200;
37
+ readonly jitterMs: 80;
38
+ readonly defaultTimeoutMs: 3000;
39
+ readonly extendedTimeoutMs: 3500;
40
+ readonly hierarchyCacheTtlMs: 3500;
41
+ readonly verifyCacheTtlMs: 2000;
42
+ };
43
+ /** Delays applied after various UI interactions to allow animations or state changes to settle. */
44
+ readonly settle: {
45
+ readonly tapMs: number;
46
+ readonly backMs: number;
47
+ readonly launchMs: number;
48
+ readonly stopMs: number;
49
+ readonly keyboardDismissMs: number;
50
+ readonly scrollMs: number;
51
+ readonly toggleMs: number;
52
+ readonly selectMs: number;
53
+ readonly inputFocusMs: number;
54
+ readonly inputClearMs: number;
55
+ readonly inputDoneMs: number;
56
+ readonly submitWaitMs: number;
57
+ };
58
+ /** Parameters for Android gesture generation, calculating bounds, and swipe physics. */
59
+ readonly gestures: {
60
+ readonly swipeDurationMs: 300;
61
+ readonly longPressDurationMs: 1000;
62
+ readonly bottomNavThresholdRatio: 0.88;
63
+ readonly tapTargetYRatio: 0.96;
64
+ };
65
+ /** Settings for the AutonomousRecorder component monitoring live device usage. */
66
+ readonly recorder: {
67
+ readonly staleTapTimeoutMs: 3000;
68
+ readonly asyncRefreshDelayMs: 80;
69
+ readonly heartbeatIntervalMs: 1500;
70
+ };
71
+ /** Screen geometry defaults when device cannot report dimensions. */
72
+ readonly screen: {
73
+ readonly fallbackWidth: 1080;
74
+ readonly fallbackHeight: 2400;
75
+ };
76
+ /** Visual defect detection thresholds and settings. */
77
+ readonly visual: {
78
+ readonly overlapRatio: 0.2;
79
+ };
80
+ /** Device connection and resilience parameters. */
81
+ readonly device: {
82
+ readonly maxDeviceRetries: 2;
83
+ readonly autoReconnect: true;
84
+ };
85
+ /** Programmatic flow control, loops, and conditional execution. */
86
+ readonly flow: {
87
+ readonly maxLoopIterations: 50;
88
+ readonly waitUntilTimeoutMs: 10000;
89
+ readonly defaultRetryCount: 3;
90
+ };
91
+ /** AI step expansion, semantic locator resolution, and self-healing. */
92
+ readonly ai: {
93
+ readonly provider: "heuristic" | "openai" | "anthropic" | "ollama" | "mock";
94
+ readonly model: "gpt-4o-mini";
95
+ readonly selfHealing: true;
96
+ readonly confidenceThreshold: 0.75;
97
+ readonly maxHealingAttempts: 2;
98
+ readonly endpoint: "";
99
+ };
100
+ /** Autonomous locator learning and persistent memory configuration. */
101
+ readonly memory: {
102
+ readonly staleThresholdDays: number;
103
+ readonly staleDecayAmount: 0.2;
104
+ readonly minConfidenceFloor: 0.2;
105
+ readonly maxHealedConfidence: 0.65;
106
+ };
107
+ /** UI Hierarchy XML parser configuration (SP-05). */
108
+ readonly parser: {
109
+ readonly mode: "regex" | "streaming";
110
+ };
111
+ /** Safety guard configuration for autonomous actions (AX-09, AX-10). */
112
+ readonly safety: {
113
+ readonly mode: "strict" | "moderate" | "interactive" | "disabled";
114
+ readonly customBlacklist: readonly string[];
115
+ };
116
+ /** Autonomous Explorer v3 settings (AX-12, AX-15, AX-16). */
117
+ readonly explorer: {
118
+ readonly strategy: "dfs" | "heuristic";
119
+ readonly maxTabs: number;
120
+ readonly maxScreens: number;
121
+ readonly maxDepth: number;
122
+ readonly stepBudget: number;
123
+ readonly screenshots: "state-change" | "failure-only" | "all";
124
+ };
125
+ /** Localization and multilingual taxonomy configuration. */
126
+ readonly locale: "en";
127
+ };
128
+ /**
129
+ * Returns a polling delay with random jitter to prevent thundering herd
130
+ * and reduce contention with the ADB daemon.
131
+ *
132
+ * @param baseMs The base delay in milliseconds. Defaults to CONFIG.polling.intervalMs.
133
+ * @param jitterMs The maximum jitter range in milliseconds. Defaults to CONFIG.polling.jitterMs.
134
+ * @returns A computed delay in milliseconds including base and jitter.
135
+ */
136
+ export declare function getJitteredPollDelay(baseMs?: number, jitterMs?: number): number;