@empiricalrun/test-gen 0.21.9 → 0.22.2

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,5 +1,44 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.22.2
4
+
5
+ ### Patch Changes
6
+
7
+ - d35239e: fix: update imports for test and expect to fixtures
8
+ - Updated dependencies [2de783d]
9
+ - @empiricalrun/llm@0.7.0
10
+
11
+ ## 0.22.1
12
+
13
+ ### Patch Changes
14
+
15
+ - b96491f: fix: typescript errors for valid CommonJS module imports
16
+
17
+ ## 0.22.0
18
+
19
+ ### Minor Changes
20
+
21
+ - 4676ab7: feat: use gpt-4o-2024-08-06 as default
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [1770926]
26
+ - Updated dependencies [4676ab7]
27
+ - @empiricalrun/llm@0.6.0
28
+
29
+ ## 0.21.11
30
+
31
+ ### Patch Changes
32
+
33
+ - e2b7a29: fix: codegen adding extra changes than the requested task
34
+ - 29cad4a: feat: use vercel kv
35
+
36
+ ## 0.21.10
37
+
38
+ ### Patch Changes
39
+
40
+ - e077e2a: fix: verification agent should use model configured from test token
41
+
3
42
  ## 0.21.9
4
43
 
5
44
  ### Patch Changes
@@ -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;AASvD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AAED,wBAAsB,2BAA2B,CAAC,SAAS,EAAE,aAAa,iBA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rC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,MAAM,CAAC,CAkDjB;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"}
@@ -28,7 +28,8 @@ async function prepareFileForBrowsingAgent(genConfig) {
28
28
  const logger = new logger_1.CustomLogger();
29
29
  if (!fs_extra_1.default.existsSync(specPath)) {
30
30
  await fs_extra_1.default.createFile(specPath);
31
- await fs_extra_1.default.writeFile(specPath, (0, web_1.addNewImport)("", ["test", "expect"], "@playwright/test"));
31
+ const fileContentWithImports = (0, web_1.addNewImport)("", ["test", "expect"], (0, web_1.getFixtureImportPath)(specPath));
32
+ await fs_extra_1.default.writeFile(specPath, fileContentWithImports, "utf-8");
32
33
  }
33
34
  if (name && steps && steps.length) {
34
35
  const existingContents = await fs_extra_1.default.readFile(specPath, "utf-8");
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAgJrB"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAkJrB"}
@@ -67,7 +67,7 @@ async function generateTest(testCase, file, options) {
67
67
  logger.success("Test generated successfully!");
68
68
  const readWriteFileSpan = trace.span({ name: "write-to-file" });
69
69
  let contents = fs_extra_1.default.readFileSync(file, "utf-8");
70
- const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(response);
70
+ const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(response, testCase?.name);
71
71
  let updatedContent = prependContent + contents + `\n\n${strippedContent}`;
72
72
  if (isUpdate) {
73
73
  const testBlock = (0, web_1.getTypescriptTestBlock)(testCase?.name, contents);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/verification/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,GAAG,EACH,KAAK,EACL,IAAI,EACJ,YAAY,GACb,EAAE;IACD,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;;;GA8DA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/verification/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,GAAG,EACH,KAAK,EACL,IAAI,EACJ,YAAY,GACb,EAAE;IACD,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;;;GA6DA"}
@@ -48,7 +48,6 @@ ${conversation.join("\n")}
48
48
  },
49
49
  },
50
50
  ],
51
- model: "gpt-4o",
52
51
  modelParameters: {
53
52
  tool_choice: "required",
54
53
  },
@@ -1,9 +1,10 @@
1
1
  export declare function getTypescriptTestBlock(scenarioName: string, content: string): string | undefined;
2
2
  export declare function appendToTestBlock(testBlock: string, content: string): string;
3
3
  export declare function validateTypescript(filePath: string): string[];
4
- export declare function stripAndPrependImports(content: string): Promise<string[]>;
4
+ export declare function stripAndPrependImports(content: string, testName: string): Promise<(string | undefined)[]>;
5
5
  export declare function lintErrors(filePath: string): Promise<void>;
6
6
  export declare function formatCode(filePath: string): Promise<void>;
7
7
  export declare function addNewImport(contents: string, modules: string[], pkg: string): string;
8
8
  export declare function removeTestOnly(filePath: string): Promise<void>;
9
+ export declare function getFixtureImportPath(filePath: string): string;
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAMA,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAYpB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAmD7D;AAED,wBAAsB,sBAAsB,CAAC,OAAO,EAAE,MAAM,qBAM3D;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAShD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAQhD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,UAE5E;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,iBAIpD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAMA,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAYpB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG5E;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAwD7D;AAED,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,mCAOjB;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAShD;AAED,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,iBAQhD;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,UAE5E;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,iBAIpD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,UAcpD"}
@@ -3,7 +3,7 @@ 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.removeTestOnly = exports.addNewImport = exports.formatCode = exports.lintErrors = exports.stripAndPrependImports = exports.validateTypescript = exports.appendToTestBlock = exports.getTypescriptTestBlock = void 0;
6
+ exports.getFixtureImportPath = exports.removeTestOnly = exports.addNewImport = exports.formatCode = exports.lintErrors = exports.stripAndPrependImports = exports.validateTypescript = exports.appendToTestBlock = exports.getTypescriptTestBlock = void 0;
7
7
  const eslint_1 = require("eslint");
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const prettier_1 = __importDefault(require("prettier"));
@@ -25,12 +25,13 @@ function appendToTestBlock(testBlock, content) {
25
25
  exports.appendToTestBlock = appendToTestBlock;
26
26
  function validateTypescript(filePath) {
27
27
  // Create a compiler host to read files
28
- const compilerHost = typescript_1.default.createCompilerHost({
29
- esModuleInterop: true,
30
- });
28
+ const compilerHost = typescript_1.default.createCompilerHost({});
31
29
  compilerHost.readFile = (file) => fs_extra_1.default.readFileSync(file, "utf8");
32
30
  // Create a program with a single source file
33
- const program = typescript_1.default.createProgram([filePath], {}, compilerHost);
31
+ const program = typescript_1.default.createProgram([filePath], {
32
+ esModuleInterop: true,
33
+ allowSyntheticDefaultImports: true,
34
+ }, compilerHost);
34
35
  // Get the source file
35
36
  const sourceFile = program.getSourceFile(filePath);
36
37
  // Get and report any syntactic errors
@@ -73,10 +74,10 @@ function validateTypescript(filePath) {
73
74
  return errors;
74
75
  }
75
76
  exports.validateTypescript = validateTypescript;
76
- async function stripAndPrependImports(content) {
77
+ async function stripAndPrependImports(content, testName) {
77
78
  const importRegexp = /import\s+\{[^}]*\}\s+from\s+["'][^"']+["'];?/g;
78
79
  const imports = content.match(importRegexp);
79
- const strippedContent = content.replace(importRegexp, "");
80
+ const strippedContent = getTypescriptTestBlock(testName, content);
80
81
  const prependContent = (imports?.join("\n") || "") + "\n\n";
81
82
  return [prependContent, strippedContent];
82
83
  }
@@ -112,3 +113,19 @@ async function removeTestOnly(filePath) {
112
113
  return fs_extra_1.default.writeFile(filePath, updatedContent);
113
114
  }
114
115
  exports.removeTestOnly = removeTestOnly;
116
+ function getFixtureImportPath(filePath) {
117
+ // get the depth from the tests folder
118
+ // assumption fixtures are always int the folder tests/fixtures
119
+ const subFolder = filePath.split("/tests/")[1];
120
+ const subFolderDepth = subFolder?.split("/").length
121
+ ? subFolder?.split("/").length - 1
122
+ : 0;
123
+ // create an array of path segments to the fixtures file
124
+ const fixturesPath = [
125
+ "./",
126
+ subFolderDepth ? new Array(subFolderDepth).fill("../").join("") : "",
127
+ "fixtures",
128
+ ].join("");
129
+ return fixturesPath;
130
+ }
131
+ exports.getFixtureImportPath = getFixtureImportPath;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ts-path-import-validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-path-import-validate.d.ts","sourceRoot":"","sources":["../../../../../../src/bin/utils/platform/web/test-files/ts-path-import-validate.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ console.log(path_1.default);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE3E,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAItD,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,WAAsB,CAAC;AAE5D,eAAO,MAAM,aAAa,EAAE,QAAmB,CAAC;AAEhD,eAAO,MAAM,wBAAwB,EAAE,eAEtC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE3E,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAItD,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,WAAsB,CAAC;AAE5D,eAAO,MAAM,aAAa,EAAE,QAA8B,CAAC;AAE3D,eAAO,MAAM,wBAAwB,EAAE,eAEtC,CAAC"}
@@ -7,7 +7,7 @@ exports.MODEL_API_KEYS = {
7
7
  openai: process.env.OPENAI_API_KEY || "",
8
8
  };
9
9
  exports.DEFAULT_MODEL_PROVIDER = "openai";
10
- exports.DEFAULT_MODEL = "gpt-4o";
10
+ exports.DEFAULT_MODEL = "gpt-4o-2024-08-06";
11
11
  exports.DEFAULT_MODEL_PARAMETERS = {
12
12
  temperature: 0.5,
13
13
  };
@@ -27,7 +27,7 @@ class FileService {
27
27
  if (testFilePath) {
28
28
  const testFile = fs_1.default.readFileSync(testFilePath, "utf-8");
29
29
  const updatedTestFile = testFile.replace(/await createTest\([\s\S]*?\);\n/, "\n" + generatedCode);
30
- const importStatement = `import { test, expect } from "@playwright/test";`;
30
+ const importStatement = `import { test, expect } from "${(0, web_1.getFixtureImportPath)(testFilePath)}";`;
31
31
  fs_1.default.writeFileSync(testFilePath, importStatement + "\n" + updatedTestFile, "utf-8");
32
32
  await (0, web_1.lintErrors)(testFilePath);
33
33
  return res.send({ success: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.21.9",
3
+ "version": "0.22.2",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -41,7 +41,7 @@
41
41
  "ts-morph": "^23.0.0",
42
42
  "tsx": "^4.16.2",
43
43
  "typescript": "^5.3.3",
44
- "@empiricalrun/llm": "^0.5.0",
44
+ "@empiricalrun/llm": "^0.7.0",
45
45
  "@empiricalrun/reporter": "^0.16.1"
46
46
  },
47
47
  "devDependencies": {