Skip to content

Commit f8cf30e

Browse files
authored
Merge branch 'aws:master' into master
2 parents 2866478 + 1c778ac commit f8cf30e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+271
-365
lines changed

packages/amazonq/.c8rc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
"report-dir": "../../coverage/amazonq",
33
"reporter": ["lcov"],
44
"all": true,
5-
"include": ["src/**", "dist/src/**"],
6-
"exclude": ["dist/test/**", "src/test/**"]
5+
"exclude": ["**/test*/**", "**/node_modules/**"]
76
}

packages/amazonq/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
"lint": "true",
5858
"watch": "npm run clean && npm run buildScripts && tsc -watch -p ./",
5959
"testCompile": "npm run clean && npm run buildScripts && npm run compileOnly",
60-
"test": "npm run testCompile && c8 ts-node ../core/scripts/test/test.ts dist/test/unit/index.js ../core/dist/src/testFixtures/workspaceFolder",
61-
"testE2E": "npm run testCompile && c8 ts-node ../core/scripts/test/testE2E.ts dist/test/e2e/index.js ../core/dist/src/testFixtures/workspaceFolder",
60+
"test": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/test.ts dist/test/unit/index.js ../core/dist/src/testFixtures/workspaceFolder",
61+
"testE2E": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/testE2E.ts dist/test/e2e/index.js ../core/dist/src/testFixtures/workspaceFolder",
6262
"webRun": "npx @vscode/test-web --open-devtools --browserOption=--disable-web-security --waitForDebugger=9222 --extensionDevelopmentPath=. .",
6363
"webWatch": "npm run clean && npm run buildScripts && webpack --mode development --watch",
6464
"serve": "webpack serve --config-name mainServe --mode development",

packages/amazonq/test/unit/amazonq/onboardingPage/walkthrough.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55

66
import assert from 'assert'
77
import { showAmazonQWalkthroughOnce } from 'aws-core-vscode/amazonq'
8-
import { FakeMemento } from 'aws-core-vscode/test'
98
import sinon from 'sinon'
109

1110
describe('showAmazonQWalkthroughOnce', function () {
1211
it('only shows once', async function () {
13-
const state = new FakeMemento()
1412
const showWalkthroughStub = sinon.stub()
1513
assert.deepStrictEqual(showWalkthroughStub.callCount, 0)
16-
await showAmazonQWalkthroughOnce(state, showWalkthroughStub)
14+
await showAmazonQWalkthroughOnce(showWalkthroughStub)
1715
// Show walkthrough since our state indicates we haven't shown before
1816
assert.deepStrictEqual(showWalkthroughStub.callCount, 1)
1917

20-
await showAmazonQWalkthroughOnce(state, showWalkthroughStub)
18+
await showAmazonQWalkthroughOnce(showWalkthroughStub)
2119
// On the second call we do not show again since we've shown before.
2220
assert.deepStrictEqual(showWalkthroughStub.callCount, 1)
2321
})

packages/amazonq/test/unit/codewhisperer/commands/onAcceptance.test.ts

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
AuthUtil,
1818
} from 'aws-core-vscode/codewhisperer'
1919
import { resetCodeWhispererGlobalVariables, createMockTextEditor } from 'aws-core-vscode/test'
20-
import { assertTelemetryCurried, FakeExtensionContext } from 'aws-core-vscode/test'
20+
import { assertTelemetryCurried } from 'aws-core-vscode/test'
2121
import { globals } from 'aws-core-vscode/shared'
2222
import { extensionVersion } from 'aws-core-vscode/shared'
2323

@@ -37,7 +37,6 @@ describe('onAcceptance', function () {
3737
it('Should enqueue an event object to tracker', async function () {
3838
const mockEditor = createMockTextEditor()
3939
const trackerSpy = sinon.spy(CodeWhispererTracker.prototype, 'enqueue')
40-
const extensionContext = await FakeExtensionContext.create()
4140
const fakeReferences = [
4241
{
4342
message: '',
@@ -49,22 +48,19 @@ describe('onAcceptance', function () {
4948
},
5049
},
5150
]
52-
await onAcceptance(
53-
{
54-
editor: mockEditor,
55-
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 26)),
56-
effectiveRange: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 26)),
57-
acceptIndex: 0,
58-
recommendation: "print('Hello World!')",
59-
requestId: '',
60-
sessionId: '',
61-
triggerType: 'OnDemand',
62-
completionType: 'Line',
63-
language: 'python',
64-
references: fakeReferences,
65-
},
66-
extensionContext.globalState
67-
)
51+
await onAcceptance({
52+
editor: mockEditor,
53+
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 26)),
54+
effectiveRange: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 26)),
55+
acceptIndex: 0,
56+
recommendation: "print('Hello World!')",
57+
requestId: '',
58+
sessionId: '',
59+
triggerType: 'OnDemand',
60+
completionType: 'Line',
61+
language: 'python',
62+
references: fakeReferences,
63+
})
6864
const actualArg = trackerSpy.getCall(0).args[0] as AcceptedSuggestionEntry
6965
assert.ok(trackerSpy.calledOnce)
7066
assert.strictEqual(actualArg.originalString, 'def two_sum(nums, target):')
@@ -79,7 +75,7 @@ describe('onAcceptance', function () {
7975
})
8076

8177
it('Should report telemetry that records this user decision event', async function () {
82-
await globals.context.globalState.update('CODEWHISPERER_USER_GROUP', {
78+
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
8379
group: UserGroup.Control,
8480
version: extensionVersion,
8581
})
@@ -97,23 +93,19 @@ describe('onAcceptance', function () {
9793
session.triggerType = 'OnDemand'
9894
session.setCompletionType(0, session.recommendations[0])
9995
const assertTelemetry = assertTelemetryCurried('codewhisperer_userDecision')
100-
const extensionContext = await FakeExtensionContext.create()
101-
await onAcceptance(
102-
{
103-
editor: mockEditor,
104-
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
105-
effectiveRange: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 26)),
106-
acceptIndex: 0,
107-
recommendation: "print('Hello World!')",
108-
requestId: '',
109-
sessionId: '',
110-
triggerType: 'OnDemand',
111-
completionType: 'Line',
112-
language: 'python',
113-
references: undefined,
114-
},
115-
extensionContext.globalState
116-
)
96+
await onAcceptance({
97+
editor: mockEditor,
98+
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
99+
effectiveRange: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 26)),
100+
acceptIndex: 0,
101+
recommendation: "print('Hello World!')",
102+
requestId: '',
103+
sessionId: '',
104+
triggerType: 'OnDemand',
105+
completionType: 'Line',
106+
language: 'python',
107+
references: undefined,
108+
})
117109
assertTelemetry({
118110
codewhispererRequestId: 'test',
119111
codewhispererSessionId: 'test',

packages/amazonq/test/unit/codewhisperer/commands/onInlineAcceptance.test.ts

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as vscode from 'vscode'
88
import * as sinon from 'sinon'
99
import { resetCodeWhispererGlobalVariables, createMockTextEditor } from 'aws-core-vscode/test'
1010
import { assertTelemetryCurried } from 'aws-core-vscode/test'
11-
import { FakeMemento } from 'aws-core-vscode/test'
1211
import {
1312
onInlineAcceptance,
1413
RecommendationHandler,
@@ -36,28 +35,24 @@ describe('onInlineAcceptance', function () {
3635
it('Should dispose inline completion provider', async function () {
3736
const mockEditor = createMockTextEditor()
3837
const spy = sinon.spy(RecommendationHandler.instance, 'disposeInlineCompletion')
39-
const globalState = new FakeMemento()
40-
await onInlineAcceptance(
41-
{
42-
editor: mockEditor,
43-
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
44-
effectiveRange: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
45-
acceptIndex: 0,
46-
recommendation: "print('Hello World!')",
47-
requestId: '',
48-
sessionId: '',
49-
triggerType: 'OnDemand',
50-
completionType: 'Line',
51-
language: 'python',
52-
references: undefined,
53-
},
54-
globalState
55-
)
38+
await onInlineAcceptance({
39+
editor: mockEditor,
40+
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
41+
effectiveRange: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
42+
acceptIndex: 0,
43+
recommendation: "print('Hello World!')",
44+
requestId: '',
45+
sessionId: '',
46+
triggerType: 'OnDemand',
47+
completionType: 'Line',
48+
language: 'python',
49+
references: undefined,
50+
})
5651
assert.ok(spy.calledWith())
5752
})
5853

5954
it('Should report telemetry that records this user decision event', async function () {
60-
await globals.context.globalState.update('CODEWHISPERER_USER_GROUP', {
55+
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
6156
group: UserGroup.Classifier,
6257
version: extensionVersion,
6358
})
@@ -76,23 +71,19 @@ describe('onInlineAcceptance', function () {
7671
session.triggerType = 'OnDemand'
7772
session.setCompletionType(0, session.recommendations[0])
7873
const assertTelemetry = assertTelemetryCurried('codewhisperer_userDecision')
79-
const globalState = new FakeMemento()
80-
await onInlineAcceptance(
81-
{
82-
editor: mockEditor,
83-
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
84-
effectiveRange: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
85-
acceptIndex: 0,
86-
recommendation: "print('Hello World!')",
87-
requestId: '',
88-
sessionId: '',
89-
triggerType: 'OnDemand',
90-
completionType: 'Line',
91-
language: 'python',
92-
references: undefined,
93-
},
94-
globalState
95-
)
74+
await onInlineAcceptance({
75+
editor: mockEditor,
76+
range: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
77+
effectiveRange: new vscode.Range(new vscode.Position(1, 0), new vscode.Position(1, 21)),
78+
acceptIndex: 0,
79+
recommendation: "print('Hello World!')",
80+
requestId: '',
81+
sessionId: '',
82+
triggerType: 'OnDemand',
83+
completionType: 'Line',
84+
language: 'python',
85+
references: undefined,
86+
})
9687
assertTelemetry({
9788
codewhispererRequestId: 'test',
9889
codewhispererSessionId: 'test',

packages/amazonq/test/unit/codewhisperer/service/codewhisperer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('codewhisperer', async function () {
115115
ideCategory: 'VSCODE',
116116
operatingSystem: getOperatingSystem(),
117117
product: 'CodeWhisperer',
118-
clientId: getClientId(globals.context.globalState),
118+
clientId: getClientId(globals.globalState),
119119
}
120120

121121
await codeWhispererClient.sendTelemetryEvent({ telemetryEvent: userTriggerDecisionPayload })

packages/amazonq/test/unit/codewhisperer/service/recommendationHandler.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
import {
2323
assertTelemetryCurried,
2424
stub,
25-
FakeMemento,
2625
createMockTextEditor,
2726
resetCodeWhispererGlobalVariables,
2827
} from 'aws-core-vscode/test'
@@ -41,7 +40,6 @@ describe('recommendationHandler', function () {
4140
})
4241

4342
describe('getRecommendations', async function () {
44-
const fakeMemeto = new FakeMemento()
4543
const mockClient = stub(DefaultCodeWhispererClient)
4644
const mockEditor = createMockTextEditor()
4745
const testStartUrl = 'testStartUrl'
@@ -63,8 +61,7 @@ describe('recommendationHandler', function () {
6361
it('should assign correct recommendations given input', async function () {
6462
assert.strictEqual(CodeWhispererCodeCoverageTracker.instances.size, 0)
6563
assert.strictEqual(
66-
CodeWhispererCodeCoverageTracker.getTracker(mockEditor.document.languageId, fakeMemeto)
67-
?.serviceInvocationCount,
64+
CodeWhispererCodeCoverageTracker.getTracker(mockEditor.document.languageId)?.serviceInvocationCount,
6865
0
6966
)
7067

@@ -86,8 +83,7 @@ describe('recommendationHandler', function () {
8683
const expected: RecommendationsList = [{ content: "print('Hello World!')" }, { content: '' }]
8784
assert.deepStrictEqual(actual, expected)
8885
assert.strictEqual(
89-
CodeWhispererCodeCoverageTracker.getTracker(mockEditor.document.languageId, fakeMemeto)
90-
?.serviceInvocationCount,
86+
CodeWhispererCodeCoverageTracker.getTracker(mockEditor.document.languageId)?.serviceInvocationCount,
9187
1
9288
)
9389
})
@@ -114,7 +110,7 @@ describe('recommendationHandler', function () {
114110
})
115111

116112
it('should call telemetry function that records a CodeWhisperer service invocation', async function () {
117-
await globals.context.globalState.update('CODEWHISPERER_USER_GROUP', {
113+
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
118114
group: UserGroup.CrossFile,
119115
version: extensionVersion,
120116
})
@@ -166,7 +162,7 @@ describe('recommendationHandler', function () {
166162
})
167163

168164
it('should call telemetry function that records a Empty userDecision event', async function () {
169-
await globals.context.globalState.update('CODEWHISPERER_USER_GROUP', {
165+
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
170166
group: UserGroup.CrossFile,
171167
version: extensionVersion,
172168
})

packages/amazonq/test/unit/codewhisperer/tracker/codewhispererCodeCoverageTracker.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from 'aws-core-vscode/codewhisperer'
1717
import { createMockDocument, createMockTextEditor, resetCodeWhispererGlobalVariables } from 'aws-core-vscode/test'
1818
import { globals, extensionVersion } from 'aws-core-vscode/shared'
19-
import { assertTelemetryCurried, FakeMemento } from 'aws-core-vscode/test'
19+
import { assertTelemetryCurried } from 'aws-core-vscode/test'
2020

2121
describe('codewhispererCodecoverageTracker', function () {
2222
const language = 'python'
@@ -64,7 +64,6 @@ describe('codewhispererCodecoverageTracker', function () {
6464
})
6565

6666
describe('test isActive', function () {
67-
const fakeMemeto = new FakeMemento()
6867
let tracker: CodeWhispererCodeCoverageTracker | undefined
6968

7069
afterEach(async function () {
@@ -77,7 +76,7 @@ describe('codewhispererCodecoverageTracker', function () {
7776
sinon.stub(TelemetryHelper.instance, 'isTelemetryEnabled').returns(true)
7877
sinon.stub(AuthUtil.instance, 'isConnected').returns(false)
7978

80-
tracker = CodeWhispererCodeCoverageTracker.getTracker('python', fakeMemeto)
79+
tracker = CodeWhispererCodeCoverageTracker.getTracker('python')
8180
if (!tracker) {
8281
assert.fail()
8382
}
@@ -89,7 +88,7 @@ describe('codewhispererCodecoverageTracker', function () {
8988
sinon.stub(TelemetryHelper.instance, 'isTelemetryEnabled').returns(false)
9089
sinon.stub(AuthUtil.instance, 'isConnected').returns(false)
9190

92-
tracker = CodeWhispererCodeCoverageTracker.getTracker('java', fakeMemeto)
91+
tracker = CodeWhispererCodeCoverageTracker.getTracker('java')
9392
if (!tracker) {
9493
assert.fail()
9594
}
@@ -101,7 +100,7 @@ describe('codewhispererCodecoverageTracker', function () {
101100
sinon.stub(TelemetryHelper.instance, 'isTelemetryEnabled').returns(true)
102101
sinon.stub(AuthUtil.instance, 'isConnected').returns(true)
103102

104-
tracker = CodeWhispererCodeCoverageTracker.getTracker('javascript', fakeMemeto)
103+
tracker = CodeWhispererCodeCoverageTracker.getTracker('javascript')
105104
if (!tracker) {
106105
assert.fail()
107106
}

packages/amazonq/test/unit/codewhisperer/tracker/codewhispererTracker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('codewhispererTracker', function () {
9595
})
9696

9797
it('Should call recordCodewhispererUserModification with suggestion event', async function () {
98-
await globals.context.globalState.update('CODEWHISPERER_USER_GROUP', {
98+
await globals.globalState.update('CODEWHISPERER_USER_GROUP', {
9999
group: UserGroup.CrossFile,
100100
version: extensionVersion,
101101
})

packages/core/src/amazonq/onboardingPage/walkthrough.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ import vscode from 'vscode'
1515
* Show the Amazon Q walkthrough one time forever when the user adds an Amazon Q connection.
1616
* All subsequent calls to this do nothing.
1717
*/
18-
export async function showAmazonQWalkthroughOnce(
19-
state = globals.context.globalState,
20-
showWalkthrough = () => openAmazonQWalkthrough.execute()
21-
) {
22-
const hasShownWalkthroughId = 'aws.amazonq.hasShownWalkthrough'
23-
const hasShownWalkthrough = state.get(hasShownWalkthroughId, false)
18+
export async function showAmazonQWalkthroughOnce(showWalkthrough = () => openAmazonQWalkthrough.execute()) {
19+
const hasShownWalkthrough = globals.globalState.tryGet('aws.amazonq.hasShownWalkthrough', Boolean, false)
2420
if (hasShownWalkthrough) {
2521
return
2622
}
@@ -30,7 +26,7 @@ export async function showAmazonQWalkthroughOnce(
3026
return
3127
}
3228

33-
await state.update(hasShownWalkthroughId, true)
29+
await globals.globalState.update('aws.amazonq.hasShownWalkthrough', true)
3430
await showWalkthrough()
3531
}
3632

0 commit comments

Comments
 (0)