-
Couldn't load subscription status.
- Fork 724
telemetry(amazonq): calculate % of non-generated (user-written) code #5991
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6363f66
reduce system status poll freq
leigaol 6d36cbe
Merge branch 'master' of github.com:leigaol/aws-toolkit-vscode
leigaol ce1733a
ai gen
leigaol 0036757
ai code gen
leigaol dd72f01
more code
leigaol ad0e018
update
leigaol 288617f
update
leigaol 26150f4
minimize changes
leigaol d99e4d1
update
leigaol f75c58a
fix cyclic dependency
leigaol d2c9ff1
add unit test
leigaol 7b6f975
fix test case
leigaol 8eaf48d
use runtime language
leigaol 69b374c
simplify changes
leigaol c6e2161
Merge branch 'aws:master' into ai_gen
leigaol cf1c069
lint
leigaol 32a4af5
merge
leigaol 3781ef9
Update packages/amazonq/test/unit/codewhisperer/tracker/userWrittenCo…
leigaol 97e8d56
update Q editing reset timer
leigaol 57260e8
Merge branch 'master' of github.com:leigaol/aws-toolkit-vscode into a…
leigaol f9a9b00
add comments
leigaol 955b9f6
Merge branch 'master' into ai_gen
leigaol f65acde
feedback fixes
leigaol 7a724ab
fix ci
leigaol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
packages/amazonq/test/unit/codewhisperer/tracker/userWrittenCodeTracker.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import assert from 'assert' | ||
| import * as sinon from 'sinon' | ||
| import * as vscode from 'vscode' | ||
| import { UserWrittenCodeTracker, TelemetryHelper, AuthUtil } from 'aws-core-vscode/codewhisperer' | ||
| import { createMockDocument, resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test' | ||
|
|
||
| describe('userWrittenCodeTracker', function () { | ||
| describe('test isActive', function () { | ||
| afterEach(async function () { | ||
| await resetCodeWhispererGlobalVariables() | ||
| UserWrittenCodeTracker.instance.reset() | ||
| sinon.restore() | ||
| }) | ||
|
|
||
| it('inactive case: telemetryEnable = true, isConnected = false', function () { | ||
| sinon.stub(TelemetryHelper.instance, 'isTelemetryEnabled').returns(true) | ||
| sinon.stub(AuthUtil.instance, 'isConnected').returns(false) | ||
| assert.strictEqual(UserWrittenCodeTracker.instance.isActive(), false) | ||
| }) | ||
|
|
||
| it('inactive case: telemetryEnabled = false, isConnected = false', function () { | ||
| sinon.stub(TelemetryHelper.instance, 'isTelemetryEnabled').returns(false) | ||
| sinon.stub(AuthUtil.instance, 'isConnected').returns(false) | ||
| assert.strictEqual(UserWrittenCodeTracker.instance.isActive(), false) | ||
| }) | ||
|
|
||
| it('active case: telemetryEnabled = true, isConnected = true', function () { | ||
| sinon.stub(TelemetryHelper.instance, 'isTelemetryEnabled').returns(true) | ||
| sinon.stub(AuthUtil.instance, 'isConnected').returns(true) | ||
| assert.strictEqual(UserWrittenCodeTracker.instance.isActive(), true) | ||
| }) | ||
| }) | ||
|
|
||
| describe('onDocumentChange', function () { | ||
| let tracker: UserWrittenCodeTracker | undefined | ||
|
|
||
| beforeEach(async function () { | ||
| await resetCodeWhispererGlobalVariables() | ||
| tracker = UserWrittenCodeTracker.instance | ||
| if (tracker) { | ||
| sinon.stub(tracker, 'isActive').returns(true) | ||
| } | ||
| }) | ||
|
|
||
| afterEach(function () { | ||
| sinon.restore() | ||
| UserWrittenCodeTracker.instance.reset() | ||
| }) | ||
|
|
||
| it('Should skip when content change size is more than 50', function () { | ||
| if (!tracker) { | ||
| assert.fail() | ||
| } | ||
| tracker.onQFeatureInvoked() | ||
| tracker.onTextDocumentChange({ | ||
| reason: undefined, | ||
| document: createMockDocument(), | ||
| contentChanges: [ | ||
| { | ||
| range: new vscode.Range(0, 0, 0, 600), | ||
| rangeOffset: 0, | ||
| rangeLength: 600, | ||
| text: 'def twoSum(nums, target):\nfor '.repeat(20), | ||
| }, | ||
| ], | ||
| }) | ||
| assert.strictEqual(tracker.getUserWrittenCharacters('python'), 0) | ||
| assert.strictEqual(tracker.getUserWrittenLines('python'), 0) | ||
| }) | ||
|
|
||
| it('Should not skip when content change size is less than 50', function () { | ||
| if (!tracker) { | ||
| assert.fail() | ||
| } | ||
| tracker.onQFeatureInvoked() | ||
| tracker.onTextDocumentChange({ | ||
| reason: undefined, | ||
| document: createMockDocument(), | ||
| contentChanges: [ | ||
| { | ||
| range: new vscode.Range(0, 0, 0, 49), | ||
| rangeOffset: 0, | ||
| rangeLength: 49, | ||
| text: 'a = 123'.repeat(7), | ||
| }, | ||
| ], | ||
| }) | ||
| tracker.onTextDocumentChange({ | ||
| reason: undefined, | ||
| document: createMockDocument('', 'test.java', 'java'), | ||
| contentChanges: [ | ||
| { | ||
| range: new vscode.Range(0, 0, 1, 3), | ||
| rangeOffset: 0, | ||
| rangeLength: 11, | ||
| text: 'a = 123\nbcd', | ||
| }, | ||
| ], | ||
| }) | ||
| assert.strictEqual(tracker.getUserWrittenCharacters('python'), 49) | ||
| assert.strictEqual(tracker.getUserWrittenLines('python'), 0) | ||
| assert.strictEqual(tracker.getUserWrittenCharacters('java'), 11) | ||
| assert.strictEqual(tracker.getUserWrittenLines('java'), 1) | ||
| assert.strictEqual(tracker.getUserWrittenLines('cpp'), 0) | ||
| }) | ||
|
|
||
| it('Should skip when Q is editing', function () { | ||
| if (!tracker) { | ||
| assert.fail() | ||
| } | ||
| tracker.onQFeatureInvoked() | ||
| tracker.onQStartsMakingEdits() | ||
| tracker.onTextDocumentChange({ | ||
| reason: undefined, | ||
| document: createMockDocument(), | ||
| contentChanges: [ | ||
| { | ||
| range: new vscode.Range(0, 0, 0, 30), | ||
| rangeOffset: 0, | ||
| rangeLength: 30, | ||
| text: 'def twoSum(nums, target):\nfor', | ||
| }, | ||
| ], | ||
| }) | ||
| tracker.onQFinishesEdits() | ||
| tracker.onTextDocumentChange({ | ||
| reason: undefined, | ||
| document: createMockDocument(), | ||
| contentChanges: [ | ||
| { | ||
| range: new vscode.Range(0, 0, 0, 2), | ||
| rangeOffset: 0, | ||
| rangeLength: 2, | ||
| text: '\na', | ||
| }, | ||
| ], | ||
| }) | ||
| assert.strictEqual(tracker.getUserWrittenCharacters('python'), 2) | ||
| assert.strictEqual(tracker.getUserWrittenLines('python'), 1) | ||
| }) | ||
|
|
||
| it('Should not reduce tokens when delete', function () { | ||
| if (!tracker) { | ||
| assert.fail() | ||
| } | ||
| const doc = createMockDocument('import math', 'test.py', 'python') | ||
|
|
||
| tracker.onQFeatureInvoked() | ||
| tracker.onTextDocumentChange({ | ||
| reason: undefined, | ||
| document: doc, | ||
| contentChanges: [ | ||
| { | ||
| range: new vscode.Range(0, 0, 0, 1), | ||
| rangeOffset: 0, | ||
| rangeLength: 0, | ||
| text: 'a', | ||
| }, | ||
| ], | ||
| }) | ||
| tracker.onTextDocumentChange({ | ||
| reason: undefined, | ||
| document: doc, | ||
| contentChanges: [ | ||
| { | ||
| range: new vscode.Range(0, 0, 0, 1), | ||
| rangeOffset: 0, | ||
| rangeLength: 0, | ||
| text: 'b', | ||
| }, | ||
| ], | ||
| }) | ||
| assert.strictEqual(tracker.getUserWrittenCharacters('python'), 2) | ||
| tracker.onTextDocumentChange({ | ||
| reason: undefined, | ||
| document: doc, | ||
| contentChanges: [ | ||
| { | ||
| range: new vscode.Range(0, 0, 0, 1), | ||
| rangeOffset: 1, | ||
| rangeLength: 1, | ||
| text: '', | ||
| }, | ||
| ], | ||
| }) | ||
| assert.strictEqual(tracker.getUserWrittenCharacters('python'), 2) | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.