@@ -5,7 +5,6 @@ package software.aws.toolkits.jetbrains.services.codewhisperer
5
5
6
6
import com.google.gson.Gson
7
7
import com.intellij.openapi.application.ApplicationManager
8
- import com.intellij.openapi.application.runInEdt
9
8
import com.intellij.openapi.command.WriteCommandAction
10
9
import com.intellij.openapi.editor.Editor
11
10
import com.intellij.openapi.ui.popup.JBPopup
@@ -41,6 +40,7 @@ import software.aws.toolkits.core.telemetry.MetricEvent
41
40
import software.aws.toolkits.core.telemetry.TelemetryBatcher
42
41
import software.aws.toolkits.core.telemetry.TelemetryPublisher
43
42
import software.aws.toolkits.jetbrains.services.codewhisperer.CodeWhispererTestUtil.emptyListResponse
43
+ import software.aws.toolkits.jetbrains.services.codewhisperer.CodeWhispererTestUtil.keystrokeInput
44
44
import software.aws.toolkits.jetbrains.services.codewhisperer.CodeWhispererTestUtil.listOfEmptyRecommendationResponse
45
45
import software.aws.toolkits.jetbrains.services.codewhisperer.CodeWhispererTestUtil.listOfMixedEmptyAndNonEmptyRecommendationResponse
46
46
import software.aws.toolkits.jetbrains.services.codewhisperer.CodeWhispererTestUtil.pythonResponse
@@ -508,11 +508,11 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
508
508
val fixture = projectRule.fixture
509
509
val emptyFile = fixture.addFileToProject(" /anotherFile.py" , " " )
510
510
// simulate users typing behavior of the following
511
- // def addTwoNumbers(
511
+ // user hit one key stroke
512
512
runInEdtAndWait {
513
513
fixture.openFileInEditor(emptyFile.virtualFile)
514
514
WriteCommandAction .runWriteCommandAction(project) {
515
- fixture.editor.appendString(pythonTestLeftContext )
515
+ fixture.editor.appendString(keystrokeInput )
516
516
}
517
517
}
518
518
// simulate users accepting the recommendation and delete part of the recommendation
@@ -533,7 +533,7 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
533
533
CodeWhispererCodeCoverageTracker .getInstance(project, CodeWhispererPython .INSTANCE ).dispose()
534
534
535
535
val acceptedTokensSize = pythonResponse.completions()[0 ].content().length - deletedTokenByUser
536
- val totalTokensSize = pythonTestLeftContext .length + pythonResponse.completions()[0 ].content().length
536
+ val totalTokensSize = keystrokeInput .length + pythonResponse.completions()[0 ].content().length
537
537
538
538
val metricCaptor = argumentCaptor<MetricEvent >()
539
539
verify(batcher, atLeastOnce()).enqueue(metricCaptor.capture())
@@ -554,24 +554,23 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
554
554
val project = projectRule.project
555
555
val fixture = projectRule.fixture
556
556
val emptyFile = fixture.addFileToProject(" /anotherFile.py" , " " )
557
- // simulate users typing behavior of the following
558
- // def addTwoNumbers
557
+ // simulate users typing behavior
559
558
runInEdtAndWait {
560
559
fixture.openFileInEditor(emptyFile.virtualFile)
561
560
WriteCommandAction .runWriteCommandAction(project) {
562
- fixture.editor.appendString(pythonTestLeftContext )
561
+ fixture.editor.appendString(keystrokeInput )
563
562
}
564
563
}
565
564
// simulate users accepting the recommendation
566
565
// (x, y):\n return x + y
567
- val anotherCodeSnippet = " \n def functionWritenByMyself(): \n\t pass() "
566
+ val anotherKeyStrokeInput = " \n "
568
567
withCodeWhispererServiceInvokedAndWait {
569
568
popupManagerSpy.popupComponents.acceptButton.doClick()
570
569
}
571
570
572
571
runInEdtAndWait {
573
572
WriteCommandAction .runWriteCommandAction(project) {
574
- fixture.editor.appendString(anotherCodeSnippet )
573
+ fixture.editor.appendString(anotherKeyStrokeInput )
575
574
val currentOffset = fixture.editor.caretModel.offset
576
575
// delete 1 char
577
576
fixture.editor.document.deleteString(currentOffset - 1 , currentOffset)
@@ -581,7 +580,7 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
581
580
}
582
581
583
582
val acceptedTokensSize = pythonResponse.completions()[0 ].content().length
584
- val totalTokensSize = pythonTestLeftContext .length + pythonResponse.completions()[0 ].content().length + anotherCodeSnippet.length
583
+ val totalTokensSize = keystrokeInput .length + pythonResponse.completions()[0 ].content().length + 1
585
584
586
585
val metricCaptor = argumentCaptor<MetricEvent >()
587
586
verify(batcher, atLeastOnce()).enqueue(metricCaptor.capture())
@@ -605,17 +604,21 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
605
604
val userGroup = CodeWhispererUserGroupSettings .getInstance().getUserGroup()
606
605
val project = projectRule.project
607
606
val fixture = projectRule.fixture
608
- fixture.configureByText(" /file1.py" , pythonTestLeftContext)
609
- runInEdt {
610
- fixture.editor.caretModel.moveToOffset(fixture.editor.document.textLength)
607
+ val emptyFile = fixture.addFileToProject(" /anotherFile.py" , pythonTestLeftContext)
608
+ // simulate users typing behavior
609
+ runInEdtAndWait {
610
+ fixture.openFileInEditor(emptyFile.virtualFile)
611
+ WriteCommandAction .runWriteCommandAction(project) {
612
+ fixture.editor.appendString(keystrokeInput)
613
+ }
611
614
}
612
- val file2 = fixture.addFileToProject(" ./file2.py" , " Pre-existing string" )
613
615
614
616
// accept recommendation in file1.py
615
617
withCodeWhispererServiceInvokedAndWait {
616
618
popupManagerSpy.popupComponents.acceptButton.doClick()
617
619
}
618
620
621
+ val file2 = fixture.addFileToProject(" ./file2.py" , " Pre-existing string" )
619
622
// switch to file2.py and delete code there
620
623
runInEdtAndWait {
621
624
fixture.openFileInEditor(file2.virtualFile)
@@ -634,8 +637,8 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
634
637
codePercentage,
635
638
1 ,
636
639
" codewhispererAcceptedTokens" to pythonResponse.completions()[0 ].content().length.toString(),
637
- " codewhispererTotalTokens" to pythonResponse.completions()[0 ].content().length.toString(),
638
- " codewhispererPercentage" to " 100 " ,
640
+ " codewhispererTotalTokens" to ( 1 + pythonResponse.completions()[0 ].content().length) .toString(),
641
+ " codewhispererPercentage" to " 96 " ,
639
642
" codewhispererUserGroup" to userGroup.name,
640
643
)
641
644
}
@@ -663,7 +666,7 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
663
666
runInEdtAndWait {
664
667
fixture.openFileInEditor(emptyFile.virtualFile)
665
668
WriteCommandAction .runWriteCommandAction(project) {
666
- fixture.editor.appendString(" $pythonTestLeftContext (" )
669
+ fixture.editor.appendString(" (" )
667
670
// add closing paren but not move the caret position, simulating IDE's behavior
668
671
fixture.editor.document.insertString(fixture.editor.caretModel.offset, " )" )
669
672
}
@@ -675,7 +678,7 @@ class CodeWhispererTelemetryTest : CodeWhispererTestBase() {
675
678
CodeWhispererCodeCoverageTracker .getInstance(project, CodeWhispererPython .INSTANCE ).dispose()
676
679
677
680
val acceptedTokensSize = " x, y):\n return x + y" .length
678
- val totalTokensSize = " $pythonTestLeftContext ( " .length + acceptedTokensSize
681
+ val totalTokensSize = " () " .length + acceptedTokensSize
679
682
val metricCaptor = argumentCaptor<MetricEvent >()
680
683
verify(batcher, atLeastOnce()).enqueue(metricCaptor.capture())
681
684
assertEventsContainsFieldsAndCount(
0 commit comments