@empiricalrun/test-gen 0.33.0 → 0.33.1
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/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"AAmBA,KAAK,iBAAiB,GAAG;IACvB;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,6BAA6B,CAAC,EAClD,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACjB,EAAE,iBAAiB,iBAyEnB"}
|
|
@@ -38,6 +38,9 @@ async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, p
|
|
|
38
38
|
const pageVar = await (0, web_1.getPageVariableNameFromCreateTest)(testFilePath);
|
|
39
39
|
console.log(`Detected playwright project name: ${project}`);
|
|
40
40
|
// run playwright test which will internally run the master agent
|
|
41
|
+
const testsDirectory = `${process.cwd()}/tests`;
|
|
42
|
+
const teardowns = new utils_2.TeardownManager(testsDirectory);
|
|
43
|
+
await teardowns.skipAll();
|
|
41
44
|
let command = `npx playwright test ${testFilePath} --retries 0 --project ${project} --timeout 0`;
|
|
42
45
|
if (!process.env.CI) {
|
|
43
46
|
command = command.concat(` --headed`);
|
|
@@ -59,6 +62,7 @@ async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, p
|
|
|
59
62
|
console.error(error);
|
|
60
63
|
isError = true;
|
|
61
64
|
}
|
|
65
|
+
teardowns.unskipAll();
|
|
62
66
|
// clean up the file if there is any error
|
|
63
67
|
if (isError) {
|
|
64
68
|
try {
|
|
@@ -35,4 +35,13 @@ export declare function getPromptForNextAction({ pageSnapshot, task, previousAct
|
|
|
35
35
|
lastActionErrors: string[];
|
|
36
36
|
promptType?: string;
|
|
37
37
|
}): Promise<import("openai/resources/index.mjs").ChatCompletionMessageParam[]>;
|
|
38
|
+
export declare class TeardownManager {
|
|
39
|
+
private directory;
|
|
40
|
+
constructor(directory: string);
|
|
41
|
+
private teardownFiles;
|
|
42
|
+
private getAllTeardownFiles;
|
|
43
|
+
private skipTeardownFile;
|
|
44
|
+
skipAll(): Promise<void>;
|
|
45
|
+
unskipAll(): void;
|
|
46
|
+
}
|
|
38
47
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAiBvD,OAAO,EAAe,aAAa,EAAE,MAAM,aAAa,CAAC;AAKzD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AA4ED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,aAAa,GACvB,OAAO,CAAC,MAAM,CAAC,CA0DjB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBAiBxD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,QA6BjD;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAM1E;AAWD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,EACtC,gBAAgB,GAAE,MAAM,EAAU,GACjC,OAAO,CAAC,MAAM,CAAC,CA+CjB;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,YAAiB,EACjB,IAAS,EACT,eAAoB,EACpB,gBAAqB,EACrB,UAAyC,GAC1C,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,8EASA;AAED,qBAAa,eAAe;IACd,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM;IACrC,OAAO,CAAC,aAAa,CAAqB;YAE5B,mBAAmB;YAUnB,gBAAgB;IAsBjB,OAAO;IAuBb,SAAS;CAKjB"}
|
|
@@ -3,14 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPromptForNextAction = exports.detectProjectName = exports.readPlaywrightConfig = exports.canRunMasterAgent = exports.injectPwLocatorGenerator = exports.prepareFileForMasterAgent = exports.prepareBrowsingAgentTask = exports.isRegExp = void 0;
|
|
6
|
+
exports.TeardownManager = exports.getPromptForNextAction = exports.detectProjectName = exports.readPlaywrightConfig = exports.canRunMasterAgent = exports.injectPwLocatorGenerator = exports.prepareFileForMasterAgent = exports.prepareBrowsingAgentTask = exports.isRegExp = void 0;
|
|
7
7
|
const llm_1 = require("@empiricalrun/llm");
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
10
|
const minimatch_1 = require("minimatch");
|
|
11
|
+
const ts_morph_1 = require("ts-morph");
|
|
11
12
|
const api_1 = __importDefault(require("tsx/cjs/api"));
|
|
12
13
|
const logger_1 = require("../../bin/logger");
|
|
13
14
|
const context_1 = require("../../bin/utils/context");
|
|
15
|
+
const fs_1 = require("../../bin/utils/fs");
|
|
14
16
|
const web_1 = require("../../bin/utils/platform/web");
|
|
15
17
|
const reporter_1 = require("../../reporter");
|
|
16
18
|
const create_test_block_1 = require("../codegen/create-test-block");
|
|
@@ -271,3 +273,56 @@ async function getPromptForNextAction({ pageSnapshot = "", task = "", previousAc
|
|
|
271
273
|
return prompt;
|
|
272
274
|
}
|
|
273
275
|
exports.getPromptForNextAction = getPromptForNextAction;
|
|
276
|
+
class TeardownManager {
|
|
277
|
+
directory;
|
|
278
|
+
constructor(directory) {
|
|
279
|
+
this.directory = directory;
|
|
280
|
+
}
|
|
281
|
+
teardownFiles = [];
|
|
282
|
+
async getAllTeardownFiles() {
|
|
283
|
+
const teardownFileRegex = /.*\.teardown\.ts/;
|
|
284
|
+
const teardownFiles = await (0, fs_1.readFilesInDirectory)(this.directory, (fileName) => teardownFileRegex.test(fileName));
|
|
285
|
+
return teardownFiles;
|
|
286
|
+
}
|
|
287
|
+
async skipTeardownFile(filePath) {
|
|
288
|
+
const project = new ts_morph_1.Project();
|
|
289
|
+
const sourceFile = project.addSourceFileAtPath(filePath);
|
|
290
|
+
sourceFile
|
|
291
|
+
.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
|
|
292
|
+
.forEach((callExpression) => {
|
|
293
|
+
const expression = callExpression.getExpression();
|
|
294
|
+
if (expression.getText() === "teardown") {
|
|
295
|
+
expression.replaceWithText("teardown.skip");
|
|
296
|
+
}
|
|
297
|
+
else if (expression.getText() === "test") {
|
|
298
|
+
expression.replaceWithText("test.skip");
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
// Save the modified file
|
|
302
|
+
sourceFile.save().catch((error) => {
|
|
303
|
+
console.error(`Error updating the file: ${filePath}`, error);
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
async skipAll() {
|
|
307
|
+
this.teardownFiles = await this.getAllTeardownFiles();
|
|
308
|
+
await Promise.all(this.teardownFiles.map(async ({ filePath }) => await this.skipTeardownFile(filePath)));
|
|
309
|
+
process.on("beforeExit", () => {
|
|
310
|
+
this.unskipAll();
|
|
311
|
+
});
|
|
312
|
+
process.on("exit", () => {
|
|
313
|
+
this.unskipAll();
|
|
314
|
+
});
|
|
315
|
+
process.on("SIGINT", () => {
|
|
316
|
+
this.unskipAll();
|
|
317
|
+
});
|
|
318
|
+
process.on("SIGTERM", () => {
|
|
319
|
+
this.unskipAll();
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
unskipAll() {
|
|
323
|
+
this.teardownFiles.forEach(({ filePath, content }) => {
|
|
324
|
+
fs_extra_1.default.writeFileSync(filePath, content, "utf-8");
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
exports.TeardownManager = TeardownManager;
|