@empiricalrun/test-gen 0.28.2 → 0.28.4

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,17 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.28.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 2d27074: fix: add test for nested test update
8
+
9
+ ## 0.28.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 5ab2120: Revert "fix: incomplete llm response for ts error fix"
14
+
3
15
  ## 0.28.2
4
16
 
5
17
  ### 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;AAWvD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AAqDD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,aAAa,GACvB,OAAO,CAAC,MAAM,CAAC,CAmCjB;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,GACrC,OAAO,CAAC,MAAM,CAAC,CA8CjB;AAED,wBAAsB,sBAAsB,CAAC,EAC3C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Ae,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,8EASA"}
@@ -52,6 +52,7 @@ async function prepareFileForUpdateScenario(genConfig) {
52
52
  testCode: codePrompt,
53
53
  pomCode: pomPrompt,
54
54
  testCase: testCase,
55
+ options: genConfig.options,
55
56
  });
56
57
  const testFileContent = await fs_extra_1.default.readFile(specPath, "utf-8");
57
58
  const { testBlock, testNode } = (0, web_1.getTypescriptTestBlock)({
@@ -1,12 +1,13 @@
1
1
  import { TraceClient } from "@empiricalrun/llm";
2
2
  import { CustomLogger } from "../../bin/logger";
3
- import { TestCase } from "../../types";
4
- export declare function validateAndFixTypescriptErrors({ trace, logger, file, testCode, pomCode, testCase, }: {
3
+ import { TestCase, TestGenConfigOptions } from "../../types";
4
+ export declare function validateAndFixTypescriptErrors({ trace, logger, file, testCode, pomCode, testCase, options, }: {
5
5
  trace?: TraceClient;
6
6
  logger?: CustomLogger;
7
7
  file: string;
8
8
  testCode: string;
9
9
  pomCode: string;
10
10
  testCase: TestCase;
11
+ options?: TestGenConfigOptions;
11
12
  }): Promise<void>;
12
13
  //# sourceMappingURL=fix-ts-errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fix-ts-errors.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/fix-ts-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAK3D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,wBAAsB,8BAA8B,CAAC,EACnD,KAAK,EACL,MAA2B,EAC3B,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,QAAQ,GACT,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;CACpB,iBA8DA"}
1
+ {"version":3,"file":"fix-ts-errors.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/fix-ts-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAQhD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,8BAA8B,CAAC,EACnD,KAAK,EACL,MAA2B,EAC3B,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,OAAO,GACR,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,iBAoEA"}
@@ -5,12 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.validateAndFixTypescriptErrors = void 0;
7
7
  const llm_1 = require("@empiricalrun/llm");
8
- const generative_ai_1 = require("@google/generative-ai");
9
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
10
- const remove_markdown_1 = __importDefault(require("remove-markdown"));
11
9
  const logger_1 = require("../../bin/logger");
12
10
  const web_1 = require("../../bin/utils/platform/web");
13
- async function validateAndFixTypescriptErrors({ trace, logger = new logger_1.CustomLogger(), file, testCode, pomCode, testCase, }) {
11
+ const constants_1 = require("../../constants");
12
+ async function validateAndFixTypescriptErrors({ trace, logger = new logger_1.CustomLogger(), file, testCode, pomCode, testCase, options, }) {
14
13
  const validateTypesSpan = trace?.span({ name: "detect-type-errors-in-file" });
15
14
  logger.log("Validating types...");
16
15
  let errors = (0, web_1.validateTypescript)(file);
@@ -44,15 +43,20 @@ async function validateAndFixTypescriptErrors({ trace, logger = new logger_1.Cus
44
43
  scenaioName: testCase.name,
45
44
  });
46
45
  promptSpan?.end({ output: { instruction } });
47
- const genAI = new generative_ai_1.GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
48
- const model = genAI.getGenerativeModel({ model: "gemini-1.5-pro-latest" });
49
- const prompt = instruction.map((p) => p.content);
50
- const llmOutputTrace = trace?.span({ name: "llm-output" });
51
- const message = await model.generateContent(prompt);
52
- llmOutputTrace?.end({ output: { message: message.response.text() } });
53
- const removeMarkdownSpan = trace?.span({ name: "remove-markdown" });
54
- let response = (0, remove_markdown_1.default)(message.response.text() || "");
55
- removeMarkdownSpan?.end({ output: { response } });
46
+ const llm = new llm_1.LLM({
47
+ trace,
48
+ provider: options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
49
+ defaultModel: options?.model || constants_1.DEFAULT_MODEL,
50
+ providerApiKey: constants_1.MODEL_API_KEYS[options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER],
51
+ });
52
+ const message = await llm.createChatCompletion({
53
+ messages: instruction,
54
+ modelParameters: {
55
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
56
+ ...options?.modelParameters,
57
+ },
58
+ });
59
+ const response = message?.content || "";
56
60
  const readWriteFileSpan = trace?.span({ name: "write-to-file" });
57
61
  await fs_extra_1.default.writeFile(file, response, "utf-8");
58
62
  readWriteFileSpan?.end({ output: { response } });
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAI7D,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAiGrB"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAI7D,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAkGrB"}
@@ -77,7 +77,7 @@ async function generateTest(testCase, file, options) {
77
77
  logger.success("Test generated successfully!");
78
78
  const readWriteFileSpan = trace.span({ name: "write-to-file" });
79
79
  let contents = fs_extra_1.default.readFileSync(file, "utf-8");
80
- const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(response, testCase?.name, testCase?.suites);
80
+ const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(response, testCase?.name, []);
81
81
  let updatedContent = prependContent + contents + `\n\n${strippedContent}`;
82
82
  await fs_extra_1.default.writeFile(file, updatedContent, "utf-8");
83
83
  readWriteFileSpan.end({ output: { updatedContent } });
@@ -91,6 +91,7 @@ async function generateTest(testCase, file, options) {
91
91
  testCode: codePrompt,
92
92
  pomCode: pomPrompt,
93
93
  testCase: testCase,
94
+ options,
94
95
  });
95
96
  trace.event({ name: "format-file" });
96
97
  await (0, web_1.formatCode)(file);
@@ -1 +1 @@
1
- {"version":3,"file":"update-flow.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/update-flow.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAmB3B,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAI7D,KAAK,eAAe,GAAG,QAAQ,GAAG;IAChC,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,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B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAiE7B"}
@@ -15,7 +15,7 @@ const constants_1 = require("../../constants");
15
15
  const session_1 = require("../../session");
16
16
  const fix_ts_errors_1 = require("./fix-ts-errors");
17
17
  const utils_1 = require("./utils");
18
- async function applyFileChanges({ validateTypes = true, trace, testCase, fileChanges, logger, pomPrompt, codePrompt, }) {
18
+ async function applyFileChanges({ validateTypes = true, trace, testCase, fileChanges, logger, testGenOptions, pomPrompt, codePrompt, }) {
19
19
  await Promise.allSettled(fileChanges.map(async (fileChange) => {
20
20
  if (!fileChange.filePath) {
21
21
  return;
@@ -23,14 +23,14 @@ async function applyFileChanges({ validateTypes = true, trace, testCase, fileCha
23
23
  const { testBlock: testBlockUpdate } = (0, web_1.getTypescriptTestBlock)({
24
24
  scenarioName: testCase?.name || "",
25
25
  content: fileChange.newCode || "",
26
- suites: testCase?.suites,
26
+ suites: [], // suites should be empty here since we ask LLM to send immediate parent AST node for the code update. so there won't be any nesting here, just the test block
27
27
  });
28
28
  if (testBlockUpdate) {
29
29
  // assuming the test case getting updated
30
30
  // maintaining the previous accuracy of the test case update
31
31
  const readWriteFileSpan = trace.span({ name: "write-to-file" });
32
32
  let contents = await fs_extra_1.default.readFile(fileChange.filePath, "utf-8");
33
- const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(fileChange.newCode, testCase?.name, testCase?.suites);
33
+ const [prependContent, strippedContent] = await (0, web_1.stripAndPrependImports)(fileChange.newCode, testCase?.name, []);
34
34
  let updatedContent = prependContent + contents + `\n\n${strippedContent}`;
35
35
  const { testBlock } = (0, web_1.getTypescriptTestBlock)({
36
36
  scenarioName: testCase?.name,
@@ -77,6 +77,7 @@ async function applyFileChanges({ validateTypes = true, trace, testCase, fileCha
77
77
  testCode: codePrompt,
78
78
  pomCode: pomPrompt,
79
79
  testCase: testCase,
80
+ options: testGenOptions,
80
81
  });
81
82
  }
82
83
  trace.event({ name: "format-file" });
@@ -152,6 +153,7 @@ async function updateTest(testCase, file, options, logging = true, validate = tr
152
153
  testCase,
153
154
  fileChanges,
154
155
  logger,
156
+ testGenOptions: options,
155
157
  pomPrompt: pomPrompt,
156
158
  codePrompt: codePrompt,
157
159
  });
@@ -216,6 +218,7 @@ async function appendCreateTestBlock({ testCase, file, options, trace, validateT
216
218
  testCase,
217
219
  fileChanges,
218
220
  logger,
221
+ testGenOptions: options,
219
222
  pomPrompt: pomPrompt,
220
223
  codePrompt: codePrompt,
221
224
  validateTypes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.28.2",
3
+ "version": "0.28.4",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -18,7 +18,6 @@
18
18
  "@actions/core": "^1.10.1",
19
19
  "@aws-sdk/client-s3": "^3.614.0",
20
20
  "@aws-sdk/s3-request-presigner": "^3.614.0",
21
- "@google/generative-ai": "^0.15.0",
22
21
  "@playwright/test": "^1.44.1",
23
22
  "@types/sanitize-html": "^2.11.0",
24
23
  "commander": "^12.1.0",
@@ -44,8 +43,8 @@
44
43
  "ts-morph": "^23.0.0",
45
44
  "tsx": "^4.16.2",
46
45
  "typescript": "^5.3.3",
47
- "@empiricalrun/llm": "^0.9.2",
48
46
  "@empiricalrun/r2-uploader": "^0.3.0",
47
+ "@empiricalrun/llm": "^0.9.2",
49
48
  "@empiricalrun/reporter": "^0.18.2"
50
49
  },
51
50
  "devDependencies": {
@@ -0,0 +1,10 @@
1
+ import { config as dotenvConfig } from "dotenv";
2
+ import { defineConfig } from "vitest/config";
3
+
4
+ dotenvConfig({ path: [".env.local", ".env"] });
5
+
6
+ export default defineConfig({
7
+ test: {
8
+ setupFiles: ["dotenv/config"],
9
+ },
10
+ });