From da98dd3d9c5234ee432064955f270da9f7735520 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Thu, 31 Jul 2025 14:32:15 -0700 Subject: [PATCH] test: telemetry --- gui/src/redux/thunks/callToolById.ts | 7 ++++- gui/src/redux/thunks/streamNormalInput.ts | 9 ------ .../thunks/streamResponse_toolCalls.test.ts | 28 +++++++++++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/gui/src/redux/thunks/callToolById.ts b/gui/src/redux/thunks/callToolById.ts index 1f94a8ab0..614ebbc37 100644 --- a/gui/src/redux/thunks/callToolById.ts +++ b/gui/src/redux/thunks/callToolById.ts @@ -33,8 +33,13 @@ export const callToolById = createAsyncThunk< // Track tool call acceptance and start timing const startTime = Date.now(); + + // Check if this is an auto-approved tool + const toolSettings = state.ui.toolSettings; + const isAutoApproved = toolSettings[toolCallState.toolCall.function.name] === "allowedWithoutPermission"; + posthog.capture("gui_tool_call_decision", { - decision: "accept", + decision: isAutoApproved ? "auto_accept" : "accept", toolName: toolCallState.toolCall.function.name, toolCallId: toolCallId, }); diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index fe74ed886..6e3939a5b 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -69,15 +69,6 @@ async function handleToolCallExecution( // Only run if we have auto-approve for all if (allAutoApproved && toolCallStates.length > 0) { - // Track auto-approved tool execution - toolCallStates.forEach((toolCallState) => { - posthog.capture("gui_tool_call_decision", { - decision: "auto_accept", - toolName: toolCallState.toolCall.function.name, - toolCallId: toolCallState.toolCallId, - }); - }); - const toolCallPromises = toolCallStates.map(async (toolCallState) => { const response = await dispatch( callToolById({ toolCallId: toolCallState.toolCallId }), diff --git a/gui/src/redux/thunks/streamResponse_toolCalls.test.ts b/gui/src/redux/thunks/streamResponse_toolCalls.test.ts index 122d4c4e3..b9e3351c5 100644 --- a/gui/src/redux/thunks/streamResponse_toolCalls.test.ts +++ b/gui/src/redux/thunks/streamResponse_toolCalls.test.ts @@ -556,6 +556,20 @@ describe("streamResponseThunk - tool calls", () => { expect(result.type).toBe("chat/streamResponse/fulfilled"); + // Verify telemetry events for auto-approved tool execution + expect(mockPosthog.capture).toHaveBeenCalledWith("gui_tool_call_decision", { + decision: "auto_accept", + toolName: "search_codebase", + toolCallId: "tool-call-1", + }); + + expect(mockPosthog.capture).toHaveBeenCalledWith("gui_tool_call_outcome", { + succeeded: true, + toolName: "search_codebase", + errorMessage: undefined, + duration_ms: expect.any(Number), + }); + // Verify final state after tool call execution const finalState = mockStoreWithToolSettings.getState(); expect(finalState).toEqual({ @@ -2722,6 +2736,20 @@ describe("streamResponseThunk - tool calls", () => { }, ]); + // Verify telemetry events for manual approval flow + expect(mockPosthog.capture).toHaveBeenCalledWith("gui_tool_call_decision", { + decision: "accept", + toolName: "search_codebase", + toolCallId: "tool-approval-flow-1", + }); + + expect(mockPosthog.capture).toHaveBeenCalledWith("gui_tool_call_outcome", { + succeeded: true, + toolName: "search_codebase", + errorMessage: undefined, + duration_ms: expect.any(Number), + }); + // Verify IDE messenger calls for tool execution expect(mockIdeMessengerApproval.request).toHaveBeenCalledWith( "tools/call",