@empiricalrun/test-gen 0.47.2 → 0.47.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 +26 -0
- package/dist/actions/index.d.ts +1 -1
- package/dist/actions/index.js +1 -1
- package/dist/agent/browsing/index.d.ts.map +1 -1
- package/dist/agent/browsing/index.js +2 -3
- package/dist/agent/browsing/run.d.ts +4 -1
- package/dist/agent/browsing/run.d.ts.map +1 -1
- package/dist/agent/browsing/run.js +8 -3
- package/dist/agent/browsing/utils.d.ts +6 -13
- package/dist/agent/browsing/utils.d.ts.map +1 -1
- package/dist/agent/browsing/utils.js +9 -38
- package/dist/agent/chat.d.ts +7 -0
- package/dist/agent/chat.d.ts.map +1 -0
- package/dist/agent/chat.js +89 -0
- package/dist/agent/codegen/create-test-block.d.ts +2 -3
- package/dist/agent/codegen/create-test-block.d.ts.map +1 -1
- package/dist/agent/codegen/create-test-block.js +4 -9
- package/dist/agent/codegen/fix-ts-errors.d.ts +2 -3
- package/dist/agent/codegen/fix-ts-errors.d.ts.map +1 -1
- package/dist/agent/codegen/fix-ts-errors.js +4 -5
- package/dist/agent/codegen/generate-code-apply-changes.d.ts.map +1 -1
- package/dist/agent/codegen/generate-code-apply-changes.js +5 -6
- package/dist/agent/codegen/run.d.ts +6 -4
- package/dist/agent/codegen/run.d.ts.map +1 -1
- package/dist/agent/codegen/run.js +8 -6
- package/dist/agent/codegen/update-flow.d.ts +7 -5
- package/dist/agent/codegen/update-flow.d.ts.map +1 -1
- package/dist/agent/codegen/update-flow.js +9 -49
- package/dist/agent/codegen/utils.d.ts +2 -16
- package/dist/agent/codegen/utils.d.ts.map +1 -1
- package/dist/agent/codegen/utils.js +3 -41
- package/dist/agent/diagnosis-agent/index.d.ts +2 -9
- package/dist/agent/diagnosis-agent/index.d.ts.map +1 -1
- package/dist/agent/diagnosis-agent/index.js +1 -8
- package/dist/agent/enrich-prompt/index.d.ts.map +1 -1
- package/dist/agent/enrich-prompt/index.js +0 -1
- package/dist/agent/infer-agent/index.d.ts.map +1 -1
- package/dist/agent/infer-agent/index.js +0 -9
- package/dist/agent/master/browser-tests/index.spec.js +15 -1
- package/dist/agent/master/element-annotation.d.ts.map +1 -1
- package/dist/agent/master/element-annotation.js +1 -2
- package/dist/agent/master/execute-browser-action.d.ts.map +1 -1
- package/dist/agent/master/execute-browser-action.js +1 -2
- package/dist/agent/master/execute-skill-action.d.ts.map +1 -1
- package/dist/agent/master/execute-skill-action.js +1 -2
- package/dist/agent/master/next-action.d.ts.map +1 -1
- package/dist/agent/master/next-action.js +2 -3
- package/dist/agent/master/planner.d.ts.map +1 -1
- package/dist/agent/master/planner.js +1 -2
- package/dist/agent/master/run.d.ts.map +1 -1
- package/dist/agent/master/run.js +1 -2
- package/dist/agent/master/scroller.d.ts.map +1 -1
- package/dist/agent/master/scroller.js +2 -3
- package/dist/agent/planner/run-time-planner.d.ts.map +1 -1
- package/dist/agent/planner/run-time-planner.js +1 -2
- package/dist/bin/index.js +49 -34
- package/dist/bin/utils/index.d.ts +1 -0
- package/dist/bin/utils/index.d.ts.map +1 -1
- package/dist/bin/utils/index.js +9 -3
- package/dist/file/server.d.ts +2 -0
- package/dist/file/server.d.ts.map +1 -1
- package/dist/file/server.js +18 -1
- package/dist/tools/browser-agent.d.ts +16 -0
- package/dist/tools/browser-agent.d.ts.map +1 -0
- package/dist/tools/browser-agent.js +76 -0
- package/dist/tools/codegen-agent.d.ts +9 -0
- package/dist/tools/codegen-agent.d.ts.map +1 -0
- package/dist/tools/codegen-agent.js +44 -0
- package/dist/tools/test-run.d.ts +10 -0
- package/dist/tools/test-run.d.ts.map +1 -0
- package/dist/tools/test-run.js +35 -0
- package/dist/utils/git.d.ts +2 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +11 -0
- package/package.json +3 -2
- package/dist/agent/utils.d.ts +0 -2
- package/dist/agent/utils.d.ts.map +0 -1
- package/dist/agent/utils.js +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.47.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 007ef65: feat: master agent tool call returns git patch on successful runs
|
|
8
|
+
- c4ddc2c: feat: chat can use codegen agent as a tool call
|
|
9
|
+
- e1903b7: feat: add master agent as a tool call for chat
|
|
10
|
+
- 4b18733: chore: simplify interface to prepare for tool call
|
|
11
|
+
- 6328aaf: feat: test-gen can use test-run package as a tool call
|
|
12
|
+
- e4bf218: fix: update append-create-test prompt to emphasize task without location hints
|
|
13
|
+
- 7748c7b: chore: remove options from prepare file workflow
|
|
14
|
+
- 72a8cf2: feat: chat agent only needs prompt string
|
|
15
|
+
- d995e4c: feat: enable conversation along with test-run tool call
|
|
16
|
+
- 848cb88: fix: trace hierarchy in prep for master agent
|
|
17
|
+
- Updated dependencies [72a8cf2]
|
|
18
|
+
- Updated dependencies [242f659]
|
|
19
|
+
- Updated dependencies [6328aaf]
|
|
20
|
+
- Updated dependencies [d995e4c]
|
|
21
|
+
- @empiricalrun/test-run@0.7.1
|
|
22
|
+
|
|
23
|
+
## 0.47.3
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 56ed4eb: chore: remove parseJson utility, let it throw exceptions
|
|
28
|
+
|
|
3
29
|
## 0.47.2
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/dist/actions/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class PlaywrightActions {
|
|
|
9
9
|
constructor(page: TestGenPage, stateVariables?: Record<string, any>);
|
|
10
10
|
executeAction(name: string | undefined, args: ActionArgs, trace?: TraceClient): Promise<string | undefined>;
|
|
11
11
|
getBrowsingActionSchemas(): ActionSchema[];
|
|
12
|
-
|
|
12
|
+
getSkillsActionSchemas(): ActionSchema[];
|
|
13
13
|
generateCode(): {
|
|
14
14
|
code: string;
|
|
15
15
|
importPaths: string[];
|
package/dist/actions/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAMlD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC;AAEF,wBAAsB,6BAA6B,CAAC,EAClD,MAAM,EACN,IAAI,EACJ,OAAO,EACP,GAAG,EACH,KAAK,GACN,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,iBAAiB,CAAC;IAC3B,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CA8D1C"}
|
|
@@ -6,7 +6,6 @@ const constants_1 = require("../../constants");
|
|
|
6
6
|
const promptTemplate_0 = "{{#section \"system\"}}\nYou are a browser automation agent who is given a task to generate code for navigation and assertion. This task is your\ngoal and you must achieve it.\n\nYou will be provided with already executed actions and basis that you need to pick the next step to achieve the task.\nRemember that the goal must be achieved.\n\nYou will be provided with the web page snapshot in the form of Document Object Model. Based on the goal and available\ntool calls you need to pick the appropriate tool call.\n\nInstructions:\n- Take actions one at a time. Do not try to take multiple actions\n- You can respond with multiple assertions in one shot\n- Do not repeat the same actions again otherwise your response will be marked INVALID\n- Avoid repeating errors which we got while executing the last action\n- Stick to the task provided to you and mark the task done once the task is complete\n- Do not execute any action which is not mentioned in the task\n- Do not repeat actions which are already executed more than twice otherwise your response will be marked INVALID\n- Always refer to \"Executed actions\" before deciding your next action for completion of the task.\n- End the task done if all actions required for task are executed\n{{/section}}\n\n{{#section \"user\"}}\nTask:\n{{task}}\n\nCurrent page snapshot:\n{{pageSnapshot}}\n{{/section}}";
|
|
7
7
|
const reporter_1 = require("../../reporter");
|
|
8
8
|
const html_1 = require("../../utils/html");
|
|
9
|
-
const utils_1 = require("../utils");
|
|
10
9
|
async function executeTaskUsingBrowsingAgent({ action, page, actions, llm, trace, }) {
|
|
11
10
|
let generatedCodeSteps;
|
|
12
11
|
const tools = actions.getBrowsingActionSchemas();
|
|
@@ -48,9 +47,9 @@ async function executeTaskUsingBrowsingAgent({ action, page, actions, llm, trace
|
|
|
48
47
|
const toolCallsSpan = browsingAgentSpan?.span({ name: "tool-calls" });
|
|
49
48
|
for (const i in toolCalls) {
|
|
50
49
|
const toolCall = toolCalls[i];
|
|
51
|
-
const args =
|
|
50
|
+
const args = JSON.parse(toolCall.function.arguments);
|
|
52
51
|
try {
|
|
53
|
-
const code = await actions.executeAction(toolCall.function.name,
|
|
52
|
+
const code = await actions.executeAction(toolCall.function.name, JSON.parse(toolCall.function.arguments), toolCallsSpan);
|
|
54
53
|
generatedCodeSteps = {
|
|
55
54
|
// Passing reason as action, in order to pass the correct action that took place to runtime planner
|
|
56
55
|
action: args.reason,
|
|
@@ -14,6 +14,9 @@ type GenerateTestsType = {
|
|
|
14
14
|
* filePathToUpdate,
|
|
15
15
|
* }
|
|
16
16
|
*/
|
|
17
|
-
export declare function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, pwProjectsFilter, testGenToken, repoDir, }: GenerateTestsType): Promise<
|
|
17
|
+
export declare function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, pwProjectsFilter, testGenToken, repoDir, }: GenerateTestsType): Promise<{
|
|
18
|
+
isError: boolean;
|
|
19
|
+
error: string;
|
|
20
|
+
}>;
|
|
18
21
|
export {};
|
|
19
22
|
//# sourceMappingURL=run.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/run.ts"],"names":[],"mappings":"AAiBA,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,6BAA6B,CAAC,EAClD,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,OAAO,GACR,EAAE,iBAAiB;;;GAkFnB"}
|
|
@@ -20,9 +20,9 @@ const utils_1 = require("./utils");
|
|
|
20
20
|
* }
|
|
21
21
|
*/
|
|
22
22
|
async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, pwProjectsFilter, testGenToken, repoDir, }) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (!fs_extra_1.default.existsSync(testFilePath)) {
|
|
24
|
+
throw new Error(`File for master agent to run not found: ${testFilePath}`);
|
|
25
|
+
}
|
|
26
26
|
// detect available http port on the machine
|
|
27
27
|
const port = await (0, detect_port_1.default)(3030);
|
|
28
28
|
// start a file service to handle file updates from agent
|
|
@@ -84,5 +84,10 @@ async function generateTestsUsingMasterAgent({ testFilePath, filePathToUpdate, p
|
|
|
84
84
|
// throw the error because of which test gen failed
|
|
85
85
|
throw Error(error);
|
|
86
86
|
}
|
|
87
|
+
await fileService.stop();
|
|
88
|
+
return {
|
|
89
|
+
isError,
|
|
90
|
+
error,
|
|
91
|
+
};
|
|
87
92
|
}
|
|
88
93
|
exports.generateTestsUsingMasterAgent = generateTestsUsingMasterAgent;
|
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
-
import type {
|
|
2
|
+
import type { TestCase } from "@empiricalrun/shared-types";
|
|
3
3
|
import { Page } from "playwright";
|
|
4
4
|
import { PlaywrightTestConfig } from "playwright/test";
|
|
5
5
|
export declare function isRegExp(obj: any): obj is RegExp;
|
|
6
6
|
export declare function prepareBrowsingAgentTask(steps: string[]): string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare function prepareFileForMasterAgent(genConfig: TestGenConfig, trace?: TraceClient): Promise<string>;
|
|
7
|
+
export declare function prepareFileForMasterAgent({ testCase, specPath, trace, }: {
|
|
8
|
+
testCase: TestCase;
|
|
9
|
+
specPath: string;
|
|
10
|
+
trace?: TraceClient;
|
|
11
|
+
}): Promise<string>;
|
|
13
12
|
export declare function injectPwLocatorGenerator(page: Page): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* Function to validate if the test file path are valid.
|
|
16
|
-
* @throws if there are any missing dependencies for master agent to run.
|
|
17
|
-
* @param {string} filePath
|
|
18
|
-
*/
|
|
19
|
-
export declare function canRunMasterAgent(filePath: string): void;
|
|
20
13
|
/**
|
|
21
14
|
* function to read playwright config from the source repo
|
|
22
15
|
* @return {*} {Promise<PlaywrightTestConfig>}
|
|
@@ -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,
|
|
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,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAIxE,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;AA+FD,wBAAsB,yBAAyB,CAAC,EAC9C,QAAQ,EACR,QAAQ,EACR,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,MAAM,CAAC,CAyDlB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBA2HxD;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,oBAAoB,CAAC,CAM/B;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"}
|
|
@@ -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.TeardownManager = exports.detectProjectName = exports.readPlaywrightConfig = exports.
|
|
6
|
+
exports.TeardownManager = exports.detectProjectName = exports.readPlaywrightConfig = exports.injectPwLocatorGenerator = exports.prepareFileForMasterAgent = exports.prepareBrowsingAgentTask = exports.isRegExp = void 0;
|
|
7
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
8
|
const minimatch_1 = require("minimatch");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
@@ -37,12 +37,7 @@ async function addImportForCreateTest(testFilePath) {
|
|
|
37
37
|
}
|
|
38
38
|
await fs_extra_1.default.writeFile(testFilePath, (0, web_1.addNewImport)(await fs_extra_1.default.readFile(testFilePath, "utf-8"), ["createTest"], importSource));
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
* Function to prepare test file for update scenarios for master agent to run
|
|
42
|
-
* @param {TestGenConfig} genConfig
|
|
43
|
-
*/
|
|
44
|
-
async function prepareFileForUpdateScenario(genConfig, trace) {
|
|
45
|
-
const { specPath, testCase } = genConfig;
|
|
40
|
+
async function prepareFileForUpdateScenario({ testCase, specPath, trace, }) {
|
|
46
41
|
const { name, suites } = testCase;
|
|
47
42
|
await (0, web_1.addUserContextFixture)({
|
|
48
43
|
scenarioName: name,
|
|
@@ -55,7 +50,6 @@ async function prepareFileForUpdateScenario(genConfig, trace) {
|
|
|
55
50
|
testCase,
|
|
56
51
|
file: specPath,
|
|
57
52
|
validateTypes: false,
|
|
58
|
-
options: genConfig.options,
|
|
59
53
|
});
|
|
60
54
|
const createTestFilePath = suggestion?.updatedFiles[0] || "";
|
|
61
55
|
console.log("appending to existing test block");
|
|
@@ -78,15 +72,7 @@ async function prepareFileForUpdateScenario(genConfig, trace) {
|
|
|
78
72
|
},
|
|
79
73
|
});
|
|
80
74
|
await (0, web_1.appendScopeToCreateTest)(createTestFilePath, scopeVariables);
|
|
81
|
-
// extract the createTest function and pass the scoped vars
|
|
82
|
-
const updateFileSpan = trace?.span({
|
|
83
|
-
name: "update-file-span",
|
|
84
|
-
input: {
|
|
85
|
-
createTestFilePath,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
75
|
await addImportForCreateTest(createTestFilePath);
|
|
89
|
-
updateFileSpan?.end();
|
|
90
76
|
const { pomPrompt, nonSpecFilePrompt } = await (0, context_1.contextForGeneration)(createTestFilePath);
|
|
91
77
|
await (0, fix_ts_errors_1.validateAndFixTypescriptErrors)({
|
|
92
78
|
trace,
|
|
@@ -94,7 +80,6 @@ async function prepareFileForUpdateScenario(genConfig, trace) {
|
|
|
94
80
|
pomCode: pomPrompt,
|
|
95
81
|
nonSpecFileCode: nonSpecFilePrompt,
|
|
96
82
|
testCase: testCase,
|
|
97
|
-
options: genConfig.options,
|
|
98
83
|
});
|
|
99
84
|
const testFileContent = await fs_extra_1.default.readFile(specPath, "utf-8");
|
|
100
85
|
const { testBlock, testNode } = (0, web_1.getTypescriptTestBlock)({
|
|
@@ -111,17 +96,11 @@ async function prepareFileForUpdateScenario(genConfig, trace) {
|
|
|
111
96
|
}
|
|
112
97
|
return createTestFilePath;
|
|
113
98
|
}
|
|
114
|
-
|
|
115
|
-
* Function to prepare test file for master agent to run
|
|
116
|
-
* @param {TestGenConfig} genConfig
|
|
117
|
-
* @return {*} {Promise<string>}
|
|
118
|
-
*/
|
|
119
|
-
async function prepareFileForMasterAgent(genConfig, trace) {
|
|
99
|
+
async function prepareFileForMasterAgent({ testCase, specPath, trace, }) {
|
|
120
100
|
const prepareFileSpan = trace?.span({
|
|
121
101
|
name: "prepare-file-for-master-agent",
|
|
122
102
|
});
|
|
123
103
|
new logger_1.CustomLogger({ useReporter: true }).log(`Preparing file for master agent. [view trace](${trace?.getTraceUrl()})`);
|
|
124
|
-
const { specPath, testCase } = genConfig;
|
|
125
104
|
const { name, suites } = testCase;
|
|
126
105
|
// check if the spec file exists
|
|
127
106
|
// if no then create a new file with test and expect imports
|
|
@@ -144,9 +123,8 @@ async function prepareFileForMasterAgent(genConfig, trace) {
|
|
|
144
123
|
if (!testBlock) {
|
|
145
124
|
const newTestBlock = await (0, create_test_block_1.createEmptyTestCaseBlock)({
|
|
146
125
|
trace: prepareFileSpan,
|
|
147
|
-
testCase
|
|
126
|
+
testCase,
|
|
148
127
|
file: specPath,
|
|
149
|
-
options: genConfig.options,
|
|
150
128
|
});
|
|
151
129
|
await fs_extra_1.default.writeFile(specPath, `${existingContents} \n\n ${newTestBlock}`, "utf-8");
|
|
152
130
|
const updatedContent = (0, web_1.injectCodeSnippetBySuiteChain)({
|
|
@@ -156,7 +134,11 @@ async function prepareFileForMasterAgent(genConfig, trace) {
|
|
|
156
134
|
});
|
|
157
135
|
await fs_extra_1.default.writeFile(specPath, updatedContent, "utf-8");
|
|
158
136
|
}
|
|
159
|
-
const updatePath = await prepareFileForUpdateScenario(
|
|
137
|
+
const updatePath = await prepareFileForUpdateScenario({
|
|
138
|
+
testCase,
|
|
139
|
+
specPath,
|
|
140
|
+
trace,
|
|
141
|
+
});
|
|
160
142
|
return updatePath;
|
|
161
143
|
}
|
|
162
144
|
exports.prepareFileForMasterAgent = prepareFileForMasterAgent;
|
|
@@ -280,17 +262,6 @@ async function injectPwLocatorGenerator(page) {
|
|
|
280
262
|
}
|
|
281
263
|
}
|
|
282
264
|
exports.injectPwLocatorGenerator = injectPwLocatorGenerator;
|
|
283
|
-
/**
|
|
284
|
-
* Function to validate if the test file path are valid.
|
|
285
|
-
* @throws if there are any missing dependencies for master agent to run.
|
|
286
|
-
* @param {string} filePath
|
|
287
|
-
*/
|
|
288
|
-
function canRunMasterAgent(filePath) {
|
|
289
|
-
if (!fs_extra_1.default.existsSync(filePath)) {
|
|
290
|
-
throw new Error(`File for master agent to run not found: ${filePath}`);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
exports.canRunMasterAgent = canRunMasterAgent;
|
|
294
265
|
/**
|
|
295
266
|
* function to read playwright config from the source repo
|
|
296
267
|
* @return {*} {Promise<PlaywrightTestConfig>}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
+
import { ChatCompletionMessageParam } from "openai/resources/chat/completions.mjs";
|
|
3
|
+
export declare function chatAgent({ prompt, }: {
|
|
4
|
+
prompt: string;
|
|
5
|
+
trace?: TraceClient;
|
|
6
|
+
}): Promise<ChatCompletionMessageParam[]>;
|
|
7
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/agent/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,0BAA0B,EAE3B,MAAM,uCAAuC,CAAC;AAsC/C,wBAAsB,SAAS,CAAC,EAC9B,MAAM,GACP,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,yCA6DA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.chatAgent = void 0;
|
|
4
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
+
const human_in_the_loop_1 = require("../human-in-the-loop");
|
|
6
|
+
const browser_agent_1 = require("../tools/browser-agent");
|
|
7
|
+
const codegen_agent_1 = require("../tools/codegen-agent");
|
|
8
|
+
const test_run_1 = require("../tools/test-run");
|
|
9
|
+
const systemPrompt = `
|
|
10
|
+
You are a helpful assistant that can answer questions and help with tasks.
|
|
11
|
+
You are given a set to tools to use to fulfill the user's request.
|
|
12
|
+
|
|
13
|
+
For example, if the user asks you to run a test, you should use the runTest tool.
|
|
14
|
+
Once the test is run, you will receive the results in the form of a JSON object.
|
|
15
|
+
Summarize the results in a few sentences.
|
|
16
|
+
|
|
17
|
+
Or if the user asks you to modify a test, you should use the
|
|
18
|
+
generateTestWithCodegen or the generateTestWithBrowserAgent tool. Read their
|
|
19
|
+
descriptions to understand what each tool does.
|
|
20
|
+
`;
|
|
21
|
+
const getToolExecutor = (toolName) => {
|
|
22
|
+
if (toolName === "runTest") {
|
|
23
|
+
return test_run_1.runTestTool;
|
|
24
|
+
}
|
|
25
|
+
else if (toolName === "generateTestWithCodegen") {
|
|
26
|
+
return codegen_agent_1.generateTestWithCodegenTool;
|
|
27
|
+
}
|
|
28
|
+
else if (toolName === "generateTestWithBrowserAgent") {
|
|
29
|
+
return browser_agent_1.generateTestWithBrowserAgentTool;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error(`Tool name ${toolName} not found`);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
async function chatAgent({ prompt, }) {
|
|
36
|
+
let userPrompt = prompt;
|
|
37
|
+
let chatHistory = [
|
|
38
|
+
{ role: "system", content: systemPrompt },
|
|
39
|
+
{ role: "user", content: userPrompt },
|
|
40
|
+
];
|
|
41
|
+
const llm = new llm_1.LLM({ provider: "openai" });
|
|
42
|
+
let response;
|
|
43
|
+
let shouldAskUserForInput = false;
|
|
44
|
+
let pendingToolCalls = [];
|
|
45
|
+
while (!userPrompt.toLowerCase().includes("stop")) {
|
|
46
|
+
if (pendingToolCalls.length > 0) {
|
|
47
|
+
const toolCall = pendingToolCalls.shift();
|
|
48
|
+
if (!toolCall) {
|
|
49
|
+
throw new Error("No tool call found");
|
|
50
|
+
}
|
|
51
|
+
console.log("Executing tool call:", toolCall.function.name, "with args:", toolCall.function.arguments);
|
|
52
|
+
const toolExecutor = getToolExecutor(toolCall.function.name);
|
|
53
|
+
const toolArgs = JSON.parse(toolCall.function.arguments);
|
|
54
|
+
const toolResult = await toolExecutor(toolArgs);
|
|
55
|
+
chatHistory.push({
|
|
56
|
+
role: "tool",
|
|
57
|
+
content: JSON.stringify(toolResult),
|
|
58
|
+
tool_call_id: toolCall.id,
|
|
59
|
+
});
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (shouldAskUserForInput) {
|
|
63
|
+
userPrompt = await human_in_the_loop_1.humanLoop.getFeedback({
|
|
64
|
+
message: "Your response?",
|
|
65
|
+
});
|
|
66
|
+
chatHistory.push({ role: "user", content: userPrompt });
|
|
67
|
+
shouldAskUserForInput = false;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
response = await llm.createChatCompletion({
|
|
71
|
+
model: "gpt-4o",
|
|
72
|
+
messages: chatHistory,
|
|
73
|
+
tools: [test_run_1.schema, codegen_agent_1.schema, browser_agent_1.schema],
|
|
74
|
+
});
|
|
75
|
+
if (!response) {
|
|
76
|
+
throw new Error("No response from LLM");
|
|
77
|
+
}
|
|
78
|
+
chatHistory.push(response);
|
|
79
|
+
if (response.tool_calls) {
|
|
80
|
+
pendingToolCalls.push(...response.tool_calls);
|
|
81
|
+
}
|
|
82
|
+
else if (response.content) {
|
|
83
|
+
console.log("Assistant response:", response.content);
|
|
84
|
+
shouldAskUserForInput = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return chatHistory;
|
|
88
|
+
}
|
|
89
|
+
exports.chatAgent = chatAgent;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
-
import type { TestCase
|
|
3
|
-
export declare function createEmptyTestCaseBlock({ testCase, file,
|
|
2
|
+
import type { TestCase } from "@empiricalrun/shared-types";
|
|
3
|
+
export declare function createEmptyTestCaseBlock({ testCase, file, trace, }: {
|
|
4
4
|
testCase: TestCase;
|
|
5
5
|
file: string;
|
|
6
|
-
options?: TestGenConfigOptions;
|
|
7
6
|
trace?: TraceClient;
|
|
8
7
|
}): Promise<string | undefined>;
|
|
9
8
|
//# sourceMappingURL=create-test-block.d.ts.map
|
|
@@ -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;AAC3B,OAAO,KAAK,
|
|
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;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAc3D,wBAAsB,wBAAwB,CAAC,EAC7C,QAAQ,EACR,IAAI,EACJ,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,+BA+CA"}
|
|
@@ -8,7 +8,7 @@ const web_1 = require("../../bin/utils/platform/web");
|
|
|
8
8
|
const constants_1 = require("../../constants");
|
|
9
9
|
const promptTemplate_0 = "{{#section \"system\"}}\nYou are a software test engineer who is given a task to write an empty test block.\nBased on the inputs you need to create an empty playwright test block with correctly imported fixture.\n\nThe test will contain a test name which you will need to use to build the empty test case block.\n\nYou will be provided with current tests, fixtures and page object models for you to use and create test case block as\nper the task provided to you.\n\nBefore responding you need to ensure that the code change is minimal and the change is reusable across tests. You need\nto ensure the code follows DRY principle.\n\nHere is the list of current tests and fixtures:\n\n{{testFiles}}\n\nHere is the list of current page object models:\n\n{{pageFiles}}\n{{/section}}\n\n{{#section \"user\"}}\nFollowing is the test scenario for which you need to write the empty test case block:\ntest name:\n{{scenarioName}}\n\ntask:\ncreate an empty test case block for the following test steps:\n{{scenario}}\n\ntest file path: {{scenarioFile}}\n\n------\n\nYou also need to ensure that the empty test case block has a starting page to begin test.\n\nIn order to identify the right page with which the test should start, follow the steps:\n- based on the similarities with other test cases mentioned in the file, identify the right page fixture to be imported\n- Read the page fixture methods step by step. Identify whether the fixture handles navigating to a page.\n- Identify whether other tests using the page fixture had to add separate steps for navigation or not\n- Based on the above analysis there will be following cases and choose either for the given test scenario:\n-- Case 1: if the test case scenario provided inside the task mentions about page navigation, then use that page\nnavigation. skip other cases if this case is satisfied.\n-- Case 2: refer other test cases which import similar fixtures and infer the first page navigation of this test case.\nYou should prefer tests which are in the same file. Tests within same file have higher overlaps in first page\nnavigation.\n- Once the page fixture is decided, look for userContext fixture in files. If its available then add \"userContext\" to\nthe test case block\n\n\n\nFollow these instructions before responding with output:\n- Read the code line by line and achieve the task provided to you\n- Read the dependencies of the code block by scanning through file paths and file provided to you. refer the same file\npath while responding with update\n- Focus only on the test case provided and associated JS methods called from the test case.\n- Respond only with the new empty test case block to be created and nothing else.\n- DO NOT respond with any backticks or markdown syntax\n- If \"userContext\" fixture is available in fixtures file, ensure importing that fixture in the test case block.\n- Provide a reason based on the test steps provided to you on why you chose the fixture or page.goto statement. The\nreason should be one of the list steps provided to you and mention why the case was chosen\n{{/section}}";
|
|
10
10
|
const session_1 = require("../../session");
|
|
11
|
-
async function createEmptyTestCaseBlock({ testCase, file,
|
|
11
|
+
async function createEmptyTestCaseBlock({ testCase, file, trace, }) {
|
|
12
12
|
const logger = new logger_1.CustomLogger({ useReporter: false });
|
|
13
13
|
logger.log("Creating new test block");
|
|
14
14
|
const context = await (0, context_1.contextForGeneration)(file);
|
|
@@ -20,10 +20,6 @@ async function createEmptyTestCaseBlock({ testCase, file, options, trace, }) {
|
|
|
20
20
|
name: "create-empty-test-block",
|
|
21
21
|
id: crypto.randomUUID(),
|
|
22
22
|
release: session.version,
|
|
23
|
-
tags: [
|
|
24
|
-
options?.metadata.projectName || "",
|
|
25
|
-
options?.metadata.environment || "",
|
|
26
|
-
].filter((s) => !!s),
|
|
27
23
|
});
|
|
28
24
|
const promptSpan = trace?.span({
|
|
29
25
|
name: "build-create-empty-test-case-prompt",
|
|
@@ -38,15 +34,14 @@ async function createEmptyTestCaseBlock({ testCase, file, options, trace, }) {
|
|
|
38
34
|
promptSpan?.end({ output: { prompt } });
|
|
39
35
|
const llm = new llm_1.LLM({
|
|
40
36
|
trace,
|
|
41
|
-
provider:
|
|
42
|
-
defaultModel:
|
|
43
|
-
providerApiKey: constants_1.MODEL_API_KEYS[
|
|
37
|
+
provider: constants_1.DEFAULT_MODEL_PROVIDER,
|
|
38
|
+
defaultModel: constants_1.DEFAULT_MODEL,
|
|
39
|
+
providerApiKey: constants_1.MODEL_API_KEYS[constants_1.DEFAULT_MODEL_PROVIDER],
|
|
44
40
|
});
|
|
45
41
|
const firstShotMessage = await llm.createChatCompletion({
|
|
46
42
|
messages: prompt,
|
|
47
43
|
modelParameters: {
|
|
48
44
|
...constants_1.DEFAULT_MODEL_PARAMETERS,
|
|
49
|
-
...options?.modelParameters,
|
|
50
45
|
},
|
|
51
46
|
});
|
|
52
47
|
const markdownRemoverSpan = trace?.span({
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
-
import type { TestCase
|
|
2
|
+
import type { TestCase } from "@empiricalrun/shared-types";
|
|
3
3
|
import { CustomLogger } from "../../bin/logger";
|
|
4
|
-
export declare function validateAndFixTypescriptErrors({ trace, logger, file, pomCode, nonSpecFileCode, testCase,
|
|
4
|
+
export declare function validateAndFixTypescriptErrors({ trace, logger, file, pomCode, nonSpecFileCode, testCase, }: {
|
|
5
5
|
trace?: TraceClient;
|
|
6
6
|
logger?: CustomLogger;
|
|
7
7
|
file: string;
|
|
8
8
|
pomCode: string;
|
|
9
9
|
nonSpecFileCode: string;
|
|
10
10
|
testCase: TestCase;
|
|
11
|
-
options?: TestGenConfigOptions;
|
|
12
11
|
}): Promise<void>;
|
|
13
12
|
//# sourceMappingURL=fix-ts-errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fix-ts-errors.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/fix-ts-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"fix-ts-errors.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/fix-ts-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAG3D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAUhD,wBAAsB,8BAA8B,CAAC,EACnD,KAAK,EACL,MAA2B,EAC3B,IAAI,EACJ,OAAO,EACP,eAAe,EACf,QAAQ,GACT,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;CACpB,iBAsEA"}
|
|
@@ -10,7 +10,7 @@ const logger_1 = require("../../bin/logger");
|
|
|
10
10
|
const web_1 = require("../../bin/utils/platform/web");
|
|
11
11
|
const constants_1 = require("../../constants");
|
|
12
12
|
const promptTemplate_0 = "{{#section \"system\"}}\nYou are a software engineer who is given a task to fix semantic and syntactical errors in a typescript file\n'{{scenarioFile}}' provided to you.\nYou will be provided with fixtures and page object models to use and fix errors.\n\nHere is the list of fixtures available:\n\n{{fixtureFiles}}\n\nHere is the list of current page object models available to you:\n\n{{pageFiles}}\n\nUse the above files to fix the errors.\n\nFollow these guidelines before responding with output\n- Ensure there are no type issues in the given {{scenarioFile}} file\n- For the given file respond with only the code\n- Do not respond with markdown syntax or backticks\n- Do not modify anything else apart from the code required to fix typescript error\n- Do not modify any other scenarios apart from the provided scenario name\n- Do not respond with any explanation. Respond only with the updated code.\n{{/section}}\n\n{{#section \"user\"}}\n'{{scenarioFile}}' with scenario name '{{scenarioName}}', has following typescript errors which you need to fix:\n{{errors}}\n\nHere is the content of the '{{scenarioFile}}':\n\n{{fileContent}}\n{{/section}}";
|
|
13
|
-
async function validateAndFixTypescriptErrors({ trace, logger = new logger_1.CustomLogger(), file, pomCode, nonSpecFileCode, testCase,
|
|
13
|
+
async function validateAndFixTypescriptErrors({ trace, logger = new logger_1.CustomLogger(), file, pomCode, nonSpecFileCode, testCase, }) {
|
|
14
14
|
const validateTypesSpan = trace?.span({ name: "detect-type-errors-in-file" });
|
|
15
15
|
logger.log("Validating types...");
|
|
16
16
|
let errors = (0, web_1.validateTypescript)(file);
|
|
@@ -46,15 +46,14 @@ async function validateAndFixTypescriptErrors({ trace, logger = new logger_1.Cus
|
|
|
46
46
|
promptSpan?.end({ output: { instruction } });
|
|
47
47
|
const llm = new llm_1.LLM({
|
|
48
48
|
trace,
|
|
49
|
-
provider:
|
|
50
|
-
defaultModel:
|
|
51
|
-
providerApiKey: constants_1.MODEL_API_KEYS[
|
|
49
|
+
provider: constants_1.DEFAULT_MODEL_PROVIDER,
|
|
50
|
+
defaultModel: constants_1.DEFAULT_MODEL,
|
|
51
|
+
providerApiKey: constants_1.MODEL_API_KEYS[constants_1.DEFAULT_MODEL_PROVIDER],
|
|
52
52
|
});
|
|
53
53
|
const message = await llm.createChatCompletion({
|
|
54
54
|
messages: instruction,
|
|
55
55
|
modelParameters: {
|
|
56
56
|
...constants_1.DEFAULT_MODEL_PARAMETERS,
|
|
57
|
-
...options?.modelParameters,
|
|
58
57
|
},
|
|
59
58
|
});
|
|
60
59
|
const response = message?.content || "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-code-apply-changes.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/generate-code-apply-changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQrE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"generate-code-apply-changes.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/generate-code-apply-changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQrE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAMhD,OAAO,EAAsB,UAAU,EAAE,MAAM,SAAS,CAAC;AAqLzD,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,UAkD3D;AA2DD,wBAAsB,2BAA2B,CAAC,EAChD,IAAI,EACJ,KAAK,EACL,MAAM,EACN,gBAAgB,GACjB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,gBAAgB,EAAE,MAAM,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC,CAAC;CACjE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAuIxB"}
|
|
@@ -8,9 +8,8 @@ const llm_1 = require("@empiricalrun/llm");
|
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const constants_1 = require("../../constants");
|
|
11
|
-
const utils_1 = require("../utils");
|
|
12
11
|
const types_1 = require("./types");
|
|
13
|
-
const
|
|
12
|
+
const utils_1 = require("./utils");
|
|
14
13
|
function getCodeEditorToolCalls() {
|
|
15
14
|
const strReplace = {
|
|
16
15
|
name: "code-block-replace",
|
|
@@ -160,7 +159,7 @@ async function getPlanForCodeEditorAgent({ prompt, trace, }) {
|
|
|
160
159
|
}
|
|
161
160
|
if (completion.tool_calls[0].function.name === "change_plan") {
|
|
162
161
|
const args = completion.tool_calls[0].function.arguments;
|
|
163
|
-
const plan =
|
|
162
|
+
const plan = JSON.parse(args).plan;
|
|
164
163
|
return plan;
|
|
165
164
|
}
|
|
166
165
|
}
|
|
@@ -342,7 +341,7 @@ async function generateCodeAndApplyChanges({ task, trace, logger, getRelevantFil
|
|
|
342
341
|
}
|
|
343
342
|
await Promise.all(createFileToolCalls.map((tc) => {
|
|
344
343
|
return (async () => {
|
|
345
|
-
const args =
|
|
344
|
+
const args = JSON.parse(tc.function.arguments);
|
|
346
345
|
updatedFiles.push({
|
|
347
346
|
filePath: args.filePath,
|
|
348
347
|
oldCode: "",
|
|
@@ -360,13 +359,13 @@ async function generateCodeAndApplyChanges({ task, trace, logger, getRelevantFil
|
|
|
360
359
|
}
|
|
361
360
|
// Filter out the tool calls which are for replacing code in existing files
|
|
362
361
|
const fileChanges = strReplaceToolCalls
|
|
363
|
-
.map((toolCall) =>
|
|
362
|
+
.map((toolCall) => JSON.parse(toolCall.function.arguments))
|
|
364
363
|
.filter((f) => f.filePath && fs_extra_1.default.existsSync(f.filePath));
|
|
365
364
|
// We add all the suggested changes to the updatedFiles array
|
|
366
365
|
// This is used to validate and format files later
|
|
367
366
|
updatedFiles.push(...fileChanges);
|
|
368
367
|
// applyChangesResponse contains the errors occurred while applying the changes
|
|
369
|
-
const updates = await (0,
|
|
368
|
+
const updates = await (0, utils_1.applyFileChangesUsingStrReplace)({
|
|
370
369
|
trace: codeEditorSpan,
|
|
371
370
|
fileChanges,
|
|
372
371
|
logger,
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
-
import type { TestCase
|
|
2
|
+
import type { TestCase } from "@empiricalrun/shared-types";
|
|
3
3
|
import OpenAI from "openai";
|
|
4
|
-
import { CustomLogger } from "../../bin/logger";
|
|
5
4
|
import { CreateTestCodeUpdate } from "./types";
|
|
6
5
|
export declare function createTestWithCodeAgent({ testCase, file, repoFiles, trace, }: {
|
|
7
6
|
testCase: TestCase;
|
|
8
7
|
file: string;
|
|
9
8
|
repoFiles: string | undefined;
|
|
10
9
|
trace?: TraceClient;
|
|
11
|
-
logger?: CustomLogger;
|
|
12
10
|
}): Promise<{
|
|
13
11
|
prompt: OpenAI.Chat.Completions.ChatCompletionMessageParam[];
|
|
14
12
|
agentResponse: string;
|
|
15
13
|
fileChanges: CreateTestCodeUpdate[];
|
|
16
14
|
}>;
|
|
17
|
-
export declare function
|
|
15
|
+
export declare function generateTestWithCodegen({ testCase, file, trace, }: {
|
|
16
|
+
testCase: TestCase;
|
|
17
|
+
file: string;
|
|
18
|
+
trace?: TraceClient;
|
|
19
|
+
}): Promise<TestCase[] | void>;
|
|
18
20
|
//# 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,EAAsB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAc5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAQ/C,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;CACrB,GAAG,OAAO,CAAC;IACV,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,0BAA0B,EAAE,CAAC;IAC7D,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,oBAAoB,EAAE,CAAC;CACrC,CAAC,CAyDD;AAED,wBAAsB,uBAAuB,CAAC,EAC5C,QAAQ,EACR,IAAI,EACJ,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,GAAG,OAAO,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,CAgE7B"}
|
|
@@ -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.
|
|
6
|
+
exports.generateTestWithCodegen = 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");
|
|
@@ -65,7 +65,7 @@ ${testCase.steps.join("\n")}`;
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
exports.createTestWithCodeAgent = createTestWithCodeAgent;
|
|
68
|
-
async function
|
|
68
|
+
async function generateTestWithCodegen({ testCase, file, trace, }) {
|
|
69
69
|
const logger = new logger_1.CustomLogger();
|
|
70
70
|
if (!fs_extra_1.default.existsSync(file)) {
|
|
71
71
|
logger.log(`Creating a new spec file: ${file}`);
|
|
@@ -82,7 +82,11 @@ async function generateTest(testCase, file, options, trace) {
|
|
|
82
82
|
const isUpdate = !!testBlock;
|
|
83
83
|
if (isUpdate) {
|
|
84
84
|
logger.log(`Updating the test '${testCase.name}': [View trace](${trace?.getTraceUrl()})`);
|
|
85
|
-
return await (0, update_flow_1.updateTest)(
|
|
85
|
+
return await (0, update_flow_1.updateTest)({
|
|
86
|
+
testCase,
|
|
87
|
+
file,
|
|
88
|
+
trace,
|
|
89
|
+
});
|
|
86
90
|
}
|
|
87
91
|
const testgenUpdatesReporter = new reporter_1.TestGenUpdatesReporter();
|
|
88
92
|
void testgenUpdatesReporter.sendMessage(`Updating test code as per the task. \n View [trace](${trace?.getTraceUrl()})`);
|
|
@@ -94,7 +98,6 @@ async function generateTest(testCase, file, options, trace) {
|
|
|
94
98
|
file,
|
|
95
99
|
repoFiles,
|
|
96
100
|
trace,
|
|
97
|
-
logger,
|
|
98
101
|
});
|
|
99
102
|
await (0, utils_1.applyFileChangesForCreateTest)({
|
|
100
103
|
trace,
|
|
@@ -114,6 +117,5 @@ async function generateTest(testCase, file, options, trace) {
|
|
|
114
117
|
}
|
|
115
118
|
})();
|
|
116
119
|
}));
|
|
117
|
-
await (0, llm_1.flushAllTraces)();
|
|
118
120
|
}
|
|
119
|
-
exports.
|
|
121
|
+
exports.generateTestWithCodegen = generateTestWithCodegen;
|