@empiricalrun/test-gen 0.40.0 → 0.41.0
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 +18 -0
- package/dist/agent/codegen/repo-edit.d.ts.map +1 -1
- package/dist/agent/codegen/repo-edit.js +6 -2
- package/dist/agent/codegen/update-flow.d.ts.map +1 -1
- package/dist/agent/codegen/update-flow.js +19 -2
- package/dist/agent/codegen/utils.d.ts +18 -4
- package/dist/agent/codegen/utils.d.ts.map +1 -1
- package/dist/agent/codegen/utils.js +44 -31
- package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
- package/dist/bin/utils/platform/web/index.js +7 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.41.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 02c37c0: feat: upgrade pw version
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [02c37c0]
|
|
12
|
+
- @empiricalrun/reporter@0.22.0
|
|
13
|
+
|
|
14
|
+
## 0.40.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- b45c035: fix: sequentially execute file updates and validation in codegen
|
|
19
|
+
- b3069f1: fix: handle empty files while applying prettier format
|
|
20
|
+
|
|
3
21
|
## 0.40.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -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;
|
|
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;AAexE,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,KAAK,EACL,SAAS,GACV,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE;QACX,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;KAC5B,EAAE,CAAC;CACL,CAAC,CA6GD;AAED,wBAAsB,aAAa,CAAC,EAClC,KAAK,EACL,IAAI,GACL,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,0BAA0B,EAAE,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE;QACX,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;KAC5B,EAAE,CAAC;CACL,CAAC,CAwED"}
|
|
@@ -157,7 +157,6 @@ async function repoEditAgent({ trace, task, }) {
|
|
|
157
157
|
});
|
|
158
158
|
const updates = repoAgentOutput.fileChanges;
|
|
159
159
|
const fileUpdateResponses = await (0, utils_1.applyFileChanges)({
|
|
160
|
-
validateTypes: false,
|
|
161
160
|
trace,
|
|
162
161
|
testCase: {},
|
|
163
162
|
fileChanges: updates.filter((f) => f.filePath && fsSync.existsSync(f.filePath)),
|
|
@@ -174,12 +173,17 @@ async function repoEditAgent({ trace, task, }) {
|
|
|
174
173
|
})),
|
|
175
174
|
});
|
|
176
175
|
await (0, utils_1.applyFileChanges)({
|
|
177
|
-
validateTypes: false,
|
|
178
176
|
trace,
|
|
179
177
|
testCase: {},
|
|
180
178
|
fileChanges: updatedFileChanges,
|
|
181
179
|
});
|
|
182
180
|
}
|
|
181
|
+
await (0, utils_1.validateTypesAndFormatCode)({
|
|
182
|
+
validateTypes: false,
|
|
183
|
+
trace,
|
|
184
|
+
testCase: {},
|
|
185
|
+
fileChanges: updates.filter((f) => f.filePath && fsSync.existsSync(f.filePath)),
|
|
186
|
+
});
|
|
183
187
|
const newFileUpdates = updates.filter((f) => !fsSync.existsSync(f.filePath));
|
|
184
188
|
await Promise.all(newFileUpdates.map((f) => {
|
|
185
189
|
return (async () => {
|
|
@@ -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;AAG3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAYxE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAIL,eAAe,
|
|
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;AAG3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAYxE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AA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,YAAY,EAAE,MAAM,CAAC;CACtB,mBAuGA;AAED,wBAAsB,qBAAqB,CAAC,EAC1C,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,EACL,aAAoB,GACrB,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAqD7B"}
|
|
@@ -100,7 +100,6 @@ async function updateTest(testCase, file, options, logging = true, validate = tr
|
|
|
100
100
|
});
|
|
101
101
|
console.log(`fileChanges ${testCase.steps.join("")}`, fileChanges);
|
|
102
102
|
const fileUpdateResponses = await (0, utils_1.applyFileChanges)({
|
|
103
|
-
validateTypes: validate,
|
|
104
103
|
trace: updateTestSpan,
|
|
105
104
|
testCase,
|
|
106
105
|
fileChanges,
|
|
@@ -121,7 +120,6 @@ async function updateTest(testCase, file, options, logging = true, validate = tr
|
|
|
121
120
|
})),
|
|
122
121
|
});
|
|
123
122
|
await (0, utils_1.applyFileChanges)({
|
|
124
|
-
validateTypes: validate,
|
|
125
123
|
trace: updateTestSpan,
|
|
126
124
|
testCase,
|
|
127
125
|
fileChanges: filteredFileChanges,
|
|
@@ -131,6 +129,16 @@ async function updateTest(testCase, file, options, logging = true, validate = tr
|
|
|
131
129
|
nonSpecFilePrompt: nonSpecFilePrompt,
|
|
132
130
|
});
|
|
133
131
|
}
|
|
132
|
+
await (0, utils_1.validateTypesAndFormatCode)({
|
|
133
|
+
validateTypes: validate,
|
|
134
|
+
trace: updateTestSpan,
|
|
135
|
+
testCase,
|
|
136
|
+
fileChanges,
|
|
137
|
+
logger,
|
|
138
|
+
testGenOptions: options,
|
|
139
|
+
pomPrompt: pomPrompt,
|
|
140
|
+
nonSpecFilePrompt: nonSpecFilePrompt,
|
|
141
|
+
});
|
|
134
142
|
logger.success("Test generated successfully!");
|
|
135
143
|
if (trace) {
|
|
136
144
|
logger.log(`View [trace](${trace.getTraceUrl()})`);
|
|
@@ -268,6 +276,15 @@ async function appendCreateTestBlock({ testCase, file, options, trace, validateT
|
|
|
268
276
|
testGenOptions: options,
|
|
269
277
|
pomPrompt: pomPrompt,
|
|
270
278
|
nonSpecFilePrompt: nonSpecFilePrompt,
|
|
279
|
+
});
|
|
280
|
+
await (0, utils_1.validateTypesAndFormatCode)({
|
|
281
|
+
trace,
|
|
282
|
+
testCase,
|
|
283
|
+
fileChanges,
|
|
284
|
+
logger,
|
|
285
|
+
testGenOptions: options,
|
|
286
|
+
pomPrompt: pomPrompt,
|
|
287
|
+
nonSpecFilePrompt: nonSpecFilePrompt,
|
|
271
288
|
validateTypes,
|
|
272
289
|
});
|
|
273
290
|
if (trace) {
|
|
@@ -51,8 +51,7 @@ export declare function extractTestStepsSuggestions(input: string): {
|
|
|
51
51
|
export type UpdatedTestCase = TestCase & {
|
|
52
52
|
updatedFiles: string[];
|
|
53
53
|
};
|
|
54
|
-
export declare function applyFileChanges({
|
|
55
|
-
validateTypes?: boolean;
|
|
54
|
+
export declare function applyFileChanges({ trace, testCase, fileChanges, logger, }: {
|
|
56
55
|
trace?: TraceClient;
|
|
57
56
|
testCase: TestCase;
|
|
58
57
|
fileChanges: {
|
|
@@ -65,9 +64,24 @@ export declare function applyFileChanges({ validateTypes, trace, testCase, fileC
|
|
|
65
64
|
testGenOptions?: TestGenConfigOptions;
|
|
66
65
|
pomPrompt?: string;
|
|
67
66
|
nonSpecFilePrompt?: string;
|
|
68
|
-
}): Promise<
|
|
67
|
+
}): Promise<{
|
|
69
68
|
error: boolean;
|
|
70
69
|
errorMessage: string;
|
|
71
70
|
filePath: string;
|
|
72
|
-
}
|
|
71
|
+
}[]>;
|
|
72
|
+
export declare function validateTypesAndFormatCode({ validateTypes, trace, testCase, fileChanges, logger, testGenOptions, pomPrompt, nonSpecFilePrompt, }: {
|
|
73
|
+
validateTypes?: boolean;
|
|
74
|
+
trace?: TraceClient;
|
|
75
|
+
testCase: TestCase;
|
|
76
|
+
fileChanges: {
|
|
77
|
+
filePath: string | undefined;
|
|
78
|
+
oldCode: string | undefined;
|
|
79
|
+
newCode: string | undefined;
|
|
80
|
+
reason: string | undefined;
|
|
81
|
+
}[];
|
|
82
|
+
logger?: CustomLogger;
|
|
83
|
+
testGenOptions?: TestGenConfigOptions;
|
|
84
|
+
pomPrompt?: string;
|
|
85
|
+
nonSpecFilePrompt?: string;
|
|
86
|
+
}): Promise<void>;
|
|
73
87
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/utils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAMhD,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAG7D;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG;IACjD,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,EAAE,CAiBF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG;IACvD,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,MAAM,GAAG,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d,SAAS,EACT,iBAAiB,GAClB,EAAE;IACD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE;QACX,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;QAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;KAC5B,EAAE,CAAC;IACJ,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,cAAc,CAAC,EAAE,oBAAoB,CAAC;IACtC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,iBA6BA"}
|
|
@@ -3,7 +3,8 @@ 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.extractTestStepsSuggestions = exports.extractAppendTestUpdates = exports.extractTestUpdates = void 0;
|
|
6
|
+
exports.validateTypesAndFormatCode = exports.applyFileChanges = exports.extractTestStepsSuggestions = exports.extractAppendTestUpdates = exports.extractTestUpdates = void 0;
|
|
7
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
7
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
9
|
const ts_morph_1 = require("ts-morph");
|
|
9
10
|
const web_1 = require("../../bin/utils/platform/web");
|
|
@@ -88,10 +89,11 @@ function extractTestStepsSuggestions(input) {
|
|
|
88
89
|
return result.filter((r) => !!r.filePath && !!r.usageExample);
|
|
89
90
|
}
|
|
90
91
|
exports.extractTestStepsSuggestions = extractTestStepsSuggestions;
|
|
91
|
-
async function applyFileChanges({
|
|
92
|
-
|
|
92
|
+
async function applyFileChanges({ trace, testCase, fileChanges, logger, }) {
|
|
93
|
+
const results = [];
|
|
94
|
+
for (const fileChange of fileChanges) {
|
|
93
95
|
if (!fileChange.filePath) {
|
|
94
|
-
|
|
96
|
+
continue;
|
|
95
97
|
}
|
|
96
98
|
try {
|
|
97
99
|
const hasTestCaseAsUpdateContext = !!testCase?.name;
|
|
@@ -103,7 +105,7 @@ async function applyFileChanges({ validateTypes = true, trace, testCase, fileCha
|
|
|
103
105
|
const block = (0, web_1.getTypescriptTestBlock)({
|
|
104
106
|
scenarioName: testCase?.name,
|
|
105
107
|
content: fileChange.newCode || "",
|
|
106
|
-
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
|
|
108
|
+
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
|
|
107
109
|
});
|
|
108
110
|
testBlockUpdate = block.testBlock;
|
|
109
111
|
applyFileChangesSpan?.end({ output: { testBlock: testBlockUpdate } });
|
|
@@ -132,8 +134,8 @@ async function applyFileChanges({ validateTypes = true, trace, testCase, fileCha
|
|
|
132
134
|
const sourceFile = project.createSourceFile("updated-code.ts", fileChange.newCode);
|
|
133
135
|
const functions = sourceFile.getFunctions();
|
|
134
136
|
const checkForMethodSrc = project.createSourceFile("check-method.ts", `class A {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
${fileChange.newCode}
|
|
138
|
+
}`);
|
|
137
139
|
const methods = checkForMethodSrc.getDescendantsOfKind(ts_morph_1.SyntaxKind.MethodDeclaration);
|
|
138
140
|
const originalSource = project.createSourceFile("current-code.ts", contents);
|
|
139
141
|
// if there is a single function update in the file
|
|
@@ -160,9 +162,6 @@ async function applyFileChanges({ validateTypes = true, trace, testCase, fileCha
|
|
|
160
162
|
contents = originalSource.getFullText();
|
|
161
163
|
}
|
|
162
164
|
else {
|
|
163
|
-
// since we dont know what is getting updated,
|
|
164
|
-
// we believe that the patch is correct and contains few before and after lines
|
|
165
|
-
// to make the change unique for search & replace
|
|
166
165
|
// since we dont know what is getting updated,
|
|
167
166
|
// we believe that the patch is correct and contains few before and after lines
|
|
168
167
|
// to make the change unique for search & replace
|
|
@@ -171,36 +170,22 @@ async function applyFileChanges({ validateTypes = true, trace, testCase, fileCha
|
|
|
171
170
|
}
|
|
172
171
|
else {
|
|
173
172
|
logger?.error(`Unable to find the code to update in ${fileChange.filePath}`);
|
|
174
|
-
|
|
173
|
+
results.push({
|
|
175
174
|
filePath: fileChange.filePath,
|
|
176
175
|
error: true,
|
|
177
176
|
errorMessage: `The content of "old_code_block" corresponding to file path "${fileChange.filePath}" did not match the current content of the file "${fileChange.filePath}"`,
|
|
178
|
-
};
|
|
177
|
+
});
|
|
178
|
+
continue;
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
await fs_extra_1.default.writeFile(fileChange.filePath, contents, "utf-8");
|
|
182
182
|
readWriteFileSpan?.end({ output: { contents } });
|
|
183
183
|
}
|
|
184
|
-
|
|
185
|
-
if (validateTypes) {
|
|
186
|
-
await (0, fix_ts_errors_1.validateAndFixTypescriptErrors)({
|
|
187
|
-
trace,
|
|
188
|
-
logger,
|
|
189
|
-
file: fileChange.filePath,
|
|
190
|
-
pomCode: pomPrompt,
|
|
191
|
-
nonSpecFileCode: nonSpecFilePrompt,
|
|
192
|
-
testCase: testCase,
|
|
193
|
-
options: testGenOptions,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
trace?.event({ name: "format-file" });
|
|
197
|
-
await (0, web_1.formatCode)(fileChange.filePath, trace);
|
|
198
|
-
logger?.success(`${fileChange.filePath} file formatted successfully!`);
|
|
199
|
-
return {
|
|
184
|
+
results.push({
|
|
200
185
|
filePath: fileChange.filePath,
|
|
201
186
|
error: false,
|
|
202
187
|
errorMessage: "",
|
|
203
|
-
};
|
|
188
|
+
});
|
|
204
189
|
}
|
|
205
190
|
catch (e) {
|
|
206
191
|
trace?.event({
|
|
@@ -211,8 +196,36 @@ async function applyFileChanges({ validateTypes = true, trace, testCase, fileCha
|
|
|
211
196
|
},
|
|
212
197
|
});
|
|
213
198
|
console.error(`Error while applying changes to file ${fileChange.filePath}`, e);
|
|
214
|
-
return;
|
|
215
199
|
}
|
|
216
|
-
}
|
|
200
|
+
}
|
|
201
|
+
return results;
|
|
217
202
|
}
|
|
218
203
|
exports.applyFileChanges = applyFileChanges;
|
|
204
|
+
async function validateTypesAndFormatCode({ validateTypes = true, trace, testCase, fileChanges, logger, testGenOptions, pomPrompt, nonSpecFilePrompt, }) {
|
|
205
|
+
for (let fileChange of fileChanges) {
|
|
206
|
+
if (!fileChange.filePath) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
if (validateTypes) {
|
|
211
|
+
await (0, fix_ts_errors_1.validateAndFixTypescriptErrors)({
|
|
212
|
+
trace,
|
|
213
|
+
logger,
|
|
214
|
+
file: fileChange.filePath,
|
|
215
|
+
pomCode: pomPrompt ?? "",
|
|
216
|
+
nonSpecFileCode: nonSpecFilePrompt ?? "",
|
|
217
|
+
testCase: testCase,
|
|
218
|
+
options: testGenOptions,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
trace?.event({ name: "format-file" });
|
|
222
|
+
await (0, web_1.formatCode)(fileChange.filePath, trace);
|
|
223
|
+
logger?.success(`${fileChange.filePath} file formatted successfully!`);
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
console.error(`Error while formatting the file ${fileChange.filePath}`, e);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
await (0, llm_1.flushAllTraces)();
|
|
230
|
+
}
|
|
231
|
+
exports.validateTypesAndFormatCode = validateTypesAndFormatCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,OAAO,EAGL,IAAI,EAEJ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pD;AAED,wBAAsB,iCAAiC,CAAC,QAAQ,EAAE,MAAM,+BAoBvE;AAED,wBAAgB,4BAA4B,CAC1C,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,UA4CtB;AAED,eAAO,MAAM,6BAA6B;qBAKvB,MAAM;iBACV,MAAM;YACX,MAAM,EAAE;YA2DjB,CAAC;AAEF,eAAO,MAAM,iCAAiC,cACjC,MAAM,EAAE,gBACL,MAAM,sBAyBrB,CAAC;AAEF,wBAAsB,qBAAqB,CAAC,EAC1C,YAAY,EACZ,QAAQ,EACR,MAAM,GACP,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,iBA8CA;AAED,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EAAE,iBAsBzB;AAED,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;CACpB,WAYA;AAED,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,UAOA;AAED,wBAAgB,+BAA+B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CA4B5E;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQnD"}
|
|
@@ -240,6 +240,13 @@ async function lintErrors(filePath) {
|
|
|
240
240
|
exports.lintErrors = lintErrors;
|
|
241
241
|
async function formatCode(filePath, trace) {
|
|
242
242
|
const fileContent = fs_extra_1.default.readFileSync(filePath, "utf8");
|
|
243
|
+
if (!fileContent) {
|
|
244
|
+
trace?.span({
|
|
245
|
+
name: "prettier-format-output",
|
|
246
|
+
output: `${filePath} file is empty`,
|
|
247
|
+
});
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
243
250
|
const prettierConfig = {};
|
|
244
251
|
const formattedContent = await prettier_1.default.format(fileContent, {
|
|
245
252
|
...prettierConfig,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/test-gen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -62,7 +62,6 @@
|
|
|
62
62
|
"nanoid": "^5.0.7",
|
|
63
63
|
"openai": "4.47.2",
|
|
64
64
|
"picocolors": "^1.0.1",
|
|
65
|
-
"playwright": "1.47.1",
|
|
66
65
|
"prettier": "^3.2.5",
|
|
67
66
|
"remove-markdown": "^0.5.5",
|
|
68
67
|
"sanitize-html": "^2.13.0",
|
|
@@ -70,19 +69,20 @@
|
|
|
70
69
|
"ts-morph": "^24.0.0",
|
|
71
70
|
"tsx": "^4.16.2",
|
|
72
71
|
"typescript": "^5.3.3",
|
|
73
|
-
"@empiricalrun/reporter": "^0.21.6",
|
|
74
72
|
"@empiricalrun/llm": "^0.9.29",
|
|
75
|
-
"@empiricalrun/r2-uploader": "^0.3.7"
|
|
73
|
+
"@empiricalrun/r2-uploader": "^0.3.7",
|
|
74
|
+
"@empiricalrun/reporter": "^0.22.0"
|
|
76
75
|
},
|
|
77
76
|
"devDependencies": {
|
|
78
|
-
"@playwright/test": "1.
|
|
77
|
+
"@playwright/test": "1.49.1",
|
|
79
78
|
"@types/detect-port": "^1.3.5",
|
|
80
79
|
"@types/express": "^4.17.21",
|
|
81
80
|
"@types/fs-extra": "^11.0.4",
|
|
82
81
|
"@types/js-levenshtein": "^1.1.3",
|
|
83
82
|
"@types/lodash.isequal": "^4.5.8",
|
|
84
83
|
"@types/md5": "^2.3.5",
|
|
85
|
-
"js-levenshtein": "^1.1.6"
|
|
84
|
+
"js-levenshtein": "^1.1.6",
|
|
85
|
+
"playwright": "1.49.1"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"dev": "tsc --build --watch",
|