@empiricalrun/test-gen 0.51.1 → 0.51.2

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,12 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.51.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ecd3c30: fix: show loader when claude is working
8
+ - ad6c96f: fix: prune test-run tool call response for input tokens
9
+
3
10
  ## 0.51.1
4
11
 
5
12
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/agent/chat.ts"],"names":[],"mappings":"AA8EA,wBAAsB,SAAS,CAAC,EAC9B,SAAwC,EACxC,mBAAmB,GACpB,EAAE;IACD,SAAS,CAAC,EAAE,4BAA4B,GAAG,4BAA4B,CAAC;IACxE,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;;;;GA6FA"}
1
+ {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/agent/chat.ts"],"names":[],"mappings":"AA8EA,wBAAsB,SAAS,CAAC,EAC9B,SAAwC,EACxC,mBAAmB,GACpB,EAAE;IACD,SAAS,CAAC,EAAE,4BAA4B,GAAG,4BAA4B,CAAC;IACxE,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;;;;GA0GA"}
@@ -72,8 +72,15 @@ const toolExecutors = {
72
72
  str_replace_editor: claude_1.strReplaceEditorTool,
73
73
  };
74
74
  async function chatAgent({ chatModel = "claude-3-7-sonnet-20250219", useDiskForChatState, }) {
75
+ const ora = (await import("ora")).default;
75
76
  let userPrompt = undefined;
76
77
  let chatState = useDiskForChatState ? claude_1.ChatState.load() : new claude_1.ChatState(false);
78
+ const handleSigInt = () => {
79
+ console.log("\nExiting. Usage summary:", chatState.getUsageSummary());
80
+ process.exit(0);
81
+ };
82
+ process.once("SIGINT", handleSigInt);
83
+ process.once("SIGTERM", handleSigInt);
77
84
  if (chatState.askUserForInput) {
78
85
  // Show last message to the user for context when we loaded from disk
79
86
  const messages = chatState.messages;
@@ -115,12 +122,13 @@ async function chatAgent({ chatModel = "claude-3-7-sonnet-20250219", useDiskForC
115
122
  }
116
123
  const toolUse = chatState.getPendingToolCall();
117
124
  if (toolUse) {
118
- console.log("Executing tool:", toolUse.name, "with args:", toolUse.input);
125
+ const spinner = ora(`Executing tool ${toolUse.name} with args: ${JSON.stringify(toolUse.input)}`).start();
119
126
  const toolExecutor = toolExecutors[toolUse.name];
120
127
  if (!toolExecutor) {
121
128
  throw new Error(`Tool ${toolUse.name} not found`);
122
129
  }
123
130
  const toolResult = await toolExecutor(toolUse.input);
131
+ spinner.succeed(`Tool ${toolUse.name} completed`);
124
132
  chatState.pushMessage({
125
133
  role: "user",
126
134
  content: [
@@ -134,6 +142,7 @@ async function chatAgent({ chatModel = "claude-3-7-sonnet-20250219", useDiskForC
134
142
  });
135
143
  continue;
136
144
  }
145
+ const spinner = ora("Claude is working...").start();
137
146
  const response = await (0, claude_1.createClaudeMessage)({
138
147
  systemPrompt,
139
148
  messages: chatState.getMessagesForCreateCompletion(),
@@ -141,6 +150,7 @@ async function chatAgent({ chatModel = "claude-3-7-sonnet-20250219", useDiskForC
141
150
  model: chatModel,
142
151
  withStrReplaceEditor: true,
143
152
  });
153
+ spinner.stop();
144
154
  if (!response) {
145
155
  throw new Error("No response from LLM");
146
156
  }
@@ -0,0 +1,4 @@
1
+ import type { Tool } from "../types";
2
+ export declare function extractPathAfterSourceRepo(fullPath: string): string;
3
+ export declare const testRunTool: Tool;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/test-run-fetcher/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAWrC,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOnE;AAED,eAAO,MAAM,WAAW,EAAE,IAwHzB,CAAC"}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testRunTool = exports.extractPathAfterSourceRepo = void 0;
4
+ const zod_1 = require("zod");
5
+ const TestRunSchema = zod_1.z.object({
6
+ testRunUrl: zod_1.z
7
+ .string()
8
+ .describe("The full URL of the test run (e.g. https://dash.empirical.run/sortment-tests/test-runs/20269 or with query params like ?status=failed)"),
9
+ });
10
+ function extractPathAfterSourceRepo(fullPath) {
11
+ const parts = fullPath.split("source-repo");
12
+ if (parts.length <= 1) {
13
+ return fullPath;
14
+ }
15
+ else {
16
+ return parts[1].replace(/^\/|\/$/g, "");
17
+ }
18
+ }
19
+ exports.extractPathAfterSourceRepo = extractPathAfterSourceRepo;
20
+ exports.testRunTool = {
21
+ schema: {
22
+ name: "fetchTestRunDetails",
23
+ description: "Fetch details about a test run using its URL",
24
+ parameters: TestRunSchema,
25
+ },
26
+ execute: async (input) => {
27
+ const { testRunUrl } = input;
28
+ // Remove query parameters if they exist
29
+ const urlWithoutParams = testRunUrl.split("?")[0] || testRunUrl;
30
+ // Extract the run ID and repo name from the URL
31
+ const urlParts = urlWithoutParams.split("/");
32
+ const runId = urlParts.pop(); // Last part is the run ID
33
+ const repoName = urlParts[urlParts.length - 2]; // Second to last part is the repo name
34
+ if (!runId || !repoName) {
35
+ throw new Error("Invalid test run URL - could not extract run ID or repo name");
36
+ }
37
+ // Make the API call to fetch test run details
38
+ const response = await fetch(`https://dash.empirical.run/api/test-runs/${runId}?repo_name=${repoName}`, {
39
+ method: "GET",
40
+ headers: {
41
+ Authorization: "weQPMWKT",
42
+ },
43
+ });
44
+ if (!response.ok) {
45
+ return {
46
+ result: `Failed to fetch test run details: ${response.statusText}`,
47
+ isError: true,
48
+ };
49
+ }
50
+ const data = (await response.json());
51
+ // To efficiently use input_tokens, we
52
+ // 1. Truncate stack trace to last 300 characters
53
+ // 2. Remove request/response headers from network metadata
54
+ // 3. Focus on failed tests only
55
+ if (data.data?.test_run?.flattenedSummaryDetails) {
56
+ data.data.test_run.flattenedSummaryDetails =
57
+ data.data.test_run.flattenedSummaryDetails.map((detail) => {
58
+ // Truncate stack trace to last 300 characters
59
+ if (detail.failed_run_metadata?.stack) {
60
+ const stack = detail.failed_run_metadata.stack;
61
+ // TODO: change to last 10 lines
62
+ detail.failed_run_metadata.stack =
63
+ stack.length > 300 ? `...${stack.slice(-300)}` : stack;
64
+ }
65
+ // Remove headers from network metadata
66
+ if (detail.network_metadata?.failed_calls) {
67
+ detail.network_metadata.failed_calls =
68
+ detail.network_metadata.failed_calls.map((call) => ({
69
+ ...call,
70
+ request: { ...call.request, headers: [] },
71
+ response: { ...call.response, headers: [] },
72
+ }));
73
+ }
74
+ if (detail.network_metadata?.failed_calls_within_time_range) {
75
+ detail.network_metadata.failed_calls_within_time_range =
76
+ detail.network_metadata.failed_calls_within_time_range.map((call) => ({
77
+ ...call,
78
+ request: { ...call.request, headers: [] },
79
+ response: { ...call.response, headers: [] },
80
+ }));
81
+ }
82
+ return detail;
83
+ });
84
+ }
85
+ const failedTests = data.data?.test_run?.flattenedSummaryDetails.filter((detail) => detail.status === "failed");
86
+ const failedTestInMarkdown = failedTests
87
+ ?.map((detail) => {
88
+ const { nesting } = detail.failed_run_metadata;
89
+ return {
90
+ testName: nesting.slice(1).join(" > "),
91
+ fileName: extractPathAfterSourceRepo(detail.failed_run_metadata.location.file),
92
+ detail,
93
+ };
94
+ })
95
+ .map((test) => {
96
+ return `
97
+ ### Test name: ${test.testName}
98
+ File: ${test.fileName}
99
+
100
+ Failure data below
101
+
102
+ \`\`\`json
103
+ ${JSON.stringify(test.detail, null, 2)}
104
+ \`\`\`
105
+ `;
106
+ })
107
+ .join("\n\n");
108
+ const markdownResponse = `
109
+ # Test run details
110
+
111
+ ## Run info
112
+ - Run ID: ${runId}
113
+ - Repository: ${repoName}
114
+ - Started at: ${data.data?.test_run?.testRun.run_started_at}
115
+ - Ended at: ${data.data?.test_run?.testRun.run_ended_at}
116
+ - Duration: ${data.data?.test_run?.testRun.duration} seconds
117
+ - Environment name: ${data.data?.test_run?.testRun.environment_name}
118
+
119
+ ## Failed tests
120
+ ${failedTestInMarkdown}
121
+ `;
122
+ return {
123
+ result: markdownResponse,
124
+ isError: false,
125
+ };
126
+ },
127
+ };
@@ -0,0 +1,120 @@
1
+ type Project = {
2
+ id: number;
3
+ org_id: number;
4
+ name: string;
5
+ repo_name: string;
6
+ };
7
+ type TestRun = {
8
+ id: number;
9
+ run_id: number;
10
+ project_id: number;
11
+ total_count: number;
12
+ unique_count: number;
13
+ success_count: number;
14
+ failed_count: number;
15
+ skipped_count: number;
16
+ flaky_count: number;
17
+ run_ended_at: string;
18
+ run_started_at: string;
19
+ created_at: string;
20
+ duration: number;
21
+ test_run_branch: string;
22
+ summary_url: string;
23
+ trigger_type: string;
24
+ state: string;
25
+ build_id: number;
26
+ environment_id: number;
27
+ metadata: Record<string, any>;
28
+ test_run_head_sha: string;
29
+ };
30
+ type TestRunEnriched = TestRun & {
31
+ environment_name: string | null;
32
+ environment_slug: string | null;
33
+ commit: string | null;
34
+ commit_url: string | null;
35
+ build_branch: string | null;
36
+ build_url: string | null;
37
+ };
38
+ type FailedRunMetadata = {
39
+ stack: string;
40
+ trace: string;
41
+ videos: string[];
42
+ nesting: string[];
43
+ location: {
44
+ file: string;
45
+ line: number;
46
+ column: number;
47
+ };
48
+ start_time: string;
49
+ pw_test_id: string;
50
+ varying_retries: boolean;
51
+ };
52
+ type CapturedNetworkFailure = {
53
+ endpoint: string;
54
+ status: number;
55
+ timestamp: string;
56
+ distanceFromFailureInMilliseconds: number;
57
+ method: string;
58
+ request: {
59
+ headers: {
60
+ [any: string]: string;
61
+ }[];
62
+ };
63
+ response: {
64
+ headers: {
65
+ [any: string]: string;
66
+ }[];
67
+ };
68
+ };
69
+ type TestCaseSummaryDetail = {
70
+ id: number;
71
+ test_case_id: number;
72
+ test_run_id: number;
73
+ status: string;
74
+ test_project: string;
75
+ failure_type: string;
76
+ failure_type_description: string;
77
+ last_commit_before_run_started_at: string;
78
+ merged_summary?: {
79
+ content: string;
80
+ } | null;
81
+ successful_run_metadata: {
82
+ videos: string[];
83
+ test_id?: string;
84
+ test_run_id?: string;
85
+ } | null;
86
+ failed_run_metadata: FailedRunMetadata;
87
+ visual_diff_summary: {
88
+ failedStep: string;
89
+ reason: string;
90
+ summary: string;
91
+ videos_picked_for_comparison: {
92
+ failure: string;
93
+ success: string;
94
+ };
95
+ } | null;
96
+ error_stack_summary?: {
97
+ content: string;
98
+ } | null;
99
+ network_metadata: {
100
+ failed_calls: CapturedNetworkFailure[];
101
+ failed_calls_within_time_range: CapturedNetworkFailure[];
102
+ } | null;
103
+ created_at: string;
104
+ slug: string;
105
+ failing_line: string;
106
+ };
107
+ export type GetTestRunApiResponse = {
108
+ data: {
109
+ test_run: {
110
+ project: Project;
111
+ testRun: TestRunEnriched;
112
+ flattenedSummaryDetails: TestCaseSummaryDetail[];
113
+ };
114
+ } | null;
115
+ error?: {
116
+ message: string;
117
+ };
118
+ };
119
+ export {};
120
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tools/test-run-fetcher/types.ts"],"names":[],"mappings":"AACA,KAAK,OAAO,GAAG;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,OAAO,GAAG;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,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,EAAE,CAAC;KAC1D,GAAG,IAAI,CAAC;IACT,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE;QACJ,QAAQ,EAAE;YACR,OAAO,EAAE,OAAO,CAAC;YACjB,OAAO,EAAE,eAAe,CAAC;YACzB,uBAAuB,EAAE,qBAAqB,EAAE,CAAC;SAClD,CAAC;KACH,GAAG,IAAI,CAAC;IACT,KAAK,CAAC,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.51.1",
3
+ "version": "0.51.2",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
@@ -64,6 +64,7 @@
64
64
  "minimatch": "^10.0.1",
65
65
  "nanoid": "^5.0.7",
66
66
  "openai": "4.87.3",
67
+ "ora": "^8.1.0",
67
68
  "picocolors": "^1.0.1",
68
69
  "prettier": "^3.2.5",
69
70
  "remove-markdown": "^0.5.5",
@@ -1,3 +0,0 @@
1
- import type { Tool } from "./types";
2
- export declare const testRunTool: Tool;
3
- //# sourceMappingURL=test-run-fetcher.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-run-fetcher.d.ts","sourceRoot":"","sources":["../../src/tools/test-run-fetcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAUpC,eAAO,MAAM,WAAW,EAAE,IA0DzB,CAAC"}
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.testRunTool = void 0;
4
- const zod_1 = require("zod");
5
- const TestRunSchema = zod_1.z.object({
6
- testRunUrl: zod_1.z
7
- .string()
8
- .describe("The full URL of the test run (e.g. https://dash.empirical.run/sortment-tests/test-runs/20269 or with query params like ?status=failed)"),
9
- });
10
- exports.testRunTool = {
11
- schema: {
12
- name: "fetchTestRunDetails",
13
- description: "Fetch details about a test run using its URL",
14
- parameters: TestRunSchema,
15
- },
16
- execute: async (input) => {
17
- const { testRunUrl } = input;
18
- // Remove query parameters if they exist
19
- const urlWithoutParams = testRunUrl.split("?")[0] || testRunUrl;
20
- // Extract the run ID and repo name from the URL
21
- const urlParts = urlWithoutParams.split("/");
22
- const runId = urlParts.pop(); // Last part is the run ID
23
- const repoName = urlParts[urlParts.length - 2]; // Second to last part is the repo name
24
- if (!runId || !repoName) {
25
- throw new Error("Invalid test run URL - could not extract run ID or repo name");
26
- }
27
- // Make the API call to fetch test run details
28
- const response = await fetch(`https://dash.empirical.run/api/test-runs/${runId}?repo_name=${repoName}`, {
29
- method: "GET",
30
- headers: {
31
- Authorization: "weQPMWKT",
32
- },
33
- });
34
- if (!response.ok) {
35
- return {
36
- result: `Failed to fetch test run details: ${response.statusText}`,
37
- isError: true,
38
- };
39
- }
40
- const data = await response.json();
41
- // Format the response as markdown
42
- const markdownResponse = `
43
- # Test Run Details
44
-
45
- ## Run Information
46
- - **Run ID**: ${runId}
47
- - **Repository**: ${repoName}
48
-
49
- ## Test Run Data
50
- \`\`\`json
51
- ${JSON.stringify(data, null, 2)}
52
- \`\`\`
53
- `;
54
- return {
55
- result: markdownResponse,
56
- isError: false,
57
- };
58
- },
59
- };