Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ import * as vscode from 'vscode'
import * as sinon from 'sinon'
import {
onAcceptance,
UserGroup,
AcceptedSuggestionEntry,
session,
CodeWhispererTracker,
RecommendationHandler,
CodeWhispererUserGroupSettings,
AuthUtil,
} from 'aws-core-vscode/codewhisperer'
import { resetCodeWhispererGlobalVariables, createMockTextEditor } from 'aws-core-vscode/test'
import { assertTelemetryCurried } from 'aws-core-vscode/test'
import { globals } from 'aws-core-vscode/shared'
import { extensionVersion } from 'aws-core-vscode/shared'

describe('onAcceptance', function () {
describe('onAcceptance', function () {
Expand All @@ -31,7 +27,6 @@ describe('onAcceptance', function () {
afterEach(function () {
sinon.restore()
session.reset()
CodeWhispererUserGroupSettings.instance.reset()
})

it('Should enqueue an event object to tracker', async function () {
Expand Down Expand Up @@ -75,11 +70,6 @@ describe('onAcceptance', function () {
})

it('Should report telemetry that records this user decision event', async function () {
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
group: UserGroup.Control,
version: extensionVersion,
})

const testStartUrl = 'testStartUrl'
sinon.stub(AuthUtil.instance, 'startUrl').value(testStartUrl)
const mockEditor = createMockTextEditor()
Expand Down Expand Up @@ -117,7 +107,6 @@ describe('onAcceptance', function () {
codewhispererCompletionType: 'Line',
codewhispererLanguage: 'python',
credentialStartUrl: testStartUrl,
codewhispererUserGroup: 'Control',
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ import * as vscode from 'vscode'
import * as sinon from 'sinon'
import { resetCodeWhispererGlobalVariables, createMockTextEditor } from 'aws-core-vscode/test'
import { assertTelemetryCurried } from 'aws-core-vscode/test'
import {
onInlineAcceptance,
RecommendationHandler,
AuthUtil,
session,
CodeWhispererUserGroupSettings,
UserGroup,
} from 'aws-core-vscode/codewhisperer'
import { onInlineAcceptance, RecommendationHandler, AuthUtil, session } from 'aws-core-vscode/codewhisperer'
import { globals } from 'aws-core-vscode/shared'
import { extensionVersion } from 'aws-core-vscode/shared'

Expand All @@ -29,7 +22,6 @@ describe('onInlineAcceptance', function () {
afterEach(function () {
sinon.restore()
session.reset()
CodeWhispererUserGroupSettings.instance.reset()
})

it('Should dispose inline completion provider', async function () {
Expand All @@ -53,7 +45,6 @@ describe('onInlineAcceptance', function () {

it('Should report telemetry that records this user decision event', async function () {
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
group: UserGroup.Classifier,
version: extensionVersion,
})

Expand Down Expand Up @@ -95,7 +86,6 @@ describe('onInlineAcceptance', function () {
codewhispererCompletionType: 'Line',
codewhispererLanguage: 'python',
credentialStartUrl: testStartUrl,
codewhispererUserGroup: 'Classifier',
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import {
resetCodeWhispererGlobalVariables,
} from 'aws-core-vscode/test'
import * as EditorContext from 'aws-core-vscode/codewhisperer'
import * as CodeWhispererConstants from 'aws-core-vscode/codewhisperer'
import {
ConfigurationEntry,
DocumentChangedSource,
KeyStrokeHandler,
DefaultDocumentChangedType,
RecommendationService,
CodeWhispererUserGroupSettings,
ClassifierTrigger,
isInlineCompletionEnabled,
RecommendationHandler,
Expand Down Expand Up @@ -52,7 +50,6 @@ describe('keyStrokeHandler', function () {
})
afterEach(function () {
sinon.restore()
CodeWhispererUserGroupSettings.instance.reset()
})

it('Whatever the input is, should skip when automatic trigger is turned off, should not call invokeAutomatedTrigger', async function () {
Expand Down Expand Up @@ -145,19 +142,13 @@ describe('keyStrokeHandler', function () {
}
})

async function testShouldInvoke(
input: string,
shouldTrigger: boolean,
rightContext: string = '',
userGroup: CodeWhispererConstants.UserGroup = CodeWhispererConstants.UserGroup.Control
) {
async function testShouldInvoke(input: string, shouldTrigger: boolean, rightContext: string = '') {
const mockEditor = createMockTextEditor(rightContext, 'test.js', 'javascript', 0, 0)
const mockEvent: vscode.TextDocumentChangeEvent = createTextDocumentChangeEvent(
mockEditor.document,
new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 1)),
input
)
CodeWhispererUserGroupSettings.instance.userGroup = userGroup
await KeyStrokeHandler.instance.processKeyStroke(mockEvent, mockEditor, mockClient, config)
assert.strictEqual(
invokeSpy.called,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import {
ReferenceInlineProvider,
session,
AuthUtil,
CodeWhispererUserGroupSettings,
DefaultCodeWhispererClient,
RecommendationsList,
ConfigurationEntry,
RecommendationHandler,
CodeWhispererCodeCoverageTracker,
UserGroup,
supplementalContextUtil,
} from 'aws-core-vscode/codewhisperer'
import {
Expand All @@ -26,7 +24,6 @@ import {
resetCodeWhispererGlobalVariables,
} from 'aws-core-vscode/test'
// import * as supplementalContextUtil from 'aws-core-vscode/codewhisperer'
import { globals, extensionVersion } from 'aws-core-vscode/shared'

describe('recommendationHandler', function () {
const config: ConfigurationEntry = {
Expand Down Expand Up @@ -55,7 +52,6 @@ describe('recommendationHandler', function () {

afterEach(function () {
sinon.restore()
CodeWhispererUserGroupSettings.instance.reset()
})

it('should assign correct recommendations given input', async function () {
Expand Down Expand Up @@ -110,11 +106,6 @@ describe('recommendationHandler', function () {
})

it('should call telemetry function that records a CodeWhisperer service invocation', async function () {
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
group: UserGroup.CrossFile,
version: extensionVersion,
})

const mockServerResult = {
recommendations: [{ content: "print('Hello World!')" }, { content: '' }],
$response: {
Expand Down Expand Up @@ -157,16 +148,10 @@ describe('recommendationHandler', function () {
codewhispererSupplementalContextTimeout: false,
codewhispererSupplementalContextLatency: 0,
codewhispererSupplementalContextLength: 100,
codewhispererUserGroup: 'CrossFile',
})
})

it('should call telemetry function that records a Empty userDecision event', async function () {
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
group: UserGroup.CrossFile,
version: extensionVersion,
})

const mockServerResult = {
recommendations: [],
nextToken: '',
Expand Down Expand Up @@ -198,7 +183,6 @@ describe('recommendationHandler', function () {
codewhispererCompletionType: 'Line',
codewhispererLanguage: 'python',
credentialStartUrl: testStartUrl,
codewhispererUserGroup: 'CrossFile',
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ describe.skip('CodeWhisperer telemetry', async function () {
codewhispererSuggestionState: 'Accept',
codewhispererSuggestionImportCount: 0,
codewhispererTypeaheadLength: 0,
codewhispererUserGroup: 'Control',
...ops,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@
import assert from 'assert'
import * as sinon from 'sinon'
import * as vscode from 'vscode'
import {
CodeWhispererCodeCoverageTracker,
vsCodeState,
TelemetryHelper,
AuthUtil,
UserGroup,
CodeWhispererUserGroupSettings,
} from 'aws-core-vscode/codewhisperer'
import { CodeWhispererCodeCoverageTracker, vsCodeState, TelemetryHelper, AuthUtil } from 'aws-core-vscode/codewhisperer'
import { createMockDocument, createMockTextEditor, resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test'
import { globals, extensionVersion } from 'aws-core-vscode/shared'
import { globals } from 'aws-core-vscode/shared'
import { assertTelemetryCurried } from 'aws-core-vscode/test'

describe('codewhispererCodecoverageTracker', function () {
Expand Down Expand Up @@ -516,21 +509,14 @@ describe('codewhispererCodecoverageTracker', function () {
if (tracker) {
sinon.stub(tracker, 'isActive').returns(true)
}
CodeWhispererUserGroupSettings.instance.reset()
})

afterEach(function () {
sinon.restore()
CodeWhispererCodeCoverageTracker.instances.clear()
CodeWhispererUserGroupSettings.instance.reset()
})

it('should emit correct code coverage telemetry in python file', async function () {
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
group: UserGroup.Control,
version: extensionVersion,
})

const tracker = CodeWhispererCodeCoverageTracker.getTracker(language)

const assertTelemetry = assertTelemetryCurried('codewhisperer_codePercentage')
Expand All @@ -545,16 +531,10 @@ describe('codewhispererCodecoverageTracker', function () {
codewhispererSuggestedTokens: 7,
codewhispererPercentage: 7,
successCount: 1,
codewhispererUserGroup: 'Control',
})
})

it('should emit correct code coverage telemetry when success count = 0', async function () {
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
group: UserGroup.Control,
version: extensionVersion,
})

const tracker = CodeWhispererCodeCoverageTracker.getTracker('java')

const assertTelemetry = assertTelemetryCurried('codewhisperer_codePercentage')
Expand All @@ -574,7 +554,6 @@ describe('codewhispererCodecoverageTracker', function () {
codewhispererSuggestedTokens: 18,
codewhispererPercentage: 60,
successCount: 2,
codewhispererUserGroup: 'Control',
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
import assert from 'assert'
import * as sinon from 'sinon'
import { assertTelemetryCurried } from 'aws-core-vscode/test'
import {
AuthUtil,
CodeWhispererTracker,
UserGroup,
CodeWhispererUserGroupSettings,
} from 'aws-core-vscode/codewhisperer'
import { AuthUtil, CodeWhispererTracker } from 'aws-core-vscode/codewhisperer'
import { resetCodeWhispererGlobalVariables, createAcceptedSuggestionEntry } from 'aws-core-vscode/test'
import { globals, extensionVersion } from 'aws-core-vscode/shared'
import { globals } from 'aws-core-vscode/shared'

describe('codewhispererTracker', function () {
describe('enqueue', function () {
Expand Down Expand Up @@ -86,20 +81,7 @@ describe('codewhispererTracker', function () {
})

describe('emitTelemetryOnSuggestion', function () {
beforeEach(function () {
CodeWhispererUserGroupSettings.instance.reset()
})

afterEach(function () {
CodeWhispererUserGroupSettings.instance.reset()
})

it('Should call recordCodewhispererUserModification with suggestion event', async function () {
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
group: UserGroup.CrossFile,
version: extensionVersion,
})

const testStartUrl = 'testStartUrl'
sinon.stub(AuthUtil.instance, 'startUrl').value(testStartUrl)
const suggestion = createAcceptedSuggestionEntry()
Expand All @@ -114,7 +96,6 @@ describe('codewhispererTracker', function () {
codewhispererCompletionType: 'Line',
codewhispererLanguage: 'java',
credentialStartUrl: testStartUrl,
codewhispererUserGroup: 'CrossFile',
codewhispererCharactersAccepted: suggestion.originalString.length,
codewhispererCharactersModified: 0,
})
Expand Down
Loading
Loading