@empiricalrun/test-gen 0.41.2 → 0.41.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.41.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 399f968: test: fix eslint mock test output
|
|
8
|
+
- 4c35992: fix: import statements with alias were getting removed from file
|
|
9
|
+
|
|
10
|
+
## 0.41.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 1d39892: fix: repo edit exception
|
|
15
|
+
|
|
3
16
|
## 0.41.2
|
|
4
17
|
|
|
5
18
|
### Patch 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;
|
|
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;AAErD,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,CAmED"}
|
|
@@ -1,34 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
6
|
exports.repoEditAgent = exports.generateCodeUsingRepoAgent = void 0;
|
|
30
7
|
const llm_1 = require("@empiricalrun/llm");
|
|
31
|
-
const fsSync = __importStar(require("fs"));
|
|
32
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
33
9
|
const path_1 = require("path");
|
|
34
10
|
const context_1 = require("../../bin/utils/context");
|
|
@@ -147,7 +123,6 @@ Task: ${task}
|
|
|
147
123
|
}
|
|
148
124
|
exports.generateCodeUsingRepoAgent = generateCodeUsingRepoAgent;
|
|
149
125
|
async function repoEditAgent({ trace, task, }) {
|
|
150
|
-
console.log("mock test", fs_extra_1.default.readdir(""));
|
|
151
126
|
const testgenUpdatesReporter = new reporter_1.TestGenUpdatesReporter();
|
|
152
127
|
void testgenUpdatesReporter.sendMessage(`Updating test code as per the task. \n View [trace](${trace?.getTraceUrl()})`);
|
|
153
128
|
const { prompt: repoFiles } = await (0, context_1.generateTxtForRepository)();
|
|
@@ -160,7 +135,7 @@ async function repoEditAgent({ trace, task, }) {
|
|
|
160
135
|
const fileUpdateResponses = await (0, utils_1.applyFileChanges)({
|
|
161
136
|
trace,
|
|
162
137
|
testCase: {},
|
|
163
|
-
fileChanges: updates.filter((f) => f.filePath &&
|
|
138
|
+
fileChanges: updates.filter((f) => f.filePath && fs_extra_1.default.existsSync(f.filePath)),
|
|
164
139
|
});
|
|
165
140
|
const errorResponses = fileUpdateResponses.filter((f) => f?.error);
|
|
166
141
|
if (errorResponses.length > 0) {
|
|
@@ -179,7 +154,7 @@ async function repoEditAgent({ trace, task, }) {
|
|
|
179
154
|
fileChanges: updatedFileChanges,
|
|
180
155
|
});
|
|
181
156
|
}
|
|
182
|
-
const newFileUpdates = updates.filter((f) => !
|
|
157
|
+
const newFileUpdates = updates.filter((f) => !fs_extra_1.default.existsSync(f.filePath));
|
|
183
158
|
await Promise.all(newFileUpdates.map((f) => {
|
|
184
159
|
return (async () => {
|
|
185
160
|
await fs_extra_1.default.mkdir((0, path_1.dirname)(f.filePath), { recursive: true });
|
|
@@ -194,7 +169,7 @@ async function repoEditAgent({ trace, task, }) {
|
|
|
194
169
|
});
|
|
195
170
|
await Promise.all(updates.map((f) => {
|
|
196
171
|
return (async () => {
|
|
197
|
-
if (
|
|
172
|
+
if (fs_extra_1.default.existsSync(f.filePath)) {
|
|
198
173
|
await (0, web_1.lintErrors)(f.filePath);
|
|
199
174
|
}
|
|
200
175
|
})();
|
|
@@ -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;
|
|
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;AAMhD,OAAO,EAGL,IAAI,EAEJ,UAAU,EAEX,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,eAAO,MAAM,gCAAgC,eAC/B,UAAU,KACrB,MAgBF,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,YAAY,EACZ,MAAM,EACN,OAAO,GACR,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAA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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"}
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.isSyntaxValid = exports.getVariableDeclarationsFromCode = exports.buildTestNamePrompt = exports.isTestPresent = exports.appendScopeToCreateTest = exports.addUserContextFixture = exports.importAllExportsStmtFromFilePaths = exports.injectCodeSnippetBySuiteChain = exports.replaceCreateTestWithNewCode = exports.getPageVariableNameFromCreateTest = exports.getFixtureImportPath = exports.removeTestOnly = exports.addNewImport = exports.formatCode = exports.lintErrors = exports.stripAndPrependImports = exports.validateTypescript = exports.appendToTestBlock = exports.findFirstSerialDescribeBlock = exports.hasTopLevelDescribeConfigureWithSerialMode = exports.getTypescriptTestBlock = exports.getTestModuleAliasFromSourceFile = void 0;
|
|
7
7
|
const parser_1 = require("@babel/parser");
|
|
8
8
|
const eslint_1 = require("eslint");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
10
|
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
12
11
|
const path_1 = __importDefault(require("path"));
|
|
@@ -177,7 +176,7 @@ exports.appendToTestBlock = appendToTestBlock;
|
|
|
177
176
|
function validateTypescript(filePath) {
|
|
178
177
|
// Create a compiler host to read files
|
|
179
178
|
const compilerHost = typescript_1.default.createCompilerHost({});
|
|
180
|
-
compilerHost.readFile = (file) =>
|
|
179
|
+
compilerHost.readFile = (file) => fs_extra_1.default.readFileSync(file, "utf8");
|
|
181
180
|
// Create a program with a single source file
|
|
182
181
|
const program = typescript_1.default.createProgram([filePath], {
|
|
183
182
|
esModuleInterop: true,
|
|
@@ -301,6 +300,34 @@ async function getPageVariableNameFromCreateTest(filePath) {
|
|
|
301
300
|
return pageVariableName?.split(" ")[0];
|
|
302
301
|
}
|
|
303
302
|
exports.getPageVariableNameFromCreateTest = getPageVariableNameFromCreateTest;
|
|
303
|
+
function resolveImportsFromFixtures({ fixtureImportNode, testAlias, filePath, updatedTestFile, }) {
|
|
304
|
+
const imports = {};
|
|
305
|
+
const importClause = fixtureImportNode.getImportClause();
|
|
306
|
+
if (!importClause) {
|
|
307
|
+
return updatedTestFile;
|
|
308
|
+
}
|
|
309
|
+
const namedImports = importClause.getNamedImports().map((imp) => {
|
|
310
|
+
// aliasNode is truthy if the import is aliased (e.g. import { test as setup } ...)
|
|
311
|
+
const aliasNode = imp.getAliasNode();
|
|
312
|
+
const originalImportName = imp.getName();
|
|
313
|
+
const aliasImportName = aliasNode?.getText();
|
|
314
|
+
const importName = aliasImportName || originalImportName;
|
|
315
|
+
imports[originalImportName] = imp.getText();
|
|
316
|
+
return importName;
|
|
317
|
+
});
|
|
318
|
+
const isComplete = namedImports.includes(testAlias) && namedImports.includes("expect");
|
|
319
|
+
if (!isComplete) {
|
|
320
|
+
if (!Object.keys(imports).includes("test")) {
|
|
321
|
+
imports["test"] = "test";
|
|
322
|
+
}
|
|
323
|
+
if (!Object.keys(imports).includes("expect")) {
|
|
324
|
+
imports["expect"] = "expect";
|
|
325
|
+
}
|
|
326
|
+
const expectedImports = `import { ${Object.values(imports).join(", ")} } from "${getFixtureImportPath(filePath)}";`;
|
|
327
|
+
updatedTestFile = updatedTestFile.replace(fixtureImportNode.getText(), expectedImports);
|
|
328
|
+
}
|
|
329
|
+
return updatedTestFile;
|
|
330
|
+
}
|
|
304
331
|
function replaceCreateTestWithNewCode(filePath, contents, generatedCode) {
|
|
305
332
|
const project = new ts_morph_1.Project();
|
|
306
333
|
const sourceFile = project.createSourceFile("test.ts", contents);
|
|
@@ -317,17 +344,12 @@ function replaceCreateTestWithNewCode(filePath, contents, generatedCode) {
|
|
|
317
344
|
const fixtureImportNode = sourceFile.getFirstDescendant((node) => !!(node.isKind(ts_morph_1.SyntaxKind.ImportDeclaration) &&
|
|
318
345
|
node.getText().includes("fixtures")));
|
|
319
346
|
if (fixtureImportNode) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
347
|
+
updatedTestFile = resolveImportsFromFixtures({
|
|
348
|
+
fixtureImportNode,
|
|
349
|
+
testAlias,
|
|
350
|
+
filePath,
|
|
351
|
+
updatedTestFile,
|
|
325
352
|
});
|
|
326
|
-
const isComplete = namedImports.includes(testAlias) && namedImports.includes("expect");
|
|
327
|
-
if (!isComplete) {
|
|
328
|
-
const expectedImports = `import { test, expect } from "${getFixtureImportPath(filePath)}";`;
|
|
329
|
-
updatedTestFile = updatedTestFile.replace(fixtureImportNode.getText(), expectedImports);
|
|
330
|
-
}
|
|
331
353
|
}
|
|
332
354
|
return updatedTestFile;
|
|
333
355
|
}
|