@empiricalrun/test-gen 0.31.25 → 0.32.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.32.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e22c1eb: feat: add support for extracting lexical scoped variables
8
+
9
+ ## 0.31.26
10
+
11
+ ### Patch Changes
12
+
13
+ - 9cfa0b9: feat: add support for user context in fixtures
14
+
3
15
  ## 0.31.25
4
16
 
5
17
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAavD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAK5C,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AA2DD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,aAAa,GACvB,OAAO,CAAC,MAAM,CAAC,CA2CjB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBAiBxD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,QA6BjD;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAM1E;AAWD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,MAAM,CAAC,CA8CjB;AAED,wBAAsB,sBAAsB,CAAC,EAC3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Ae,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,8EASA"}
@@ -33,6 +33,11 @@ exports.prepareBrowsingAgentTask = prepareBrowsingAgentTask;
33
33
  async function prepareFileForUpdateScenario(genConfig) {
34
34
  const { specPath, testCase } = genConfig;
35
35
  const { name, suites } = testCase;
36
+ await (0, web_1.addUserContextFixture)({
37
+ scenarioName: name,
38
+ filePath: specPath,
39
+ suites,
40
+ });
36
41
  // update the test case with appropriate location for createTest
37
42
  // TODO: reduce the payload for this LLM call. Only provide test file and page files which are used in the test block
38
43
  // this will help with faster response
@@ -0,0 +1,10 @@
1
+ import { TraceClient } from "@empiricalrun/llm";
2
+ import { TestGenConfigOptions } from "../../types";
3
+ export declare function getLexicalScopedVars({ trace, testFile, referencePoint, testName, options, }: {
4
+ trace?: TraceClient;
5
+ testFile: string;
6
+ referencePoint: string;
7
+ testName: string;
8
+ options?: TestGenConfigOptions;
9
+ }): Promise<string[]>;
10
+ //# sourceMappingURL=lexical-scoped-vars.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lexical-scoped-vars.d.ts","sourceRoot":"","sources":["../../../src/agent/codegen/lexical-scoped-vars.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAQhE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAsB,oBAAoB,CAAC,EACzC,KAAK,EACL,QAAQ,EACR,cAAc,EACd,QAAQ,EACR,OAAO,GACR,EAAE;IACD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,oBAAoB,CAAC;CAChC,qBA2DA"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLexicalScopedVars = void 0;
4
+ const llm_1 = require("@empiricalrun/llm");
5
+ const constants_1 = require("../../constants");
6
+ async function getLexicalScopedVars({ trace, testFile, referencePoint, testName, options, }) {
7
+ const fetchLexicalScopedVarsSpan = trace?.span({
8
+ name: "lexical-scoped-vars",
9
+ });
10
+ const promptSpan = fetchLexicalScopedVarsSpan?.span({
11
+ name: "lexical-scoped-vars-prompt",
12
+ });
13
+ const instruction = await (0, llm_1.getPrompt)("lexical-scope-variables", {
14
+ testFile: testFile || "",
15
+ referencePoint: referencePoint || "",
16
+ testName: testName || "",
17
+ });
18
+ promptSpan?.end({ output: { instruction } });
19
+ const llm = new llm_1.LLM({
20
+ trace: fetchLexicalScopedVarsSpan,
21
+ provider: options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER,
22
+ defaultModel: options?.model || constants_1.DEFAULT_MODEL,
23
+ providerApiKey: constants_1.MODEL_API_KEYS[options?.modelProvider || constants_1.DEFAULT_MODEL_PROVIDER],
24
+ });
25
+ const message = await llm.createChatCompletion({
26
+ messages: instruction,
27
+ modelParameters: {
28
+ ...constants_1.DEFAULT_MODEL_PARAMETERS,
29
+ ...options?.modelParameters,
30
+ },
31
+ responseFormat: {
32
+ type: "json_schema",
33
+ json_schema: {
34
+ name: "reasoning_with_variables",
35
+ strict: true,
36
+ schema: {
37
+ type: "object",
38
+ properties: {
39
+ reason: {
40
+ type: "string",
41
+ description: "The reason or explanation.",
42
+ },
43
+ variables: {
44
+ type: "array",
45
+ description: "A list of variables.",
46
+ items: {
47
+ type: "string",
48
+ },
49
+ },
50
+ },
51
+ required: ["reason", "variables"],
52
+ additionalProperties: false,
53
+ },
54
+ },
55
+ },
56
+ });
57
+ const response = JSON.parse(message?.content || "{}");
58
+ fetchLexicalScopedVarsSpan?.end({ output: { response } });
59
+ return response.variables;
60
+ }
61
+ exports.getLexicalScopedVars = getLexicalScopedVars;
@@ -155,7 +155,7 @@ async function createTestUsingMasterAgent({ task, page, testCase, options, }) {
155
155
  reason: JSON.parse(toolCall.function.arguments).reason,
156
156
  };
157
157
  void testGenReporter.sendMessage(output.reason);
158
- logger.log(`Next Action: ${output.reason}`);
158
+ logger.log(`Next Action: ${output.action}`);
159
159
  if (toolCall.function.name === skill_1.SKILL_USAGE) {
160
160
  await actions.executeAction(toolCall.function.name, args, masterAgentActionSpan);
161
161
  }
@@ -55,4 +55,9 @@ export declare const injectCodeSnippetBySuiteChain: ({ testFileContent, codeSnip
55
55
  suites: string[];
56
56
  }) => string;
57
57
  export declare const importAllExportsStmtFromFilePaths: (filePaths: string[], testFilePath: string) => Promise<string[]>;
58
+ export declare function addUserContextFixture({ scenarioName, filePath, suites, }: {
59
+ scenarioName: string;
60
+ filePath: string;
61
+ suites: string[];
62
+ }): Promise<void>;
58
63
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/bin/utils/platform/web/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,IAAI,EAIL,MAAM,UAAU,CAAC;AAGlB;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,YAAY,EACZ,MAAM,EACN,OAAO,GACR,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG;IACF,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,EAAE,IAAI,GAAG,SAAS,CAAC;CAC5B,CAuCA;AAwBD,wBAAsB,0CAA0C,CAC9D,QAAQ,EAAE,MAAM,oBA+BjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,IAAI,GAAG,SAAS,GACrB,IAAI,GAAG,SAAS,CA4BlB;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE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AAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,iBAsDA"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.importAllExportsStmtFromFilePaths = exports.injectCodeSnippetBySuiteChain = exports.replaceCreateTestWithNewCode = exports.getPageVariableNameFromCreateTest = exports.getFixtureImportPath = exports.removeTestOnly = exports.addNewImport = exports.formatCode = exports.lintErrors = exports.stripAndPrependImports = exports.validateTypescript = exports.appendToTestBlock = exports.findFirstSerialDescribeBlock = exports.hasTopLevelDescribeConfigureWithSerialMode = exports.getTypescriptTestBlock = void 0;
6
+ exports.addUserContextFixture = exports.importAllExportsStmtFromFilePaths = exports.injectCodeSnippetBySuiteChain = exports.replaceCreateTestWithNewCode = exports.getPageVariableNameFromCreateTest = exports.getFixtureImportPath = exports.removeTestOnly = exports.addNewImport = exports.formatCode = exports.lintErrors = exports.stripAndPrependImports = exports.validateTypescript = exports.appendToTestBlock = exports.findFirstSerialDescribeBlock = exports.hasTopLevelDescribeConfigureWithSerialMode = exports.getTypescriptTestBlock = void 0;
7
7
  const eslint_1 = require("eslint");
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
@@ -372,3 +372,44 @@ const importAllExportsStmtFromFilePaths = async (filePaths, testFilePath) => {
372
372
  return statements;
373
373
  };
374
374
  exports.importAllExportsStmtFromFilePaths = importAllExportsStmtFromFilePaths;
375
+ async function addUserContextFixture({ scenarioName, filePath, suites, }) {
376
+ // TODO: remove this check when we support user context across repos
377
+ let fixtureContent = "";
378
+ try {
379
+ fixtureContent = await fs_extra_1.default.readFile("./tests/fixtures.ts", "utf-8");
380
+ }
381
+ catch (e) {
382
+ // do nothing
383
+ }
384
+ if (!fixtureContent || !fixtureContent.includes("userContext")) {
385
+ return;
386
+ }
387
+ const fileContent = await fs_extra_1.default.readFile(filePath, "utf-8");
388
+ const { testNode } = getTypescriptTestBlock({
389
+ scenarioName,
390
+ content: fileContent,
391
+ suites,
392
+ });
393
+ const currentBlock = testNode?.getText();
394
+ const testCallExpression = testNode?.getFirstDescendantByKind(ts_morph_1.SyntaxKind.CallExpression);
395
+ if (testCallExpression?.getExpression().getText() === "test") {
396
+ const arrowFunction = testCallExpression.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ArrowFunction);
397
+ if (arrowFunction) {
398
+ const param = arrowFunction.getParameters()[0]; // Get the first parameter
399
+ const destructuringParam = param?.getFirstDescendantByKind(ts_morph_1.SyntaxKind.ObjectBindingPattern);
400
+ if (destructuringParam) {
401
+ const elements = destructuringParam.getElements();
402
+ const userContextExists = elements.some((e) => e.getText().includes("userContext"));
403
+ console.log("userContextExists", userContextExists);
404
+ if (!userContextExists) {
405
+ const updatedImport = destructuringParam
406
+ .getText()
407
+ .replace("}", ", userContext }");
408
+ destructuringParam.replaceWithText(updatedImport);
409
+ await fs_extra_1.default.writeFile(filePath, fileContent.replace(currentBlock, testNode.getText()), "utf-8");
410
+ }
411
+ }
412
+ }
413
+ }
414
+ }
415
+ exports.addUserContextFixture = addUserContextFixture;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.31.25",
3
+ "version": "0.32.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -18,7 +18,7 @@
18
18
  "@actions/core": "^1.10.1",
19
19
  "@aws-sdk/client-s3": "^3.614.0",
20
20
  "@aws-sdk/s3-request-presigner": "^3.614.0",
21
- "@playwright/test": "^1.44.1",
21
+ "@playwright/test": "1.47.1",
22
22
  "@types/sanitize-html": "^2.11.0",
23
23
  "commander": "^12.1.0",
24
24
  "detect-port": "^1.6.1",
@@ -36,7 +36,7 @@
36
36
  "nanoid": "^5.0.7",
37
37
  "openai": "^4.47.2",
38
38
  "picocolors": "^1.0.1",
39
- "playwright": "^1.44.1",
39
+ "playwright": "1.47.1",
40
40
  "prettier": "^3.2.5",
41
41
  "remove-markdown": "^0.5.5",
42
42
  "sanitize-html": "^2.13.0",