diff options
Diffstat (limited to 'packages/core/src/telemetry/uiTelemetry.test.ts')
| -rw-r--r-- | packages/core/src/telemetry/uiTelemetry.test.ts | 74 |
1 files changed, 58 insertions, 16 deletions
diff --git a/packages/core/src/telemetry/uiTelemetry.test.ts b/packages/core/src/telemetry/uiTelemetry.test.ts index cd509a8e..a64f839e 100644 --- a/packages/core/src/telemetry/uiTelemetry.test.ts +++ b/packages/core/src/telemetry/uiTelemetry.test.ts @@ -108,6 +108,10 @@ describe('UiTelemetryService', () => { }, byName: {}, }, + files: { + totalLinesAdded: 0, + totalLinesRemoved: 0, + }, }); expect(service.getLastPromptTokenCount()).toBe(0); }); @@ -342,9 +346,9 @@ describe('UiTelemetryService', () => { ToolConfirmationOutcome.ProceedOnce, ); service.addEvent({ - ...JSON.parse(JSON.stringify(new ToolCallEvent(toolCall))), + ...structuredClone(new ToolCallEvent(toolCall)), 'event.name': EVENT_TOOL_CALL, - }); + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }); const metrics = service.getMetrics(); const { tools } = metrics; @@ -376,9 +380,9 @@ describe('UiTelemetryService', () => { ToolConfirmationOutcome.Cancel, ); service.addEvent({ - ...JSON.parse(JSON.stringify(new ToolCallEvent(toolCall))), + ...structuredClone(new ToolCallEvent(toolCall)), 'event.name': EVENT_TOOL_CALL, - }); + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }); const metrics = service.getMetrics(); const { tools } = metrics; @@ -410,9 +414,9 @@ describe('UiTelemetryService', () => { ToolConfirmationOutcome.ModifyWithEditor, ); service.addEvent({ - ...JSON.parse(JSON.stringify(new ToolCallEvent(toolCall))), + ...structuredClone(new ToolCallEvent(toolCall)), 'event.name': EVENT_TOOL_CALL, - }); + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }); const metrics = service.getMetrics(); const { tools } = metrics; @@ -426,9 +430,9 @@ describe('UiTelemetryService', () => { it('should process a ToolCallEvent without a decision', () => { const toolCall = createFakeCompletedToolCall('test_tool', true, 100); service.addEvent({ - ...JSON.parse(JSON.stringify(new ToolCallEvent(toolCall))), + ...structuredClone(new ToolCallEvent(toolCall)), 'event.name': EVENT_TOOL_CALL, - }); + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }); const metrics = service.getMetrics(); const { tools } = metrics; @@ -462,13 +466,13 @@ describe('UiTelemetryService', () => { ); service.addEvent({ - ...JSON.parse(JSON.stringify(new ToolCallEvent(toolCall1))), + ...structuredClone(new ToolCallEvent(toolCall1)), 'event.name': EVENT_TOOL_CALL, - }); + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }); service.addEvent({ - ...JSON.parse(JSON.stringify(new ToolCallEvent(toolCall2))), + ...structuredClone(new ToolCallEvent(toolCall2)), 'event.name': EVENT_TOOL_CALL, - }); + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }); const metrics = service.getMetrics(); const { tools } = metrics; @@ -497,13 +501,13 @@ describe('UiTelemetryService', () => { const toolCall1 = createFakeCompletedToolCall('tool_A', true, 100); const toolCall2 = createFakeCompletedToolCall('tool_B', false, 200); service.addEvent({ - ...JSON.parse(JSON.stringify(new ToolCallEvent(toolCall1))), + ...structuredClone(new ToolCallEvent(toolCall1)), 'event.name': EVENT_TOOL_CALL, - }); + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }); service.addEvent({ - ...JSON.parse(JSON.stringify(new ToolCallEvent(toolCall2))), + ...structuredClone(new ToolCallEvent(toolCall2)), 'event.name': EVENT_TOOL_CALL, - }); + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }); const metrics = service.getMetrics(); const { tools } = metrics; @@ -629,4 +633,42 @@ describe('UiTelemetryService', () => { expect(spy).toHaveBeenCalledOnce(); }); }); + + describe('Tool Call Event with Line Count Metadata', () => { + it('should aggregate valid line count metadata', () => { + const toolCall = createFakeCompletedToolCall('test_tool', true, 100); + const event = { + ...structuredClone(new ToolCallEvent(toolCall)), + 'event.name': EVENT_TOOL_CALL, + metadata: { + ai_added_lines: 10, + ai_removed_lines: 5, + }, + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }; + + service.addEvent(event); + + const metrics = service.getMetrics(); + expect(metrics.files.totalLinesAdded).toBe(10); + expect(metrics.files.totalLinesRemoved).toBe(5); + }); + + it('should ignore null/undefined values in line count metadata', () => { + const toolCall = createFakeCompletedToolCall('test_tool', true, 100); + const event = { + ...structuredClone(new ToolCallEvent(toolCall)), + 'event.name': EVENT_TOOL_CALL, + metadata: { + ai_added_lines: null, + ai_removed_lines: undefined, + }, + } as ToolCallEvent & { 'event.name': typeof EVENT_TOOL_CALL }; + + service.addEvent(event); + + const metrics = service.getMetrics(); + expect(metrics.files.totalLinesAdded).toBe(0); + expect(metrics.files.totalLinesRemoved).toBe(0); + }); + }); }); |
