@empiricalrun/test-gen 0.31.25 → 0.32.1
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 +20 -0
- package/dist/agent/browsing/run.d.ts +7 -1
- package/dist/agent/browsing/run.d.ts.map +1 -1
- package/dist/agent/browsing/run.js +2 -2
- package/dist/agent/browsing/utils.d.ts +1 -1
- package/dist/agent/browsing/utils.d.ts.map +1 -1
- package/dist/agent/browsing/utils.js +8 -2
- package/dist/agent/codegen/lexical-scoped-vars.d.ts +10 -0
- package/dist/agent/codegen/lexical-scoped-vars.d.ts.map +1 -0
- package/dist/agent/codegen/lexical-scoped-vars.js +61 -0
- package/dist/agent/master/run.js +1 -1
- package/dist/bin/index.js +1 -0
- package/dist/bin/utils/platform/web/index.d.ts +5 -0
- package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
- package/dist/bin/utils/platform/web/index.js +42 -1
- package/dist/bin/utils/scenarios/index.d.ts.map +1 -1
- package/dist/bin/utils/scenarios/index.js +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.32.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7373dea: fix: project detection should use environment pw project filter
|
|
8
|
+
- Updated dependencies [ff77220]
|
|
9
|
+
- @empiricalrun/r2-uploader@0.3.4
|
|
10
|
+
|
|
11
|
+
## 0.32.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- e22c1eb: feat: add support for extracting lexical scoped variables
|
|
16
|
+
|
|
17
|
+
## 0.31.26
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 9cfa0b9: feat: add support for user context in fixtures
|
|
22
|
+
|
|
3
23
|
## 0.31.25
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -11,6 +11,12 @@ type GenerateTestsType = {
|
|
|
11
11
|
* @type {string}
|
|
12
12
|
*/
|
|
13
13
|
filePathToUpdate: string;
|
|
14
|
+
/**
|
|
15
|
+
* playwright projects to filter
|
|
16
|
+
*
|
|
17
|
+
* @type {string[]}
|
|
18
|
+
*/
|
|
19
|
+
pwProjectsFilter: string[];
|
|
14
20
|
};
|
|
15
21
|
/**
|
|
16
22
|
*
|
|
@@ -21,6 +27,6 @@ type GenerateTestsType = {
|
|
|
21
27
|
* filePathToUpdate,
|
|
22
28
|
* }
|
|
23
29
|
*/
|
|
24
|
-
export declare function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, }: GenerateTestsType): Promise<void>;
|
|
30
|
+
export declare function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, pwProjectsFilter, }: GenerateTestsType): Promise<void>;
|
|
25
31
|
export {};
|
|
26
32
|
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"AAkBA,KAAK,iBAAiB,GAAG;IACvB;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"AAkBA,KAAK,iBAAiB,GAAG;IACvB;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,6BAA6B,CAAC,EAClD,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACjB,EAAE,iBAAiB,iBAmEnB"}
|
|
@@ -20,7 +20,7 @@ const utils_2 = require("./utils");
|
|
|
20
20
|
* filePathToUpdate,
|
|
21
21
|
* }
|
|
22
22
|
*/
|
|
23
|
-
async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, }) {
|
|
23
|
+
async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, pwProjectsFilter, }) {
|
|
24
24
|
// valiate if the file path and file to update are valid
|
|
25
25
|
// also warn users if they are on older version of test-gen
|
|
26
26
|
(0, utils_2.canRunMasterAgent)(testFilePath);
|
|
@@ -34,7 +34,7 @@ async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, }
|
|
|
34
34
|
// read playwright config from ./playwright.config.ts of source repo
|
|
35
35
|
const playwrightConfig = await (0, utils_2.readPlaywrightConfig)();
|
|
36
36
|
// detect the playwright project name for the given test file and playwright config
|
|
37
|
-
const project = await (0, utils_2.detectProjectName)(testFilePath, playwrightConfig);
|
|
37
|
+
const project = await (0, utils_2.detectProjectName)(testFilePath, playwrightConfig, pwProjectsFilter);
|
|
38
38
|
const pageVar = await (0, web_1.getPageVariableNameFromCreateTest)(testFilePath);
|
|
39
39
|
console.log(`Detected playwright project name: ${project}`);
|
|
40
40
|
// run playwright test which will internally run the master agent
|
|
@@ -27,7 +27,7 @@ export declare function readPlaywrightConfig(): Promise<PlaywrightTestConfig>;
|
|
|
27
27
|
* @param testFilePath
|
|
28
28
|
* @returns
|
|
29
29
|
*/
|
|
30
|
-
export declare function detectProjectName(testFilePath: string, playwrightConfig: PlaywrightTestConfig): Promise<string>;
|
|
30
|
+
export declare function detectProjectName(testFilePath: string, playwrightConfig: PlaywrightTestConfig, pwProjectsFilter?: string[]): Promise<string>;
|
|
31
31
|
export declare function getPromptForNextAction({ pageSnapshot, task, previousActions, lastActionErrors, promptType, }: {
|
|
32
32
|
pageSnapshot: string;
|
|
33
33
|
task: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAcvD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AAgED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,aAAa,GACvB,OAAO,CAAC,MAAM,CAAC,CA2CjB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBAiBxD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,QA6BjD;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAM1E;AAWD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,EACtC,gBAAgB,GAAE,MAAM,EAAU,GACjC,OAAO,CAAC,MAAM,CAAC,CA+CjB;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,YAAiB,EACjB,IAAS,EACT,eAAoB,EACpB,gBAAqB,EACrB,UAAyC,GAC1C,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,8EASA"}
|
|
@@ -33,6 +33,11 @@ exports.prepareBrowsingAgentTask = prepareBrowsingAgentTask;
|
|
|
33
33
|
async function prepareFileForUpdateScenario(genConfig) {
|
|
34
34
|
const { specPath, testCase } = genConfig;
|
|
35
35
|
const { name, suites } = testCase;
|
|
36
|
+
await (0, web_1.addUserContextFixture)({
|
|
37
|
+
scenarioName: name,
|
|
38
|
+
filePath: specPath,
|
|
39
|
+
suites,
|
|
40
|
+
});
|
|
36
41
|
// update the test case with appropriate location for createTest
|
|
37
42
|
// TODO: reduce the payload for this LLM call. Only provide test file and page files which are used in the test block
|
|
38
43
|
// this will help with faster response
|
|
@@ -188,7 +193,7 @@ function matchAgainstPattern(pattern, filePathToTest) {
|
|
|
188
193
|
* @param testFilePath
|
|
189
194
|
* @returns
|
|
190
195
|
*/
|
|
191
|
-
async function detectProjectName(testFilePath, playwrightConfig) {
|
|
196
|
+
async function detectProjectName(testFilePath, playwrightConfig, pwProjectsFilter = ["*"]) {
|
|
192
197
|
const filePath = testFilePath.replace("./tests/", "");
|
|
193
198
|
if (!playwrightConfig.projects || playwrightConfig.projects.length === 0) {
|
|
194
199
|
throw new Error(`No projects found in playwright config.`);
|
|
@@ -224,7 +229,8 @@ async function detectProjectName(testFilePath, playwrightConfig) {
|
|
|
224
229
|
return "";
|
|
225
230
|
}
|
|
226
231
|
})
|
|
227
|
-
.filter((p) => !!p)
|
|
232
|
+
.filter((p) => !!p)
|
|
233
|
+
.filter((p) => pwProjectsFilter.some((f) => matchAgainstPattern(f, p)));
|
|
228
234
|
if (filteredProjectNames.length === 0) {
|
|
229
235
|
throw new Error(`No project found for the test file: ${testFilePath} in playwright config.`);
|
|
230
236
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
+
import { TestGenConfigOptions } from "../../types";
|
|
3
|
+
export declare function getLexicalScopedVars({ trace, testFile, referencePoint, testName, options, }: {
|
|
4
|
+
trace?: TraceClient;
|
|
5
|
+
testFile: string;
|
|
6
|
+
referencePoint: string;
|
|
7
|
+
testName: string;
|
|
8
|
+
options?: TestGenConfigOptions;
|
|
9
|
+
}): Promise<string[]>;
|
|
10
|
+
//# sourceMappingURL=lexical-scoped-vars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexical-scoped-vars.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/lexical-scoped-vars.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,oBAAoB,CAAC,EACzC,KAAK,EACL,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,OAAO,GACR,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,qBA2DA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLexicalScopedVars = void 0;
|
|
4
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
async function getLexicalScopedVars({ trace, testFile, referencePoint, testName, options, }) {
|
|
7
|
+
const fetchLexicalScopedVarsSpan = trace?.span({
|
|
8
|
+
name: "lexical-scoped-vars",
|
|
9
|
+
});
|
|
10
|
+
const promptSpan = fetchLexicalScopedVarsSpan?.span({
|
|
11
|
+
name: "lexical-scoped-vars-prompt",
|
|
12
|
+
});
|
|
13
|
+
const instruction = await (0, llm_1.getPrompt)("lexical-scope-variables", {
|
|
14
|
+
testFile: testFile || "",
|
|
15
|
+
referencePoint: referencePoint || "",
|
|
16
|
+
testName: testName || "",
|
|
17
|
+
});
|
|
18
|
+
promptSpan?.end({ output: { instruction } });
|
|
19
|
+
const llm = new llm_1.LLM({
|
|
20
|
+
trace: fetchLexicalScopedVarsSpan,
|
|
21
|
+
provider: options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
|
|
22
|
+
defaultModel: options?.model || constants_1.DEFAULT_MODEL,
|
|
23
|
+
providerApiKey: constants_1.MODEL_API_KEYS[options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER],
|
|
24
|
+
});
|
|
25
|
+
const message = await llm.createChatCompletion({
|
|
26
|
+
messages: instruction,
|
|
27
|
+
modelParameters: {
|
|
28
|
+
...constants_1.DEFAULT_MODEL_PARAMETERS,
|
|
29
|
+
...options?.modelParameters,
|
|
30
|
+
},
|
|
31
|
+
responseFormat: {
|
|
32
|
+
type: "json_schema",
|
|
33
|
+
json_schema: {
|
|
34
|
+
name: "reasoning_with_variables",
|
|
35
|
+
strict: true,
|
|
36
|
+
schema: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
reason: {
|
|
40
|
+
type: "string",
|
|
41
|
+
description: "The reason or explanation.",
|
|
42
|
+
},
|
|
43
|
+
variables: {
|
|
44
|
+
type: "array",
|
|
45
|
+
description: "A list of variables.",
|
|
46
|
+
items: {
|
|
47
|
+
type: "string",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
required: ["reason", "variables"],
|
|
52
|
+
additionalProperties: false,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const response = JSON.parse(message?.content || "{}");
|
|
58
|
+
fetchLexicalScopedVarsSpan?.end({ output: { response } });
|
|
59
|
+
return response.variables;
|
|
60
|
+
}
|
|
61
|
+
exports.getLexicalScopedVars = getLexicalScopedVars;
|
package/dist/agent/master/run.js
CHANGED
|
@@ -155,7 +155,7 @@ async function createTestUsingMasterAgent({ task, page, testCase, options, }) {
|
|
|
155
155
|
reason: JSON.parse(toolCall.function.arguments).reason,
|
|
156
156
|
};
|
|
157
157
|
void testGenReporter.sendMessage(output.reason);
|
|
158
|
-
logger.log(`Next Action: ${output.
|
|
158
|
+
logger.log(`Next Action: ${output.action}`);
|
|
159
159
|
if (toolCall.function.name === skill_1.SKILL_USAGE) {
|
|
160
160
|
await actions.executeAction(toolCall.function.name, args, masterAgentActionSpan);
|
|
161
161
|
}
|
package/dist/bin/index.js
CHANGED
|
@@ -55,4 +55,9 @@ export declare const injectCodeSnippetBySuiteChain: ({ testFileContent, codeSnip
|
|
|
55
55
|
suites: string[];
|
|
56
56
|
}) => string;
|
|
57
57
|
export declare const importAllExportsStmtFromFilePaths: (filePaths: string[], testFilePath: string) => Promise<string[]>;
|
|
58
|
+
export declare function addUserContextFixture({ scenarioName, filePath, suites, }: {
|
|
59
|
+
scenarioName: string;
|
|
60
|
+
filePath: string;
|
|
61
|
+
suites: string[];
|
|
62
|
+
}): Promise<void>;
|
|
58
63
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,IAAI,EAIL,MAAM,UAAU,CAAC;AAGlB;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,YAAY,EACZ,MAAM,EACN,OAAO,GACR,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG;IACF,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,EAAE,IAAI,GAAG,SAAS,CAAC;CAC5B,CAuCA;AAwBD,wBAAsB,0CAA0C,CAC9D,QAAQ,EAAE,MAAM,oBA+BjB;AAED;;;;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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,iBAsDA"}
|
|
@@ -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.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 = void 0;
|
|
6
|
+
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 = void 0;
|
|
7
7
|
const eslint_1 = require("eslint");
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
@@ -372,3 +372,44 @@ const importAllExportsStmtFromFilePaths = async (filePaths, testFilePath) => {
|
|
|
372
372
|
return statements;
|
|
373
373
|
};
|
|
374
374
|
exports.importAllExportsStmtFromFilePaths = importAllExportsStmtFromFilePaths;
|
|
375
|
+
async function addUserContextFixture({ scenarioName, filePath, suites, }) {
|
|
376
|
+
// TODO: remove this check when we support user context across repos
|
|
377
|
+
let fixtureContent = "";
|
|
378
|
+
try {
|
|
379
|
+
fixtureContent = await fs_extra_1.default.readFile("./tests/fixtures.ts", "utf-8");
|
|
380
|
+
}
|
|
381
|
+
catch (e) {
|
|
382
|
+
// do nothing
|
|
383
|
+
}
|
|
384
|
+
if (!fixtureContent || !fixtureContent.includes("userContext")) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const fileContent = await fs_extra_1.default.readFile(filePath, "utf-8");
|
|
388
|
+
const { testNode } = getTypescriptTestBlock({
|
|
389
|
+
scenarioName,
|
|
390
|
+
content: fileContent,
|
|
391
|
+
suites,
|
|
392
|
+
});
|
|
393
|
+
const currentBlock = testNode?.getText();
|
|
394
|
+
const testCallExpression = testNode?.getFirstDescendantByKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
395
|
+
if (testCallExpression?.getExpression().getText() === "test") {
|
|
396
|
+
const arrowFunction = testCallExpression.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ArrowFunction);
|
|
397
|
+
if (arrowFunction) {
|
|
398
|
+
const param = arrowFunction.getParameters()[0]; // Get the first parameter
|
|
399
|
+
const destructuringParam = param?.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ObjectBindingPattern);
|
|
400
|
+
if (destructuringParam) {
|
|
401
|
+
const elements = destructuringParam.getElements();
|
|
402
|
+
const userContextExists = elements.some((e) => e.getText().includes("userContext"));
|
|
403
|
+
console.log("userContextExists", userContextExists);
|
|
404
|
+
if (!userContextExists) {
|
|
405
|
+
const updatedImport = destructuringParam
|
|
406
|
+
.getText()
|
|
407
|
+
.replace("}", ", userContext }");
|
|
408
|
+
destructuringParam.replaceWithText(updatedImport);
|
|
409
|
+
await fs_extra_1.default.writeFile(filePath, fileContent.replace(currentBlock, testNode.getText()), "utf-8");
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
exports.addUserContextFixture = addUserContextFixture;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/bin/utils/scenarios/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/bin/utils/scenarios/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EAEd,MAAM,gBAAgB,CAAC;AAaxB,iBAAe,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAiB3E;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export type FileContent = {
|
|
|
5
5
|
filePath: string;
|
|
6
6
|
content: string;
|
|
7
7
|
};
|
|
8
|
+
export type Environment = {
|
|
9
|
+
name: string;
|
|
10
|
+
slug: string;
|
|
11
|
+
playwrightProjects: string[];
|
|
12
|
+
};
|
|
8
13
|
export type TestGenConfigOptions = {
|
|
9
14
|
agent: "code" | "master";
|
|
10
15
|
model: LLMModel;
|
|
@@ -26,6 +31,7 @@ export type TestGenConfig = {
|
|
|
26
31
|
specPath: string;
|
|
27
32
|
testCase: TestCase;
|
|
28
33
|
build?: Build;
|
|
34
|
+
environment?: Environment;
|
|
29
35
|
options?: TestGenConfigOptions;
|
|
30
36
|
};
|
|
31
37
|
export type TestCase = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,eAAe,EACf,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAA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AAQ,EAAE,CACR,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KACzB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/test-gen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@actions/core": "^1.10.1",
|
|
19
19
|
"@aws-sdk/client-s3": "^3.614.0",
|
|
20
20
|
"@aws-sdk/s3-request-presigner": "^3.614.0",
|
|
21
|
-
"@playwright/test": "
|
|
21
|
+
"@playwright/test": "1.47.1",
|
|
22
22
|
"@types/sanitize-html": "^2.11.0",
|
|
23
23
|
"commander": "^12.1.0",
|
|
24
24
|
"detect-port": "^1.6.1",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"nanoid": "^5.0.7",
|
|
37
37
|
"openai": "^4.47.2",
|
|
38
38
|
"picocolors": "^1.0.1",
|
|
39
|
-
"playwright": "
|
|
39
|
+
"playwright": "1.47.1",
|
|
40
40
|
"prettier": "^3.2.5",
|
|
41
41
|
"remove-markdown": "^0.5.5",
|
|
42
42
|
"sanitize-html": "^2.13.0",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"ts-morph": "^23.0.0",
|
|
45
45
|
"tsx": "^4.16.2",
|
|
46
46
|
"typescript": "^5.3.3",
|
|
47
|
+
"@empiricalrun/r2-uploader": "^0.3.4",
|
|
47
48
|
"@empiricalrun/llm": "^0.9.4",
|
|
48
|
-
"@empiricalrun/r2-uploader": "^0.3.3",
|
|
49
49
|
"@empiricalrun/reporter": "^0.20.7"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|