testchimp-runner-core 0.0.34 → 0.0.36

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 (150) hide show
  1. package/dist/execution-service.d.ts +1 -4
  2. package/dist/execution-service.d.ts.map +1 -1
  3. package/dist/execution-service.js +155 -468
  4. package/dist/execution-service.js.map +1 -1
  5. package/dist/index.d.ts +3 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +11 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/orchestrator/decision-parser.d.ts +18 -0
  10. package/dist/orchestrator/decision-parser.d.ts.map +1 -0
  11. package/dist/orchestrator/decision-parser.js +127 -0
  12. package/dist/orchestrator/decision-parser.js.map +1 -0
  13. package/dist/orchestrator/index.d.ts +4 -2
  14. package/dist/orchestrator/index.d.ts.map +1 -1
  15. package/dist/orchestrator/index.js +14 -2
  16. package/dist/orchestrator/index.js.map +1 -1
  17. package/dist/orchestrator/orchestrator-agent.d.ts +17 -14
  18. package/dist/orchestrator/orchestrator-agent.d.ts.map +1 -1
  19. package/dist/orchestrator/orchestrator-agent.js +534 -204
  20. package/dist/orchestrator/orchestrator-agent.js.map +1 -1
  21. package/dist/orchestrator/orchestrator-prompts.d.ts +14 -2
  22. package/dist/orchestrator/orchestrator-prompts.d.ts.map +1 -1
  23. package/dist/orchestrator/orchestrator-prompts.js +529 -247
  24. package/dist/orchestrator/orchestrator-prompts.js.map +1 -1
  25. package/dist/orchestrator/page-som-handler.d.ts +106 -0
  26. package/dist/orchestrator/page-som-handler.d.ts.map +1 -0
  27. package/dist/orchestrator/page-som-handler.js +1353 -0
  28. package/dist/orchestrator/page-som-handler.js.map +1 -0
  29. package/dist/orchestrator/som-types.d.ts +149 -0
  30. package/dist/orchestrator/som-types.d.ts.map +1 -0
  31. package/dist/orchestrator/som-types.js +87 -0
  32. package/dist/orchestrator/som-types.js.map +1 -0
  33. package/dist/orchestrator/tool-registry.d.ts +2 -0
  34. package/dist/orchestrator/tool-registry.d.ts.map +1 -1
  35. package/dist/orchestrator/tool-registry.js.map +1 -1
  36. package/dist/orchestrator/tools/index.d.ts +4 -1
  37. package/dist/orchestrator/tools/index.d.ts.map +1 -1
  38. package/dist/orchestrator/tools/index.js +7 -2
  39. package/dist/orchestrator/tools/index.js.map +1 -1
  40. package/dist/orchestrator/tools/refresh-som-markers.d.ts +12 -0
  41. package/dist/orchestrator/tools/refresh-som-markers.d.ts.map +1 -0
  42. package/dist/orchestrator/tools/refresh-som-markers.js +64 -0
  43. package/dist/orchestrator/tools/refresh-som-markers.js.map +1 -0
  44. package/dist/orchestrator/tools/view-previous-screenshot.d.ts +15 -0
  45. package/dist/orchestrator/tools/view-previous-screenshot.d.ts.map +1 -0
  46. package/dist/orchestrator/tools/view-previous-screenshot.js +92 -0
  47. package/dist/orchestrator/tools/view-previous-screenshot.js.map +1 -0
  48. package/dist/orchestrator/types.d.ts +23 -1
  49. package/dist/orchestrator/types.d.ts.map +1 -1
  50. package/dist/orchestrator/types.js +11 -1
  51. package/dist/orchestrator/types.js.map +1 -1
  52. package/dist/scenario-service.d.ts +5 -0
  53. package/dist/scenario-service.d.ts.map +1 -1
  54. package/dist/scenario-service.js +17 -0
  55. package/dist/scenario-service.js.map +1 -1
  56. package/dist/scenario-worker-class.d.ts +4 -0
  57. package/dist/scenario-worker-class.d.ts.map +1 -1
  58. package/dist/scenario-worker-class.js +18 -3
  59. package/dist/scenario-worker-class.js.map +1 -1
  60. package/dist/testing/agent-tester.d.ts +35 -0
  61. package/dist/testing/agent-tester.d.ts.map +1 -0
  62. package/dist/testing/agent-tester.js +84 -0
  63. package/dist/testing/agent-tester.js.map +1 -0
  64. package/dist/testing/ref-translator-tester.d.ts +44 -0
  65. package/dist/testing/ref-translator-tester.d.ts.map +1 -0
  66. package/dist/testing/ref-translator-tester.js +104 -0
  67. package/dist/testing/ref-translator-tester.js.map +1 -0
  68. package/dist/utils/hierarchical-selector.d.ts +47 -0
  69. package/dist/utils/hierarchical-selector.d.ts.map +1 -0
  70. package/dist/utils/hierarchical-selector.js +212 -0
  71. package/dist/utils/hierarchical-selector.js.map +1 -0
  72. package/dist/utils/page-info-retry.d.ts +14 -0
  73. package/dist/utils/page-info-retry.d.ts.map +1 -0
  74. package/dist/utils/page-info-retry.js +60 -0
  75. package/dist/utils/page-info-retry.js.map +1 -0
  76. package/dist/utils/page-info-utils.d.ts +1 -0
  77. package/dist/utils/page-info-utils.d.ts.map +1 -1
  78. package/dist/utils/page-info-utils.js +46 -18
  79. package/dist/utils/page-info-utils.js.map +1 -1
  80. package/dist/utils/ref-attacher.d.ts +21 -0
  81. package/dist/utils/ref-attacher.d.ts.map +1 -0
  82. package/dist/utils/ref-attacher.js +149 -0
  83. package/dist/utils/ref-attacher.js.map +1 -0
  84. package/dist/utils/ref-translator.d.ts +49 -0
  85. package/dist/utils/ref-translator.d.ts.map +1 -0
  86. package/dist/utils/ref-translator.js +276 -0
  87. package/dist/utils/ref-translator.js.map +1 -0
  88. package/package.json +6 -1
  89. package/RELEASE_0.0.26.md +0 -165
  90. package/RELEASE_0.0.27.md +0 -236
  91. package/RELEASE_0.0.28.md +0 -286
  92. package/plandocs/BEFORE_AFTER_VERIFICATION.md +0 -148
  93. package/plandocs/COORDINATE_MODE_DIAGNOSIS.md +0 -144
  94. package/plandocs/CREDIT_CALLBACK_ARCHITECTURE.md +0 -253
  95. package/plandocs/HUMAN_LIKE_IMPROVEMENTS.md +0 -642
  96. package/plandocs/IMPLEMENTATION_STATUS.md +0 -108
  97. package/plandocs/INTEGRATION_COMPLETE.md +0 -322
  98. package/plandocs/MULTI_AGENT_ARCHITECTURE_REVIEW.md +0 -844
  99. package/plandocs/ORCHESTRATOR_MVP_SUMMARY.md +0 -539
  100. package/plandocs/PHASE1_ABSTRACTION_COMPLETE.md +0 -241
  101. package/plandocs/PHASE1_FINAL_STATUS.md +0 -210
  102. package/plandocs/PHASE_1_COMPLETE.md +0 -165
  103. package/plandocs/PHASE_1_SUMMARY.md +0 -184
  104. package/plandocs/PLANNING_SESSION_SUMMARY.md +0 -372
  105. package/plandocs/PROMPT_OPTIMIZATION_ANALYSIS.md +0 -120
  106. package/plandocs/PROMPT_SANITY_CHECK.md +0 -120
  107. package/plandocs/SCRIPT_CLEANUP_FEATURE.md +0 -201
  108. package/plandocs/SCRIPT_GENERATION_ARCHITECTURE.md +0 -364
  109. package/plandocs/SELECTOR_IMPROVEMENTS.md +0 -139
  110. package/plandocs/SESSION_SUMMARY_v0.0.33.md +0 -151
  111. package/plandocs/TROUBLESHOOTING_SESSION.md +0 -72
  112. package/plandocs/VISION_DIAGNOSTICS_IMPROVEMENTS.md +0 -336
  113. package/plandocs/VISUAL_AGENT_EVOLUTION_PLAN.md +0 -396
  114. package/plandocs/WHATS_NEW_v0.0.33.md +0 -183
  115. package/src/auth-config.ts +0 -84
  116. package/src/credit-usage-service.ts +0 -188
  117. package/src/env-loader.ts +0 -103
  118. package/src/execution-service.ts +0 -1413
  119. package/src/file-handler.ts +0 -104
  120. package/src/index.ts +0 -422
  121. package/src/llm-facade.ts +0 -821
  122. package/src/llm-provider.ts +0 -53
  123. package/src/model-constants.ts +0 -35
  124. package/src/orchestrator/index.ts +0 -34
  125. package/src/orchestrator/orchestrator-agent.ts +0 -862
  126. package/src/orchestrator/orchestrator-agent.ts.backup +0 -1386
  127. package/src/orchestrator/orchestrator-prompts.ts +0 -474
  128. package/src/orchestrator/tool-registry.ts +0 -182
  129. package/src/orchestrator/tools/check-page-ready.ts +0 -75
  130. package/src/orchestrator/tools/extract-data.ts +0 -92
  131. package/src/orchestrator/tools/index.ts +0 -12
  132. package/src/orchestrator/tools/inspect-page.ts +0 -42
  133. package/src/orchestrator/tools/recall-history.ts +0 -72
  134. package/src/orchestrator/tools/take-screenshot.ts +0 -128
  135. package/src/orchestrator/tools/verify-action-result.ts +0 -159
  136. package/src/orchestrator/types.ts +0 -248
  137. package/src/playwright-mcp-service.ts +0 -224
  138. package/src/progress-reporter.ts +0 -144
  139. package/src/prompts.ts +0 -842
  140. package/src/providers/backend-proxy-llm-provider.ts +0 -91
  141. package/src/providers/local-llm-provider.ts +0 -38
  142. package/src/scenario-service.ts +0 -232
  143. package/src/scenario-worker-class.ts +0 -1089
  144. package/src/script-utils.ts +0 -203
  145. package/src/types.ts +0 -239
  146. package/src/utils/browser-utils.ts +0 -348
  147. package/src/utils/coordinate-converter.ts +0 -162
  148. package/src/utils/page-info-utils.ts +0 -250
  149. package/testchimp-runner-core-0.0.33.tgz +0 -0
  150. package/tsconfig.json +0 -19
@@ -1,104 +0,0 @@
1
- /**
2
- * File Handler Interface
3
- * Defines how different platforms handle file operations
4
- */
5
-
6
- export interface FileHandler {
7
- /**
8
- * Read test file content
9
- * @param filePath Path to the test file
10
- * @returns File content as string
11
- */
12
- readTestFile(filePath: string): Promise<string>;
13
-
14
- /**
15
- * Resolve a relative path to an absolute path based on the current working directory
16
- * @param relativePath Relative path to resolve
17
- * @returns Absolute path
18
- */
19
- resolvePath(relativePath: string): string;
20
-
21
- /**
22
- * Check if a file exists
23
- * @param filePath Path to check
24
- * @returns True if file exists
25
- */
26
- fileExists(filePath: string): Promise<boolean>;
27
- }
28
-
29
- /**
30
- * Local File Handler - Direct file system operations
31
- * Used by VS Code extension for local development
32
- */
33
- export class LocalFileHandler implements FileHandler {
34
- private fs = require('fs');
35
- private path = require('path');
36
- private basePath: string;
37
-
38
- constructor(basePath?: string) {
39
- this.basePath = basePath || String(process.cwd());
40
- }
41
-
42
- async readTestFile(filePath: string): Promise<string> {
43
- return this.fs.readFileSync(String(filePath), 'utf8');
44
- }
45
-
46
- resolvePath(relativePath: string): string {
47
- return this.path.resolve(String(this.basePath), String(relativePath));
48
- }
49
-
50
- async fileExists(filePath: string): Promise<boolean> {
51
- try {
52
- return this.fs.existsSync(String(filePath));
53
- } catch {
54
- return false;
55
- }
56
- }
57
- }
58
-
59
- /**
60
- * CI/CD File Handler - For CI/CD environments
61
- * Used by GitHub Actions for CI/CD environments
62
- */
63
- export class CIFileHandler implements FileHandler {
64
- private fs = require('fs');
65
- private path = require('path');
66
- private basePath: string;
67
-
68
- constructor(basePath?: string) {
69
- this.basePath = basePath || String(process.cwd());
70
- }
71
-
72
- async readTestFile(filePath: string): Promise<string> {
73
- return this.fs.readFileSync(String(filePath), 'utf8');
74
- }
75
-
76
- resolvePath(relativePath: string): string {
77
- return this.path.resolve(String(this.basePath), String(relativePath));
78
- }
79
-
80
- async fileExists(filePath: string): Promise<boolean> {
81
- try {
82
- return this.fs.existsSync(String(filePath));
83
- } catch {
84
- return false;
85
- }
86
- }
87
- }
88
-
89
- /**
90
- * No-op File Handler - For testing or when file operations are not needed
91
- */
92
- export class NoOpFileHandler implements FileHandler {
93
- async readTestFile(filePath: string): Promise<string> {
94
- return '';
95
- }
96
-
97
- resolvePath(relativePath: string): string {
98
- return relativePath;
99
- }
100
-
101
- async fileExists(filePath: string): Promise<boolean> {
102
- return false;
103
- }
104
- }
package/src/index.ts DELETED
@@ -1,422 +0,0 @@
1
- /**
2
- * TestChimp Runner Core
3
- * Shared functionality for VS Code extension and GitHub Actions
4
- */
5
-
6
- // Core services
7
- import { ExecutionService } from './execution-service';
8
- import { ScenarioService } from './scenario-service';
9
- import { ScenarioWorker } from './scenario-worker-class';
10
- import { PlaywrightMCPService } from './playwright-mcp-service';
11
- import { LLMFacade } from './llm-facade';
12
- import { AuthConfig } from './auth-config';
13
- import { CreditUsageService, CreditUsageCallback, CreditUsage, CreditUsageReason } from './credit-usage-service';
14
-
15
- export { ExecutionService, ScenarioService, ScenarioWorker, PlaywrightMCPService, LLMFacade, CreditUsageService, CreditUsageCallback, CreditUsage, CreditUsageReason };
16
-
17
- // File handlers
18
- import { FileHandler, LocalFileHandler, CIFileHandler, NoOpFileHandler } from './file-handler';
19
- export { FileHandler, LocalFileHandler, CIFileHandler, NoOpFileHandler };
20
-
21
- // LLM Provider interfaces
22
- import { LLMProvider, LLMRequest, LLMResponse } from './llm-provider';
23
- import { ProgressReporter, StepProgress, JobProgress, StepExecutionStatus, StepInfo } from './progress-reporter';
24
- import { BackendProxyLLMProvider } from './providers/backend-proxy-llm-provider';
25
- import { LocalLLMProvider } from './providers/local-llm-provider';
26
-
27
- export { LLMProvider, LLMRequest, LLMResponse };
28
- export { ProgressReporter, StepProgress, JobProgress, StepExecutionStatus, StepInfo };
29
- export { BackendProxyLLMProvider, LocalLLMProvider };
30
-
31
- // Orchestrator (tool-using agent)
32
- import type { AgentConfig } from './orchestrator';
33
- export {
34
- OrchestratorAgent,
35
- ToolRegistry,
36
- Tool,
37
- ToolParameter,
38
- ToolExecutionContext,
39
- AgentConfig,
40
- AgentContext,
41
- AgentDecision,
42
- JourneyMemory,
43
- MemoryStep,
44
- OrchestratorStepResult,
45
- SelfReflection,
46
- ToolCall,
47
- ToolResult,
48
- DEFAULT_AGENT_CONFIG,
49
- // Tools (information-gathering only)
50
- TakeScreenshotTool,
51
- RecallHistoryTool,
52
- InspectPageTool,
53
- CheckPageReadyTool,
54
- ExtractDataTool
55
- } from './orchestrator';
56
-
57
- // Types
58
- export * from './types';
59
- export { PageInfo, InteractiveElement } from './utils/page-info-utils';
60
-
61
- // Authentication
62
- export * from './auth-config';
63
-
64
- // Environment configuration
65
- export { loadEnvConfig } from './env-loader';
66
-
67
- // Script utilities
68
- export * from './script-utils';
69
-
70
- // Main TestChimp service class
71
- export class TestChimpService {
72
- private executionService: ExecutionService;
73
- public scenarioService: ScenarioService; // Make public for event listening
74
- private playwrightService: PlaywrightMCPService;
75
- private llmProvider: LLMProvider;
76
- private progressReporter?: ProgressReporter;
77
- private creditUsageService: CreditUsageService;
78
- private fileHandler: FileHandler;
79
- private authConfig: AuthConfig | null;
80
- private backendUrl: string;
81
- private logger?: (message: string, level?: 'log' | 'error' | 'warn') => void;
82
- private orchestratorOptions?: { useOrchestrator?: boolean; orchestratorConfig?: Partial<AgentConfig>; debugMode?: boolean };
83
- private outputChannel?: any; // Store outputChannel to preserve it across service recreations
84
- private creditUsageCallback?: CreditUsageCallback; // Store credit callback to preserve it across service recreations
85
-
86
- constructor(
87
- fileHandler?: FileHandler,
88
- authConfig?: AuthConfig,
89
- backendUrl?: string,
90
- maxWorkers?: number,
91
- llmProvider?: LLMProvider,
92
- progressReporter?: ProgressReporter,
93
- orchestratorOptions?: { useOrchestrator?: boolean; orchestratorConfig?: Partial<AgentConfig>; debugMode?: boolean },
94
- creditUsageCallback?: CreditUsageCallback
95
- ) {
96
- this.fileHandler = fileHandler || new NoOpFileHandler();
97
- this.authConfig = authConfig || null;
98
- this.backendUrl = backendUrl || 'https://featureservice.testchimp.io'; // Default to production
99
- this.progressReporter = progressReporter;
100
- this.orchestratorOptions = orchestratorOptions;
101
- this.creditUsageCallback = creditUsageCallback;
102
-
103
- // Use provided LLM provider or default to backend proxy (backward compatible)
104
- this.llmProvider = llmProvider || new BackendProxyLLMProvider(authConfig, backendUrl);
105
-
106
- this.playwrightService = new PlaywrightMCPService();
107
- // Pass credit callback to constructor - preserved across recreations via this.creditUsageCallback
108
- this.creditUsageService = new CreditUsageService(this.authConfig || undefined, this.backendUrl, this.creditUsageCallback);
109
-
110
- // Create services with providers
111
- this.executionService = new ExecutionService(
112
- this.authConfig || undefined,
113
- this.backendUrl,
114
- maxWorkers || 10,
115
- this.llmProvider, // Pass the LLM provider
116
- this.progressReporter // Pass the progress reporter
117
- );
118
-
119
- this.scenarioService = new ScenarioService(
120
- maxWorkers || 2,
121
- this.fileHandler,
122
- this.llmProvider,
123
- this.progressReporter,
124
- this.authConfig || undefined,
125
- this.backendUrl,
126
- this.orchestratorOptions // Pass orchestrator options
127
- );
128
- }
129
-
130
- /**
131
- * Set authentication configuration for the service
132
- * Recreates LLM provider and services with new auth config
133
- */
134
- async setAuthConfig(authConfig: AuthConfig): Promise<void> {
135
- this.authConfig = authConfig;
136
- this.creditUsageService.setAuthConfig(authConfig);
137
-
138
- // Recreate LLM provider with new auth config
139
- this.llmProvider = new BackendProxyLLMProvider(authConfig, this.backendUrl);
140
-
141
- // Set logger on new provider if we have one
142
- if (this.logger) {
143
- this.llmProvider.setLogger?.(this.logger);
144
- }
145
-
146
- // Recreate services with new provider AND pass llmProvider and progressReporter
147
- this.executionService = new ExecutionService(
148
- this.authConfig,
149
- this.backendUrl,
150
- 10,
151
- this.llmProvider, // Pass the LLM provider
152
- this.progressReporter // Pass the progress reporter
153
- );
154
-
155
- this.scenarioService = new ScenarioService(
156
- 2,
157
- this.fileHandler,
158
- this.llmProvider,
159
- this.progressReporter,
160
- this.authConfig,
161
- this.backendUrl,
162
- this.orchestratorOptions // Pass orchestrator options
163
- );
164
-
165
- // Set logger on recreated services if we have one
166
- if (this.logger) {
167
- this.executionService.setLogger(this.logger);
168
- this.scenarioService.setLogger(this.logger);
169
- }
170
-
171
- // Reapply outputChannel if we have one (critical for orchestrator logs)
172
- if (this.outputChannel) {
173
- this.scenarioService.setOutputChannel(this.outputChannel);
174
- }
175
-
176
- // Reinitialize the services
177
- await this.executionService.initialize();
178
- await this.scenarioService.initialize();
179
- }
180
-
181
- /**
182
- * Set backend URL for the service
183
- * Recreates LLM provider and services with new backend URL
184
- */
185
- setBackendUrl(backendUrl: string): void {
186
- this.backendUrl = backendUrl;
187
-
188
- // Recreate LLM provider with new backend URL
189
- this.llmProvider = new BackendProxyLLMProvider(this.authConfig || undefined, backendUrl);
190
-
191
- // Set logger on new provider if we have one
192
- if (this.logger) {
193
- this.llmProvider.setLogger?.(this.logger);
194
- }
195
-
196
- // Recreate services with new provider (preserve credit callback)
197
- this.creditUsageService = new CreditUsageService(this.authConfig || undefined, this.backendUrl, this.creditUsageCallback);
198
- this.executionService = new ExecutionService(
199
- this.authConfig || undefined,
200
- this.backendUrl,
201
- 10,
202
- this.llmProvider, // Pass the LLM provider
203
- this.progressReporter // Pass the progress reporter
204
- );
205
-
206
- this.scenarioService = new ScenarioService(
207
- 2,
208
- this.fileHandler,
209
- this.llmProvider,
210
- this.progressReporter,
211
- this.authConfig || undefined,
212
- this.backendUrl,
213
- this.orchestratorOptions // Pass orchestrator options
214
- );
215
-
216
- // Set logger on recreated services if we have one
217
- if (this.logger) {
218
- this.executionService.setLogger(this.logger);
219
- this.scenarioService.setLogger(this.logger);
220
- }
221
-
222
- // Reapply outputChannel if we have one (critical for orchestrator logs)
223
- if (this.outputChannel) {
224
- this.scenarioService.setOutputChannel(this.outputChannel);
225
- }
226
- }
227
-
228
- /**
229
- * Set logger callback for capturing execution logs
230
- */
231
- setLogger(logger: (message: string, level?: 'log' | 'error' | 'warn') => void): void {
232
- this.logger = logger;
233
- this.executionService.setLogger(logger);
234
- this.scenarioService.setLogger(logger);
235
- this.llmProvider.setLogger?.(logger);
236
- this.creditUsageService.setLogger(logger);
237
- }
238
-
239
- /**
240
- * Set output channel for worker logs (VS Code OutputChannel)
241
- * This enables orchestrator thinking logs to appear in output console
242
- */
243
- setOutputChannel(outputChannel: any): void {
244
- this.outputChannel = outputChannel; // Store for future service recreations
245
- if (typeof this.scenarioService?.setOutputChannel === 'function') {
246
- this.scenarioService.setOutputChannel(outputChannel);
247
- }
248
- }
249
-
250
- /**
251
- * Set credit usage callback
252
- * Server-side: Use callback to update DB directly (no axios calls)
253
- * Client-side: Don't set callback, uses auth for axios calls to backend
254
- */
255
- setCreditUsageCallback(callback: CreditUsageCallback): void {
256
- this.creditUsageCallback = callback; // Store for future service recreations
257
- this.creditUsageService.setCreditUsageCallback(callback);
258
- }
259
-
260
- /**
261
- * Log a message using the configured logger
262
- */
263
- private log(message: string, level: 'log' | 'error' | 'warn' = 'log'): void {
264
- if (this.logger) {
265
- this.logger(message, level);
266
- }
267
- // No console fallback - logs are routed to consumer
268
- }
269
-
270
- /**
271
- * Get current authentication configuration
272
- */
273
- getAuthConfig(): AuthConfig | null {
274
- return this.authConfig;
275
- }
276
-
277
- async initialize(): Promise<void> {
278
- await this.playwrightService.initialize();
279
- await this.executionService.initialize();
280
- await this.scenarioService.initialize();
281
- }
282
-
283
- async shutdown(): Promise<void> {
284
- // Cleanup resources
285
- }
286
-
287
- // Scenario generation
288
- async generateScript(
289
- scenario: string,
290
- testName?: string,
291
- config?: string,
292
- model?: string,
293
- scenarioFileName?: string,
294
- existingBrowser?: any,
295
- existingContext?: any,
296
- existingPage?: any
297
- ): Promise<string> {
298
- return this.scenarioService.processScenario(
299
- scenario,
300
- testName,
301
- config,
302
- model,
303
- scenarioFileName,
304
- existingBrowser,
305
- existingContext,
306
- existingPage
307
- );
308
- }
309
-
310
- // Test execution
311
- async executeScript(request: any): Promise<any> {
312
- // Read script content if not provided but scriptFilePath is
313
- if (!request.script && request.scriptFilePath) {
314
- try {
315
- const resolvedPath = this.fileHandler.resolvePath(request.scriptFilePath);
316
- request.script = await this.fileHandler.readTestFile(resolvedPath);
317
- this.log(`Read script content from file: ${resolvedPath}`);
318
- } catch (error) {
319
- throw new Error(`Failed to read script file: ${error}`);
320
- }
321
- }
322
-
323
- // Read Playwright config content if not provided but playwrightConfigFilePath is
324
- if (!request.playwrightConfig && request.playwrightConfigFilePath) {
325
- try {
326
- const resolvedPath = this.fileHandler.resolvePath(request.playwrightConfigFilePath);
327
- request.playwrightConfig = await this.fileHandler.readTestFile(resolvedPath);
328
- this.log(`Read Playwright config content from file: ${resolvedPath}`);
329
- } catch (error) {
330
- this.log(`Failed to read Playwright config file: ${error}. Using default configuration.`, 'warn');
331
- // Don't throw error, just use default config
332
- }
333
- }
334
-
335
- // Log content status
336
- if (request.script) {
337
- this.log(`Using provided script content (${request.script.length} characters)`);
338
- } else if (request.steps && request.steps.length > 0) {
339
- this.log(`Using ${request.steps.length} pre-parsed steps (script will be generated if needed)`);
340
- } else {
341
- throw new Error('Script content is required. Provide either script or scriptFilePath.');
342
- }
343
-
344
- if (request.playwrightConfig) {
345
- this.log(`Using provided Playwright config (${request.playwrightConfig.length} characters)`);
346
- } else {
347
- this.log(`Using default Playwright configuration`);
348
- }
349
-
350
- const result = await this.executionService.executeScript(request);
351
-
352
- // Return result - consumer decides what to do with updated_script
353
- return result;
354
- }
355
-
356
- // Test execution with AI repair
357
- async executeScriptWithAIRepair(request: any): Promise<any> {
358
- const repairRequest = { ...request, mode: 'RUN_WITH_AI_REPAIR' };
359
- return this.executeScript(repairRequest);
360
- }
361
-
362
- // Credit usage reporting methods
363
- async reportScriptGenerationCredit(jobId?: string): Promise<void> {
364
- return this.creditUsageService.reportScriptGenerationCredit(jobId);
365
- }
366
-
367
- async reportAIRepairCredit(jobId?: string): Promise<void> {
368
- return this.creditUsageService.reportAIRepairCredit(jobId);
369
- }
370
-
371
- // Find TestChimp smart/managed tests (prioritizes Smart Test detection)
372
- findTestChimpTests(directory: string, recursive: boolean = true): string[] {
373
- const fs = require('fs');
374
- const path = require('path');
375
-
376
- const testFiles: string[] = [];
377
-
378
- function scanDir(dir: string) {
379
- try {
380
- const items = fs.readdirSync(String(dir));
381
-
382
- for (const item of items) {
383
- const fullPath = path.join(String(dir), String(item));
384
- const stat = fs.statSync(String(fullPath));
385
-
386
- if (stat.isDirectory() && recursive) {
387
- scanDir(fullPath);
388
- } else if (stat.isFile() && isTestChimpTest(fullPath)) {
389
- testFiles.push(fullPath);
390
- }
391
- }
392
- } catch (error) {
393
- // Skip directories that can't be read
394
- }
395
- }
396
-
397
- function isTestChimpTest(filePath: string): boolean {
398
- // Check if file is a test file (including smart test files)
399
- if (!filePath.match(/\.(smart\.spec|spec|test)\.(js|ts)$/)) {
400
- return false;
401
- }
402
-
403
- try {
404
- // Read file content
405
- const content = fs.readFileSync(filePath, 'utf8');
406
-
407
- // Check for TestChimp markers - only exact comment phrases
408
- const testChimpMarkers = [
409
- /This is a TestChimp Smart Test/i,
410
- /This is a TestChimp Managed Test/i
411
- ];
412
-
413
- return testChimpMarkers.some(marker => marker.test(content));
414
- } catch (error) {
415
- return false;
416
- }
417
- }
418
-
419
- scanDir(directory);
420
- return testFiles;
421
- }
422
- }