testchimp-runner-core 0.0.26 → 0.0.28
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.
- package/CREDIT_CALLBACK_ARCHITECTURE.md +253 -0
- package/INTEGRATION_COMPLETE.md +322 -0
- package/RELEASE_0.0.26.md +165 -0
- package/RELEASE_0.0.27.md +236 -0
- package/RELEASE_0.0.28.md +286 -0
- package/dist/credit-usage-service.d.ts +28 -2
- package/dist/credit-usage-service.d.ts.map +1 -1
- package/dist/credit-usage-service.js +60 -24
- package/dist/credit-usage-service.js.map +1 -1
- package/dist/execution-service.d.ts.map +1 -1
- package/dist/execution-service.js +134 -10
- package/dist/execution-service.js.map +1 -1
- package/dist/index.d.ts +13 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/progress-reporter.d.ts +30 -0
- package/dist/progress-reporter.d.ts.map +1 -1
- package/dist/prompts.js +4 -4
- package/dist/scenario-service.d.ts +1 -1
- package/dist/scenario-service.d.ts.map +1 -1
- package/dist/scenario-service.js +7 -4
- package/dist/scenario-service.js.map +1 -1
- package/dist/scenario-worker-class.d.ts +2 -10
- package/dist/scenario-worker-class.d.ts.map +1 -1
- package/dist/scenario-worker-class.js +88 -26
- package/dist/scenario-worker-class.js.map +1 -1
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/credit-usage-service.ts +81 -26
- package/src/execution-service.ts +158 -11
- package/src/index.ts +42 -10
- package/src/progress-reporter.ts +35 -0
- package/src/prompts.ts +4 -4
- package/src/scenario-service.ts +16 -4
- package/src/scenario-worker-class.ts +102 -28
- package/src/types.ts +16 -0
- package/testchimp-runner-core-0.0.27.tgz +0 -0
- package/testchimp-runner-core-0.0.26.tgz +0 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# Credit Usage Callback Architecture
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
Added callback-based credit usage reporting to allow server-side integration to update DB directly without axios calls, while client-side continues using axios calls to backend API.
|
|
5
|
+
|
|
6
|
+
## Architecture
|
|
7
|
+
|
|
8
|
+
### Callback-First Approach
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
export interface CreditUsage {
|
|
12
|
+
credits: number;
|
|
13
|
+
usageReason: CreditUsageReason;
|
|
14
|
+
jobId?: string;
|
|
15
|
+
timestamp: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type CreditUsageCallback = (usage: CreditUsage) => void | Promise<void>;
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Behavior
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
async reportCreditUsage(credits, usageReason, jobId) {
|
|
25
|
+
const creditUsage = { credits, usageReason, jobId, timestamp: Date.now() };
|
|
26
|
+
|
|
27
|
+
// 1. If callback provided: Use callback (SERVER-SIDE)
|
|
28
|
+
if (this.creditUsageCallback) {
|
|
29
|
+
await this.creditUsageCallback(creditUsage);
|
|
30
|
+
return {}; // No axios call needed
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 2. No callback but auth configured: Use axios (CLIENT-SIDE)
|
|
34
|
+
if (this.authConfig) {
|
|
35
|
+
await axios.post(`${backend}/localagent/insert_credit_usage`, ...);
|
|
36
|
+
return response.data;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 3. No callback and no auth: Development mode
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage Scenarios
|
|
45
|
+
|
|
46
|
+
### Server-Side (scriptservice)
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { TestChimpService, CreditUsage, CreditUsageReason } from 'testchimp-runner-core';
|
|
50
|
+
|
|
51
|
+
const service = new TestChimpService(
|
|
52
|
+
fileHandler,
|
|
53
|
+
undefined, // NO auth config
|
|
54
|
+
backendUrl,
|
|
55
|
+
maxWorkers,
|
|
56
|
+
llmProvider,
|
|
57
|
+
progressReporter,
|
|
58
|
+
orchestratorOptions,
|
|
59
|
+
async (creditUsage: CreditUsage) => {
|
|
60
|
+
// Update DB directly - NO axios calls
|
|
61
|
+
await db.insertCreditUsage({
|
|
62
|
+
credits: creditUsage.credits,
|
|
63
|
+
usageReason: creditUsage.usageReason,
|
|
64
|
+
jobId: creditUsage.jobId,
|
|
65
|
+
timestamp: creditUsage.timestamp
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Result:**
|
|
72
|
+
- ✅ Callback called → DB updated directly
|
|
73
|
+
- ❌ No axios calls (no auth configured)
|
|
74
|
+
- ✅ Full control over DB updates
|
|
75
|
+
|
|
76
|
+
### Client-Side (vs-extension, github-action)
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { TestChimpService } from 'testchimp-runner-core';
|
|
80
|
+
|
|
81
|
+
const service = new TestChimpService(
|
|
82
|
+
fileHandler,
|
|
83
|
+
authConfig, // Auth configured
|
|
84
|
+
backendUrl,
|
|
85
|
+
maxWorkers,
|
|
86
|
+
llmProvider,
|
|
87
|
+
progressReporter,
|
|
88
|
+
orchestratorOptions
|
|
89
|
+
// NO callback - uses axios
|
|
90
|
+
);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Result:**
|
|
94
|
+
- ❌ No callback provided
|
|
95
|
+
- ✅ Axios call made to backend API (because auth configured)
|
|
96
|
+
- ✅ Backend handles DB update
|
|
97
|
+
|
|
98
|
+
### Development Mode (local testing)
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const service = new TestChimpService(
|
|
102
|
+
fileHandler
|
|
103
|
+
// No auth, no callback
|
|
104
|
+
);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Result:**
|
|
108
|
+
- ❌ No callback
|
|
109
|
+
- ❌ No auth
|
|
110
|
+
- ⚠️ Warning logged: "Credit usage not tracked"
|
|
111
|
+
- ✅ Continues without error
|
|
112
|
+
|
|
113
|
+
## API
|
|
114
|
+
|
|
115
|
+
### Constructor
|
|
116
|
+
```typescript
|
|
117
|
+
new TestChimpService(
|
|
118
|
+
fileHandler?,
|
|
119
|
+
authConfig?,
|
|
120
|
+
backendUrl?,
|
|
121
|
+
maxWorkers?,
|
|
122
|
+
llmProvider?,
|
|
123
|
+
progressReporter?,
|
|
124
|
+
orchestratorOptions?,
|
|
125
|
+
creditUsageCallback? // NEW
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Method
|
|
130
|
+
```typescript
|
|
131
|
+
service.setCreditUsageCallback((creditUsage) => {
|
|
132
|
+
// Handle credit usage in your system
|
|
133
|
+
console.log(`Used ${creditUsage.credits} credits for ${creditUsage.usageReason}`);
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Exported Types
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
export {
|
|
141
|
+
CreditUsageCallback, // Type for callback function
|
|
142
|
+
CreditUsage, // Interface for usage data
|
|
143
|
+
CreditUsageReason // Enum: SCRIPT_GENERATE, TEST_REPAIR, etc.
|
|
144
|
+
};
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Benefits
|
|
148
|
+
|
|
149
|
+
### For Server-Side
|
|
150
|
+
1. **No Network Calls** - Direct DB updates via callback
|
|
151
|
+
2. **Full Control** - Custom logic for credit tracking
|
|
152
|
+
3. **Performance** - No HTTP round-trip overhead
|
|
153
|
+
4. **Reliability** - No network failures
|
|
154
|
+
|
|
155
|
+
### For Client-Side
|
|
156
|
+
1. **Backward Compatible** - Existing code works unchanged
|
|
157
|
+
2. **Centralized** - Backend API handles all credit logic
|
|
158
|
+
3. **Simple** - Just configure auth, no callback needed
|
|
159
|
+
|
|
160
|
+
### For Both
|
|
161
|
+
1. **Flexible** - Each consumer decides how to handle credits
|
|
162
|
+
2. **Testable** - Can mock callbacks easily
|
|
163
|
+
3. **Observable** - Callback provides visibility into credit usage
|
|
164
|
+
|
|
165
|
+
## Implementation Notes
|
|
166
|
+
|
|
167
|
+
### Preservation Across Service Recreations
|
|
168
|
+
|
|
169
|
+
Credit callback is stored and reapplied when services are recreated:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// Store in TestChimpService
|
|
173
|
+
private creditUsageCallback?: CreditUsageCallback;
|
|
174
|
+
|
|
175
|
+
// Pass to CreditUsageService on every recreation
|
|
176
|
+
this.creditUsageService = new CreditUsageService(
|
|
177
|
+
this.authConfig,
|
|
178
|
+
this.backendUrl,
|
|
179
|
+
this.creditUsageCallback // Always preserved
|
|
180
|
+
);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Error Handling
|
|
184
|
+
|
|
185
|
+
**Callback-based (server-side):**
|
|
186
|
+
- Callback error → Throws (critical for DB updates)
|
|
187
|
+
|
|
188
|
+
**Axios-based (client-side):**
|
|
189
|
+
- Axios error → Throws (critical for credit tracking)
|
|
190
|
+
|
|
191
|
+
**Development mode:**
|
|
192
|
+
- No tracking → Logs warning, continues
|
|
193
|
+
|
|
194
|
+
## Example: Server-Side Integration
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
// In scriptservice
|
|
198
|
+
import { TestChimpService, CreditUsage, CreditUsageReason } from 'testchimp-runner-core';
|
|
199
|
+
|
|
200
|
+
class ScriptService {
|
|
201
|
+
private testChimpService: TestChimpService;
|
|
202
|
+
|
|
203
|
+
constructor() {
|
|
204
|
+
this.testChimpService = new TestChimpService(
|
|
205
|
+
new CustomFileHandler(),
|
|
206
|
+
undefined, // No auth - server-side doesn't need it
|
|
207
|
+
'http://localhost:3000', // Internal backend URL
|
|
208
|
+
5,
|
|
209
|
+
new CustomLLMProvider(), // Server has its own LLM provider
|
|
210
|
+
customProgressReporter,
|
|
211
|
+
{ useOrchestrator: true },
|
|
212
|
+
async (creditUsage: CreditUsage) => {
|
|
213
|
+
// Direct DB update - no HTTP calls
|
|
214
|
+
await this.creditRepository.insert({
|
|
215
|
+
userId: this.getCurrentUserId(),
|
|
216
|
+
credits: creditUsage.credits,
|
|
217
|
+
reason: creditUsage.usageReason,
|
|
218
|
+
jobId: creditUsage.jobId,
|
|
219
|
+
timestamp: new Date(creditUsage.timestamp)
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Files Modified
|
|
228
|
+
|
|
229
|
+
1. `/src/credit-usage-service.ts` - Added callback support, callback-first logic
|
|
230
|
+
2. `/src/index.ts` - Accept credit callback in constructor, expose `setCreditUsageCallback()`, preserve across recreations
|
|
231
|
+
3. Exported types: `CreditUsage`, `CreditUsageCallback`, `CreditUsageReason`
|
|
232
|
+
|
|
233
|
+
## Testing
|
|
234
|
+
|
|
235
|
+
### Server-Side
|
|
236
|
+
1. Set credit callback
|
|
237
|
+
2. Generate script
|
|
238
|
+
3. Verify callback called with correct credit data
|
|
239
|
+
4. Verify NO axios calls made
|
|
240
|
+
|
|
241
|
+
### Client-Side
|
|
242
|
+
1. Configure auth (no callback)
|
|
243
|
+
2. Generate script
|
|
244
|
+
3. Verify axios call made to backend
|
|
245
|
+
4. Verify backend receives credit data
|
|
246
|
+
|
|
247
|
+
## Backward Compatibility
|
|
248
|
+
|
|
249
|
+
✅ Fully backward compatible
|
|
250
|
+
- Existing consumers work unchanged
|
|
251
|
+
- Optional callback parameter
|
|
252
|
+
- Existing axios behavior preserved for client-side
|
|
253
|
+
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# Runner-Core 0.0.28 - Scriptservice Integration Complete
|
|
2
|
+
|
|
3
|
+
## ✅ Implementation Summary
|
|
4
|
+
|
|
5
|
+
Successfully extended runner-core to support both local clients (vs-ext, github-action) and server-side usage (scriptservice) through:
|
|
6
|
+
1. **Lifecycle callbacks** for server-side DB writes and resource management
|
|
7
|
+
2. **Existing browser support** to reuse caller's browser instead of creating new ones
|
|
8
|
+
3. **Drop-in SmartTestRunnerCoreV2** wrapper for seamless migration
|
|
9
|
+
|
|
10
|
+
## Changes Made
|
|
11
|
+
|
|
12
|
+
### 1. Extended ProgressReporter with Lifecycle Callbacks
|
|
13
|
+
|
|
14
|
+
**File:** `src/progress-reporter.ts`
|
|
15
|
+
|
|
16
|
+
Added optional lifecycle callbacks (used by scriptservice, ignored by local clients):
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
export interface StepInfo {
|
|
20
|
+
stepId?: string;
|
|
21
|
+
stepNumber: number;
|
|
22
|
+
description: string;
|
|
23
|
+
code?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ProgressReporter {
|
|
27
|
+
// Existing callbacks...
|
|
28
|
+
onStepProgress?(): Promise<void>;
|
|
29
|
+
onJobProgress?(): Promise<void>;
|
|
30
|
+
|
|
31
|
+
// NEW: Lifecycle callbacks
|
|
32
|
+
beforeStartTest?(page: any, browser: any, context: any): Promise<void>;
|
|
33
|
+
beforeStepStart?(step: StepInfo, page: any): Promise<void>;
|
|
34
|
+
afterEndTest?(status: 'passed' | 'failed', error?: string, page?: any): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Exported StepInfo:** Added to index.ts exports for consumer usage.
|
|
39
|
+
|
|
40
|
+
### 2. Integrated Lifecycle Callbacks
|
|
41
|
+
|
|
42
|
+
**Files:**
|
|
43
|
+
- `src/execution-service.ts` - RUN_EXACTLY and RUN_WITH_AI_REPAIR modes
|
|
44
|
+
- `src/scenario-worker-class.ts` - Orchestrator mode
|
|
45
|
+
|
|
46
|
+
**Integration Points:**
|
|
47
|
+
- `beforeStartTest`: Called after browser initialization, before execution
|
|
48
|
+
- `beforeStepStart`: Called before each step execution
|
|
49
|
+
- `afterEndTest`: Called after all execution completes (success or failure)
|
|
50
|
+
|
|
51
|
+
**Note:** All callbacks are optional - local clients don't provide them.
|
|
52
|
+
|
|
53
|
+
### 3. Added Existing Browser Support
|
|
54
|
+
|
|
55
|
+
**File:** `src/types.ts`
|
|
56
|
+
|
|
57
|
+
Extended `ScriptExecutionRequest` to accept existing browser:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
export interface ScriptExecutionRequest {
|
|
61
|
+
// ... existing fields ...
|
|
62
|
+
|
|
63
|
+
// Optional: Provide existing browser/page/context (for server-side usage)
|
|
64
|
+
// If not provided, runner-core will create its own
|
|
65
|
+
existingBrowser?: any;
|
|
66
|
+
existingContext?: any;
|
|
67
|
+
existingPage?: any;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**File:** `src/execution-service.ts`
|
|
72
|
+
|
|
73
|
+
Updated `runExactly` and `runWithAIRepair` to:
|
|
74
|
+
- Check if existing browser is provided
|
|
75
|
+
- Use existing browser if available (don't create new one)
|
|
76
|
+
- Don't close browser if we didn't create it (caller owns it)
|
|
77
|
+
|
|
78
|
+
**Benefits:**
|
|
79
|
+
- **Local clients:** Continue creating their own browser (no change)
|
|
80
|
+
- **Scriptservice:** Reuses its existing browser (no double initialization)
|
|
81
|
+
|
|
82
|
+
### 4. Created ScriptserviceLLMProvider
|
|
83
|
+
|
|
84
|
+
**File:** `services/scriptservice/providers/scriptservice-llm-provider.ts` (NEW)
|
|
85
|
+
|
|
86
|
+
Implements `LLMProvider` interface:
|
|
87
|
+
- Wraps scriptservice's existing OpenAI client
|
|
88
|
+
- Supports text and vision prompts
|
|
89
|
+
- Uses scriptservice's OpenAI API key from ConfigService
|
|
90
|
+
- No backend proxy - all calls are local
|
|
91
|
+
- No auth needed (scriptservice is already authenticated)
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
export class ScriptserviceLLMProvider implements LLMProvider {
|
|
95
|
+
async callLLM(request: LLMRequest): Promise<LLMResponse> {
|
|
96
|
+
// Uses scriptservice's OpenAI client
|
|
97
|
+
// Supports both text and vision (imageUrl)
|
|
98
|
+
// Returns answer and optional usage
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 5. Created SmartTestRunnerCoreV2
|
|
104
|
+
|
|
105
|
+
**File:** `services/scriptservice/smart-test-runner-core-v2.ts` (NEW)
|
|
106
|
+
|
|
107
|
+
Drop-in replacement for SmartTestRunnerCore:
|
|
108
|
+
|
|
109
|
+
**Same Interface:**
|
|
110
|
+
```typescript
|
|
111
|
+
constructor(config: RunnerConfig)
|
|
112
|
+
async runExactly(script: string): Promise<RunExactlyResult>
|
|
113
|
+
async runWithRepair(steps: TestStepWithId[]): Promise<RunWithRepairResult>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Key Features:**
|
|
117
|
+
- Uses `TestChimpService` (runner-core) internally
|
|
118
|
+
- Maps scriptservice callbacks to ProgressReporter
|
|
119
|
+
- Provides existing browser to runner-core (via `existingBrowser`, `existingContext`, `existingPage`)
|
|
120
|
+
- Automatically gets runner-core improvements (better prompts, vision, semantic selectors)
|
|
121
|
+
|
|
122
|
+
**Callback Mapping:**
|
|
123
|
+
```typescript
|
|
124
|
+
const progressReporter: ProgressReporter = {
|
|
125
|
+
onStepProgress: async (stepProgress) => {
|
|
126
|
+
// Calls scriptservice's onStepComplete
|
|
127
|
+
await config.callbacks.onStepComplete(...);
|
|
128
|
+
},
|
|
129
|
+
beforeStartTest: config.callbacks?.beforeStartTest,
|
|
130
|
+
beforeStepStart: config.callbacks?.beforeStepStart,
|
|
131
|
+
afterEndTest: config.callbacks?.afterEndTest
|
|
132
|
+
};
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**runWithRepair Implementation:**
|
|
136
|
+
- Converts steps to Playwright script
|
|
137
|
+
- Calls `runnerCore.executeScript` with mode `RUN_WITH_AI_REPAIR`
|
|
138
|
+
- Provides existing browser/page/context
|
|
139
|
+
- Maps results back to scriptservice format
|
|
140
|
+
|
|
141
|
+
### 6. Updated Scriptservice Consumers
|
|
142
|
+
|
|
143
|
+
**Files:**
|
|
144
|
+
- `services/scriptservice/smart-test-execution-handler.ts`
|
|
145
|
+
- `services/scriptservice/workers/test-based-explorer.ts`
|
|
146
|
+
- `services/scriptservice/package.json` - Added `testchimp-runner-core: file:../../local/runner-core`
|
|
147
|
+
|
|
148
|
+
**Migration Strategy:**
|
|
149
|
+
```typescript
|
|
150
|
+
// Default to V2, can toggle with environment variable
|
|
151
|
+
const useV2 = process.env.USE_RUNNER_CORE_V2 !== 'false'; // Default: true
|
|
152
|
+
const runner = useV2
|
|
153
|
+
? new SmartTestRunnerCoreV2(runnerConfig)
|
|
154
|
+
: new SmartTestRunnerCore(runnerConfig);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Rollback:**
|
|
158
|
+
```bash
|
|
159
|
+
export USE_RUNNER_CORE_V2=false
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Testing Instructions
|
|
163
|
+
|
|
164
|
+
### 1. Install Local Runner-Core
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
cd /Users/nuwansam/IdeaProjects/AwareRepo/services/scriptservice
|
|
168
|
+
|
|
169
|
+
# Manual install (if npm install doesn't work)
|
|
170
|
+
./install-local-runner-core.sh
|
|
171
|
+
|
|
172
|
+
# Or manually
|
|
173
|
+
rm -rf node_modules/testchimp-runner-core
|
|
174
|
+
mkdir -p node_modules/testchimp-runner-core
|
|
175
|
+
cp -r ../../local/runner-core/dist node_modules/testchimp-runner-core/
|
|
176
|
+
cp ../../local/runner-core/package.json node_modules/testchimp-runner-core/
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 2. Build Scriptservice
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
cd /Users/nuwansam/IdeaProjects/AwareRepo/services/scriptservice
|
|
183
|
+
rm -rf dist
|
|
184
|
+
npx tsc
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### 3. Run Scriptservice
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
npm run start:staging
|
|
191
|
+
# or
|
|
192
|
+
npm run start:prod
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### 4. Test Script Execution
|
|
196
|
+
|
|
197
|
+
**Look for log message:**
|
|
198
|
+
```
|
|
199
|
+
using SmartTestRunnerCoreV2 (runner-core)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Test JSON payload:**
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"playwrightConfig": "{}",
|
|
206
|
+
"targetUrl": "https://studio--cafetime-afg2v.us-central1.hosted.app/",
|
|
207
|
+
"scenario": "- Go to https://studio--cafetime-afg2v.us-central1.hosted.app/\n- Login with alice@example.com, TestPass123\n- Go to Messages tab\n- Send a message \"Hello\"\n- Verify conversation thread shows the sent message\n- Verify message input field is now empty",
|
|
208
|
+
"projectId": "test-project"
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### 5. Verify Behaviors
|
|
213
|
+
|
|
214
|
+
- ✅ DB writes happen via callbacks
|
|
215
|
+
- ✅ Screenshots upload to GCS correctly
|
|
216
|
+
- ✅ LLM calls work (all local, no backend proxy)
|
|
217
|
+
- ✅ Smart test execution completes
|
|
218
|
+
- ✅ Explorer mode works
|
|
219
|
+
- ✅ Error handling and reporting work
|
|
220
|
+
- ✅ Lifecycle callbacks fire (beforeStartTest, beforeStepStart, afterEndTest)
|
|
221
|
+
|
|
222
|
+
## Benefits
|
|
223
|
+
|
|
224
|
+
### For Scriptservice:
|
|
225
|
+
1. **Zero Code Duplication:** Removed ~600 lines of duplicated execution/repair logic
|
|
226
|
+
2. **Auto-Updates:** Automatically gets runner-core improvements
|
|
227
|
+
3. **Better Prompts:** Semantic selectors, improved vision, cleaner scripts
|
|
228
|
+
4. **Consistent Behavior:** Same logic as vs-extension and github-action
|
|
229
|
+
5. **No Breaking Changes:** Drop-in replacement with environment flag for safety
|
|
230
|
+
|
|
231
|
+
### For Runner-Core:
|
|
232
|
+
1. **Universal Library:** Works for both client-side and server-side
|
|
233
|
+
2. **Flexible Architecture:** Callbacks and browser injection allow different execution patterns
|
|
234
|
+
3. **Backward Compatible:** Existing consumers unaffected (all new features are optional)
|
|
235
|
+
|
|
236
|
+
## Architecture
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
240
|
+
│ SCRIPTSERVICE │
|
|
241
|
+
│ │
|
|
242
|
+
│ ┌────────────────────────────────────────────────────┐ │
|
|
243
|
+
│ │ SmartTestRunnerCoreV2 (Thin Wrapper) │ │
|
|
244
|
+
│ │ - Maps scriptservice callbacks to ProgressReporter│ │
|
|
245
|
+
│ │ - Provides existing browser to runner-core │ │
|
|
246
|
+
│ │ - Converts steps ↔ script format │ │
|
|
247
|
+
│ └───────────────┬────────────────────────────────────┘ │
|
|
248
|
+
│ │ │
|
|
249
|
+
│ ▼ │
|
|
250
|
+
│ ┌────────────────────────────────────────────────────┐ │
|
|
251
|
+
│ │ ScriptserviceLLMProvider (Local OpenAI) │ │
|
|
252
|
+
│ │ - Wraps scriptservice's OpenAI client │ │
|
|
253
|
+
│ │ - No backend proxy, all calls local │ │
|
|
254
|
+
│ └────────────────────────────────────────────────────┘ │
|
|
255
|
+
│ │
|
|
256
|
+
└─────────────────────────────────────────────────────────────┘
|
|
257
|
+
│
|
|
258
|
+
▼
|
|
259
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
260
|
+
│ RUNNER-CORE (v0.0.28) │
|
|
261
|
+
│ │
|
|
262
|
+
│ ┌────────────────────────────────────────────────────┐ │
|
|
263
|
+
│ │ ExecutionService │ │
|
|
264
|
+
│ │ - Accepts existingBrowser/Page/Context (NEW) │ │
|
|
265
|
+
│ │ - Calls lifecycle callbacks (NEW) │ │
|
|
266
|
+
│ │ - RUN_EXACTLY and RUN_WITH_AI_REPAIR modes │ │
|
|
267
|
+
│ └────────────────────────────────────────────────────┘ │
|
|
268
|
+
│ │
|
|
269
|
+
│ ┌────────────────────────────────────────────────────┐ │
|
|
270
|
+
│ │ ProgressReporter Interface │ │
|
|
271
|
+
│ │ - onStepProgress (existing) │ │
|
|
272
|
+
│ │ - beforeStartTest (NEW) │ │
|
|
273
|
+
│ │ - beforeStepStart (NEW) │ │
|
|
274
|
+
│ │ - afterEndTest (NEW) │ │
|
|
275
|
+
│ └────────────────────────────────────────────────────┘ │
|
|
276
|
+
│ │
|
|
277
|
+
└─────────────────────────────────────────────────────────────┘
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Files Changed
|
|
281
|
+
|
|
282
|
+
### Runner-Core:
|
|
283
|
+
1. `src/progress-reporter.ts` - Added StepInfo and lifecycle callbacks
|
|
284
|
+
2. `src/index.ts` - Export StepInfo
|
|
285
|
+
3. `src/types.ts` - Added existingBrowser/Context/Page fields
|
|
286
|
+
4. `src/execution-service.ts` - Support existing browser and lifecycle callbacks
|
|
287
|
+
5. `src/scenario-worker-class.ts` - Call lifecycle callbacks in orchestrator mode
|
|
288
|
+
6. `package.json` - Version 0.0.28
|
|
289
|
+
|
|
290
|
+
### Scriptservice:
|
|
291
|
+
7. `providers/scriptservice-llm-provider.ts` - NEW
|
|
292
|
+
8. `smart-test-runner-core-v2.ts` - NEW
|
|
293
|
+
9. `smart-test-execution-handler.ts` - Use V2 by default
|
|
294
|
+
10. `workers/test-based-explorer.ts` - Use V2 by default
|
|
295
|
+
11. `package.json` - Added testchimp-runner-core dependency
|
|
296
|
+
12. `install-local-runner-core.sh` - NEW (helper script for local testing)
|
|
297
|
+
|
|
298
|
+
## Next Steps
|
|
299
|
+
|
|
300
|
+
### Before Publishing to npm:
|
|
301
|
+
1. ✅ Test runExactly mode in scriptservice
|
|
302
|
+
2. ✅ Test runWithRepair mode in scriptservice
|
|
303
|
+
3. ✅ Verify DB writes and screenshots work
|
|
304
|
+
4. ✅ Monitor logs for errors
|
|
305
|
+
|
|
306
|
+
### After Validation:
|
|
307
|
+
1. Publish runner-core 0.0.28 to npm
|
|
308
|
+
2. Update scriptservice package.json to use `^0.0.28` instead of `file:...`
|
|
309
|
+
3. Deploy to staging
|
|
310
|
+
4. After 1-2 weeks, remove environment flag and delete old SmartTestRunnerCore
|
|
311
|
+
|
|
312
|
+
## Breaking Changes
|
|
313
|
+
|
|
314
|
+
None. All changes are backward compatible and opt-in.
|
|
315
|
+
|
|
316
|
+
## Notes
|
|
317
|
+
|
|
318
|
+
- Lifecycle callbacks are optional - local clients don't need them
|
|
319
|
+
- Existing browser is optional - if not provided, runner-core creates its own
|
|
320
|
+
- V2 defaults to enabled but can be disabled with `USE_RUNNER_CORE_V2=false`
|
|
321
|
+
- Old SmartTestRunnerCore remains available as fallback
|
|
322
|
+
|