diff --git a/src/extension/ai/events.ts b/src/extension/ai/events.ts index 3e160dd5b..a4924237c 100644 --- a/src/extension/ai/events.ts +++ b/src/extension/ai/events.ts @@ -58,7 +58,7 @@ export class EventReporter implements IEventReporter { event.type = LogEventType.EXECUTE event.cells = cells event.contextId = SessionManager.getManager().getID() - this.reportEvents([event]) + return this.reportEvents([event]) } async reportEvents(events: LogEvent[]) { @@ -86,7 +86,7 @@ export class NullOpEventReporter implements IEventReporter { } } -var _globalReporter = new NullOpEventReporter() +let _globalReporter = new NullOpEventReporter() // getEventReporter returns the global event reporter export function getEventReporter(): IEventReporter { diff --git a/src/extension/kernel.ts b/src/extension/kernel.ts index 3eb2474b8..1484e5e2b 100644 --- a/src/extension/kernel.ts +++ b/src/extension/kernel.ts @@ -692,7 +692,8 @@ export class Kernel implements Disposable { } TelemetryReporter.sendTelemetryEvent('cell.startExecute') - getEventReporter().reportExecution(cell) + // todo(sebastian): rewrite to use non-blocking impl + await getEventReporter().reportExecution(cell) runmeExec.start(Date.now()) const annotations = getAnnotations(cell) diff --git a/tests/extension/kernel.test.ts b/tests/extension/kernel.test.ts index 222b08063..a35a6c8c3 100644 --- a/tests/extension/kernel.test.ts +++ b/tests/extension/kernel.test.ts @@ -9,9 +9,19 @@ import { APIMethod } from '../../src/types' import * as platform from '../../src/extension/messages/platformRequest/saveCellExecution' import { isPlatformAuthEnabled } from '../../src/utils/configuration' import { askAlternativeOutputsAction } from '../../src/extension/commands' +import { getEventReporter } from '../../src/extension/ai/events' + +const reportExecution = vi.fn() vi.mock('vscode') vi.mock('vscode-telemetry') +vi.mock('../../src/extension/ai/events', async () => { + return { + getEventReporter: () => ({ + reportExecution, + }), + } +}) vi.mock('../../src/extension/utils', async () => { return { getKeyInfo: vi.fn((cell) => ({ key: cell.languageId, uriResource: false })), @@ -325,6 +335,7 @@ suite('_doExecuteCell', () => { beforeEach(() => { vi.mocked(workspace.openTextDocument).mockReset() vi.mocked(TelemetryReporter.sendTelemetryEvent).mockClear() + vi.mocked(reportExecution).mockClear() }) test('calls proper executor if present', async () => { @@ -350,6 +361,7 @@ suite('_doExecuteCell', () => { } as any) // @ts-expect-error mocked out expect(executors.foobar).toBeCalledTimes(1) + expect(getEventReporter().reportExecution).toBeCalledTimes(1) expect(TelemetryReporter.sendTelemetryEvent).toHaveBeenCalledWith('cell.startExecute') expect(TelemetryReporter.sendTelemetryEvent).toHaveBeenCalledWith('cell.endExecute', { 'cell.success': undefined, @@ -388,6 +400,7 @@ suite('_doExecuteCell', () => { console.error(e) } + expect(getEventReporter().reportExecution).toBeCalledTimes(1) expect(TelemetryReporter.sendTelemetryEvent).toHaveBeenCalledWith('cell.startExecute') expect(TelemetryReporter.sendTelemetryEvent).toHaveBeenCalledWith('cell.endExecute', { 'cell.success': 'false',