@empiricalrun/test-gen 0.42.26 → 0.42.27

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,12 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.42.27
4
+
5
+ ### Patch Changes
6
+
7
+ - 9fc1b40: test: increase timeout for lexical test
8
+ - 1f18628: fix: separate out create test and repo edit LLM calls and remove str replace flag
9
+
3
10
  ## 0.42.26
4
11
 
5
12
  ### Patch Changes
@@ -130,7 +130,7 @@ function getPlannerToolCalls() {
130
130
  }
131
131
  async function getPlanForCodeEditorAgent({ prompt, trace, }) {
132
132
  const promptSpan = trace?.span({
133
- name: "planner-agent",
133
+ name: "repo-edit-planner-agent",
134
134
  input: {
135
135
  prompt,
136
136
  },
@@ -2,22 +2,20 @@ import { TraceClient } from "@empiricalrun/llm";
2
2
  import { ChatCompletionMessageParam } from "openai/resources/index.mjs";
3
3
  import { CustomLogger } from "../../bin/logger";
4
4
  import { CodeUpdate } from "./types";
5
- export declare function generateCodeUsingRepoAgent({ task, trace, repoFiles, useStrReplace, logger, }: {
5
+ export declare function generateCodeUsingRepoAgent({ task, trace, repoFiles, logger, }: {
6
6
  trace?: TraceClient;
7
7
  task: string;
8
8
  repoFiles: string;
9
- useStrReplace?: boolean;
10
9
  logger?: CustomLogger;
11
10
  }): Promise<{
12
11
  prompt: ChatCompletionMessageParam[];
13
12
  agentResponse: string;
14
13
  fileChanges: CodeUpdate[];
15
14
  }>;
16
- export declare function repoEditAgent({ trace, task, logger, useStrReplace, }: {
15
+ export declare function repoEditAgent({ trace, task, logger, }: {
17
16
  trace?: TraceClient;
18
17
  task: string;
19
18
  logger?: CustomLogger;
20
- useStrReplace?: boolean;
21
19
  }): Promise<{
22
20
  prompt: ChatCompletionMessageParam[];
23
21
  fileChanges: CodeUpdate[];
@@ -1 +1 @@
1
- {"version":3,"file":"repo-edit.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/repo-edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAGxE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAUhD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAOrC,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,KAAK,EACL,SAAS,EACT,aAAa,EACb,MAAM,GACP,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CAAC,CAwJD;AAED,wBAAsB,aAAa,CAAC,EAClC,KAAK,EACL,IAAI,EACJ,MAAM,EACN,aAAa,GACd,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CAAC,CA0ED"}
1
+ {"version":3,"file":"repo-edit.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/repo-edit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAQhD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,KAAK,EACL,SAAS,EAET,MAAM,GACP,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CAAC,CA6CD;AAED,wBAAsB,aAAa,CAAC,EAClC,KAAK,EACL,IAAI,EACJ,MAAM,GACP,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B,CAAC,CAqCD"}
@@ -4,31 +4,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.repoEditAgent = exports.generateCodeUsingRepoAgent = void 0;
7
- const llm_1 = require("@empiricalrun/llm");
8
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const path_1 = require("path");
10
8
  const context_1 = require("../../bin/utils/context");
11
9
  const web_1 = require("../../bin/utils/platform/web");
12
- const constants_1 = require("../../constants");
13
10
  const reporter_1 = require("../../reporter");
14
11
  const generate_code_apply_changes_1 = require("./generate-code-apply-changes");
15
- const test_update_feedback_1 = require("./test-update-feedback");
16
12
  const utils_1 = require("./utils");
17
- async function generateCodeUsingRepoAgent({ task, trace, repoFiles, useStrReplace, logger, }) {
13
+ async function generateCodeUsingRepoAgent({ task, trace, repoFiles, logger, }) {
18
14
  const repoEditSpan = trace?.span({
19
15
  name: "repo-edit",
20
16
  input: { task },
21
17
  });
22
- // TODO: remove this once we test this flow
23
- if (useStrReplace) {
24
- const prompt = [
25
- {
26
- role: "system",
27
- content: (0, generate_code_apply_changes_1.systemPromptBuilderForRepoEdit)(repoFiles),
28
- },
29
- {
30
- role: "user",
31
- content: `
18
+ const prompt = [
19
+ {
20
+ role: "system",
21
+ content: (0, generate_code_apply_changes_1.systemPromptBuilderForRepoEdit)(repoFiles),
22
+ },
23
+ {
24
+ role: "user",
25
+ content: `
32
26
  You need to work towards completing the task provided to you.
33
27
 
34
28
  Task:
@@ -43,127 +37,25 @@ In order to execute the task, FOLLOW BELOW STEPS:
43
37
 
44
38
  If all the changes are done, respond with "exit" tool call otherwise respond with "change-plan" tool call.
45
39
  `,
46
- },
47
- ];
48
- const fileChanges = await (0, generate_code_apply_changes_1.generateCodeAndApplyChanges)({
49
- task,
50
- trace: repoEditSpan,
51
- getRelevantFiles: async () => await (0, context_1.generateTxtForRepository)(),
52
- logger,
53
- });
54
- repoEditSpan?.end({
55
- output: { fileChanges },
56
- });
57
- return {
58
- prompt,
59
- fileChanges,
60
- agentResponse: "",
61
- };
62
- }
63
- const prompt = [
64
- {
65
- role: "system",
66
- content: `
67
- You are a software test engineer who is given a task to update code in a Playwright test repository.
68
- You will be provided with current test files, fixtures and page object models for you to use and update code as per the task provided to you.
69
- You need to respond with file path and updated code block inside the file.
70
-
71
- Directory structure for the repository:
72
- └── /
73
- ├── tests/
74
- ├────test-data/
75
- │ └── index.ts
76
- ├── pages/
77
- ├── playwright.config.ts
78
- ├── app_knowledge.md
79
- ├── .eslintrc.js
80
- ├── package.json
81
- └── tsconfig.json
82
-
83
- Explanation of repository structure:
84
- - tests: this is a directory where all tests and fixtures are kept. All spec files here end with ".spec.ts" as naming convention. There is an exception for Playwright fixtures file. Fixtures file is named as "fixtures.ts"
85
- - test-data: this is a directory where all the test data are kept.
86
- - pages: this is a directory where all reusable page object model methods are kept. Page object model methods are written in a pure functional convention. These methods are reusable methods created to be used across tests. This is also a directory where all the utility methods are kept which can be executed independent of the Playwright tests.
87
-
88
- Coding principles and guidelines:
89
-
90
- ## Code Style and Structure
91
- - Write concise, maintainable, and technically accurate TypeScript code with relevant examples.
92
- - Use functional and declarative programming patterns; avoid classes.
93
- - Use types to describe the shape of data and the behavior of functions.
94
- - Favour iteration and modularisation to adhere to DRY principles and avoid code duplication.
95
- - Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
96
- - Organise files systematically: each file should contain only related content, such as exported components, subcomponents, helpers, static content, and types.
97
- - Page object models are pure functions and are stateless.
98
-
99
- ## Naming Conventions
100
- - Use lowercase with dashes for directories (e.g., components/auth-wizard).
101
- - Favour named exports for functions.
102
-
103
- ## TypeScript Usage
104
- - Use TypeScript for all code; prefer interfaces over types for their extendability and ability to merge.
105
- - Avoid enums; use maps instead for better type safety and flexibility.
106
- - Use functional components with TypeScript interfaces.
107
-
108
- ## Syntax and Formatting
109
- - Use the "function" keyword for pure functions to benefit from hoisting and clarity.
110
-
111
- Here is the list of files:
112
- ${repoFiles}
113
- `,
114
- },
115
- {
116
- role: "user",
117
- content: `
118
- Task: ${task}
119
-
120
-
121
- ## Follow these instructions before responding with output:
122
- - Read the code line by line and ensure that achieve the task provided to you
123
- - Read the dependencies of the code block by scanning through file paths and file provided to you. refer the same file path while responding with output.
124
- - Focus only on the test case provided and associated JS methods called from the test case.
125
- - Since the response will be used to search and replace blocks, always respond with output which includes the full lexical scope surrounding the modified code.
126
- - If there are any updates inside test code block, ensure responding with full test block with unchanged code as well
127
- - Each code block should contain edits to only one code block in file path
128
- - DO NOT respond with any backticks or markdown syntax
129
- - Respond only with file path where the code block to be updated is present, old code block, new code block and a one liner reason for the change
130
- - Respond with <file_path></file_path>, <old_code_block></old_code_block>, <new_code_block></new_code_block> and <change></change> as xml tags
131
- - The reason for change should adhere to coding principles provided and review if the updated code is present in the file path mentioned
132
- - The code change should belong to the right file path
133
- - The response must start with <file_path>
134
- - Use the repository structure provided, whenever needed create directories which are not present
135
- `,
136
40
  },
137
41
  ];
138
- const llm = new llm_1.LLM({
139
- trace: repoEditSpan,
140
- provider: "anthropic",
141
- defaultModel: "claude-3-5-sonnet-20240620",
142
- providerApiKey: constants_1.MODEL_API_KEYS["anthropic"],
143
- });
144
- const updatedUsageExampleMessage = await llm.createChatCompletion({
145
- messages: prompt,
42
+ const fileChanges = await (0, generate_code_apply_changes_1.generateCodeAndApplyChanges)({
43
+ task,
146
44
  trace: repoEditSpan,
147
- traceName: "repo-edit-agent-llm",
148
- modelParameters: {
149
- ...constants_1.DEFAULT_MODEL_PARAMETERS,
150
- },
45
+ getRelevantFiles: async () => await (0, context_1.generateTxtForRepository)(),
46
+ logger,
151
47
  });
152
- const updates = (0, utils_1.extractTestUpdates)(updatedUsageExampleMessage?.content);
153
48
  repoEditSpan?.end({
154
- output: { updates },
155
- input: {
156
- task,
157
- },
49
+ output: { fileChanges },
158
50
  });
159
51
  return {
160
52
  prompt,
161
- agentResponse: updatedUsageExampleMessage?.content,
162
- fileChanges: updates,
53
+ fileChanges,
54
+ agentResponse: "",
163
55
  };
164
56
  }
165
57
  exports.generateCodeUsingRepoAgent = generateCodeUsingRepoAgent;
166
- async function repoEditAgent({ trace, task, logger, useStrReplace, }) {
58
+ async function repoEditAgent({ trace, task, logger, }) {
167
59
  const testgenUpdatesReporter = new reporter_1.TestGenUpdatesReporter();
168
60
  void testgenUpdatesReporter.sendMessage(`Updating test code as per the task. \n View [trace](${trace?.getTraceUrl()})`);
169
61
  logger?.log(`Starting repo agent: [trace](${trace?.getTraceUrl()})`);
@@ -172,44 +64,14 @@ async function repoEditAgent({ trace, task, logger, useStrReplace, }) {
172
64
  task,
173
65
  trace,
174
66
  repoFiles: repoFiles,
175
- useStrReplace,
176
67
  logger,
177
68
  });
178
69
  const updates = repoAgentOutput.fileChanges;
179
- if (!useStrReplace) {
180
- const fileUpdateResponses = await (0, utils_1.applyFileChangesForRepoEdit)({
181
- trace,
182
- fileChanges: updates.filter((f) => f.filePath && fs_extra_1.default.existsSync(f.filePath)),
183
- });
184
- const errorResponses = fileUpdateResponses.filter((f) => f?.error);
185
- if (errorResponses.length > 0) {
186
- const updatedFileChanges = await (0, test_update_feedback_1.applyTestUpdateFeedbacks)({
187
- trace,
188
- oldPrompt: repoAgentOutput.prompt,
189
- agentResponse: repoAgentOutput.agentResponse,
190
- feedbacks: errorResponses.map((e) => ({
191
- filePath: e?.filePath,
192
- errorMessage: e?.errorMessage,
193
- })),
194
- });
195
- await (0, utils_1.applyFileChangesForRepoEdit)({
196
- trace,
197
- fileChanges: updatedFileChanges,
198
- });
199
- }
200
- const newFileUpdates = updates.filter((f) => !fs_extra_1.default.existsSync(f.filePath));
201
- await Promise.all(newFileUpdates.map((f) => {
202
- return (async () => {
203
- await fs_extra_1.default.mkdir((0, path_1.dirname)(f.filePath), { recursive: true });
204
- await fs_extra_1.default.writeFile(f.filePath, f.newCode, "utf-8");
205
- })();
206
- }));
207
- }
208
70
  await (0, utils_1.validateTypesAndFormatCode)({
209
71
  validateTypes: true,
210
72
  trace,
211
73
  testCase: {},
212
- fileChanges: updates,
74
+ filePaths: updates.map((f) => f.filePath),
213
75
  });
214
76
  await Promise.all(updates.map((f) => {
215
77
  return (async () => {
@@ -1,4 +1,16 @@
1
1
  import { TraceClient } from "@empiricalrun/llm";
2
2
  import type { TestCase, TestGenConfigOptions } from "@empiricalrun/shared-types";
3
+ import { CustomLogger } from "../../bin/logger";
4
+ export declare function createTestWithCodeAgent({ testCase, file, repoFiles, trace, }: {
5
+ testCase: TestCase;
6
+ file: string;
7
+ repoFiles: string | undefined;
8
+ trace?: TraceClient;
9
+ logger?: CustomLogger;
10
+ }): Promise<{
11
+ prompt: import("openai/resources/index.mjs").ChatCompletionMessageParam[];
12
+ agentResponse: string;
13
+ fileChanges: import("./types").CreateTestCodeUpdate[];
14
+ }>;
3
15
  export declare function generateTest(testCase: TestCase, file: string, options: TestGenConfigOptions, trace?: TraceClient): Promise<TestCase[] | void>;
4
16
  //# sourceMappingURL=run.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EACV,QAAQ,EACR,oBAAoB,EACrB,MAAM,4BAA4B,CAAC;AAUpC,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,EAC7B,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAsC5B"}
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,QAAQ,EACR,oBAAoB,EACrB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAmBhD,wBAAsB,uBAAuB,CAAC,EAC5C,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB;;;;GAuDA;AAED,wBAAsB,YAAY,CAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,oBAAoB,EAC7B,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CA8D5B"}
@@ -3,15 +3,66 @@ 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.generateTest = void 0;
6
+ exports.generateTest = exports.createTestWithCodeAgent = void 0;
7
7
  const llm_1 = require("@empiricalrun/llm");
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const logger_1 = require("../../bin/logger");
10
10
  const context_1 = require("../../bin/utils/context");
11
11
  const web_1 = require("../../bin/utils/platform/web");
12
- const repo_edit_1 = require("./repo-edit");
12
+ const constants_1 = require("../../constants");
13
+ const promptTemplate_0 = "{{#section \"system\"}}\nYou are a software test engineer who is given a task to write test cases in a Playwright test repository.\nYou will be provided with current test files, fixtures and page object models for you to use and update code as per the\ntask provided to you.\nYou need to respond with file path, the new test code block to be updated in the file and the reason for the change.\n\nHere is the list of files:\n\n{{repoFiles}}\n{{/section}}\n\n{{#section \"user\"}}\nTask: {{task}}\n\n## Follow these instructions before responding with output:\n- Respond with <file_path></file_path>, <code_block></code_block> and <change></change> as xml tags\n- Only respond with single code_block in the response containing only the test code block to be updated\n- If the test already exists, do not update the file\n{{/section}}";
14
+ const reporter_1 = require("../../reporter");
13
15
  const update_flow_1 = require("./update-flow");
14
16
  const utils_1 = require("./utils");
17
+ async function createTestWithCodeAgent({ testCase, file, repoFiles, trace, }) {
18
+ const task = `
19
+ Create a new test case with name '${testCase.name}' at file path '${file}'
20
+ ${testCase.suites.length
21
+ ? `
22
+ Put this test case inside describe blocks named: ${testCase.suites.join(" > ")}`
23
+ : ""}
24
+
25
+ In the above test, write code that performs these actions and ONLY these actions:
26
+ ${testCase.steps.join("\n")}`;
27
+ const prompt = (0, llm_1.compilePrompt)(promptTemplate_0, {
28
+ task,
29
+ repoFiles,
30
+ });
31
+ const createTestSpan = trace?.span({
32
+ name: "create-test",
33
+ input: {
34
+ testCase,
35
+ repoFiles,
36
+ testFilePath: file,
37
+ task,
38
+ },
39
+ });
40
+ const llm = new llm_1.LLM({
41
+ trace,
42
+ provider: "anthropic",
43
+ defaultModel: "claude-3-5-sonnet-20240620",
44
+ providerApiKey: constants_1.MODEL_API_KEYS["anthropic"],
45
+ });
46
+ const updatedUsageExampleMessage = await llm.createChatCompletion({
47
+ messages: prompt,
48
+ trace,
49
+ traceName: "create-test-llm",
50
+ modelParameters: {
51
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
52
+ },
53
+ });
54
+ const updates = (0, utils_1.extractCreateTestUpdates)(updatedUsageExampleMessage?.content);
55
+ createTestSpan?.end({
56
+ output: { updates },
57
+ });
58
+ console.log("Updates: ", updates);
59
+ return {
60
+ prompt,
61
+ agentResponse: updatedUsageExampleMessage?.content,
62
+ fileChanges: updates,
63
+ };
64
+ }
65
+ exports.createTestWithCodeAgent = createTestWithCodeAgent;
15
66
  async function generateTest(testCase, file, options, trace) {
16
67
  const logger = new logger_1.CustomLogger();
17
68
  if (!fs_extra_1.default.existsSync(file)) {
@@ -19,32 +70,48 @@ async function generateTest(testCase, file, options, trace) {
19
70
  fs_extra_1.default.createFileSync(file);
20
71
  }
21
72
  const context = await (0, context_1.contextForGeneration)(file);
22
- const { codePrompt, pomPrompt, testFileContent } = context;
73
+ const { testFileContent } = context;
23
74
  const { testBlock } = (0, web_1.getTypescriptTestBlock)({
24
75
  scenarioName: testCase?.name,
25
76
  content: testFileContent,
26
77
  suites: testCase?.suites,
27
78
  });
79
+ // Update the test if it already exists
28
80
  const isUpdate = !!testBlock;
29
81
  if (isUpdate) {
30
82
  logger.log(`Updating the test '${testCase.name}': [View trace](${trace?.getTraceUrl()})`);
31
83
  return await (0, update_flow_1.updateTest)(testCase, file, options, true, true, trace);
32
84
  }
33
- const createTestSpan = trace?.span({
34
- name: "create-test",
35
- input: {
36
- testCase,
37
- testFiles: codePrompt,
38
- pageFiles: pomPrompt,
39
- testFilePath: file,
40
- },
41
- });
42
- const repoAgentResponse = await (0, repo_edit_1.repoEditAgent)({
85
+ const testgenUpdatesReporter = new reporter_1.TestGenUpdatesReporter();
86
+ void testgenUpdatesReporter.sendMessage(`Updating test code as per the task. \n View [trace](${trace?.getTraceUrl()})`);
87
+ logger?.log(`Creating a new test case '${testCase.name}': [trace](${trace?.getTraceUrl()})`);
88
+ // Create the test if it doesn't exist
89
+ const { prompt: repoFiles } = await (0, context_1.generateTxtForRepository)();
90
+ const updates = await createTestWithCodeAgent({
91
+ testCase,
92
+ file,
93
+ repoFiles,
43
94
  trace,
44
- task: (0, utils_1.getTaskForCreateTest)({ testCase, file }),
45
95
  logger,
46
96
  });
47
- createTestSpan?.end({ output: repoAgentResponse.fileChanges });
97
+ await (0, utils_1.applyFileChangesForCreateTest)({
98
+ trace,
99
+ fileChanges: updates.fileChanges,
100
+ testgenUpdatesReporter,
101
+ });
102
+ await (0, utils_1.validateTypesAndFormatCode)({
103
+ validateTypes: true,
104
+ trace,
105
+ testCase: {},
106
+ filePaths: updates.fileChanges.map((f) => f.filePath),
107
+ });
108
+ await Promise.all(updates.fileChanges.map((f) => {
109
+ return (async () => {
110
+ if (fs_extra_1.default.existsSync(f.filePath)) {
111
+ await (0, web_1.lintErrors)(f.filePath);
112
+ }
113
+ })();
114
+ }));
48
115
  await (0, llm_1.flushAllTraces)();
49
116
  }
50
117
  exports.generateTest = generateTest;
@@ -5,6 +5,11 @@ export type CodeUpdate = {
5
5
  newCode: string | undefined;
6
6
  reason: string | undefined;
7
7
  };
8
+ export type CreateTestCodeUpdate = {
9
+ filePath: string | undefined;
10
+ code: string | undefined;
11
+ reason: string | undefined;
12
+ };
8
13
  export type FileUpdateResponse = {
9
14
  error: boolean;
10
15
  errorMessage: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,OA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IAC3B,WAAW,gBAAgB;CAC5B"}
@@ -134,7 +134,7 @@ async function updateTest(testCase, file, options, logging = true, validate = tr
134
134
  validateTypes: validate,
135
135
  trace: updateTestSpan,
136
136
  testCase,
137
- fileChanges,
137
+ filePaths: fileChanges.map((f) => f.filePath),
138
138
  logger,
139
139
  testGenOptions: options,
140
140
  pomPrompt: pomPrompt,
@@ -280,7 +280,7 @@ async function appendCreateTestBlock({ testCase, file, options, trace, validateT
280
280
  await (0, utils_1.validateTypesAndFormatCode)({
281
281
  trace,
282
282
  testCase,
283
- fileChanges,
283
+ filePaths: fileChanges.map((f) => f.filePath),
284
284
  logger,
285
285
  testGenOptions: options,
286
286
  pomPrompt: pomPrompt,
@@ -1,7 +1,8 @@
1
1
  import { TraceClient } from "@empiricalrun/llm";
2
2
  import type { TestCase, TestGenConfigOptions } from "@empiricalrun/shared-types";
3
3
  import { CustomLogger } from "../../bin/logger";
4
- import { CodeUpdate, FileUpdateResponse } from "./types";
4
+ import { TestGenUpdatesReporter } from "../../reporter";
5
+ import { CodeUpdate, CreateTestCodeUpdate, FileUpdateResponse } from "./types";
5
6
  /**
6
7
  *
7
8
  * method to extract file path and code updates for the LLM response of update flow
@@ -15,6 +16,18 @@ import { CodeUpdate, FileUpdateResponse } from "./types";
15
16
  * }[])}
16
17
  */
17
18
  export declare function extractTestUpdates(input: string): CodeUpdate[];
19
+ /**
20
+ *
21
+ * method to extract file path and code updates for the LLM response of create flow
22
+ * @export
23
+ * @param {string} input
24
+ * @return {*} {({
25
+ * filePath: string | undefined;
26
+ * code: string | undefined;
27
+ * reason: string | undefined;
28
+ * }[])}
29
+ */
30
+ export declare function extractCreateTestUpdates(input: string): CreateTestCodeUpdate[];
18
31
  /**
19
32
  *
20
33
  * method to extract append create test updates
@@ -44,20 +57,16 @@ export declare function extractTestStepsSuggestions(input: string): {
44
57
  reason: string;
45
58
  methodName: string;
46
59
  }[];
47
- export declare function validateTypesAndFormatCode({ validateTypes, trace, testCase, fileChanges, logger, testGenOptions, pomPrompt, nonSpecFilePrompt, }: {
60
+ export declare function validateTypesAndFormatCode({ validateTypes, trace, testCase, filePaths, logger, testGenOptions, pomPrompt, nonSpecFilePrompt, }: {
48
61
  validateTypes?: boolean;
49
62
  trace?: TraceClient;
50
63
  testCase: TestCase;
51
- fileChanges: CodeUpdate[];
64
+ filePaths: (string | undefined)[];
52
65
  logger?: CustomLogger;
53
66
  testGenOptions?: TestGenConfigOptions;
54
67
  pomPrompt?: string;
55
68
  nonSpecFilePrompt?: string;
56
69
  }): Promise<void>;
57
- export declare function getTaskForCreateTest({ testCase, file, }: {
58
- testCase: TestCase;
59
- file: string;
60
- }): string;
61
70
  export declare function applyFileChangesUsingStrReplace({ trace, fileChanges, logger, }: {
62
71
  trace?: TraceClient;
63
72
  fileChanges: CodeUpdate[];
@@ -75,20 +84,11 @@ export declare function searchAndReplaceCodeUsingStrReplace({ logger, fileChange
75
84
  result: FileUpdateResponse;
76
85
  updatedContent: string;
77
86
  }>;
78
- export declare function applyFileChangesForRepoEdit({ trace, fileChanges, logger, }: {
87
+ export declare function applyFileChangesForCreateTest({ trace, fileChanges, testgenUpdatesReporter, }: {
79
88
  trace?: TraceClient;
80
- fileChanges: {
81
- filePath: string | undefined;
82
- oldCode: string | undefined;
83
- newCode: string | undefined;
84
- reason: string | undefined;
85
- }[];
86
- logger?: CustomLogger;
87
- }): Promise<{
88
- error: boolean;
89
- errorMessage: string;
90
- filePath: string;
91
- }[]>;
89
+ fileChanges: CreateTestCodeUpdate[];
90
+ testgenUpdatesReporter?: TestGenUpdatesReporter;
91
+ }): Promise<void>;
92
92
  export declare function searchAndReplaceCode({ logger, fileChange, }: {
93
93
  fileChange: {
94
94
  filePath: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EACV,Q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
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.applyFileChanges = exports.searchAndReplaceCode = exports.applyFileChangesForRepoEdit = exports.searchAndReplaceCodeUsingStrReplace = exports.applyFileChangesUsingStrReplace = exports.getTaskForCreateTest = exports.validateTypesAndFormatCode = exports.extractTestStepsSuggestions = exports.extractAppendTestUpdates = exports.extractTestUpdates = void 0;
6
+ exports.applyFileChanges = exports.searchAndReplaceCode = exports.applyFileChangesForCreateTest = exports.searchAndReplaceCodeUsingStrReplace = exports.applyFileChangesUsingStrReplace = exports.validateTypesAndFormatCode = exports.extractTestStepsSuggestions = exports.extractAppendTestUpdates = exports.extractCreateTestUpdates = exports.extractTestUpdates = void 0;
7
7
  const llm_1 = require("@empiricalrun/llm");
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const ts_morph_1 = require("ts-morph");
@@ -38,6 +38,33 @@ function extractTestUpdates(input) {
38
38
  return result;
39
39
  }
40
40
  exports.extractTestUpdates = extractTestUpdates;
41
+ /**
42
+ *
43
+ * method to extract file path and code updates for the LLM response of create flow
44
+ * @export
45
+ * @param {string} input
46
+ * @return {*} {({
47
+ * filePath: string | undefined;
48
+ * code: string | undefined;
49
+ * reason: string | undefined;
50
+ * }[])}
51
+ */
52
+ function extractCreateTestUpdates(input) {
53
+ const result = [];
54
+ // TODO: use better structure for this. Do not kill me for this please.
55
+ const regex = /<file_path>(.*?)<\/file_path>[\s\S]*?<code_block>([\s\S]*?)<\/code_block>[\s\S]*?<change>([\s\S]*?)<\/change>/g;
56
+ let match;
57
+ while ((match = regex.exec(input)) !== null) {
58
+ const [, filePath, code, reason] = match;
59
+ result.push({
60
+ filePath: filePath?.trim(),
61
+ code: code?.trim(),
62
+ reason: reason?.trim(),
63
+ });
64
+ }
65
+ return result;
66
+ }
67
+ exports.extractCreateTestUpdates = extractCreateTestUpdates;
41
68
  /**
42
69
  *
43
70
  * method to extract append create test updates
@@ -89,9 +116,9 @@ function extractTestStepsSuggestions(input) {
89
116
  return result.filter((r) => !!r.filePath && !!r.usageExample);
90
117
  }
91
118
  exports.extractTestStepsSuggestions = extractTestStepsSuggestions;
92
- async function validateTypesAndFormatCode({ validateTypes = true, trace, testCase, fileChanges, logger, testGenOptions, pomPrompt, nonSpecFilePrompt, }) {
93
- for (let fileChange of fileChanges) {
94
- if (!fileChange.filePath) {
119
+ async function validateTypesAndFormatCode({ validateTypes = true, trace, testCase, filePaths, logger, testGenOptions, pomPrompt, nonSpecFilePrompt, }) {
120
+ for (let filePath of filePaths) {
121
+ if (!filePath) {
95
122
  continue;
96
123
  }
97
124
  try {
@@ -99,7 +126,7 @@ async function validateTypesAndFormatCode({ validateTypes = true, trace, testCas
99
126
  await (0, fix_ts_errors_1.validateAndFixTypescriptErrors)({
100
127
  trace,
101
128
  logger,
102
- file: fileChange.filePath,
129
+ file: filePath,
103
130
  pomCode: pomPrompt ?? "",
104
131
  nonSpecFileCode: nonSpecFilePrompt ?? "",
105
132
  testCase: testCase,
@@ -107,29 +134,16 @@ async function validateTypesAndFormatCode({ validateTypes = true, trace, testCas
107
134
  });
108
135
  }
109
136
  trace?.event({ name: "format-file" });
110
- await (0, web_1.formatCode)(fileChange.filePath, trace);
111
- logger?.success(`${fileChange.filePath} file formatted successfully!`);
137
+ await (0, web_1.formatCode)(filePath, trace);
138
+ logger?.success(`${filePath} file formatted successfully!`);
112
139
  }
113
140
  catch (e) {
114
- console.error(`Error while formatting the file ${fileChange.filePath}`, e);
141
+ console.error(`Error while formatting the file ${filePath}`, e);
115
142
  }
116
143
  }
117
144
  await (0, llm_1.flushAllTraces)();
118
145
  }
119
146
  exports.validateTypesAndFormatCode = validateTypesAndFormatCode;
120
- function getTaskForCreateTest({ testCase, file, }) {
121
- return `
122
- Create a new test case with name '${testCase.name}' at file path '${file}'
123
- ${testCase.suites.length
124
- ? `
125
- Put this test case inside describe blocks named: ${testCase.suites.join(" > ")}`
126
- : ""}
127
-
128
- In the above test, write code that performs these actions and ONLY these actions:
129
- ${testCase.steps.join("\n")}
130
- `;
131
- }
132
- exports.getTaskForCreateTest = getTaskForCreateTest;
133
147
  async function applyFileChangesUsingStrReplace({ trace, fileChanges, logger, }) {
134
148
  const repoEditFileChangesSpan = trace?.span({
135
149
  name: "repo-edit-file-changes",
@@ -211,11 +225,10 @@ async function searchAndReplaceCodeUsingStrReplace({ logger, fileChange, }) {
211
225
  };
212
226
  }
213
227
  exports.searchAndReplaceCodeUsingStrReplace = searchAndReplaceCodeUsingStrReplace;
214
- async function applyFileChangesForRepoEdit({ trace, fileChanges, logger, }) {
228
+ async function applyFileChangesForCreateTest({ trace, fileChanges, testgenUpdatesReporter, }) {
215
229
  const repoEditFileChangesSpan = trace?.span({
216
- name: "repo-edit-file-changes",
230
+ name: "create-test-file-changes",
217
231
  });
218
- const results = [];
219
232
  for (const fileChange of fileChanges) {
220
233
  if (!fileChange.filePath) {
221
234
  continue;
@@ -227,33 +240,33 @@ async function applyFileChangesForRepoEdit({ trace, fileChanges, logger, }) {
227
240
  fileChange,
228
241
  },
229
242
  });
230
- const { result, updatedContent } = await searchAndReplaceCode({
231
- logger,
232
- fileChange,
233
- });
234
- if (result.error) {
235
- logger?.error(`Unable to find the code to update in ${result.filePath}`);
236
- }
237
- else {
238
- await fs_extra_1.default.writeFile(fileChange.filePath, updatedContent, "utf-8");
239
- readWriteFileSpan?.end({ output: { updatedContent } });
243
+ if (fileChange.code) {
244
+ const currentContent = fs_extra_1.default.existsSync(fileChange.filePath)
245
+ ? await fs_extra_1.default.readFile(fileChange.filePath, "utf-8")
246
+ : "";
247
+ await fs_extra_1.default.writeFile(fileChange.filePath, currentContent
248
+ ? `${currentContent}\n\n${fileChange.code}`
249
+ : fileChange.code, "utf-8");
250
+ const updatedFileContent = await fs_extra_1.default.readFile(fileChange.filePath, "utf-8");
251
+ readWriteFileSpan?.end({
252
+ output: { fileChange, updatedFile: updatedFileContent },
253
+ });
240
254
  }
241
- results.push(result);
242
255
  }
243
256
  catch (e) {
244
257
  trace?.event({
245
- name: "repo-edit-file-changes-error",
258
+ name: "create-test-file-changes-error",
246
259
  output: {
247
260
  filePath: fileChange.filePath,
248
261
  error: e,
249
262
  },
250
263
  });
264
+ void testgenUpdatesReporter?.sendMessage(`Error while applying changes to file ${fileChange.filePath}, error: ${e}`);
251
265
  console.error(`Error while applying changes to file ${fileChange.filePath}`, e);
252
266
  }
253
267
  }
254
- return results;
255
268
  }
256
- exports.applyFileChangesForRepoEdit = applyFileChangesForRepoEdit;
269
+ exports.applyFileChangesForCreateTest = applyFileChangesForCreateTest;
257
270
  async function searchAndReplaceCode({ logger, fileChange, }) {
258
271
  let contents = await fs_extra_1.default.readFile(fileChange.filePath, "utf-8");
259
272
  // since we dont know what is getting updated,
package/dist/bin/index.js CHANGED
@@ -79,7 +79,6 @@ async function runAgent(testGenConfig) {
79
79
  trace,
80
80
  task: testGenConfig.testCase.steps.join("\n"),
81
81
  logger,
82
- useStrReplace: testGenConfig.options?.useStrReplace,
83
82
  });
84
83
  return;
85
84
  }
@@ -1 +1 @@
1
- {"version":3,"file":"add-scenario-agent.evals.d.ts","sourceRoot":"","sources":["../../src/evals/add-scenario-agent.evals.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAqCpC,QAAA,MAAM,4BAA4B,EAAE,UAqBnC,CAAC;AAEF,eAAe,4BAA4B,CAAC"}
1
+ {"version":3,"file":"add-scenario-agent.evals.d.ts","sourceRoot":"","sources":["../../src/evals/add-scenario-agent.evals.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AA2BpC,QAAA,MAAM,4BAA4B,EAAE,UAsBnC,CAAC;AAEF,eAAe,4BAA4B,CAAC"}
@@ -4,8 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
- const repo_edit_1 = require("../agent/codegen/repo-edit");
8
- const utils_1 = require("../agent/codegen/utils");
7
+ const run_1 = require("../agent/codegen/run");
9
8
  function evaluateEqualityScore({ currentOutput, expectedOutput, }) {
10
9
  for (const expectedFile of expectedOutput) {
11
10
  if (!currentOutput.find((output) => {
@@ -23,8 +22,9 @@ function evaluateEqualityScore({ currentOutput, expectedOutput, }) {
23
22
  const addScenarioCodeAgentEvaluate = async ({ item, trace }) => {
24
23
  const { testCase, testFilePath, pageFiles, testFiles } = item.input;
25
24
  const repoFiles = pageFiles + testFiles;
26
- const repoAgentOutput = await (0, repo_edit_1.generateCodeUsingRepoAgent)({
27
- task: (0, utils_1.getTaskForCreateTest)({ testCase, file: testFilePath }),
25
+ const repoAgentOutput = await (0, run_1.createTestWithCodeAgent)({
26
+ testCase,
27
+ file: testFilePath,
28
28
  trace,
29
29
  repoFiles,
30
30
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.42.26",
3
+ "version": "0.42.27",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -71,9 +71,9 @@
71
71
  "ts-morph": "^23.0.0",
72
72
  "tsx": "^4.16.2",
73
73
  "typescript": "^5.3.3",
74
+ "@empiricalrun/reporter": "^0.23.1",
74
75
  "@empiricalrun/llm": "^0.9.34",
75
- "@empiricalrun/r2-uploader": "^0.3.8",
76
- "@empiricalrun/reporter": "^0.23.1"
76
+ "@empiricalrun/r2-uploader": "^0.3.8"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@playwright/test": "1.47.1",
@@ -88,7 +88,7 @@
88
88
  "js-levenshtein": "^1.1.6",
89
89
  "playwright": "1.47.1",
90
90
  "ts-patch": "^3.3.0",
91
- "@empiricalrun/shared-types": "0.0.2"
91
+ "@empiricalrun/shared-types": "0.0.3"
92
92
  },
93
93
  "scripts": {
94
94
  "dev": "tspc --build --watch",