@empiricalrun/test-gen 0.35.8 → 0.36.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/actions/index.d.ts +2 -2
- package/dist/actions/index.d.ts.map +1 -1
- package/dist/actions/index.js +6 -2
- package/dist/actions/press.d.ts +4 -0
- package/dist/actions/press.d.ts.map +1 -0
- package/dist/actions/press.js +56 -0
- package/dist/actions/skill.d.ts.map +1 -1
- package/dist/actions/skill.js +4 -3
- package/dist/agent/browsing/utils.d.ts.map +1 -1
- package/dist/agent/browsing/utils.js +19 -2
- package/dist/agent/codegen/create-test-block.d.ts.map +1 -1
- package/dist/agent/codegen/create-test-block.js +1 -1
- package/dist/agent/codegen/lexical-scoped-vars.d.ts +2 -3
- package/dist/agent/codegen/lexical-scoped-vars.d.ts.map +1 -1
- package/dist/agent/codegen/lexical-scoped-vars.js +2 -3
- package/dist/agent/codegen/skills-retriever.d.ts.map +1 -1
- package/dist/agent/codegen/skills-retriever.js +1 -1
- package/dist/agent/codegen/update-flow.js +2 -2
- package/dist/agent/master/run.d.ts +3 -2
- package/dist/agent/master/run.d.ts.map +1 -1
- package/dist/agent/master/run.js +2 -2
- package/dist/bin/utils/platform/web/index.d.ts +4 -1
- package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
- package/dist/bin/utils/platform/web/index.js +45 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.36.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 89f9bdd: feat: add support for context variables
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- ba10561: fix: consider "setup" and "teardown" aliases as test block
|
|
12
|
+
- Updated dependencies [a2eb6a1]
|
|
13
|
+
- @empiricalrun/llm@0.9.23
|
|
14
|
+
|
|
15
|
+
## 0.35.9
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 04ca7f3: feat: add locator.press action
|
|
20
|
+
|
|
3
21
|
## 0.35.8
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { Page } from "playwright";
|
|
|
3
3
|
import { ActionSchema } from "../types";
|
|
4
4
|
export declare class PlaywrightActions {
|
|
5
5
|
private page;
|
|
6
|
+
private stateVariables;
|
|
6
7
|
private actionGenerators;
|
|
7
8
|
private recordedActions;
|
|
8
|
-
|
|
9
|
-
constructor(page: Page);
|
|
9
|
+
constructor(page: Page, stateVariables?: Record<string, any>);
|
|
10
10
|
executeAction(name: string | undefined, args: Record<string, any>, trace?: TraceClient): Promise<void>;
|
|
11
11
|
getBrowsingActionSchemas(): ActionSchema[];
|
|
12
12
|
getMasterActionSchemas(): ActionSchema[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIlC,OAAO,EAAE,YAAY,EAA6B,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIlC,OAAO,EAAE,YAAY,EAA6B,MAAM,UAAU,CAAC;AAYnE,qBAAa,iBAAiB;IAQ1B,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,cAAc;IARxB,OAAO,CAAC,gBAAgB,CAA8B;IACtD,OAAO,CAAC,eAAe,CAInB;gBAEM,IAAI,EAAE,IAAI,EACV,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM;IAiB5C,aAAa,CACjB,IAAI,oBAAa,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,KAAK,CAAC,EAAE,WAAW;IAgDrB,wBAAwB,IAAI,YAAY,EAAE;IAmB1C,sBAAsB,IAAI,YAAY,EAAE;IAUxC,YAAY,IAAI;QACd,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,EAAE,CAAC;KACvB;IAUD,gBAAgB,CAAC,KAAK,EAAE,MAAM;IAO9B;;;;;;OAMG;IACH,aAAa,IAAI,OAAO;IAQxB,UAAU;CAUX"}
|
package/dist/actions/index.js
CHANGED
|
@@ -9,21 +9,24 @@ const done_1 = require("./done");
|
|
|
9
9
|
const fill_1 = require("./fill");
|
|
10
10
|
const goto_1 = require("./goto");
|
|
11
11
|
const hover_1 = require("./hover");
|
|
12
|
+
const press_1 = require("./press");
|
|
12
13
|
const reload_page_1 = require("./reload-page");
|
|
13
14
|
const skill_1 = require("./skill");
|
|
14
15
|
const text_content_1 = require("./text-content");
|
|
15
16
|
class PlaywrightActions {
|
|
16
17
|
page;
|
|
18
|
+
stateVariables;
|
|
17
19
|
actionGenerators;
|
|
18
20
|
recordedActions;
|
|
19
|
-
stateVariables = {}
|
|
20
|
-
constructor(page) {
|
|
21
|
+
constructor(page, stateVariables = {}) {
|
|
21
22
|
this.page = page;
|
|
23
|
+
this.stateVariables = stateVariables;
|
|
22
24
|
this.actionGenerators = [
|
|
23
25
|
fill_1.fillActionGenerator,
|
|
24
26
|
goto_1.gotoActionGenerator,
|
|
25
27
|
click_1.clickActionGenerator,
|
|
26
28
|
hover_1.hoverActionGenerator,
|
|
29
|
+
press_1.pressActionGenerator,
|
|
27
30
|
done_1.doneActionGenerator,
|
|
28
31
|
assert_1.assertTextVisibilityActionGenerator,
|
|
29
32
|
reload_page_1.reloadActionGenerator,
|
|
@@ -84,6 +87,7 @@ class PlaywrightActions {
|
|
|
84
87
|
fill_1.fillActionGenerator,
|
|
85
88
|
goto_1.gotoActionGenerator,
|
|
86
89
|
click_1.clickActionGenerator,
|
|
90
|
+
press_1.pressActionGenerator,
|
|
87
91
|
done_1.doneActionGenerator,
|
|
88
92
|
assert_1.assertTextVisibilityActionGenerator,
|
|
89
93
|
reload_page_1.reloadActionGenerator,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"press.d.ts","sourceRoot":"","sources":["../../src/actions/press.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAIrD,eAAO,MAAM,4BAA4B,8BAA8B,CAAC;AAExE,eAAO,MAAM,oBAAoB,EAAE,yBA4DlC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pressActionGenerator = exports.PLAYWRIGHT_PRESS_ACTION_NAME = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
exports.PLAYWRIGHT_PRESS_ACTION_NAME = "keyboard_press_on_element";
|
|
7
|
+
const pressActionGenerator = (page) => {
|
|
8
|
+
return {
|
|
9
|
+
execute: async ({ args }) => {
|
|
10
|
+
const css = args.css_selector;
|
|
11
|
+
const locator = await (0, utils_1.getPlaywrightLocatorUsingCssSelector)(css, args.xpath, page, args?.elementAnnotation);
|
|
12
|
+
const exec = new Function("page", `return page.${locator}.press("${args.key}", { timeout: 3000 })`);
|
|
13
|
+
await exec(page);
|
|
14
|
+
return {
|
|
15
|
+
locator,
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
// TODO: args transformer to be kept at a single place
|
|
19
|
+
template: (args, options) => {
|
|
20
|
+
return {
|
|
21
|
+
code: `await ${(0, utils_1.getPageVarName)()}.${options.locator}.press("${args.key}");`,
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
name: exports.PLAYWRIGHT_PRESS_ACTION_NAME,
|
|
25
|
+
schema: {
|
|
26
|
+
type: "function",
|
|
27
|
+
function: {
|
|
28
|
+
name: exports.PLAYWRIGHT_PRESS_ACTION_NAME,
|
|
29
|
+
description: "Focuses the matching element and presses a combination of the keys",
|
|
30
|
+
parameters: {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: {
|
|
33
|
+
reason: {
|
|
34
|
+
type: "string",
|
|
35
|
+
description: constants_1.DEFAULT_ACTION_REASON_PROMPT,
|
|
36
|
+
},
|
|
37
|
+
key: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "The key to press on the keyboard after focusing the element. Example: F1 - F12, Digit0- Digit9, KeyA- KeyZ, Backquote, Minus, Equal, Backslash, Backspace, Tab, Delete, Escape, ArrowDown, End, Enter, Home, Insert, PageDown, PageUp, ArrowRight, ArrowUp, etc.",
|
|
40
|
+
},
|
|
41
|
+
xpath: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "XPath selector to identify the element uniquely and click it. When creating XPATH selector, ensure they are unique and specific enough to select only one element, even if there are multiple elements of the same type (like multiple h1 elements)",
|
|
44
|
+
},
|
|
45
|
+
css_selector: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "CSS selector to identify the element uniquely.When creating CSS selectors, ensure they are unique to the page and specific enough to select only one element.",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ["reason", "key", "xpath", "css_selector"],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.pressActionGenerator = pressActionGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/actions/skill.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,cAAc;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,KAAK,EAAE;IAEnC,kBAAkB;IAIlB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE;CAG7B;AAED,eAAO,MAAM,cAAc,gBAAyB,CAAC;AAErD,eAAO,MAAM,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/actions/skill.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,WAAW,gBAAgB,CAAC;AAEzC,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,cAAM,cAAc;IACN,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,KAAK,EAAE;IAEnC,kBAAkB;IAIlB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE;CAG7B;AAED,eAAO,MAAM,cAAc,gBAAyB,CAAC;AAErD,eAAO,MAAM,oBAAoB,EAAE,yBA2FlC,CAAC"}
|
package/dist/actions/skill.js
CHANGED
|
@@ -38,18 +38,19 @@ const skillActionGenerator = (page, options) => {
|
|
|
38
38
|
const code = await (0, use_skill_1.generateSkillUsageCode)({
|
|
39
39
|
task: skillDetails.testStep,
|
|
40
40
|
sampleUsageMethod: skillDetails.usageExample,
|
|
41
|
-
scopeVariablesMapStr: JSON.stringify(options.stateVariables || {}),
|
|
41
|
+
scopeVariablesMapStr: JSON.stringify(options.stateVariables || {}, null, 2),
|
|
42
42
|
pageVariableName: (0, utils_1.getPageVarName)(),
|
|
43
43
|
trace,
|
|
44
44
|
});
|
|
45
45
|
console.log("Usage code generated", code);
|
|
46
|
-
const
|
|
46
|
+
const stateVarKeys = Object.keys(options.stateVariables || {});
|
|
47
|
+
const exec = new Function((0, utils_1.getPageVarName)(), ...imports, ...stateVarKeys,
|
|
47
48
|
// assuming all POMs are async methods
|
|
48
49
|
`
|
|
49
50
|
return (async () => {
|
|
50
51
|
return ${code}
|
|
51
52
|
})()`);
|
|
52
|
-
await exec(page, ...imports.map((i) => module[i]));
|
|
53
|
+
await exec(page, ...imports.map((i) => module[i]), ...stateVarKeys.map((s) => options.stateVariables[s]));
|
|
53
54
|
return {
|
|
54
55
|
locator: code,
|
|
55
56
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAK3D,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":"AAAA,OAAO,EAAa,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAK3D,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAiBvD,OAAO,EAAe,aAAa,EAAE,MAAM,aAAa,CAAC;AAMzD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AA4FD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,aAAa,EACxB,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC,CAuDjB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBAgCxD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,QA+BjD;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;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"}
|
|
@@ -17,6 +17,7 @@ const fs_1 = require("../../bin/utils/fs");
|
|
|
17
17
|
const web_1 = require("../../bin/utils/platform/web");
|
|
18
18
|
const create_test_block_1 = require("../codegen/create-test-block");
|
|
19
19
|
const fix_ts_errors_1 = require("../codegen/fix-ts-errors");
|
|
20
|
+
const lexical_scoped_vars_1 = require("../codegen/lexical-scoped-vars");
|
|
20
21
|
const update_flow_1 = require("../codegen/update-flow");
|
|
21
22
|
function isRegExp(obj) {
|
|
22
23
|
return (obj instanceof RegExp ||
|
|
@@ -42,8 +43,6 @@ async function prepareFileForUpdateScenario(genConfig, trace) {
|
|
|
42
43
|
suites,
|
|
43
44
|
});
|
|
44
45
|
// update the test case with appropriate location for createTest
|
|
45
|
-
// TODO: reduce the payload for this LLM call. Only provide test file and page files which are used in the test block
|
|
46
|
-
// this will help with faster response
|
|
47
46
|
const [suggestion] = await (0, update_flow_1.appendCreateTestBlock)({
|
|
48
47
|
trace,
|
|
49
48
|
testCase,
|
|
@@ -54,6 +53,24 @@ async function prepareFileForUpdateScenario(genConfig, trace) {
|
|
|
54
53
|
const createTestFilePath = suggestion?.updatedFiles[0] || "";
|
|
55
54
|
console.log("appending to existing test block");
|
|
56
55
|
console.log("updated test file path", createTestFilePath);
|
|
56
|
+
const fetchScopeVariablesSpan = trace?.span({
|
|
57
|
+
name: "fetch-scope-variables",
|
|
58
|
+
input: {
|
|
59
|
+
createTestFilePath,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const scopeVariables = await (0, lexical_scoped_vars_1.getLexicalScopedVars)({
|
|
63
|
+
file: await fs_extra_1.default.readFile(createTestFilePath, "utf-8"),
|
|
64
|
+
referencePoint: "await createTest",
|
|
65
|
+
});
|
|
66
|
+
fetchScopeVariablesSpan?.end({
|
|
67
|
+
name: "fetch-scope-variables",
|
|
68
|
+
output: {
|
|
69
|
+
variables: scopeVariables,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
await (0, web_1.appendScopeToCreateTest)(createTestFilePath, scopeVariables);
|
|
73
|
+
// extract the createTest function and pass the scoped vars
|
|
57
74
|
const updateFileSpan = trace?.span({
|
|
58
75
|
name: "update-file-span",
|
|
59
76
|
input: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-test-block.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/create-test-block.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAY3B,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,wBAAwB,CAAC,EAC7C,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,+
|
|
1
|
+
{"version":3,"file":"create-test-block.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/create-test-block.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAY3B,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,wBAAwB,CAAC,EAC7C,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,+BA0DA"}
|
|
@@ -33,7 +33,7 @@ async function createEmptyTestCaseBlock({ testCase, file, options, trace, }) {
|
|
|
33
33
|
scenarioName: testCase.name,
|
|
34
34
|
scenario: testCase.steps.join("\n"),
|
|
35
35
|
scenarioFile: file,
|
|
36
|
-
});
|
|
36
|
+
}, 17);
|
|
37
37
|
promptSpan?.end({ output: { prompt } });
|
|
38
38
|
const llm = new llm_1.LLM({
|
|
39
39
|
trace,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { TraceClient } from "@empiricalrun/llm";
|
|
2
2
|
import { TestGenConfigOptions } from "../../types";
|
|
3
|
-
export declare function getLexicalScopedVars({ trace,
|
|
3
|
+
export declare function getLexicalScopedVars({ trace, file, referencePoint, options, }: {
|
|
4
4
|
trace?: TraceClient;
|
|
5
|
-
|
|
5
|
+
file: string;
|
|
6
6
|
referencePoint: string;
|
|
7
|
-
testName: string;
|
|
8
7
|
options?: TestGenConfigOptions;
|
|
9
8
|
}): Promise<string[]>;
|
|
10
9
|
//# sourceMappingURL=lexical-scoped-vars.d.ts.map
|
|
@@ -1 +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,
|
|
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,IAAI,EACJ,cAAc,EACd,OAAO,GACR,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,qBA0DA"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLexicalScopedVars = void 0;
|
|
4
4
|
const llm_1 = require("@empiricalrun/llm");
|
|
5
5
|
const constants_1 = require("../../constants");
|
|
6
|
-
async function getLexicalScopedVars({ trace,
|
|
6
|
+
async function getLexicalScopedVars({ trace, file, referencePoint, options, }) {
|
|
7
7
|
const fetchLexicalScopedVarsSpan = trace?.span({
|
|
8
8
|
name: "lexical-scoped-vars",
|
|
9
9
|
});
|
|
@@ -11,9 +11,8 @@ async function getLexicalScopedVars({ trace, testFile, referencePoint, testName,
|
|
|
11
11
|
name: "lexical-scoped-vars-prompt",
|
|
12
12
|
});
|
|
13
13
|
const instruction = await (0, llm_1.getPrompt)("lexical-scope-variables", {
|
|
14
|
-
testFile:
|
|
14
|
+
testFile: file || "",
|
|
15
15
|
referencePoint: referencePoint || "",
|
|
16
|
-
testName: testName || "",
|
|
17
16
|
});
|
|
18
17
|
promptSpan?.end({ output: { instruction } });
|
|
19
18
|
const llm = new llm_1.LLM({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skills-retriever.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/skills-retriever.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAYhE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAG7D,eAAO,MAAM,cAAc;cAMf,QAAQ;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"skills-retriever.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/skills-retriever.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAYhE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAG7D,eAAO,MAAM,cAAc;cAMf,QAAQ;;;;;;;;;IA8CnB,CAAC;AAEF,wBAAsB,oBAAoB,CAAC,EACzC,QAAQ,EACR,OAAO,EACP,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;;;;;KA6BA"}
|
|
@@ -26,7 +26,7 @@ const fetchPomSkills = async ({ testCase, pomFiles, options, trace, }) => {
|
|
|
26
26
|
pageFiles: pomFiles,
|
|
27
27
|
scenarioName: testCase.name,
|
|
28
28
|
scenario: testCase.steps.join("\n"),
|
|
29
|
-
});
|
|
29
|
+
}, 11);
|
|
30
30
|
promptSpan?.end({ output: { prompt } });
|
|
31
31
|
const llm = new llm_1.LLM({
|
|
32
32
|
trace: fetchSkillsUsingPOMFilesSpan,
|
|
@@ -244,8 +244,8 @@ async function appendCreateTestBlock({ testCase, file, options, trace, validateT
|
|
|
244
244
|
promptSpan?.end({ output: { instruction } });
|
|
245
245
|
const [userInstruction] = instruction.filter((s) => s.role === "user");
|
|
246
246
|
const [systemInstruction] = instruction.filter((s) => s.role === "system");
|
|
247
|
-
userInstruction.content = `${systemInstruction?.content}
|
|
248
|
-
|
|
247
|
+
userInstruction.content = `${systemInstruction?.content}
|
|
248
|
+
|
|
249
249
|
${userInstruction?.content}
|
|
250
250
|
`;
|
|
251
251
|
const llm = new llm_1.LLM({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LLM, TraceClient } from "@empiricalrun/llm";
|
|
2
2
|
import { Page } from "playwright";
|
|
3
3
|
import { PlaywrightActions } from "../../actions";
|
|
4
|
-
import { TestCase } from "../../types";
|
|
4
|
+
import { ScopeVars, TestCase } from "../../types";
|
|
5
5
|
import { BrowsingAgentOptions } from "../browsing";
|
|
6
6
|
export declare function getNextAction({ task, executedActions, failedActions, pageUrl, trace, llm, options, pageScreenshot, annotatedPageScreenshot, actions, disableSkills, useHints, }: {
|
|
7
7
|
task: string;
|
|
@@ -17,11 +17,12 @@ export declare function getNextAction({ task, executedActions, failedActions, pa
|
|
|
17
17
|
disableSkills: boolean;
|
|
18
18
|
useHints: boolean;
|
|
19
19
|
}): Promise<import("openai/resources/index.mjs").ChatCompletionMessageToolCall | undefined>;
|
|
20
|
-
export declare function createTestUsingMasterAgent({ task, page, testCase, options, }: {
|
|
20
|
+
export declare function createTestUsingMasterAgent({ task, page, testCase, options, scopeVars, }: {
|
|
21
21
|
task: string;
|
|
22
22
|
page: Page;
|
|
23
23
|
testCase: TestCase;
|
|
24
24
|
options: BrowsingAgentOptions;
|
|
25
|
+
scopeVars?: ScopeVars;
|
|
25
26
|
}): Promise<{
|
|
26
27
|
code: string;
|
|
27
28
|
importPaths: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/master/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,GAAG,EACH,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAYlD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/master/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,GAAG,EACH,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAYlD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,oBAAoB,EAErB,MAAM,aAAa,CAAC;AAQrB,wBAAsB,aAAa,CAAC,EAClC,IAAI,EACJ,eAAe,EACf,aAAa,EACb,OAAO,EACP,KAAK,EACL,GAAG,EACH,OAAO,EACP,cAAc,EACd,uBAAuB,EACvB,OAAO,EACP,aAAa,EACb,QAAgB,GACjB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,GAAG,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;CACnB,2FAwFA;AAGD,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,SAAS,GACV,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;;;GA4RA"}
|
package/dist/agent/master/run.js
CHANGED
|
@@ -98,7 +98,7 @@ async function getNextAction({ task, executedActions, failedActions, pageUrl, tr
|
|
|
98
98
|
}
|
|
99
99
|
exports.getNextAction = getNextAction;
|
|
100
100
|
// let screenshotIndex = 0; // keeping this for local debugging
|
|
101
|
-
async function createTestUsingMasterAgent({ task, page, testCase, options, }) {
|
|
101
|
+
async function createTestUsingMasterAgent({ task, page, testCase, options, scopeVars, }) {
|
|
102
102
|
const useHints = options?.useHints || false;
|
|
103
103
|
const logger = new logger_1.CustomLogger({ useReporter: false });
|
|
104
104
|
const testgenUpdatesReporter = new reporter_1.TestGenUpdatesReporter();
|
|
@@ -139,7 +139,7 @@ async function createTestUsingMasterAgent({ task, page, testCase, options, }) {
|
|
|
139
139
|
options,
|
|
140
140
|
});
|
|
141
141
|
skill_1.testCaseSkills.updateSkills(skills);
|
|
142
|
-
const actions = new actions_1.PlaywrightActions(page);
|
|
142
|
+
const actions = new actions_1.PlaywrightActions(page, scopeVars);
|
|
143
143
|
await (0, utils_1.injectPwLocatorGenerator)(page);
|
|
144
144
|
trace?.update({ input: { task } });
|
|
145
145
|
let isGivenTaskDone = false;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Node } from "ts-morph";
|
|
1
|
+
import { Node, SourceFile } from "ts-morph";
|
|
2
2
|
import { TestCase } from "../../../../types";
|
|
3
|
+
export declare const getTestModuleAliasFromSourceFile: (sourceFile: SourceFile) => string;
|
|
3
4
|
/**
|
|
4
5
|
* function to get the test block and test node for the scenario
|
|
5
6
|
* @export
|
|
@@ -14,6 +15,7 @@ export declare function getTypescriptTestBlock({ scenarioName, suites, content,
|
|
|
14
15
|
}): {
|
|
15
16
|
testBlock: string | undefined;
|
|
16
17
|
testNode: Node | undefined;
|
|
18
|
+
testAlias: string;
|
|
17
19
|
};
|
|
18
20
|
export declare function hasTopLevelDescribeConfigureWithSerialMode(filePath: string): Promise<boolean>;
|
|
19
21
|
/**
|
|
@@ -61,6 +63,7 @@ export declare function addUserContextFixture({ scenarioName, filePath, suites,
|
|
|
61
63
|
filePath: string;
|
|
62
64
|
suites: string[];
|
|
63
65
|
}): Promise<void>;
|
|
66
|
+
export declare function appendScopeToCreateTest(filePath: string, scopeVariables: string[]): Promise<void>;
|
|
64
67
|
export declare function isTestPresent({ specPath, testCase, }: {
|
|
65
68
|
specPath: string;
|
|
66
69
|
testCase: TestCase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAMA,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,EAAE,MAAM,EAAE,C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BrB,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;AAED,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EAAE,iBA2BzB;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"}
|
|
@@ -3,14 +3,29 @@ 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.buildTestNamePrompt = exports.isTestPresent = 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;
|
|
6
|
+
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 eslint_1 = require("eslint");
|
|
8
|
+
const fs_1 = require("fs");
|
|
8
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
10
|
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
10
11
|
const path_1 = __importDefault(require("path"));
|
|
11
12
|
const prettier_1 = __importDefault(require("prettier"));
|
|
12
13
|
const ts_morph_1 = require("ts-morph");
|
|
13
14
|
const typescript_1 = __importDefault(require("typescript"));
|
|
15
|
+
const getTestModuleAliasFromSourceFile = (sourceFile) => {
|
|
16
|
+
return (sourceFile
|
|
17
|
+
.getImportDeclarations()
|
|
18
|
+
// Look for any import that includes "test" as a named import, regardless of module path
|
|
19
|
+
// "test" can be imported from "@playwright/test" or "<some-fixture>"
|
|
20
|
+
.find((importDecl) => importDecl
|
|
21
|
+
.getNamedImports()
|
|
22
|
+
.some((namedImport) => namedImport.getName() === "test"))
|
|
23
|
+
?.getNamedImports()
|
|
24
|
+
.find((namedImport) => namedImport.getName() === "test")
|
|
25
|
+
?.getAliasNode()
|
|
26
|
+
?.getText() || "test");
|
|
27
|
+
};
|
|
28
|
+
exports.getTestModuleAliasFromSourceFile = getTestModuleAliasFromSourceFile;
|
|
14
29
|
/**
|
|
15
30
|
* function to get the test block and test node for the scenario
|
|
16
31
|
* @export
|
|
@@ -21,11 +36,12 @@ const typescript_1 = __importDefault(require("typescript"));
|
|
|
21
36
|
function getTypescriptTestBlock({ scenarioName, suites, content, }) {
|
|
22
37
|
const project = new ts_morph_1.Project();
|
|
23
38
|
const sourceFile = project.createSourceFile("test.ts", content);
|
|
39
|
+
const testAlias = (0, exports.getTestModuleAliasFromSourceFile)(sourceFile);
|
|
24
40
|
// Get all test function nodes that match the scenario name
|
|
25
41
|
const matchingTestFunctionNodes = sourceFile
|
|
26
42
|
.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
|
|
27
43
|
.filter((node) => {
|
|
28
|
-
return Boolean(node.getExpression().getText() ===
|
|
44
|
+
return Boolean(node.getExpression().getText() === testAlias &&
|
|
29
45
|
node.getArguments()[0]?.getText().includes(scenarioName));
|
|
30
46
|
});
|
|
31
47
|
if (!suites?.length) {
|
|
@@ -33,6 +49,7 @@ function getTypescriptTestBlock({ scenarioName, suites, content, }) {
|
|
|
33
49
|
return {
|
|
34
50
|
testBlock: firstNode?.getText(),
|
|
35
51
|
testNode: firstNode,
|
|
52
|
+
testAlias,
|
|
36
53
|
};
|
|
37
54
|
}
|
|
38
55
|
// Iterate over each test function node and check if the suites match
|
|
@@ -43,6 +60,7 @@ function getTypescriptTestBlock({ scenarioName, suites, content, }) {
|
|
|
43
60
|
return {
|
|
44
61
|
testBlock: testNode.getText(),
|
|
45
62
|
testNode,
|
|
63
|
+
testAlias,
|
|
46
64
|
};
|
|
47
65
|
}
|
|
48
66
|
}
|
|
@@ -50,6 +68,7 @@ function getTypescriptTestBlock({ scenarioName, suites, content, }) {
|
|
|
50
68
|
return {
|
|
51
69
|
testBlock: undefined,
|
|
52
70
|
testNode: undefined,
|
|
71
|
+
testAlias,
|
|
53
72
|
};
|
|
54
73
|
}
|
|
55
74
|
exports.getTypescriptTestBlock = getTypescriptTestBlock;
|
|
@@ -157,7 +176,7 @@ exports.appendToTestBlock = appendToTestBlock;
|
|
|
157
176
|
function validateTypescript(filePath) {
|
|
158
177
|
// Create a compiler host to read files
|
|
159
178
|
const compilerHost = typescript_1.default.createCompilerHost({});
|
|
160
|
-
compilerHost.readFile = (file) =>
|
|
179
|
+
compilerHost.readFile = (file) => (0, fs_1.readFileSync)(file, "utf8");
|
|
161
180
|
// Create a program with a single source file
|
|
162
181
|
const program = typescript_1.default.createProgram([filePath], {
|
|
163
182
|
esModuleInterop: true,
|
|
@@ -276,6 +295,7 @@ exports.getPageVariableNameFromCreateTest = getPageVariableNameFromCreateTest;
|
|
|
276
295
|
function replaceCreateTestWithNewCode(filePath, contents, generatedCode) {
|
|
277
296
|
const project = new ts_morph_1.Project();
|
|
278
297
|
const sourceFile = project.createSourceFile("test.ts", contents);
|
|
298
|
+
const testAlias = (0, exports.getTestModuleAliasFromSourceFile)(sourceFile);
|
|
279
299
|
const createTestNode = sourceFile.getFirstDescendant((node) => !!(node.isKind(ts_morph_1.SyntaxKind.CallExpression) &&
|
|
280
300
|
node.getExpression().getText() === "createTest"));
|
|
281
301
|
const createTestWithAwait = `await ${createTestNode?.getText()}`;
|
|
@@ -294,7 +314,7 @@ function replaceCreateTestWithNewCode(filePath, contents, generatedCode) {
|
|
|
294
314
|
const namedImports = importClause
|
|
295
315
|
.getNamedImports()
|
|
296
316
|
.map((imp) => imp.getName());
|
|
297
|
-
const isComplete = namedImports.includes(
|
|
317
|
+
const isComplete = namedImports.includes(testAlias) && namedImports.includes("expect");
|
|
298
318
|
if (!isComplete) {
|
|
299
319
|
const expectedImports = `import { test, expect } from "${getFixtureImportPath(filePath)}";`;
|
|
300
320
|
updatedTestFile = updatedTestFile.replace(fixtureImportNode.getText(), expectedImports);
|
|
@@ -385,14 +405,14 @@ async function addUserContextFixture({ scenarioName, filePath, suites, }) {
|
|
|
385
405
|
return;
|
|
386
406
|
}
|
|
387
407
|
const fileContent = await fs_extra_1.default.readFile(filePath, "utf-8");
|
|
388
|
-
const { testNode } = getTypescriptTestBlock({
|
|
408
|
+
const { testNode, testAlias } = getTypescriptTestBlock({
|
|
389
409
|
scenarioName,
|
|
390
410
|
content: fileContent,
|
|
391
411
|
suites,
|
|
392
412
|
});
|
|
393
413
|
const currentBlock = testNode?.getText();
|
|
394
414
|
const testCallExpression = testNode?.getFirstDescendantByKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
395
|
-
if (testCallExpression?.getExpression().getText() ===
|
|
415
|
+
if (testCallExpression?.getExpression().getText() === testAlias) {
|
|
396
416
|
const arrowFunction = testCallExpression.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ArrowFunction);
|
|
397
417
|
if (arrowFunction) {
|
|
398
418
|
const param = arrowFunction.getParameters()[0]; // Get the first parameter
|
|
@@ -413,6 +433,25 @@ async function addUserContextFixture({ scenarioName, filePath, suites, }) {
|
|
|
413
433
|
}
|
|
414
434
|
}
|
|
415
435
|
exports.addUserContextFixture = addUserContextFixture;
|
|
436
|
+
async function appendScopeToCreateTest(filePath, scopeVariables) {
|
|
437
|
+
const contents = await fs_extra_1.default.readFile(filePath, "utf-8");
|
|
438
|
+
const project = new ts_morph_1.Project();
|
|
439
|
+
const sourceFile = project.createSourceFile("test.ts", contents);
|
|
440
|
+
const createTestNode = sourceFile.getFirstDescendant((node) => !!(node.isKind(ts_morph_1.SyntaxKind.CallExpression) &&
|
|
441
|
+
node.getExpression().getText() === "createTest"));
|
|
442
|
+
let scopeArgStr = "{ " + scopeVariables.join(", ") + " }";
|
|
443
|
+
const descendants = createTestNode
|
|
444
|
+
?.getDescendants()
|
|
445
|
+
.filter((n) => !!n.getText());
|
|
446
|
+
if (descendants &&
|
|
447
|
+
descendants.length &&
|
|
448
|
+
descendants[descendants?.length - 2]?.getText() !== ",") {
|
|
449
|
+
scopeArgStr = `, ${scopeArgStr}`;
|
|
450
|
+
}
|
|
451
|
+
createTestNode?.replaceWithText(createTestNode.getText().replace(")", `${scopeArgStr})`));
|
|
452
|
+
await fs_extra_1.default.writeFile(filePath, sourceFile.getFullText());
|
|
453
|
+
}
|
|
454
|
+
exports.appendScopeToCreateTest = appendScopeToCreateTest;
|
|
416
455
|
function isTestPresent({ specPath, testCase, }) {
|
|
417
456
|
let isTestPresent = true;
|
|
418
457
|
isTestPresent = fs_extra_1.default.existsSync(specPath);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Page } from "playwright";
|
|
2
|
-
|
|
2
|
+
import { ScopeVars } from "./types";
|
|
3
|
+
export declare function createTest(task: string, page: Page, scope?: ScopeVars): Promise<void>;
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAQlC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAOpC,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,SAAS,iBAuC3E"}
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ process.on("beforeExit", async () => await (0, llm_1.flushAllTraces)());
|
|
|
15
15
|
process.on("exit", async () => await (0, llm_1.flushAllTraces)());
|
|
16
16
|
process.on("SIGINT", async () => await (0, llm_1.flushAllTraces)());
|
|
17
17
|
process.on("SIGTERM", async () => await (0, llm_1.flushAllTraces)());
|
|
18
|
-
async function createTest(task, page) {
|
|
18
|
+
async function createTest(task, page, scope) {
|
|
19
19
|
const port = process.env.APP_PORT || 3030;
|
|
20
20
|
const testConfigArg = process.env.TEST_GEN_TOKEN;
|
|
21
21
|
const { testGenConfig } = await (0, utils_1.parseCliArgs)(testConfigArg);
|
|
@@ -46,6 +46,7 @@ async function createTest(task, page) {
|
|
|
46
46
|
},
|
|
47
47
|
...testGenConfig.options,
|
|
48
48
|
},
|
|
49
|
+
scopeVars: scope,
|
|
49
50
|
});
|
|
50
51
|
await fileService.updateTest({
|
|
51
52
|
task,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","s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AAC;CAClB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG,CACtC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE;IACP,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACrC,KACE,MAAM,CAAC;AAEZ,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC;AAEtE,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,CAAC,OAAO,EAAE;QACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC1B,KAAK,CAAC,EAAE,WAAW,CAAC;KACrB,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IAC1C,QAAQ,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;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empiricalrun/test-gen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"ts-morph": "^23.0.0",
|
|
45
45
|
"tsx": "^4.16.2",
|
|
46
46
|
"typescript": "^5.3.3",
|
|
47
|
-
"@empiricalrun/llm": "^0.9.
|
|
47
|
+
"@empiricalrun/llm": "^0.9.23",
|
|
48
48
|
"@empiricalrun/r2-uploader": "^0.3.6",
|
|
49
49
|
"@empiricalrun/reporter": "^0.21.2"
|
|
50
50
|
},
|