testchimp-runner-core 0.0.25 → 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/env-loader.d.ts +0 -5
- package/dist/env-loader.d.ts.map +1 -1
- package/dist/env-loader.js +0 -21
- package/dist/env-loader.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 +14 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -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/env-loader.ts +0 -22
- package/src/execution-service.ts +158 -11
- package/src/index.ts +54 -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/RELEASE_0.0.23.md +0 -120
- package/RELEASE_0.0.24.md +0 -161
|
@@ -12,15 +12,35 @@ export interface InsertCreditUsageRequest {
|
|
|
12
12
|
}
|
|
13
13
|
export interface InsertCreditUsageResponse {
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Credit usage information for callback
|
|
17
|
+
*/
|
|
18
|
+
export interface CreditUsage {
|
|
19
|
+
credits: number;
|
|
20
|
+
usageReason: CreditUsageReason;
|
|
21
|
+
jobId?: string;
|
|
22
|
+
timestamp: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Callback for credit usage reporting
|
|
26
|
+
* Allows consumers to track credit usage in their own systems
|
|
27
|
+
*/
|
|
28
|
+
export type CreditUsageCallback = (usage: CreditUsage) => void | Promise<void>;
|
|
15
29
|
export declare class CreditUsageService {
|
|
16
30
|
private backendUrl;
|
|
17
31
|
private authConfig;
|
|
18
32
|
private logger?;
|
|
19
|
-
|
|
33
|
+
private creditUsageCallback?;
|
|
34
|
+
constructor(authConfig?: AuthConfig, backendUrl?: string, creditUsageCallback?: CreditUsageCallback);
|
|
20
35
|
/**
|
|
21
36
|
* Set a logger callback for capturing execution logs
|
|
22
37
|
*/
|
|
23
38
|
setLogger(logger: (message: string, level?: 'log' | 'error' | 'warn') => void): void;
|
|
39
|
+
/**
|
|
40
|
+
* Set credit usage callback
|
|
41
|
+
* Allows consumers to track credit usage in their own systems
|
|
42
|
+
*/
|
|
43
|
+
setCreditUsageCallback(callback: CreditUsageCallback): void;
|
|
24
44
|
/**
|
|
25
45
|
* Log a message using the configured logger
|
|
26
46
|
*/
|
|
@@ -34,7 +54,13 @@ export declare class CreditUsageService {
|
|
|
34
54
|
*/
|
|
35
55
|
getAuthConfig(): AuthConfig | null;
|
|
36
56
|
/**
|
|
37
|
-
* Report credit usage
|
|
57
|
+
* Report credit usage via callback and/or backend
|
|
58
|
+
*
|
|
59
|
+
* Behavior:
|
|
60
|
+
* 1. If callback provided: Call callback (server-side uses this to update DB directly)
|
|
61
|
+
* 2. If NO callback but auth configured: Make axios call to backend (client-side: vs-ext, github action)
|
|
62
|
+
* 3. Server-side: Provides callback, no axios calls made
|
|
63
|
+
* 4. Client-side: No callback, uses auth for axios calls to backend
|
|
38
64
|
*/
|
|
39
65
|
reportCreditUsage(credits: number | undefined, usageReason: CreditUsageReason, jobId?: string): Promise<InsertCreditUsageResponse>;
|
|
40
66
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credit-usage-service.d.ts","sourceRoot":"","sources":["../src/credit-usage-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAkB,MAAM,eAAe,CAAC;AAG3D,oBAAY,iBAAiB;IAC3B,2BAA2B,IAAI;IAC/B,aAAa,IAAI;IACjB,WAAW,IAAI;IACf,eAAe,IAAI;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;CAEzC;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,MAAM,CAAC,CAA8D;
|
|
1
|
+
{"version":3,"file":"credit-usage-service.d.ts","sourceRoot":"","sources":["../src/credit-usage-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAkB,MAAM,eAAe,CAAC;AAG3D,oBAAY,iBAAiB;IAC3B,2BAA2B,IAAI;IAC/B,aAAa,IAAI;IACjB,WAAW,IAAI;IACf,eAAe,IAAI;CACpB;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAA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AG,OAAO,CAAC,IAAI,CAAC;CAS1D"}
|
|
@@ -15,7 +15,7 @@ var CreditUsageReason;
|
|
|
15
15
|
CreditUsageReason[CreditUsageReason["SCRIPT_GENERATE"] = 3] = "SCRIPT_GENERATE";
|
|
16
16
|
})(CreditUsageReason || (exports.CreditUsageReason = CreditUsageReason = {}));
|
|
17
17
|
class CreditUsageService {
|
|
18
|
-
constructor(authConfig, backendUrl) {
|
|
18
|
+
constructor(authConfig, backendUrl, creditUsageCallback) {
|
|
19
19
|
// Use provided backend URL or fall back to environment configuration
|
|
20
20
|
if (backendUrl) {
|
|
21
21
|
this.backendUrl = backendUrl;
|
|
@@ -26,6 +26,7 @@ class CreditUsageService {
|
|
|
26
26
|
this.backendUrl = envConfig.TESTCHIMP_BACKEND_URL;
|
|
27
27
|
}
|
|
28
28
|
this.authConfig = authConfig || null;
|
|
29
|
+
this.creditUsageCallback = creditUsageCallback;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Set a logger callback for capturing execution logs
|
|
@@ -33,6 +34,13 @@ class CreditUsageService {
|
|
|
33
34
|
setLogger(logger) {
|
|
34
35
|
this.logger = logger;
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Set credit usage callback
|
|
39
|
+
* Allows consumers to track credit usage in their own systems
|
|
40
|
+
*/
|
|
41
|
+
setCreditUsageCallback(callback) {
|
|
42
|
+
this.creditUsageCallback = callback;
|
|
43
|
+
}
|
|
36
44
|
/**
|
|
37
45
|
* Log a message using the configured logger
|
|
38
46
|
*/
|
|
@@ -55,33 +63,61 @@ class CreditUsageService {
|
|
|
55
63
|
return this.authConfig;
|
|
56
64
|
}
|
|
57
65
|
/**
|
|
58
|
-
* Report credit usage
|
|
66
|
+
* Report credit usage via callback and/or backend
|
|
67
|
+
*
|
|
68
|
+
* Behavior:
|
|
69
|
+
* 1. If callback provided: Call callback (server-side uses this to update DB directly)
|
|
70
|
+
* 2. If NO callback but auth configured: Make axios call to backend (client-side: vs-ext, github action)
|
|
71
|
+
* 3. Server-side: Provides callback, no axios calls made
|
|
72
|
+
* 4. Client-side: No callback, uses auth for axios calls to backend
|
|
59
73
|
*/
|
|
60
74
|
async reportCreditUsage(credits = 1, usageReason, jobId) {
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
const creditUsage = {
|
|
76
|
+
credits,
|
|
77
|
+
usageReason,
|
|
78
|
+
jobId,
|
|
79
|
+
timestamp: Date.now()
|
|
80
|
+
};
|
|
81
|
+
// 1. If callback provided: Use callback (server-side path)
|
|
82
|
+
if (this.creditUsageCallback) {
|
|
83
|
+
try {
|
|
84
|
+
await this.creditUsageCallback(creditUsage);
|
|
85
|
+
this.log(`Credit usage reported via callback: ${credits} credits for ${CreditUsageReason[usageReason]}`);
|
|
86
|
+
return {}; // Callback succeeded, no need for backend call
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
this.log(`Credit usage callback failed: ${error.message}`, 'error');
|
|
90
|
+
throw error; // Callback failure is critical for server-side
|
|
91
|
+
}
|
|
63
92
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
// 2. No callback: Make axios call if auth configured (client-side path: vs-ext, github action)
|
|
94
|
+
if (this.authConfig) {
|
|
95
|
+
try {
|
|
96
|
+
const authHeaders = (0, auth_config_1.getAuthHeaders)(this.authConfig);
|
|
97
|
+
const url = `${this.backendUrl}/localagent/insert_credit_usage`;
|
|
98
|
+
const request = {
|
|
99
|
+
credits,
|
|
100
|
+
usage_reason: usageReason,
|
|
101
|
+
job_id: jobId
|
|
102
|
+
};
|
|
103
|
+
const response = await axios_1.default.post(url, request, {
|
|
104
|
+
headers: {
|
|
105
|
+
...authHeaders,
|
|
106
|
+
'Content-Type': 'application/json'
|
|
107
|
+
},
|
|
108
|
+
timeout: 10000 // 10 second timeout for credit usage calls
|
|
109
|
+
});
|
|
110
|
+
this.log(`Credit usage reported to backend: ${credits} credits for ${CreditUsageReason[usageReason]}`);
|
|
111
|
+
return response.data;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
this.log(`Credit usage backend report failed: ${error.message}`, 'error');
|
|
115
|
+
throw error; // Backend failure is critical for client-side
|
|
116
|
+
}
|
|
84
117
|
}
|
|
118
|
+
// 3. No callback and no auth - no credit tracking (development mode)
|
|
119
|
+
this.log(`Credit usage not tracked (no callback or auth configured): ${credits} credits for ${CreditUsageReason[usageReason]}`, 'warn');
|
|
120
|
+
return {};
|
|
85
121
|
}
|
|
86
122
|
/**
|
|
87
123
|
* Report script generation credit usage
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credit-usage-service.js","sourceRoot":"","sources":["../src/credit-usage-service.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,+CAA2D;AAC3D,6CAA6C;AAE7C,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B,uGAA+B,CAAA;IAC/B,2EAAiB,CAAA;IACjB,uEAAe,CAAA;IACf,+EAAmB,CAAA;AACrB,CAAC,EALW,iBAAiB,iCAAjB,iBAAiB,QAK5B;
|
|
1
|
+
{"version":3,"file":"credit-usage-service.js","sourceRoot":"","sources":["../src/credit-usage-service.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,+CAA2D;AAC3D,6CAA6C;AAE7C,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B,uGAA+B,CAAA;IAC/B,2EAAiB,CAAA;IACjB,uEAAe,CAAA;IACf,+EAAmB,CAAA;AACrB,CAAC,EALW,iBAAiB,iCAAjB,iBAAiB,QAK5B;AA4BD,MAAa,kBAAkB;IAM7B,YAAY,UAAuB,EAAE,U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QACrE,IAAI,CAAC,GAAG,CAAC,8DAA8D,OAAO,gBAAgB,iBAAiB,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACxI,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,4BAA4B,CAAC,KAAc;QAC/C,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,iBAAiB,CAAC,CAAC,EAAE,iBAAiB,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;YAC1E,IAAI,CAAC,GAAG,CAAC,8CAA8C,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5F,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,oDAAoD,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;YAC/E,gEAAgE;QAClE,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,oBAAoB,CAAC,KAAc;QACvC,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,iBAAiB,CAAC,CAAC,EAAE,iBAAiB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YACtE,IAAI,CAAC,GAAG,CAAC,sCAAsC,KAAK,CAAC,CAAC,CAAC,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACpF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,4CAA4C,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;YACvE,gEAAgE;QAClE,CAAC;IACH,CAAC;CACF;AAtJD,gDAsJC"}
|
package/dist/env-loader.d.ts
CHANGED
|
@@ -16,10 +16,5 @@ export declare function loadEnvConfig(): EnvConfig;
|
|
|
16
16
|
* Get a specific environment variable
|
|
17
17
|
*/
|
|
18
18
|
export declare function getEnvVar(key: keyof EnvConfig): string | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Check if we're running in development mode (localhost)
|
|
21
|
-
* Returns false for staging and production environments
|
|
22
|
-
*/
|
|
23
|
-
export declare function isDevelopmentMode(): boolean;
|
|
24
19
|
export {};
|
|
25
20
|
//# sourceMappingURL=env-loader.d.ts.map
|
package/dist/env-loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-loader.d.ts","sourceRoot":"","sources":["../src/env-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,UAAU,SAAS;IACjB,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAID;;;GAGG;AACH,wBAAgB,aAAa,IAAI,SAAS,CA6EzC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAGlE
|
|
1
|
+
{"version":3,"file":"env-loader.d.ts","sourceRoot":"","sources":["../src/env-loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,UAAU,SAAS;IACjB,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAID;;;GAGG;AACH,wBAAgB,aAAa,IAAI,SAAS,CA6EzC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAGlE"}
|
package/dist/env-loader.js
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.loadEnvConfig = loadEnvConfig;
|
|
10
10
|
exports.getEnvVar = getEnvVar;
|
|
11
|
-
exports.isDevelopmentMode = isDevelopmentMode;
|
|
12
11
|
let cachedConfig = null;
|
|
13
12
|
/**
|
|
14
13
|
* Load environment configuration from the packaged env file
|
|
@@ -92,24 +91,4 @@ function getEnvVar(key) {
|
|
|
92
91
|
const config = loadEnvConfig();
|
|
93
92
|
return config[key];
|
|
94
93
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Check if we're running in development mode (localhost)
|
|
97
|
-
* Returns false for staging and production environments
|
|
98
|
-
*/
|
|
99
|
-
function isDevelopmentMode() {
|
|
100
|
-
try {
|
|
101
|
-
const config = loadEnvConfig();
|
|
102
|
-
const backendUrl = config.TESTCHIMP_BACKEND_URL || '';
|
|
103
|
-
// Consider it development mode if:
|
|
104
|
-
// 1. Backend URL contains localhost or 127.0.0.1
|
|
105
|
-
// 2. NODE_ENV is explicitly set to 'development'
|
|
106
|
-
const isLocalhost = backendUrl.includes('localhost') || backendUrl.includes('127.0.0.1');
|
|
107
|
-
const isDevEnv = process.env.NODE_ENV === 'development';
|
|
108
|
-
return isLocalhost || isDevEnv;
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
// If we can't determine, assume production for safety (suppress verbose logs)
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
94
|
//# sourceMappingURL=env-loader.js.map
|
package/dist/env-loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env-loader.js","sourceRoot":"","sources":["../src/env-loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAYH,sCA6EC;AAKD,8BAGC;
|
|
1
|
+
{"version":3,"file":"env-loader.js","sourceRoot":"","sources":["../src/env-loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAYH,sCA6EC;AAKD,8BAGC;AA3FD,IAAI,YAAY,GAAqB,IAAI,CAAC;AAE1C;;;GAGG;AACH,SAAgB,aAAa;IAC3B,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,IAAI,CAAC;QACH,+CAA+C;QAC/C,MAAM,aAAa,GAAG;YACpB,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC;YAC9C,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,C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,gBAAgB,CAAC,EAAE,gBAAgB;IAarC;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,KAAK,IAAI,GAAG,IAAI;IAIpF;;OAEG;IACH,OAAO,CAAC,GAAG;IAOX;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;;OAGG;IACH,aAAa,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAQ3C;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAkBtF;;OAEG;YACW,qBAAqB;IAmBnC;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAgCjG;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAsC7B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACH,OAAO,IAAI,OAAO;YAIJ,UAAU;YAiIV,eAAe;YAoKf,oBAAoB;IAgBlC,OAAO,CAAC,4BAA4B;YA8CtB,iBAAiB;YAiVjB,eAAe;IA0B7B;;OAEG;IACH,OAAO,CAAC,aAAa;YAeP,oBAAoB;YAoDpB,oBAAoB;YAiBpB,mBAAmB;IAcjC,OAAO,CAAC,mBAAmB;IA4B3B,OAAO,CAAC,yBAAyB;YA0CnB,0BAA0B;YAkF1B,iBAAiB;IA0D/B,OAAO,CAAC,qBAAqB;IAyB7B;;OAEG;YACW,iBAAiB;IAI/B;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAkC3B"}
|
|
@@ -186,12 +186,67 @@ class ExecutionService {
|
|
|
186
186
|
if (!request.script) {
|
|
187
187
|
throw new Error('Script content is required for execution. The TestChimpService should read the file and provide script content.');
|
|
188
188
|
}
|
|
189
|
+
// Check if we should use existing browser or create new one
|
|
190
|
+
const useExistingBrowser = !!(request.existingBrowser && request.existingContext && request.existingPage);
|
|
191
|
+
if (useExistingBrowser) {
|
|
192
|
+
this.log('Using existing browser/page provided by caller');
|
|
193
|
+
// Single attempt with existing browser
|
|
194
|
+
const browser = request.existingBrowser;
|
|
195
|
+
const context = request.existingContext;
|
|
196
|
+
const page = request.existingPage;
|
|
197
|
+
try {
|
|
198
|
+
// LIFECYCLE: Call beforeStartTest if provided
|
|
199
|
+
if (this.progressReporter?.beforeStartTest) {
|
|
200
|
+
await this.progressReporter.beforeStartTest(page, browser, context);
|
|
201
|
+
}
|
|
202
|
+
// Execute the script as-is
|
|
203
|
+
await this.executeScriptContent(request.script, page);
|
|
204
|
+
// LIFECYCLE: Call afterEndTest on success
|
|
205
|
+
if (this.progressReporter?.afterEndTest) {
|
|
206
|
+
await this.progressReporter.afterEndTest('passed', undefined, page);
|
|
207
|
+
}
|
|
208
|
+
// Don't close browser - caller owns it
|
|
209
|
+
return {
|
|
210
|
+
run_status: 'success',
|
|
211
|
+
num_deflake_runs: 0,
|
|
212
|
+
executionTime: Date.now() - startTime
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
lastError = error instanceof Error ? error : new Error('Script execution failed');
|
|
217
|
+
this.log(`Execution failed: ${lastError.message}`);
|
|
218
|
+
// LIFECYCLE: Call afterEndTest on failure
|
|
219
|
+
if (this.progressReporter?.afterEndTest) {
|
|
220
|
+
try {
|
|
221
|
+
await this.progressReporter.afterEndTest('failed', lastError.message, page);
|
|
222
|
+
}
|
|
223
|
+
catch (callbackError) {
|
|
224
|
+
this.log(`afterEndTest callback failed: ${callbackError}`, 'warn');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
run_status: 'failed',
|
|
229
|
+
num_deflake_runs: 0,
|
|
230
|
+
executionTime: Date.now() - startTime,
|
|
231
|
+
error: lastError.message
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// Create our own browser (original behavior)
|
|
189
236
|
for (let attempt = 1; attempt <= totalAttempts; attempt++) {
|
|
190
237
|
this.log(`Attempting deflake run ${attempt}/${totalAttempts}`);
|
|
191
238
|
const { browser, context, page } = await this.initializeBrowser(request.playwrightConfig, request.headless, request.playwrightConfigFilePath);
|
|
192
239
|
try {
|
|
240
|
+
// LIFECYCLE: Call beforeStartTest if provided
|
|
241
|
+
if (this.progressReporter?.beforeStartTest) {
|
|
242
|
+
await this.progressReporter.beforeStartTest(page, browser, context);
|
|
243
|
+
}
|
|
193
244
|
// Execute the script as-is
|
|
194
245
|
await this.executeScriptContent(request.script, page);
|
|
246
|
+
// LIFECYCLE: Call afterEndTest on success
|
|
247
|
+
if (this.progressReporter?.afterEndTest) {
|
|
248
|
+
await this.progressReporter.afterEndTest('passed', undefined, page);
|
|
249
|
+
}
|
|
195
250
|
await browser.close();
|
|
196
251
|
// Success! Return immediately
|
|
197
252
|
return {
|
|
@@ -203,6 +258,15 @@ class ExecutionService {
|
|
|
203
258
|
catch (error) {
|
|
204
259
|
lastError = error instanceof Error ? error : new Error('Script execution failed');
|
|
205
260
|
this.log(`Initial run failed: ${lastError.message}`);
|
|
261
|
+
// LIFECYCLE: Call afterEndTest on failure
|
|
262
|
+
if (this.progressReporter?.afterEndTest) {
|
|
263
|
+
try {
|
|
264
|
+
await this.progressReporter.afterEndTest('failed', lastError.message, page);
|
|
265
|
+
}
|
|
266
|
+
catch (callbackError) {
|
|
267
|
+
this.log(`afterEndTest callback failed: ${callbackError}`, 'warn');
|
|
268
|
+
}
|
|
269
|
+
}
|
|
206
270
|
try {
|
|
207
271
|
await browser.close();
|
|
208
272
|
}
|
|
@@ -231,6 +295,8 @@ class ExecutionService {
|
|
|
231
295
|
if (!request.script) {
|
|
232
296
|
throw new Error('Script content is required for AI repair. The TestChimpService should read the file and provide script content.');
|
|
233
297
|
}
|
|
298
|
+
// Check if we should use existing browser
|
|
299
|
+
const useExistingBrowser = !!(request.existingBrowser && request.existingContext && request.existingPage);
|
|
234
300
|
// First, try runExactly (which includes deflaking if configured)
|
|
235
301
|
this.log('Attempting runExactly first (with deflaking if configured)...');
|
|
236
302
|
const runExactlyResult = await this.runExactly(request, startTime, model);
|
|
@@ -241,14 +307,40 @@ class ExecutionService {
|
|
|
241
307
|
// runExactly failed, start AI repair
|
|
242
308
|
this.log('runExactly failed, starting AI repair process...');
|
|
243
309
|
try {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
this.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
310
|
+
let repairBrowser, repairContext, repairPage, steps, updatedSteps;
|
|
311
|
+
if (useExistingBrowser) {
|
|
312
|
+
// Use existing browser
|
|
313
|
+
this.log('Using existing browser for AI repair...');
|
|
314
|
+
repairBrowser = request.existingBrowser;
|
|
315
|
+
repairContext = request.existingContext;
|
|
316
|
+
repairPage = request.existingPage;
|
|
317
|
+
// Parse script into steps
|
|
318
|
+
steps = await this.parseScriptIntoSteps(request.script, model);
|
|
319
|
+
// LIFECYCLE: Call beforeStartTest if provided
|
|
320
|
+
if (this.progressReporter?.beforeStartTest) {
|
|
321
|
+
await this.progressReporter.beforeStartTest(repairPage, repairBrowser, repairContext);
|
|
322
|
+
}
|
|
323
|
+
this.log('Starting AI repair with parsed steps...');
|
|
324
|
+
updatedSteps = await this.repairStepsWithAI(steps, repairPage, repairFlexibility, model);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
// Start browser initialization and script parsing in parallel for faster startup
|
|
328
|
+
this.log('Initializing repair browser and parsing script...');
|
|
329
|
+
const results = await Promise.all([
|
|
330
|
+
this.parseScriptIntoSteps(request.script, model),
|
|
331
|
+
this.initializeBrowser(request.playwrightConfig, request.headless, request.playwrightConfigFilePath) // Use request.headless (defaults to false/headed)
|
|
332
|
+
]);
|
|
333
|
+
steps = results[0];
|
|
334
|
+
repairBrowser = results[1].browser;
|
|
335
|
+
repairContext = results[1].context;
|
|
336
|
+
repairPage = results[1].page;
|
|
337
|
+
// LIFECYCLE: Call beforeStartTest if provided
|
|
338
|
+
if (this.progressReporter?.beforeStartTest) {
|
|
339
|
+
await this.progressReporter.beforeStartTest(repairPage, repairBrowser, repairContext);
|
|
340
|
+
}
|
|
341
|
+
this.log('Starting AI repair with parsed steps...');
|
|
342
|
+
updatedSteps = await this.repairStepsWithAI(steps, repairPage, repairFlexibility, model);
|
|
343
|
+
}
|
|
252
344
|
// Always generate the updated script
|
|
253
345
|
const updatedScript = this.generateUpdatedScript(updatedSteps);
|
|
254
346
|
// Check if repair was successful by seeing if we completed all steps
|
|
@@ -273,7 +365,19 @@ class ExecutionService {
|
|
|
273
365
|
this.creditUsageService.reportAIRepairCredit().catch(error => {
|
|
274
366
|
this.log(`Failed to report credit usage for AI repair: ${error}`, 'warn');
|
|
275
367
|
});
|
|
276
|
-
|
|
368
|
+
// LIFECYCLE: Call afterEndTest (partial or complete success)
|
|
369
|
+
if (this.progressReporter?.afterEndTest) {
|
|
370
|
+
try {
|
|
371
|
+
await this.progressReporter.afterEndTest(allStepsSuccessful ? 'passed' : 'failed', allStepsSuccessful ? undefined : 'Partial repair success', repairPage);
|
|
372
|
+
}
|
|
373
|
+
catch (callbackError) {
|
|
374
|
+
this.log(`afterEndTest callback failed: ${callbackError}`, 'warn');
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// Only close browser if we created it (not provided by caller)
|
|
378
|
+
if (!useExistingBrowser) {
|
|
379
|
+
await repairBrowser.close();
|
|
380
|
+
}
|
|
277
381
|
return {
|
|
278
382
|
run_status: 'failed', // Original script failed
|
|
279
383
|
repair_status: allStepsSuccessful ? 'success' : 'partial', // Complete or partial repair success
|
|
@@ -286,7 +390,19 @@ class ExecutionService {
|
|
|
286
390
|
}
|
|
287
391
|
else {
|
|
288
392
|
// No successful repairs at all
|
|
289
|
-
|
|
393
|
+
// LIFECYCLE: Call afterEndTest (complete failure)
|
|
394
|
+
if (this.progressReporter?.afterEndTest) {
|
|
395
|
+
try {
|
|
396
|
+
await this.progressReporter.afterEndTest('failed', 'AI repair could not fix any steps', repairPage);
|
|
397
|
+
}
|
|
398
|
+
catch (callbackError) {
|
|
399
|
+
this.log(`afterEndTest callback failed: ${callbackError}`, 'warn');
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
// Only close browser if we created it (not provided by caller)
|
|
403
|
+
if (!useExistingBrowser) {
|
|
404
|
+
await repairBrowser.close();
|
|
405
|
+
}
|
|
290
406
|
return {
|
|
291
407
|
run_status: 'failed', // Original script failed
|
|
292
408
|
repair_status: 'failed',
|
|
@@ -377,6 +493,14 @@ class ExecutionService {
|
|
|
377
493
|
const step = updatedSteps[i];
|
|
378
494
|
this.log(`Loop iteration: i=${i}, step description="${step.description}", total steps=${updatedSteps.length}`);
|
|
379
495
|
try {
|
|
496
|
+
// LIFECYCLE: Call beforeStepStart if provided
|
|
497
|
+
if (this.progressReporter?.beforeStepStart) {
|
|
498
|
+
await this.progressReporter.beforeStepStart({
|
|
499
|
+
stepNumber: i + 1,
|
|
500
|
+
description: step.description,
|
|
501
|
+
code: step.code
|
|
502
|
+
}, page);
|
|
503
|
+
}
|
|
380
504
|
// Try to execute the step directly without context replay
|
|
381
505
|
this.log(`Attempting Step ${i + 1}: ${step.description}`);
|
|
382
506
|
this.log(` Code: ${step.code}`);
|