@empiricalrun/test-gen 0.42.8 → 0.42.10

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/agent/browsing/utils.d.ts.map +1 -1
  3. package/dist/agent/browsing/utils.js +1 -0
  4. package/dist/agent/codegen/create-test-block.d.ts.map +1 -1
  5. package/dist/agent/codegen/create-test-block.js +4 -2
  6. package/dist/agent/codegen/lexical-scoped-vars.d.ts.map +1 -1
  7. package/dist/agent/codegen/lexical-scoped-vars.js +6 -9
  8. package/dist/agent/codegen/promptBuilder.d.ts +3 -0
  9. package/dist/agent/codegen/promptBuilder.d.ts.map +1 -0
  10. package/dist/agent/codegen/promptBuilder.js +44 -0
  11. package/dist/agent/master/action-tool-calls.d.ts +6 -1
  12. package/dist/agent/master/action-tool-calls.d.ts.map +1 -1
  13. package/dist/agent/master/action-tool-calls.js +14 -1
  14. package/dist/agent/master/element-annotation.d.ts +1 -1
  15. package/dist/agent/master/element-annotation.d.ts.map +1 -1
  16. package/dist/agent/master/element-annotation.js +12 -3
  17. package/dist/agent/master/next-action.d.ts +10 -5
  18. package/dist/agent/master/next-action.d.ts.map +1 -1
  19. package/dist/agent/master/next-action.js +59 -11
  20. package/dist/agent/master/run.d.ts.map +1 -1
  21. package/dist/agent/master/run.js +16 -16
  22. package/dist/agent/master/scroller.d.ts +15 -0
  23. package/dist/agent/master/scroller.d.ts.map +1 -0
  24. package/dist/agent/master/scroller.js +375 -0
  25. package/dist/agent/utils.d.ts +2 -0
  26. package/dist/agent/utils.d.ts.map +1 -0
  27. package/dist/agent/utils.js +12 -0
  28. package/dist/browser-injected-scripts/annotate-elements.js +71 -48
  29. package/dist/browser-injected-scripts/annotate-elements.spec.js +5 -20
  30. package/dist/browser-injected-scripts/annotate-elements.spec.ts +4 -19
  31. package/dist/evals/master-agent.evals.d.ts.map +1 -1
  32. package/dist/evals/master-agent.evals.js +3 -4
  33. package/dist/prompts/lib/ts-transformer.d.ts +4 -0
  34. package/dist/prompts/lib/ts-transformer.d.ts.map +1 -0
  35. package/dist/prompts/lib/ts-transformer.js +90 -0
  36. package/dist/prompts/lib/vitest-plugin.d.ts +8 -0
  37. package/dist/prompts/lib/vitest-plugin.d.ts.map +1 -0
  38. package/dist/prompts/lib/vitest-plugin.js +20 -0
  39. package/dist/session/index.d.ts.map +1 -1
  40. package/dist/session/index.js +4 -0
  41. package/package.json +11 -9
  42. package/vitest.config.ts +5 -0
@@ -19,7 +19,7 @@ test("should annotate all links on empirical landing page", async ({
19
19
 
20
20
  const annotations = await page.evaluate(() => {
21
21
  // eslint-disable-next-line no-undef
22
- const { annotations } = annotateClickableElements();
22
+ const { annotations } = annotateElementsWithPreference();
23
23
 
24
24
  return Object.entries(annotations).map(([, config]) => ({
25
25
  innerText: config.node.innerText,
@@ -54,21 +54,6 @@ test("should annotate all links on empirical landing page", async ({
54
54
  tagName: "A",
55
55
  href: "https://assets-test.empirical.run/contact",
56
56
  },
57
- {
58
- innerText: "Playwright\n(opens in a new tab)",
59
- tagName: "A",
60
- href: "https://github.com/microsoft/playwright",
61
- },
62
- {
63
- innerText: "Meet with us",
64
- tagName: "A",
65
- href: "https://assets-test.empirical.run/contact",
66
- },
67
- {
68
- innerText: "Privacy Policy",
69
- tagName: "A",
70
- href: "https://assets-test.empirical.run/privacy.html",
71
- },
72
57
  ]);
73
58
  });
74
59
 
@@ -85,7 +70,7 @@ test("should annotate all important items on quizizz page", async ({
85
70
 
86
71
  const annotations = await page.evaluate(() => {
87
72
  // eslint-disable-next-line no-undef
88
- const { annotations } = annotateClickableElements();
73
+ const { annotations } = annotateElementsWithPreference();
89
74
 
90
75
  return Object.entries(annotations).map(([hint, config]) => ({
91
76
  hint,
@@ -267,7 +252,7 @@ test("should only annotate input fields on quizizz page", async ({ page }) => {
267
252
  };
268
253
  const annotations = await page.evaluate((preference) => {
269
254
  // eslint-disable-next-line no-undef
270
- const { annotations } = annotateClickableElements({
255
+ const { annotations } = annotateElementsWithPreference({
271
256
  preference: preference,
272
257
  });
273
258
 
@@ -299,7 +284,7 @@ test("should only annotate given text on quizziz page", async ({ page }) => {
299
284
  };
300
285
  const annotations = await page.evaluate((preference) => {
301
286
  // eslint-disable-next-line no-undef
302
- const { annotations } = annotateClickableElements({
287
+ const { annotations } = annotateElementsWithPreference({
303
288
  preference: preference,
304
289
  });
305
290
 
@@ -1 +1 @@
1
- {"version":3,"file":"master-agent.evals.d.ts","sourceRoot":"","sources":["../../src/evals/master-agent.evals.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,eAAO,MAAM,4BAA4B,EAAE,UA2C1C,CAAC;AAEF,eAAe,4BAA4B,CAAC"}
1
+ {"version":3,"file":"master-agent.evals.d.ts","sourceRoot":"","sources":["../../src/evals/master-agent.evals.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,eAAO,MAAM,4BAA4B,EAAE,UAwC1C,CAAC;AAEF,eAAe,4BAA4B,CAAC"}
@@ -7,7 +7,7 @@ const action_tool_calls_1 = require("../agent/master/action-tool-calls");
7
7
  const next_action_1 = require("../agent/master/next-action");
8
8
  const page_1 = require("../page");
9
9
  const masterGetNextActionEvaluator = async ({ item, trace, }) => {
10
- const { task, executedActions, failedActions, pageUrl, options, pageScreenshot, annotatedPageScreenshot, disableSkills, skills = [], annotations, } = item.input;
10
+ const { task, executedActions, failedActions, pageUrl, options, pageScreenshot, disableSkills, skills = [], } = item.input;
11
11
  const page = {};
12
12
  skill_1.testCaseSkills.updateSkills(skills);
13
13
  const actions = new actions_1.PlaywrightActions(new page_1.TestGenPage(page, "page"));
@@ -19,17 +19,16 @@ const masterGetNextActionEvaluator = async ({ item, trace, }) => {
19
19
  trace,
20
20
  options,
21
21
  pageScreenshot,
22
- annotatedPageScreenshot,
23
22
  actions,
24
23
  actionTypes: action_tool_calls_1.ActionType,
25
24
  disableSkills,
26
- annotations,
25
+ page,
27
26
  });
28
27
  return {
29
28
  scores: [
30
29
  {
31
30
  name: "action_correctness",
32
- value: item.expectedOutput.function.name === output?.function.name ? 1 : 0,
31
+ value: item.expectedOutput.function.name === output?.actionType ? 1 : 0,
33
32
  },
34
33
  ],
35
34
  output,
@@ -0,0 +1,4 @@
1
+ import * as ts from "typescript";
2
+ declare function createHandlebarsTransformer(): ts.TransformerFactory<ts.SourceFile>;
3
+ export default createHandlebarsTransformer;
4
+ //# sourceMappingURL=ts-transformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-transformer.d.ts","sourceRoot":"","sources":["../../../src/prompts/lib/ts-transformer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,iBAAS,2BAA2B,IAAI,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAkG3E;AAED,eAAe,2BAA2B,CAAC"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const fs = __importStar(require("fs"));
27
+ const path = __importStar(require("path"));
28
+ const ts = __importStar(require("typescript"));
29
+ function createHandlebarsTransformer() {
30
+ return (context) => {
31
+ // Map to store the mapping between original import identifiers and generated variable names
32
+ const importToVarMap = new Map();
33
+ const visitor = (node) => {
34
+ // Handle references to the imported identifiers
35
+ if (ts.isIdentifier(node) && importToVarMap.has(node.text)) {
36
+ return ts.factory.createIdentifier(importToVarMap.get(node.text));
37
+ }
38
+ return ts.visitEachChild(node, visitor, context);
39
+ };
40
+ return (sourceFile) => {
41
+ // Reset the import map for each source file
42
+ importToVarMap.clear();
43
+ // Keep track of generated variable names to avoid duplicates
44
+ let templateCounter = 0;
45
+ // Create a new statements array by iterating over the existing ones
46
+ const newStatements = sourceFile.statements.flatMap((stmt) => {
47
+ // Check if the statement is an import declaration for a .handlebars file
48
+ if (ts.isImportDeclaration(stmt) &&
49
+ ts.isStringLiteral(stmt.moduleSpecifier) &&
50
+ stmt.moduleSpecifier.text.endsWith(".handlebars")) {
51
+ // Ensure we have a default import (an identifier)
52
+ if (stmt.importClause &&
53
+ stmt.importClause.name &&
54
+ ts.isIdentifier(stmt.importClause.name)) {
55
+ const localIdentifier = stmt.importClause.name;
56
+ // Generate a unique variable name
57
+ const generatedVarName = `promptTemplate_${templateCounter++}`;
58
+ // Store the mapping between import identifier and generated variable name
59
+ importToVarMap.set(localIdentifier.text, generatedVarName);
60
+ // Resolve the path to the handlebars file
61
+ const containingDir = path.dirname(sourceFile.fileName);
62
+ const templatePath = path.resolve(containingDir, stmt.moduleSpecifier.text);
63
+ try {
64
+ // Read the handlebars file content
65
+ const content = fs.readFileSync(templatePath, "utf-8");
66
+ // Create a variable declaration that binds the generated name to the content
67
+ const variableStmt = ts.factory.createVariableStatement(undefined, ts.factory.createVariableDeclarationList([
68
+ ts.factory.createVariableDeclaration(ts.factory.createIdentifier(generatedVarName), undefined, undefined, ts.factory.createStringLiteral(content)),
69
+ ], ts.NodeFlags.Const));
70
+ // Replace the import declaration with the variable statement
71
+ return [variableStmt];
72
+ }
73
+ catch (error) {
74
+ console.error(`Error reading handlebars file ${templatePath}:`, error);
75
+ // If reading the file fails, keep the original import
76
+ return [stmt];
77
+ }
78
+ }
79
+ }
80
+ // For all other statements, keep them as is
81
+ return [stmt];
82
+ });
83
+ // Create updated source file with the new statements
84
+ const updatedSourceFile = ts.factory.updateSourceFile(sourceFile, newStatements);
85
+ // Visit the entire source file to transform references
86
+ return ts.visitNode(updatedSourceFile, visitor);
87
+ };
88
+ };
89
+ }
90
+ exports.default = createHandlebarsTransformer;
@@ -0,0 +1,8 @@
1
+ export declare const handlebarsLoader: {
2
+ name: string;
3
+ transform(_: any, id: string): Promise<{
4
+ code: string;
5
+ map: null;
6
+ } | null>;
7
+ };
8
+ //# sourceMappingURL=vitest-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest-plugin.d.ts","sourceRoot":"","sources":["../../../src/prompts/lib/vitest-plugin.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB;;iBAER,GAAG,MAAM,MAAM;;;;CAUnC,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handlebarsLoader = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ exports.handlebarsLoader = {
9
+ name: "handlebars-loader",
10
+ async transform(_, id) {
11
+ if (id.endsWith(".handlebars") || id.endsWith(".hbs")) {
12
+ const content = fs_1.default.readFileSync(id, "utf-8");
13
+ return {
14
+ code: `export default ${JSON.stringify(content)};`,
15
+ map: null,
16
+ };
17
+ }
18
+ return null;
19
+ },
20
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAkBA,iBAAS,iBAAiB;;;;;EAOzB;AAED,wBAAgB,iBAAiB,CAAC,EAChC,SAAS,EACT,YAAY,EACZ,UAAU,EACV,eAAe,GAChB,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB,QAIA;AAED,wBAAsB,iBAAiB,qBAItC;AAED,wBAAsB,eAAe,0DA0BpC;AAED,wBAAsB,UAAU,kBAqB/B;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAE7B,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAC;CAChB,iBAmBF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAkBA,iBAAS,iBAAiB;;;;;EAOzB;AAED,wBAAgB,iBAAiB,CAAC,EAChC,SAAS,EACT,YAAY,EACZ,UAAU,EACV,eAAe,GAChB,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB,QAIA;AAED,wBAAsB,iBAAiB,qBAItC;AAED,wBAAsB,eAAe,0DA0BpC;AAED,wBAAsB,UAAU,kBAyB/B;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAE7B,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAC;CAChB,iBAmBF"}
@@ -58,6 +58,10 @@ async function endSession() {
58
58
  if (!DASHBOARD_DOMAIN) {
59
59
  return;
60
60
  }
61
+ if (!sessionDetails.sessionId || !sessionDetails.generationId) {
62
+ console.warn("Session details missing, skipping session end");
63
+ return;
64
+ }
61
65
  const apiPath = `${DASHBOARD_DOMAIN}/api/sessions/${sessionDetails.sessionId}/generations/${sessionDetails.generationId}/state`;
62
66
  try {
63
67
  await fetch(apiPath, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.42.8",
3
+ "version": "0.42.10",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -56,6 +56,7 @@
56
56
  "fs-extra": "^11.2.0",
57
57
  "google-auth-library": "^9.10.0",
58
58
  "google-spreadsheet": "^4.1.2",
59
+ "handlebars": "^4.7.8",
59
60
  "ignore": "^5.3.1",
60
61
  "lodash.isequal": "^4.5.0",
61
62
  "md5": "^2.3.0",
@@ -68,12 +69,12 @@
68
69
  "remove-markdown": "^0.5.5",
69
70
  "sanitize-html": "^2.13.0",
70
71
  "slugify": "^1.6.6",
71
- "ts-morph": "^24.0.0",
72
+ "ts-morph": "^23.0.0",
72
73
  "tsx": "^4.16.2",
73
74
  "typescript": "^5.3.3",
74
- "@empiricalrun/llm": "^0.9.30",
75
- "@empiricalrun/r2-uploader": "^0.3.8",
76
- "@empiricalrun/reporter": "^0.22.1"
75
+ "@empiricalrun/llm": "^0.9.31",
76
+ "@empiricalrun/reporter": "^0.22.1",
77
+ "@empiricalrun/r2-uploader": "^0.3.8"
77
78
  },
78
79
  "devDependencies": {
79
80
  "@playwright/test": "1.47.1",
@@ -84,12 +85,13 @@
84
85
  "@types/lodash.isequal": "^4.5.8",
85
86
  "@types/md5": "^2.3.5",
86
87
  "js-levenshtein": "^1.1.6",
87
- "playwright": "1.47.1"
88
+ "playwright": "1.47.1",
89
+ "ts-patch": "^3.3.0"
88
90
  },
89
91
  "scripts": {
90
- "dev": "tsc --build --watch",
91
- "build": "tsc --build && cp -r src/browser-injected-scripts dist",
92
- "clean": "tsc --build --clean",
92
+ "dev": "tspc --build --watch",
93
+ "build": "tspc --build && cp -r src/browser-injected-scripts dist",
94
+ "clean": "tspc --build --clean",
93
95
  "lint": "eslint .",
94
96
  "test": "vitest run",
95
97
  "test-browser": "npx playwright test",
package/vitest.config.ts CHANGED
@@ -1,11 +1,16 @@
1
1
  import { config as dotenvConfig } from "dotenv";
2
2
  import { defineConfig } from "vitest/config";
3
3
 
4
+ import { handlebarsLoader } from "./src/prompts/lib/vitest-plugin";
5
+
4
6
  dotenvConfig({ path: [".env.local", ".env"] });
5
7
 
6
8
  export default defineConfig({
7
9
  test: {
8
10
  setupFiles: ["dotenv/config"],
9
11
  include: ["src/**/*.test.ts"],
12
+ globals: true,
10
13
  },
14
+ assetsInclude: ["**/*.handlebars"],
15
+ plugins: [handlebarsLoader],
11
16
  });