@empiricalrun/playwright-utils 0.22.6 → 0.23.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 +19 -0
- package/bundled/test-gen/actions/assert.d.ts +4 -0
- package/bundled/test-gen/actions/assert.d.ts.map +1 -0
- package/bundled/test-gen/actions/assert.js +50 -0
- package/bundled/test-gen/actions/click.d.ts +4 -0
- package/bundled/test-gen/actions/click.d.ts.map +1 -0
- package/bundled/test-gen/actions/click.js +51 -0
- package/bundled/test-gen/actions/constants/index.d.ts +2 -0
- package/bundled/test-gen/actions/constants/index.d.ts.map +1 -0
- package/bundled/test-gen/actions/constants/index.js +4 -0
- package/bundled/test-gen/actions/done.d.ts +4 -0
- package/bundled/test-gen/actions/done.d.ts.map +1 -0
- package/bundled/test-gen/actions/done.js +30 -0
- package/bundled/test-gen/actions/fill.d.ts +4 -0
- package/bundled/test-gen/actions/fill.d.ts.map +1 -0
- package/bundled/test-gen/actions/fill.js +82 -0
- package/bundled/test-gen/actions/goto.d.ts +4 -0
- package/bundled/test-gen/actions/goto.d.ts.map +1 -0
- package/bundled/test-gen/actions/goto.js +47 -0
- package/bundled/test-gen/actions/hover.d.ts +4 -0
- package/bundled/test-gen/actions/hover.d.ts.map +1 -0
- package/bundled/test-gen/actions/hover.js +51 -0
- package/bundled/test-gen/actions/index.d.ts +30 -0
- package/bundled/test-gen/actions/index.d.ts.map +1 -0
- package/bundled/test-gen/actions/index.js +159 -0
- package/bundled/test-gen/actions/next-task.d.ts +53 -0
- package/bundled/test-gen/actions/next-task.d.ts.map +1 -0
- package/bundled/test-gen/actions/next-task.js +58 -0
- package/bundled/test-gen/actions/press.d.ts +4 -0
- package/bundled/test-gen/actions/press.d.ts.map +1 -0
- package/bundled/test-gen/actions/press.js +56 -0
- package/bundled/test-gen/actions/skill.d.ts +21 -0
- package/bundled/test-gen/actions/skill.d.ts.map +1 -0
- package/bundled/test-gen/actions/skill.js +127 -0
- package/bundled/test-gen/actions/text-content.d.ts +4 -0
- package/bundled/test-gen/actions/text-content.d.ts.map +1 -0
- package/bundled/test-gen/actions/text-content.js +58 -0
- package/bundled/test-gen/actions/utils/index.d.ts +10 -0
- package/bundled/test-gen/actions/utils/index.d.ts.map +1 -0
- package/bundled/test-gen/actions/utils/index.js +109 -0
- package/bundled/test-gen/agent/browsing/index.d.ts +15 -0
- package/bundled/test-gen/agent/browsing/index.d.ts.map +1 -0
- package/bundled/test-gen/agent/browsing/index.js +68 -0
- package/bundled/test-gen/agent/browsing/run.d.ts +19 -0
- package/bundled/test-gen/agent/browsing/run.d.ts.map +1 -0
- package/bundled/test-gen/agent/browsing/run.js +88 -0
- package/bundled/test-gen/agent/browsing/utils.d.ts +41 -0
- package/bundled/test-gen/agent/browsing/utils.d.ts.map +1 -0
- package/bundled/test-gen/agent/browsing/utils.js +406 -0
- package/bundled/test-gen/agent/codegen/create-test-block.d.ts +9 -0
- package/bundled/test-gen/agent/codegen/create-test-block.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/create-test-block.js +63 -0
- package/bundled/test-gen/agent/codegen/fix-ts-errors.d.ts +13 -0
- package/bundled/test-gen/agent/codegen/fix-ts-errors.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/fix-ts-errors.js +80 -0
- package/bundled/test-gen/agent/codegen/generate-code-apply-changes.d.ts +13 -0
- package/bundled/test-gen/agent/codegen/generate-code-apply-changes.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/generate-code-apply-changes.js +381 -0
- package/bundled/test-gen/agent/codegen/lexical-scoped-vars.d.ts +9 -0
- package/bundled/test-gen/agent/codegen/lexical-scoped-vars.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/lexical-scoped-vars.js +56 -0
- package/bundled/test-gen/agent/codegen/repo-edit.d.ts +23 -0
- package/bundled/test-gen/agent/codegen/repo-edit.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/repo-edit.js +86 -0
- package/bundled/test-gen/agent/codegen/run.d.ts +16 -0
- package/bundled/test-gen/agent/codegen/run.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/run.js +119 -0
- package/bundled/test-gen/agent/codegen/skills-retriever.d.ts +26 -0
- package/bundled/test-gen/agent/codegen/skills-retriever.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/skills-retriever.js +93 -0
- package/bundled/test-gen/agent/codegen/test-update-feedback.d.ts +12 -0
- package/bundled/test-gen/agent/codegen/test-update-feedback.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/test-update-feedback.js +50 -0
- package/bundled/test-gen/agent/codegen/types.d.ts +25 -0
- package/bundled/test-gen/agent/codegen/types.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/types.js +8 -0
- package/bundled/test-gen/agent/codegen/update-flow.d.ts +34 -0
- package/bundled/test-gen/agent/codegen/update-flow.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/update-flow.js +300 -0
- package/bundled/test-gen/agent/codegen/use-skill.d.ts +11 -0
- package/bundled/test-gen/agent/codegen/use-skill.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/use-skill.js +54 -0
- package/bundled/test-gen/agent/codegen/utils.d.ts +126 -0
- package/bundled/test-gen/agent/codegen/utils.d.ts.map +1 -0
- package/bundled/test-gen/agent/codegen/utils.js +416 -0
- package/bundled/test-gen/agent/diagnosis-agent/index.d.ts +18 -0
- package/bundled/test-gen/agent/diagnosis-agent/index.d.ts.map +1 -0
- package/bundled/test-gen/agent/diagnosis-agent/index.js +105 -0
- package/bundled/test-gen/agent/diagnosis-agent/strict-mode-violation.d.ts +9 -0
- package/bundled/test-gen/agent/diagnosis-agent/strict-mode-violation.d.ts.map +1 -0
- package/bundled/test-gen/agent/diagnosis-agent/strict-mode-violation.js +31 -0
- package/bundled/test-gen/agent/enrich-prompt/index.d.ts +12 -0
- package/bundled/test-gen/agent/enrich-prompt/index.d.ts.map +1 -0
- package/bundled/test-gen/agent/enrich-prompt/index.js +81 -0
- package/bundled/test-gen/agent/enrich-prompt/utils.d.ts +6 -0
- package/bundled/test-gen/agent/enrich-prompt/utils.d.ts.map +1 -0
- package/bundled/test-gen/agent/enrich-prompt/utils.js +12 -0
- package/bundled/test-gen/agent/infer-agent/index.d.ts +10 -0
- package/bundled/test-gen/agent/infer-agent/index.d.ts.map +1 -0
- package/bundled/test-gen/agent/infer-agent/index.js +70 -0
- package/bundled/test-gen/agent/master/action-tool-calls.d.ts +42 -0
- package/bundled/test-gen/agent/master/action-tool-calls.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/action-tool-calls.js +87 -0
- package/bundled/test-gen/agent/master/browser-tests/fixtures.d.ts +9 -0
- package/bundled/test-gen/agent/master/browser-tests/fixtures.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/browser-tests/fixtures.js +33 -0
- package/bundled/test-gen/agent/master/browser-tests/index.spec.d.ts +2 -0
- package/bundled/test-gen/agent/master/browser-tests/index.spec.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/browser-tests/index.spec.js +113 -0
- package/bundled/test-gen/agent/master/browser-tests/skills.spec.d.ts +2 -0
- package/bundled/test-gen/agent/master/browser-tests/skills.spec.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/browser-tests/skills.spec.js +109 -0
- package/bundled/test-gen/agent/master/element-annotation.d.ts +30 -0
- package/bundled/test-gen/agent/master/element-annotation.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/element-annotation.js +195 -0
- package/bundled/test-gen/agent/master/execute-browser-action.d.ts +24 -0
- package/bundled/test-gen/agent/master/execute-browser-action.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/execute-browser-action.js +124 -0
- package/bundled/test-gen/agent/master/execute-skill-action.d.ts +11 -0
- package/bundled/test-gen/agent/master/execute-skill-action.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/execute-skill-action.js +25 -0
- package/bundled/test-gen/agent/master/icon-descriptor/index.d.ts +22 -0
- package/bundled/test-gen/agent/master/icon-descriptor/index.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/icon-descriptor/index.js +250 -0
- package/bundled/test-gen/agent/master/icon-descriptor/normalize-svg.d.ts +2 -0
- package/bundled/test-gen/agent/master/icon-descriptor/normalize-svg.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/icon-descriptor/normalize-svg.js +248 -0
- package/bundled/test-gen/agent/master/next-action.d.ts +22 -0
- package/bundled/test-gen/agent/master/next-action.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/next-action.js +104 -0
- package/bundled/test-gen/agent/master/planner.d.ts +15 -0
- package/bundled/test-gen/agent/master/planner.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/planner.js +144 -0
- package/bundled/test-gen/agent/master/run.d.ts +15 -0
- package/bundled/test-gen/agent/master/run.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/run.js +274 -0
- package/bundled/test-gen/agent/master/scroller.d.ts +15 -0
- package/bundled/test-gen/agent/master/scroller.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/scroller.js +375 -0
- package/bundled/test-gen/agent/master/with-hints.d.ts +17 -0
- package/bundled/test-gen/agent/master/with-hints.d.ts.map +1 -0
- package/bundled/test-gen/agent/master/with-hints.js +102 -0
- package/bundled/test-gen/agent/planner/run-time-planner.d.ts +15 -0
- package/bundled/test-gen/agent/planner/run-time-planner.d.ts.map +1 -0
- package/bundled/test-gen/agent/planner/run-time-planner.js +100 -0
- package/bundled/test-gen/agent/planner/run.d.ts +7 -0
- package/bundled/test-gen/agent/planner/run.d.ts.map +1 -0
- package/bundled/test-gen/agent/planner/run.js +127 -0
- package/bundled/test-gen/agent/utils.d.ts +2 -0
- package/bundled/test-gen/agent/utils.d.ts.map +1 -0
- package/bundled/test-gen/agent/utils.js +12 -0
- package/bundled/test-gen/bin/index.d.ts +3 -0
- package/bundled/test-gen/bin/index.d.ts.map +1 -0
- package/bundled/test-gen/bin/index.js +212 -0
- package/bundled/test-gen/bin/logger/index.d.ts +14 -0
- package/bundled/test-gen/bin/logger/index.d.ts.map +1 -0
- package/bundled/test-gen/bin/logger/index.js +57 -0
- package/bundled/test-gen/bin/utils/context.d.ts +13 -0
- package/bundled/test-gen/bin/utils/context.d.ts.map +1 -0
- package/bundled/test-gen/bin/utils/context.js +67 -0
- package/bundled/test-gen/bin/utils/fs/index.d.ts +6 -0
- package/bundled/test-gen/bin/utils/fs/index.d.ts.map +1 -0
- package/bundled/test-gen/bin/utils/fs/index.js +63 -0
- package/bundled/test-gen/bin/utils/index.d.ts +9 -0
- package/bundled/test-gen/bin/utils/index.d.ts.map +1 -0
- package/bundled/test-gen/bin/utils/index.js +64 -0
- package/bundled/test-gen/bin/utils/platform/web/index.d.ts +78 -0
- package/bundled/test-gen/bin/utils/platform/web/index.d.ts.map +1 -0
- package/bundled/test-gen/bin/utils/platform/web/index.js +544 -0
- package/bundled/test-gen/bin/utils/platform/web/test-files/ts-path-import-validate.d.ts +2 -0
- package/bundled/test-gen/bin/utils/platform/web/test-files/ts-path-import-validate.d.ts.map +1 -0
- package/bundled/test-gen/bin/utils/platform/web/test-files/ts-path-import-validate.js +7 -0
- package/bundled/test-gen/bin/utils/scenarios/index.d.ts +6 -0
- package/bundled/test-gen/bin/utils/scenarios/index.d.ts.map +1 -0
- package/bundled/test-gen/bin/utils/scenarios/index.js +57 -0
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.js +615 -0
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.spec.d.ts +2 -0
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.spec.d.ts.map +1 -0
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.spec.js +207 -0
- package/bundled/test-gen/browser-injected-scripts/annotate-elements.spec.ts +332 -0
- package/bundled/test-gen/constants/index.d.ts +7 -0
- package/bundled/test-gen/constants/index.d.ts.map +1 -0
- package/bundled/test-gen/constants/index.js +18 -0
- package/bundled/test-gen/errors/index.d.ts +5 -0
- package/bundled/test-gen/errors/index.d.ts.map +1 -0
- package/bundled/test-gen/errors/index.js +9 -0
- package/bundled/test-gen/evals/add-scenario-agent.evals.d.ts +4 -0
- package/bundled/test-gen/evals/add-scenario-agent.evals.d.ts.map +1 -0
- package/bundled/test-gen/evals/add-scenario-agent.evals.js +44 -0
- package/bundled/test-gen/evals/append-create-test-agent.evals.d.ts +4 -0
- package/bundled/test-gen/evals/append-create-test-agent.evals.d.ts.map +1 -0
- package/bundled/test-gen/evals/append-create-test-agent.evals.js +117 -0
- package/bundled/test-gen/evals/fetch-pom-skills-agent.evals.d.ts +4 -0
- package/bundled/test-gen/evals/fetch-pom-skills-agent.evals.d.ts.map +1 -0
- package/bundled/test-gen/evals/fetch-pom-skills-agent.evals.js +36 -0
- package/bundled/test-gen/evals/infer-master-or-code-agent.evals.d.ts +4 -0
- package/bundled/test-gen/evals/infer-master-or-code-agent.evals.d.ts.map +1 -0
- package/bundled/test-gen/evals/infer-master-or-code-agent.evals.js +22 -0
- package/bundled/test-gen/evals/master-agent.evals.d.ts +4 -0
- package/bundled/test-gen/evals/master-agent.evals.d.ts.map +1 -0
- package/bundled/test-gen/evals/master-agent.evals.js +35 -0
- package/bundled/test-gen/evals/type.d.ts +12 -0
- package/bundled/test-gen/evals/type.d.ts.map +1 -0
- package/bundled/test-gen/evals/type.js +2 -0
- package/bundled/test-gen/evals/update-scenario-agent.evals.d.ts +4 -0
- package/bundled/test-gen/evals/update-scenario-agent.evals.d.ts.map +1 -0
- package/bundled/test-gen/evals/update-scenario-agent.evals.js +47 -0
- package/bundled/test-gen/file/client.d.ts +14 -0
- package/bundled/test-gen/file/client.d.ts.map +1 -0
- package/bundled/test-gen/file/client.js +48 -0
- package/bundled/test-gen/file/server.d.ts +13 -0
- package/bundled/test-gen/file/server.d.ts.map +1 -0
- package/bundled/test-gen/file/server.js +52 -0
- package/bundled/test-gen/human-in-the-loop/cli.d.ts +2 -0
- package/bundled/test-gen/human-in-the-loop/cli.d.ts.map +1 -0
- package/bundled/test-gen/human-in-the-loop/cli.js +24 -0
- package/bundled/test-gen/human-in-the-loop/index.d.ts +12 -0
- package/bundled/test-gen/human-in-the-loop/index.d.ts.map +1 -0
- package/bundled/test-gen/human-in-the-loop/index.js +30 -0
- package/bundled/test-gen/human-in-the-loop/ipc.d.ts +4 -0
- package/bundled/test-gen/human-in-the-loop/ipc.d.ts.map +1 -0
- package/bundled/test-gen/human-in-the-loop/ipc.js +47 -0
- package/bundled/test-gen/index.d.ts +4 -0
- package/bundled/test-gen/index.d.ts.map +1 -0
- package/bundled/test-gen/index.js +55 -0
- package/bundled/test-gen/package.json +106 -0
- package/bundled/test-gen/page/index.d.ts +11 -0
- package/bundled/test-gen/page/index.d.ts.map +1 -0
- package/bundled/test-gen/page/index.js +16 -0
- package/bundled/test-gen/prompts/lib/ts-transformer.d.ts +4 -0
- package/bundled/test-gen/prompts/lib/ts-transformer.d.ts.map +1 -0
- package/bundled/test-gen/prompts/lib/ts-transformer.js +92 -0
- package/bundled/test-gen/reporter/index.d.ts +33 -0
- package/bundled/test-gen/reporter/index.d.ts.map +1 -0
- package/bundled/test-gen/reporter/index.js +161 -0
- package/bundled/test-gen/session/index.d.ts +20 -0
- package/bundled/test-gen/session/index.d.ts.map +1 -0
- package/bundled/test-gen/session/index.js +105 -0
- package/bundled/test-gen/test-build/index.d.ts +10 -0
- package/bundled/test-gen/test-build/index.d.ts.map +1 -0
- package/bundled/test-gen/test-build/index.js +30 -0
- package/bundled/test-gen/types/index.d.ts +69 -0
- package/bundled/test-gen/types/index.d.ts.map +1 -0
- package/bundled/test-gen/types/index.js +2 -0
- package/bundled/test-gen/uploader/index.d.ts +26 -0
- package/bundled/test-gen/uploader/index.d.ts.map +1 -0
- package/bundled/test-gen/uploader/index.js +102 -0
- package/bundled/test-gen/utils/env.d.ts +2 -0
- package/bundled/test-gen/utils/env.d.ts.map +1 -0
- package/bundled/test-gen/utils/env.js +9 -0
- package/bundled/test-gen/utils/exec.d.ts +4 -0
- package/bundled/test-gen/utils/exec.d.ts.map +1 -0
- package/bundled/test-gen/utils/exec.js +45 -0
- package/bundled/test-gen/utils/file.d.ts +2 -0
- package/bundled/test-gen/utils/file.d.ts.map +1 -0
- package/bundled/test-gen/utils/file.js +25 -0
- package/bundled/test-gen/utils/html.d.ts +4 -0
- package/bundled/test-gen/utils/html.d.ts.map +1 -0
- package/bundled/test-gen/utils/html.js +46 -0
- package/bundled/test-gen/utils/index.d.ts +2 -0
- package/bundled/test-gen/utils/index.d.ts.map +1 -0
- package/bundled/test-gen/utils/index.js +5 -0
- package/bundled/test-gen/utils/pw-test.d.ts +3 -0
- package/bundled/test-gen/utils/pw-test.d.ts.map +1 -0
- package/bundled/test-gen/utils/pw-test.js +26 -0
- package/bundled/test-gen/utils/slug.d.ts +2 -0
- package/bundled/test-gen/utils/slug.d.ts.map +1 -0
- package/bundled/test-gen/utils/slug.js +18 -0
- package/bundled/test-gen/utils/string.d.ts +2 -0
- package/bundled/test-gen/utils/string.d.ts.map +1 -0
- package/bundled/test-gen/utils/string.js +9 -0
- package/dist/overlay-tests/click.spec.js +1 -1
- package/package.json +3 -3
- package/scripts/prepare-publish.js +42 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.triggerHintsFlow = void 0;
|
|
4
|
+
const assert_1 = require("../../actions/assert");
|
|
5
|
+
const click_1 = require("../../actions/click");
|
|
6
|
+
const fill_1 = require("../../actions/fill");
|
|
7
|
+
const hover_1 = require("../../actions/hover");
|
|
8
|
+
const constants_1 = require("../../constants");
|
|
9
|
+
const triggerHintsFlow = async ({ outputFromGetNextAction, generatedAnnotations, actions, llm, trace, }) => {
|
|
10
|
+
try {
|
|
11
|
+
const hasElementAnnotation = outputFromGetNextAction?.elementAnnotation?.length &&
|
|
12
|
+
outputFromGetNextAction?.elementAnnotation?.trim()?.length &&
|
|
13
|
+
generatedAnnotations.some(
|
|
14
|
+
//@ts-ignore
|
|
15
|
+
(annotation) => annotation.elementID === outputFromGetNextAction?.elementAnnotation);
|
|
16
|
+
trace?.event({
|
|
17
|
+
name: "has-element-annotation",
|
|
18
|
+
output: {
|
|
19
|
+
hasElementAnnotation,
|
|
20
|
+
generatedAnnotations,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
if (!hasElementAnnotation) {
|
|
24
|
+
return {
|
|
25
|
+
shouldTriggerHintsFlow: false,
|
|
26
|
+
hintsExecutionCompletion: undefined,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const completion = await llm.createChatCompletion({
|
|
30
|
+
messages: [
|
|
31
|
+
{
|
|
32
|
+
role: "system",
|
|
33
|
+
content: `You are a browser automation agent who is given a task to generate code for navigation and assertion. This task is your goal and you must achieve it.
|
|
34
|
+
|
|
35
|
+
You need to pick the next step to achieve the task. Remember that the goal must be achieved.
|
|
36
|
+
|
|
37
|
+
Based on the goal and available tool calls you need to pick the appropriate tool call.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Instructions:
|
|
41
|
+
- Take actions one at a time. Do not try to take multiple actions
|
|
42
|
+
- You can respond with multiple assertions in one shot
|
|
43
|
+
- Stick to the task provided to you and mark the task done once the task is complete
|
|
44
|
+
- Do not execute any action which is not mentioned in the task`,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
role: "user",
|
|
48
|
+
content: [
|
|
49
|
+
{
|
|
50
|
+
type: "text",
|
|
51
|
+
text: `Task: ${outputFromGetNextAction?.action}`,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
tools: actions.getBrowsingActionSchemas(),
|
|
57
|
+
modelParameters: {
|
|
58
|
+
temperature: constants_1.DEFAULT_MODEL_PARAMETERS.temperature,
|
|
59
|
+
max_completion_tokens: constants_1.DEFAULT_MODEL_PARAMETERS.max_completion_tokens,
|
|
60
|
+
tool_choice: "required",
|
|
61
|
+
},
|
|
62
|
+
trace,
|
|
63
|
+
});
|
|
64
|
+
const canTriggerHintsFlow = completion?.tool_calls?.some((currentToolCall) => currentToolCall.function.name === fill_1.PLAYWRIGHT_FILL_ACTION_NAME ||
|
|
65
|
+
currentToolCall.function.name === click_1.PLAYWRIGHT_CLICK_ACTION_NAME ||
|
|
66
|
+
currentToolCall.function.name === hover_1.PLAYWRIGHT_HOVER_ACTION_NAME ||
|
|
67
|
+
currentToolCall.function.name ===
|
|
68
|
+
assert_1.PLAYWRIGHT_ASSERT_TEXT_VISIBILITY_ACTION_NAME);
|
|
69
|
+
trace?.event({
|
|
70
|
+
name: "can-trigger-hints-flow",
|
|
71
|
+
output: {
|
|
72
|
+
canTriggerHintsFlow,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
if (!canTriggerHintsFlow) {
|
|
76
|
+
return {
|
|
77
|
+
shouldTriggerHintsFlow: false,
|
|
78
|
+
hintsExecutionCompletion: undefined,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
shouldTriggerHintsFlow: true,
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
hintsExecutionCompletion: completion,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
console.error("Error in triggerHintsFlow", e);
|
|
89
|
+
trace?.event({
|
|
90
|
+
name: "trigger-hints-flow-error",
|
|
91
|
+
output: {
|
|
92
|
+
errorMessage: e?.message,
|
|
93
|
+
errorStack: e?.stack,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
shouldTriggerHintsFlow: false,
|
|
98
|
+
hintsExecutionCompletion: undefined,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.triggerHintsFlow = triggerHintsFlow;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TraceClient } from "@empiricalrun/llm";
|
|
2
|
+
import type { Page } from "playwright";
|
|
3
|
+
import { TestGenPage } from "../../types";
|
|
4
|
+
export declare function runtimePlanner({ trace, task, successfulActions, pages, currentPage, }: {
|
|
5
|
+
trace?: TraceClient;
|
|
6
|
+
successfulActions: string[];
|
|
7
|
+
task: string;
|
|
8
|
+
pages: Record<string, Page>;
|
|
9
|
+
currentPage: TestGenPage;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
pageName: string;
|
|
12
|
+
isDone: boolean;
|
|
13
|
+
reason: string;
|
|
14
|
+
}>;
|
|
15
|
+
//# sourceMappingURL=run-time-planner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-time-planner.d.ts","sourceRoot":"","sources":["../../../src/agent/planner/run-time-planner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,wBAAsB,cAAc,CAAC,EACnC,KAAK,EACL,IAAI,EACJ,iBAAiB,EACjB,KAAK,EACL,WAAW,GACZ,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC5B,WAAW,EAAE,WAAW,CAAC;CAC1B;;;;GA+FA"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runtimePlanner = void 0;
|
|
4
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
+
const promptTemplate_0 = "{{#section \"system\"}}\nYou are given a list of successfully executed actions that are done towards completing a task (which\nis also provided to you). Your goal is to analyse the list and determine if the task is completed.\n\nIf the task is not fully completed, identify which specific actions are missing\nand suggest next steps to complete the task. Assume that the conversation provided\nis entirely truthful and no additional actions were performed beyond those listed.\n\nThese actions were executed by AI agents using Playwright on a browser. These agents\nalready have access to browser tabs to execute actions. If there is a pending action,\none of the agents will execute it in the browser. However, they need your help to\nchoose which browser tab (= page) to use for the next action.\n\nTo fulfil your goal, follow these steps:\n- Divide the task into individual actions.\n- Compare each task action against the actions listed in the successfully executed actions list.\n- Identify which actions have been executed and which have not.\n- If all actions are executed, respond with the task as done.\n- If any actions are missing, respond with the task as not done, listing all actions\n and specifying which are complete and which are missing.\n- If provided with list of pages, based on the next pending action and previously executed\n action, identify the page on which next action needs to be taken\n{{/section}}\n\n{{#section \"user\"}}\nTask:\n{{task}}\n\n----\n\nSuccessfully executed actions:\n{{successfulActions}}\n\n----\n\nList of pages with their current URLs:\n{{pagesSummary}}\n\n\n{{/section}}\n";
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
async function runtimePlanner({ trace, task, successfulActions, pages, currentPage, }) {
|
|
8
|
+
const runTimePlannerSpan = trace?.span({
|
|
9
|
+
name: "runtime-planner",
|
|
10
|
+
input: {
|
|
11
|
+
task,
|
|
12
|
+
successfulActions,
|
|
13
|
+
currentPage,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const llm = new llm_1.LLM({ provider: "openai" });
|
|
17
|
+
// Add the current page to the page state variables
|
|
18
|
+
pages[currentPage.name] = currentPage.pwPageInstance;
|
|
19
|
+
const pagesSummary = pages
|
|
20
|
+
? Object.entries(pages).map(([pageName, page]) => `${pageName}: Currently on ${page.url()}`)
|
|
21
|
+
: [];
|
|
22
|
+
const pageNamesEnum = Object.keys(pages);
|
|
23
|
+
const response = await llm.createChatCompletion({
|
|
24
|
+
trace: runTimePlannerSpan,
|
|
25
|
+
traceName: "runtime-planner-llm",
|
|
26
|
+
model: "gpt-4o",
|
|
27
|
+
messages: (0, llm_1.compilePrompt)(promptTemplate_0, {
|
|
28
|
+
task,
|
|
29
|
+
successfulActions: successfulActions.join("\n"),
|
|
30
|
+
pagesSummary: pagesSummary.join("\n"),
|
|
31
|
+
}),
|
|
32
|
+
tools: [
|
|
33
|
+
{
|
|
34
|
+
type: "function",
|
|
35
|
+
function: {
|
|
36
|
+
name: "task_done",
|
|
37
|
+
description: "end the task by calling this method",
|
|
38
|
+
parameters: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
actions: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "actions extracted from task",
|
|
44
|
+
},
|
|
45
|
+
successful_actions: {
|
|
46
|
+
type: "string",
|
|
47
|
+
description: "successful actions mentioned in the conversation",
|
|
48
|
+
},
|
|
49
|
+
reason: {
|
|
50
|
+
type: "string",
|
|
51
|
+
description: "reasoning for identification of task status",
|
|
52
|
+
},
|
|
53
|
+
nextAction: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "next action to be taken",
|
|
56
|
+
},
|
|
57
|
+
pageName: {
|
|
58
|
+
type: "string",
|
|
59
|
+
enum: pageNamesEnum,
|
|
60
|
+
description: "page name for the next action.",
|
|
61
|
+
},
|
|
62
|
+
isDone: {
|
|
63
|
+
type: "boolean",
|
|
64
|
+
description: "whether the task is done",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
required: ["isDone", "reason", "pageName", "nextAction"],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
modelParameters: {
|
|
73
|
+
tool_choice: "required",
|
|
74
|
+
temperature: 0.5,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const toolCallResp = (response?.tool_calls || [])[0];
|
|
78
|
+
if (toolCallResp) {
|
|
79
|
+
const toolCall = (0, utils_1.parseJson)(toolCallResp.function.arguments);
|
|
80
|
+
const output = {
|
|
81
|
+
pageName: toolCall.pageName,
|
|
82
|
+
isDone: toolCall.isDone,
|
|
83
|
+
reason: toolCall.reason,
|
|
84
|
+
};
|
|
85
|
+
runTimePlannerSpan?.end({
|
|
86
|
+
output,
|
|
87
|
+
});
|
|
88
|
+
return output;
|
|
89
|
+
}
|
|
90
|
+
const output = {
|
|
91
|
+
pageName: "",
|
|
92
|
+
isDone: false,
|
|
93
|
+
reason: "LLM failed to generate a valid response",
|
|
94
|
+
};
|
|
95
|
+
runTimePlannerSpan?.end({
|
|
96
|
+
output,
|
|
97
|
+
});
|
|
98
|
+
return output;
|
|
99
|
+
}
|
|
100
|
+
exports.runtimePlanner = runtimePlanner;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/planner/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAcpE,wBAAsB,QAAQ,CAAC,EAC7B,IAAI,EACJ,QAAQ,EACR,KAAK,GACN,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,gBAwHA"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.planTask = void 0;
|
|
4
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
5
|
+
const context_1 = require("../../bin/utils/context");
|
|
6
|
+
const human_in_the_loop_1 = require("../../human-in-the-loop");
|
|
7
|
+
const promptTemplate_0 = "{{#section \"system\"}}\nYou are an expert software engineer in test and have capability to collaborate with user to generate a test plan.\nYou are given a task to provide a high level plan to create a test for a given scenario.\n\nYou will be provided with already added Playwright tests and page object object models which you can use generate the test plan.\nTest plan should be a list of bullet points and each bullet point representing each test step.\nYou will be provided with app knowledge which can help you groom the steps in the plan.\n\n{{#if humanLoopRequired}}\nDo NOT finish until you have a complete understanding of the plan and have all the minute details of how the test should look like.\n\nALWAYS VERIFY THE PLAN WITH USER BEFORE FINISHING. THE USER SHOULD BE ABLE TO REVIEW AND GIVE GO AHEAD TO THE PLAN.\n\nDO NOT FINISH UNTIL USER EXPLICITLY CONFIRMS THE PLAN IS GOOD TO GO.\n{{/if}}\n\n### Test Plan Creation Guidelines\n\n- **Create Subtasks:**\n - Read the task step by step and create subtasks from the given task.\n - Do not add any new steps that are not mentioned in the task.\n\n- **Enrich Subtasks:**\n - Read the provided app knowledge.\n - Enrich the subtasks based on the information from the app knowledge.\n\n- **Plan:**\n - Once all subtasks are enriched, list them as bullet points.\n - Each bullet point must start with one of the following actions: \n - Open page \n - Click on \n - Fill in \n - Assert \n - Hover on \n - Press \n - Extract textContent\n - Do not include any bullet points that do not start with the above actions.\n\n- **Additional Notes:**\n - The final output should only contain bullet points listing the test steps.\n - Do not add any assertions that are not mentioned in the task or app knowledge.\n - The plan should not reference the knowledge base used to generate it.\n\n{{/section}}\n\n{{#section \"user\"}}\n\nApp knowledge:\n{{appKnowledge}}\n\n-----\n\nCurrent tests and page object model references:\n{{fileContext}}\n\n------\n\nTask:\n{{task}}\n\n------\n{{/section}}";
|
|
8
|
+
const env_1 = require("../../utils/env");
|
|
9
|
+
async function planTask({ task, specPath, trace, }) {
|
|
10
|
+
let fileContext = "";
|
|
11
|
+
try {
|
|
12
|
+
const { pomPrompt, testFileContent } = await (0, context_1.contextForGeneration)(specPath);
|
|
13
|
+
fileContext = `
|
|
14
|
+
${testFileContent}
|
|
15
|
+
${pomPrompt}
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.warn("Failed to generate file context for planner", e);
|
|
20
|
+
}
|
|
21
|
+
const plannerSpan = trace?.span({
|
|
22
|
+
name: "planner",
|
|
23
|
+
input: {
|
|
24
|
+
task,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
// if the code in running in ci worker or github actions, disable human loop
|
|
28
|
+
const humanLoopRequired = !(0, env_1.isRunningOnCloud)();
|
|
29
|
+
const appKnowledge = await (0, context_1.fetchAppKnowledge)();
|
|
30
|
+
const messages = (0, llm_1.compilePrompt)(promptTemplate_0, {
|
|
31
|
+
appKnowledge,
|
|
32
|
+
fileContext,
|
|
33
|
+
task,
|
|
34
|
+
humanLoopRequired,
|
|
35
|
+
});
|
|
36
|
+
const llm = new llm_1.LLM({
|
|
37
|
+
provider: "openai",
|
|
38
|
+
defaultModel: "gpt-4o",
|
|
39
|
+
});
|
|
40
|
+
let maxRetries = 10;
|
|
41
|
+
const tools = [
|
|
42
|
+
{
|
|
43
|
+
type: "function",
|
|
44
|
+
function: {
|
|
45
|
+
name: "finish",
|
|
46
|
+
description: "Final output of the conversation",
|
|
47
|
+
parameters: {
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: {
|
|
50
|
+
plan: {
|
|
51
|
+
type: "string",
|
|
52
|
+
description: "Final plan which is verified by the user",
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
required: ["plan"],
|
|
56
|
+
additionalProperties: false,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
if (humanLoopRequired) {
|
|
62
|
+
tools.push({
|
|
63
|
+
type: "function",
|
|
64
|
+
function: {
|
|
65
|
+
name: "send_user_message",
|
|
66
|
+
description: "Send user message",
|
|
67
|
+
parameters: {
|
|
68
|
+
type: "object",
|
|
69
|
+
properties: {
|
|
70
|
+
message: {
|
|
71
|
+
type: "string",
|
|
72
|
+
description: "Message to be sent to the user for any confirmation or clarification",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
required: ["message"],
|
|
76
|
+
additionalProperties: false,
|
|
77
|
+
},
|
|
78
|
+
strict: true,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
while (maxRetries--) {
|
|
83
|
+
const response = await llm.createChatCompletion({
|
|
84
|
+
trace: plannerSpan,
|
|
85
|
+
traceName: "planner-llm",
|
|
86
|
+
messages,
|
|
87
|
+
tools,
|
|
88
|
+
modelParameters: {
|
|
89
|
+
temperature: 0.5,
|
|
90
|
+
tool_choice: "required",
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
const toolCall = response?.tool_calls?.[0];
|
|
94
|
+
const respStr = toolCall?.function.arguments;
|
|
95
|
+
const resp = JSON.parse(respStr || "{}");
|
|
96
|
+
// TODO: handle this as a part of actions handler
|
|
97
|
+
if (toolCall?.function.name === "send_user_message") {
|
|
98
|
+
const feedback = await human_in_the_loop_1.humanLoop.getFeedback({
|
|
99
|
+
message: resp.message,
|
|
100
|
+
});
|
|
101
|
+
messages.push(response);
|
|
102
|
+
messages.push({
|
|
103
|
+
role: "tool",
|
|
104
|
+
tool_call_id: toolCall?.id,
|
|
105
|
+
content: feedback,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const plan = resp.plan;
|
|
110
|
+
plannerSpan?.end({
|
|
111
|
+
output: {
|
|
112
|
+
plan,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
return plan;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// TODO: handle planner failure scenario
|
|
119
|
+
plannerSpan?.end({
|
|
120
|
+
output: {
|
|
121
|
+
plan: "",
|
|
122
|
+
error: "Failed to generate test plan",
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
return "";
|
|
126
|
+
}
|
|
127
|
+
exports.planTask = planTask;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/agent/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,OAMrC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseJson = void 0;
|
|
4
|
+
function parseJson(args) {
|
|
5
|
+
try {
|
|
6
|
+
return JSON.parse(args);
|
|
7
|
+
}
|
|
8
|
+
catch (e) {
|
|
9
|
+
console.error(`Failed to parse JSON with args ${args}`, e);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.parseJson = parseJson;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const llm_1 = require("@empiricalrun/llm");
|
|
8
|
+
const commander_1 = require("commander");
|
|
9
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
|
+
const run_1 = require("../agent/browsing/run");
|
|
11
|
+
const utils_1 = require("../agent/browsing/utils");
|
|
12
|
+
const repo_edit_1 = require("../agent/codegen/repo-edit");
|
|
13
|
+
const run_2 = require("../agent/codegen/run");
|
|
14
|
+
const diagnosis_agent_1 = require("../agent/diagnosis-agent");
|
|
15
|
+
const enrich_prompt_1 = require("../agent/enrich-prompt");
|
|
16
|
+
const infer_agent_1 = require("../agent/infer-agent");
|
|
17
|
+
const run_3 = require("../agent/planner/run");
|
|
18
|
+
const reporter_1 = require("../reporter");
|
|
19
|
+
const session_1 = require("../session");
|
|
20
|
+
const test_build_1 = require("../test-build");
|
|
21
|
+
const logger_1 = require("./logger");
|
|
22
|
+
const utils_2 = require("./utils");
|
|
23
|
+
const scenarios_1 = require("./utils/scenarios");
|
|
24
|
+
dotenv_1.default.config({
|
|
25
|
+
path: [".env.local", ".env"],
|
|
26
|
+
});
|
|
27
|
+
const flushEvents = async () => {
|
|
28
|
+
await (0, llm_1.flushAllTraces)();
|
|
29
|
+
};
|
|
30
|
+
process.on("beforeExit", async () => await flushEvents());
|
|
31
|
+
process.on("exit", async () => await flushEvents());
|
|
32
|
+
process.on("SIGINT", async () => await flushEvents());
|
|
33
|
+
process.on("SIGTERM", async () => await flushEvents());
|
|
34
|
+
async function resolveAgentUsingTask({ testCase, trace, }) {
|
|
35
|
+
const { response } = await (0, infer_agent_1.inferAgentBasedTask)({
|
|
36
|
+
task: testCase.steps.join("\n"),
|
|
37
|
+
trace,
|
|
38
|
+
});
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
async function runAgent(testGenConfig, testGenToken) {
|
|
42
|
+
const logger = new logger_1.CustomLogger();
|
|
43
|
+
const { specPath, testCase } = testGenConfig;
|
|
44
|
+
if (process.env.LOG_URL) {
|
|
45
|
+
try {
|
|
46
|
+
void new reporter_1.TestGenUpdatesReporter().sendLogUrl(process.env.LOG_URL);
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
console.warn("Failed to send log url to test gen update", e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const session = (0, session_1.getSessionDetails)();
|
|
53
|
+
const trace = llm_1.langfuseInstance?.trace({
|
|
54
|
+
name: "generate-test",
|
|
55
|
+
id: crypto.randomUUID(),
|
|
56
|
+
release: session.version,
|
|
57
|
+
tags: [
|
|
58
|
+
testGenConfig.options?.metadata.projectName || "",
|
|
59
|
+
testGenConfig.options?.metadata.environment || "",
|
|
60
|
+
].filter((s) => !!s),
|
|
61
|
+
});
|
|
62
|
+
if (await (0, session_1.shouldStopSession)()) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
let agentFromConfig = testGenConfig.options?.agent;
|
|
66
|
+
let agent = agentFromConfig || "auto";
|
|
67
|
+
trace?.update({
|
|
68
|
+
metadata: {
|
|
69
|
+
generationId: session.generationId,
|
|
70
|
+
sessionId: session.sessionId,
|
|
71
|
+
testUrl: session.testUrl,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
if (trace) {
|
|
75
|
+
try {
|
|
76
|
+
void new reporter_1.TestGenUpdatesReporter().sendAgentTraceUrl(trace.getTraceUrl());
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
console.warn("Failed to send trace url as test gen update", e);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// assuming if there is no test case specific test name, we need to update the test case name
|
|
83
|
+
if (!testCase.name) {
|
|
84
|
+
logger.success(`Generating code for the provided task. ${process.env.LOG_URL ? `[view log](${process.env.LOG_URL})` : ""}`);
|
|
85
|
+
await (0, repo_edit_1.repoEditAgent)({
|
|
86
|
+
trace,
|
|
87
|
+
task: testGenConfig.testCase.steps.join("\n"),
|
|
88
|
+
logger,
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// TODO: this needs to be moved to an orchestrator which decides what needs to be done first before executing the sub tasks
|
|
93
|
+
if (testGenConfig.testErrorDiagnosis &&
|
|
94
|
+
testGenConfig.testErrorDiagnosis.failingLine &&
|
|
95
|
+
// TODO: fix this hardcoding of user prompt - ideally its an auto fix intent
|
|
96
|
+
testCase.steps[0]?.toLowerCase().trim() == "can you please fix the test") {
|
|
97
|
+
const { task: updatedTask } = await (0, diagnosis_agent_1.createTaskUsingFailureDiagnosis)({
|
|
98
|
+
options: testGenConfig.options,
|
|
99
|
+
trace,
|
|
100
|
+
diagnosis: testGenConfig.testErrorDiagnosis,
|
|
101
|
+
});
|
|
102
|
+
if (updatedTask) {
|
|
103
|
+
testCase.steps = [updatedTask];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (!agent || agent === "auto") {
|
|
107
|
+
agent = await resolveAgentUsingTask({
|
|
108
|
+
testCase,
|
|
109
|
+
trace,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
logger.success(`Generating test using ${agent} agent. ${process.env.LOG_URL ? `[view log](${process.env.LOG_URL})` : ""}`);
|
|
113
|
+
if (testGenConfig.testErrorDiagnosis &&
|
|
114
|
+
testGenConfig.testErrorDiagnosis.failingLine) {
|
|
115
|
+
const requestedChangeResp = await (0, enrich_prompt_1.enrichPromptWithFailingLine)({
|
|
116
|
+
trace,
|
|
117
|
+
testBlock: testGenConfig.testErrorDiagnosis.failingLine,
|
|
118
|
+
testFilePath: testGenConfig.testErrorDiagnosis.failingFile,
|
|
119
|
+
suggestionForFix: testCase.steps.join("\n"),
|
|
120
|
+
});
|
|
121
|
+
testCase.steps = [requestedChangeResp.output];
|
|
122
|
+
}
|
|
123
|
+
if (agent === "plan") {
|
|
124
|
+
const task = testCase.steps.join("\n");
|
|
125
|
+
const plan = await (0, run_3.planTask)({
|
|
126
|
+
task,
|
|
127
|
+
specPath,
|
|
128
|
+
trace,
|
|
129
|
+
});
|
|
130
|
+
new logger_1.CustomLogger({ useReporter: false }).log("Generated Plan:");
|
|
131
|
+
console.log(plan);
|
|
132
|
+
await new reporter_1.TestGenUpdatesReporter().sendMessage(plan);
|
|
133
|
+
}
|
|
134
|
+
else if (agent === "code") {
|
|
135
|
+
await (0, run_2.generateTest)(testCase, specPath, testGenConfig.options, trace);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
// this assumes we have only one scenario in test config
|
|
139
|
+
const filePathToUpdate = await (0, utils_1.prepareFileForMasterAgent)(testGenConfig, trace);
|
|
140
|
+
void (0, session_1.updateSessionStatus)(testGenConfig.options?.metadata.testSessionId, {
|
|
141
|
+
status: "agent_live_session_started",
|
|
142
|
+
});
|
|
143
|
+
await (0, run_1.generateTestsUsingMasterAgent)({
|
|
144
|
+
testFilePath: specPath,
|
|
145
|
+
filePathToUpdate,
|
|
146
|
+
pwProjectsFilter: testGenConfig.environment?.playwrightProjects,
|
|
147
|
+
testGenToken,
|
|
148
|
+
repoDir: process.cwd(),
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return agent;
|
|
152
|
+
}
|
|
153
|
+
(async function main() {
|
|
154
|
+
const program = new commander_1.Command();
|
|
155
|
+
program
|
|
156
|
+
.option("--token <token>", "Test generation token")
|
|
157
|
+
.option("--name <test-name>", "Name of the test case")
|
|
158
|
+
.option("--prompt <prompt>", "Prompt for the test case")
|
|
159
|
+
.option("--file <test-file>", "File path of the test case (inside tests dir)")
|
|
160
|
+
.option("--suites <suites>", "Comma separated list of describe blocks")
|
|
161
|
+
.parse(process.argv);
|
|
162
|
+
const options = program.opts();
|
|
163
|
+
const completedOptions = await (0, utils_2.validateAndCompleteCliOptions)(options);
|
|
164
|
+
const testGenConfig = completedOptions.token
|
|
165
|
+
? (0, scenarios_1.loadTestConfigs)(completedOptions.token)
|
|
166
|
+
: (0, scenarios_1.buildTestConfigFromOptions)(completedOptions);
|
|
167
|
+
const testGenToken = completedOptions.token
|
|
168
|
+
? completedOptions.token
|
|
169
|
+
: (0, scenarios_1.buildTokenFromOptions)(completedOptions);
|
|
170
|
+
(0, reporter_1.setReporterConfig)({
|
|
171
|
+
projectRepoName: testGenConfig.options?.metadata.projectRepoName,
|
|
172
|
+
testSessionId: testGenConfig.options?.metadata.testSessionId,
|
|
173
|
+
generationId: testGenConfig.options?.metadata.generationId,
|
|
174
|
+
});
|
|
175
|
+
(0, session_1.setSessionDetails)({
|
|
176
|
+
testCaseId: testGenConfig.testCase.id,
|
|
177
|
+
sessionId: testGenConfig.options?.metadata.testSessionId,
|
|
178
|
+
generationId: testGenConfig.options?.metadata.generationId,
|
|
179
|
+
projectRepoName: testGenConfig.options?.metadata.projectRepoName,
|
|
180
|
+
});
|
|
181
|
+
let testGenFailed = false;
|
|
182
|
+
let agentUsed;
|
|
183
|
+
try {
|
|
184
|
+
// download the build if it exists
|
|
185
|
+
await (0, test_build_1.downloadBuild)(testGenConfig.build || {});
|
|
186
|
+
agentUsed = await runAgent(testGenConfig, testGenToken);
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
testGenFailed = true;
|
|
190
|
+
new logger_1.CustomLogger().error(`Failed to generate test for the scenario. ${process.env.LOG_URL ? `[view log](${process.env.LOG_URL})` : ""}`, e?.message, e?.stack);
|
|
191
|
+
}
|
|
192
|
+
if (agentUsed &&
|
|
193
|
+
agentUsed !== "code" &&
|
|
194
|
+
agentUsed !== "plan" &&
|
|
195
|
+
testGenConfig.testCase.name &&
|
|
196
|
+
testGenConfig.options) {
|
|
197
|
+
await new reporter_1.TestGenUpdatesReporter().reportGenAssets({
|
|
198
|
+
projectRepoName: testGenConfig.options.metadata.projectRepoName,
|
|
199
|
+
testName: testGenConfig.testCase.name,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
// TODO: move these reporters to a better lifecycle
|
|
203
|
+
await (0, llm_1.flushAllTraces)();
|
|
204
|
+
await (0, logger_1.waitForLogsToFlush)();
|
|
205
|
+
await (0, session_1.endSession)();
|
|
206
|
+
if (testGenFailed) {
|
|
207
|
+
process.exit(1);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
process.exit(0);
|
|
211
|
+
}
|
|
212
|
+
})();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class CustomLogger {
|
|
2
|
+
private useReporter;
|
|
3
|
+
constructor({ useReporter }?: {
|
|
4
|
+
useReporter?: boolean | undefined;
|
|
5
|
+
});
|
|
6
|
+
private logToReporter;
|
|
7
|
+
log(message?: string, ...optionalParams: any[]): void;
|
|
8
|
+
warn(message?: string, ...optionalParams: any[]): void;
|
|
9
|
+
success(message?: string, ...optionalParams: any[]): void;
|
|
10
|
+
error(message?: string, ...optionalParams: any[]): void;
|
|
11
|
+
logEmptyLine(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function waitForLogsToFlush(): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bin/logger/index.ts"],"names":[],"mappings":"AAOA,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAkB;gBACzB,EAAE,WAAkB,EAAE;;KAAK;IAIvC,OAAO,CAAC,aAAa;IAYrB,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE;IAK9C,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE;IAK/C,OAAO,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE;IAKlD,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE;IAKhD,YAAY;CAGb;AAED,wBAAsB,kBAAkB,kBAWvC"}
|