@empiricalrun/test-gen 0.42.25 → 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 +13 -0
- package/dist/agent/browsing/utils.d.ts.map +1 -1
- package/dist/agent/browsing/utils.js +5 -1
- package/dist/agent/codegen/generate-code-apply-changes.js +1 -1
- package/dist/agent/codegen/repo-edit.d.ts +2 -4
- package/dist/agent/codegen/repo-edit.d.ts.map +1 -1
- package/dist/agent/codegen/repo-edit.js +18 -156
- package/dist/agent/codegen/run.d.ts +12 -0
- package/dist/agent/codegen/run.d.ts.map +1 -1
- package/dist/agent/codegen/run.js +82 -15
- package/dist/agent/codegen/types.d.ts +5 -0
- package/dist/agent/codegen/types.d.ts.map +1 -1
- package/dist/agent/codegen/update-flow.js +2 -2
- package/dist/agent/codegen/utils.d.ts +20 -20
- package/dist/agent/codegen/utils.d.ts.map +1 -1
- package/dist/agent/codegen/utils.js +51 -38
- package/dist/agent/master/browser-tests/index.spec.d.ts +2 -0
- package/dist/agent/master/browser-tests/index.spec.d.ts.map +1 -0
- package/dist/agent/master/browser-tests/index.spec.js +65 -0
- package/dist/bin/index.js +0 -1
- package/dist/browser-injected-scripts/annotate-elements.spec.js +0 -1
- package/dist/browser-injected-scripts/annotate-elements.spec.ts +0 -2
- package/dist/evals/add-scenario-agent.evals.d.ts.map +1 -1
- package/dist/evals/add-scenario-agent.evals.js +4 -4
- package/package.json +7 -5
- package/playwright.config.ts +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
10
|
+
## 0.42.26
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 070c16a: feat: config for master agent sanity test suite
|
|
15
|
+
|
|
3
16
|
## 0.42.25
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAe,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI7E,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAsBvD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AA8FD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,aAAa,EACxB,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC,CA0DjB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAe,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI7E,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAsBvD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AA8FD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,aAAa,EACxB,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC,CA0DjB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBA2HxD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,QAIjD;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,qBAAa,eAAe;IACd,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM;IACrC,OAAO,CAAC,aAAa,CAAqB;YAE5B,mBAAmB;YAUnB,gBAAgB;IAsBjB,OAAO;IAuBb,SAAS;CAKjB"}
|
|
@@ -164,7 +164,11 @@ function newContentsWithTestOnly(existingContents, originalTestBlock, updatedTes
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
async function injectPwLocatorGenerator(page) {
|
|
167
|
-
|
|
167
|
+
let pathToInstalledTestGen = require.resolve(".").split("dist")[0];
|
|
168
|
+
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
|
169
|
+
if (process.env.RUNNING_BROWSER_TESTS_FOR_TEST_GEN) {
|
|
170
|
+
pathToInstalledTestGen = process.cwd();
|
|
171
|
+
}
|
|
168
172
|
const annotateElementPath = path_1.default.join(pathToInstalledTestGen, "dist", "browser-injected-scripts", "annotate-elements.js");
|
|
169
173
|
if (!fs_extra_1.default.existsSync(annotateElementPath)) {
|
|
170
174
|
throw new Error(`annotate-elements.js not found at path: ${annotateElementPath}`);
|
|
@@ -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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
139
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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: {
|
|
155
|
-
input: {
|
|
156
|
-
task,
|
|
157
|
-
},
|
|
49
|
+
output: { fileChanges },
|
|
158
50
|
});
|
|
159
51
|
return {
|
|
160
52
|
prompt,
|
|
161
|
-
|
|
162
|
-
|
|
53
|
+
fileChanges,
|
|
54
|
+
agentResponse: "",
|
|
163
55
|
};
|
|
164
56
|
}
|
|
165
57
|
exports.generateCodeUsingRepoAgent = generateCodeUsingRepoAgent;
|
|
166
|
-
async function repoEditAgent({ trace, task, logger,
|
|
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
|
-
|
|
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,
|
|
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
|
|
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 {
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAGF,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG;IACvC,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,oBAAY,kBAAkB;IAC5B,WAAW,gBAAgB;IAC3B,WAAW,gBAAgB;CAC5B"}
|
|
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,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAGF,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG;IACvC,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,CAAC;AAEF,oBAAY,kBAAkB;IAC5B,WAAW,gBAAgB;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 {
|
|
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,
|
|
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
|
-
|
|
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
|
|
87
|
+
export declare function applyFileChangesForCreateTest({ trace, fileChanges, testgenUpdatesReporter, }: {
|
|
79
88
|
trace?: TraceClient;
|
|
80
|
-
fileChanges:
|
|
81
|
-
|
|
82
|
-
|
|
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,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AM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAkIxE"}
|
|
@@ -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.applyFileChanges = exports.searchAndReplaceCode = exports.
|
|
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,
|
|
93
|
-
for (let
|
|
94
|
-
if (!
|
|
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:
|
|
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)(
|
|
111
|
-
logger?.success(`${
|
|
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 ${
|
|
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
|
|
228
|
+
async function applyFileChangesForCreateTest({ trace, fileChanges, testgenUpdatesReporter, }) {
|
|
215
229
|
const repoEditFileChangesSpan = trace?.span({
|
|
216
|
-
name: "
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
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: "
|
|
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.
|
|
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,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.spec.d.ts","sourceRoot":"","sources":["../../../../src/agent/master/browser-tests/index.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 test_1 = require("@playwright/test");
|
|
7
|
+
const http_server_1 = __importDefault(require("http-server"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const run_1 = require("../run");
|
|
10
|
+
let server;
|
|
11
|
+
let PORT = 2345;
|
|
12
|
+
test_1.test.beforeAll(async () => {
|
|
13
|
+
server = http_server_1.default.createServer({
|
|
14
|
+
root: path_1.default.join(process.cwd(), "test-data"),
|
|
15
|
+
});
|
|
16
|
+
// Start the server
|
|
17
|
+
await new Promise((resolve) => {
|
|
18
|
+
server.listen(PORT, () => {
|
|
19
|
+
console.log(`Server running at http://localhost:${PORT}`);
|
|
20
|
+
resolve(true);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
test_1.test.afterAll(() => {
|
|
25
|
+
if (server) {
|
|
26
|
+
server.close();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
(0, test_1.test)("able to scroll and interact with elements", async ({ page }) => {
|
|
30
|
+
await page.goto(`http://localhost:${PORT}/blog-page.html`);
|
|
31
|
+
const response = await (0, run_1.createTestUsingMasterAgent)({
|
|
32
|
+
task: `fill test@test.com into the email field and click the submit`,
|
|
33
|
+
page,
|
|
34
|
+
options: {},
|
|
35
|
+
});
|
|
36
|
+
console.log(response);
|
|
37
|
+
(0, test_1.expect)(response.importPaths.length).toBe(0);
|
|
38
|
+
(0, test_1.expect)(response.code).toContain("await page.getByPlaceholder('Enter your email').fill(\"test@test.com\")");
|
|
39
|
+
(0, test_1.expect)(response.code).toContain("await page.getByRole('button', { name: 'Subscribe' }).click()");
|
|
40
|
+
});
|
|
41
|
+
test_1.test.skip("scroll when element does not exist", async ({ page }) => {
|
|
42
|
+
await page.goto(`http://localhost:${PORT}/blog-page.html`);
|
|
43
|
+
const response = await (0, run_1.createTestUsingMasterAgent)({
|
|
44
|
+
task: `click search button`,
|
|
45
|
+
page,
|
|
46
|
+
options: {},
|
|
47
|
+
});
|
|
48
|
+
console.log(response);
|
|
49
|
+
(0, test_1.expect)(response.importPaths.length).toBe(0);
|
|
50
|
+
(0, test_1.expect)(response.code.length).toBe(0);
|
|
51
|
+
});
|
|
52
|
+
(0, test_1.test)("agent can click icons accurately", async ({ page }) => {
|
|
53
|
+
await page.goto(`http://localhost:${PORT}/icons-navbar.html`);
|
|
54
|
+
await (0, test_1.expect)(page.getByText("select an icon")).toBeVisible();
|
|
55
|
+
const response = await (0, run_1.createTestUsingMasterAgent)({
|
|
56
|
+
task: `click on the gear icon`,
|
|
57
|
+
page,
|
|
58
|
+
options: {},
|
|
59
|
+
});
|
|
60
|
+
await (0, test_1.expect)(page.getByText("you clicked Gear")).toBeVisible();
|
|
61
|
+
console.log(response);
|
|
62
|
+
(0, test_1.expect)(response.importPaths.length).toBe(0);
|
|
63
|
+
(0, test_1.expect)(response.code).toContain("page.getByRole");
|
|
64
|
+
(0, test_1.expect)(response.code).toContain("click()");
|
|
65
|
+
});
|
package/dist/bin/index.js
CHANGED
|
@@ -180,7 +180,6 @@ const action_tool_calls_1 = require("../agent/master/action-tool-calls");
|
|
|
180
180
|
href: config.node.href,
|
|
181
181
|
}));
|
|
182
182
|
}, preference);
|
|
183
|
-
console.log("Annotations:", annotations);
|
|
184
183
|
test_1.test.expect(annotations.length).toBe(1);
|
|
185
184
|
test_1.test.expect(annotations[0]?.tagName).toBe("DIV");
|
|
186
185
|
});
|
|
@@ -296,8 +296,6 @@ test("should only annotate given text on quizziz page", async ({ page }) => {
|
|
|
296
296
|
href: config.node.href,
|
|
297
297
|
}));
|
|
298
298
|
}, preference);
|
|
299
|
-
|
|
300
|
-
console.log("Annotations:", annotations);
|
|
301
299
|
test.expect(annotations.length).toBe(1);
|
|
302
300
|
test.expect(annotations[0]?.tagName).toBe("DIV");
|
|
303
301
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-scenario-agent.evals.d.ts","sourceRoot":"","sources":["../../src/evals/add-scenario-agent.evals.ts"],"names":[],"mappings":"
|
|
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
|
|
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,
|
|
27
|
-
|
|
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.
|
|
3
|
+
"version": "0.42.27",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -71,22 +71,24 @@
|
|
|
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",
|
|
80
80
|
"@types/detect-port": "^1.3.5",
|
|
81
81
|
"@types/express": "^4.17.21",
|
|
82
82
|
"@types/fs-extra": "^11.0.4",
|
|
83
|
+
"@types/http-server": "^0.12.4",
|
|
83
84
|
"@types/js-levenshtein": "^1.1.3",
|
|
84
85
|
"@types/lodash.isequal": "^4.5.8",
|
|
85
86
|
"@types/md5": "^2.3.5",
|
|
87
|
+
"http-server": "^14.1.1",
|
|
86
88
|
"js-levenshtein": "^1.1.6",
|
|
87
89
|
"playwright": "1.47.1",
|
|
88
90
|
"ts-patch": "^3.3.0",
|
|
89
|
-
"@empiricalrun/shared-types": "0.0.
|
|
91
|
+
"@empiricalrun/shared-types": "0.0.3"
|
|
90
92
|
},
|
|
91
93
|
"scripts": {
|
|
92
94
|
"dev": "tspc --build --watch",
|
|
@@ -94,7 +96,7 @@
|
|
|
94
96
|
"clean": "tspc --build --clean",
|
|
95
97
|
"lint": "eslint .",
|
|
96
98
|
"test": "vitest run",
|
|
97
|
-
"test-browser": "npx playwright test",
|
|
99
|
+
"test-browser": "pnpm build && RUNNING_BROWSER_TESTS_FOR_TEST_GEN=1 npx playwright test",
|
|
98
100
|
"test:watch": "vitest",
|
|
99
101
|
"test:watch-files": "vitest $0 --watch"
|
|
100
102
|
}
|
package/playwright.config.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { defineConfig } from "@playwright/test";
|
|
2
2
|
|
|
3
|
+
// To run master agent sanity tests, we want our typescript
|
|
4
|
+
// transformer to be used while compiling the tests.
|
|
5
|
+
// Hence, we bypass Playwright's default TS compiler, and have
|
|
6
|
+
// it run compiled test files from /dist/
|
|
3
7
|
export default defineConfig({
|
|
4
|
-
testDir: "./
|
|
8
|
+
testDir: "./dist/.",
|
|
9
|
+
testMatch: "**/*.spec.js",
|
|
10
|
+
// Setting large timeout as master agent takes time to run.
|
|
11
|
+
timeout: 120_000,
|
|
5
12
|
});
|