Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to AI event logging #1602

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/extension/ai/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/extension/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ export class Kernel implements Disposable {
}

TelemetryReporter.sendTelemetryEvent('cell.startExecute')
getEventReporter().reportExecution(cell)
await getEventReporter().reportExecution(cell)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sourishkrout Won't this block execution below? For example, suppose the Foyle service is down. We might reasonably expect the eventReporter to buffer the events and perform some retrying. But I don't want to block actual cell execution. Is there a better pattern to achieve this?

Copy link
Member Author

@sourishkrout sourishkrout Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I incorrectly assumed the noop event reporter would be unless the "AI experiment" is turned on.

I agree with you about this. I figured there are likely a few things that need to be addressed to move to a smooth "out-of-the-box" experience.

We could rewrite the Reporter to resemble the telemetry one (don't love the impl either actually), where it separates producing (enqueuing) and reporting the events. However, I'd suggest that for the time being, we use the noop logger unless AI is turned on. And track a separate effort to make this default robust.

I can rewrite this reasonably quickly at a later point. Wdyt @jlewi?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runmeExec.start(Date.now())

const annotations = getAnnotations(cell)
Expand Down
13 changes: 13 additions & 0 deletions tests/extension/kernel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })),
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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,
Expand Down Expand Up @@ -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',
Expand Down
Loading