Skip to content

Commit 8772a2e

Browse files
committed
fix: few fixes to pass GitHub checks
1 parent 55b32d0 commit 8772a2e

File tree

7 files changed

+74
-76
lines changed

7 files changed

+74
-76
lines changed

packages/amazonq/src/app/inline/EditRendering/displayImage.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,20 @@ export class EditDecorationManager {
192192
this.imageDecorationType.dispose()
193193
this.removedCodeDecorationType.dispose()
194194
}
195+
196+
// Use process-wide singleton to prevent multiple instances on Windows
197+
static readonly decorationManagerKey = Symbol.for('aws.amazonq.decorationManager')
198+
199+
static getDecorationManager(): EditDecorationManager {
200+
const globalObj = global as any
201+
if (!globalObj[this.decorationManagerKey]) {
202+
globalObj[this.decorationManagerKey] = new EditDecorationManager()
203+
}
204+
return globalObj[this.decorationManagerKey]
205+
}
195206
}
196207

197-
// Create a singleton instance of the decoration manager
198-
export const decorationManager = new EditDecorationManager()
208+
export const decorationManager = EditDecorationManager.getDecorationManager()
199209

200210
/**
201211
* Function to replace editor's content with new code

packages/amazonq/src/app/inline/completion.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,16 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
209209
token: CancellationToken,
210210
getAllRecommendationsOptions?: GetAllRecommendationsOptions
211211
): Promise<InlineCompletionItem[]> {
212+
getLogger().info('_provideInlineCompletionItems called with: %O', {
213+
documentUri: document.uri.toString(),
214+
position,
215+
context,
216+
triggerKind: context.triggerKind === InlineCompletionTriggerKind.Automatic ? 'Automatic' : 'Invoke',
217+
})
218+
212219
// prevent concurrent API calls and write to shared state variables
213220
if (vsCodeState.isRecommendationsActive) {
221+
getLogger().info('Recommendations already active, returning empty')
214222
return []
215223
}
216224
let logstr = `GenerateCompletion metadata:\\n`

packages/amazonq/src/app/inline/recommendationService.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { InlineGeneratingMessage } from './inlineGeneratingMessage'
1515
import { CodeWhispererStatusBarManager } from 'aws-core-vscode/codewhisperer'
1616
import { TelemetryHelper } from './telemetryHelper'
1717
import { ICursorUpdateRecorder } from './cursorUpdateManager'
18-
import { globals } from 'aws-core-vscode/shared'
18+
import { globals, getLogger } from 'aws-core-vscode/shared'
1919

2020
export interface GetAllRecommendationsOptions {
2121
emitTelemetry?: boolean
@@ -70,11 +70,31 @@ export class RecommendationService {
7070
}
7171

7272
// Handle first request
73+
getLogger().info('Sending inline completion request: %O', {
74+
method: inlineCompletionWithReferencesRequestType.method,
75+
request: {
76+
textDocument: request.textDocument,
77+
position: request.position,
78+
context: request.context,
79+
},
80+
})
7381
let result: InlineCompletionListWithReferences = await languageClient.sendRequest(
7482
inlineCompletionWithReferencesRequestType.method,
7583
request,
7684
token
7785
)
86+
getLogger().info('Received inline completion response: %O', {
87+
sessionId: result.sessionId,
88+
itemCount: result.items?.length || 0,
89+
items: result.items?.map((item) => ({
90+
itemId: item.itemId,
91+
insertText:
92+
(typeof item.insertText === 'string' ? item.insertText : String(item.insertText))?.substring(
93+
0,
94+
50
95+
) + '...',
96+
})),
97+
})
7898

7999
TelemetryHelper.instance.setSdkApiCallEndTime()
80100
TelemetryHelper.instance.setSessionId(result.sessionId)
@@ -112,7 +132,7 @@ export class RecommendationService {
112132
TelemetryHelper.instance.setAllPaginationEndTime()
113133
options.emitTelemetry && TelemetryHelper.instance.tryRecordClientComponentLatency()
114134
} catch (error) {
115-
console.error('Error getting recommendations:', error)
135+
getLogger().error('Error getting recommendations: %O', error)
116136
return []
117137
} finally {
118138
// Remove all UI indicators if UI is enabled

packages/amazonq/test/unit/amazonq/apps/inline/recommendationService.test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ describe('RecommendationService', () => {
211211
sinon.assert.calledOnce(cursorUpdateManager.recordCompletionRequest as sinon.SinonStub)
212212
})
213213

214-
it('should not show UI indicators when showUi option is false', async () => {
214+
// Helper function to setup UI test
215+
function setupUITest() {
215216
const mockFirstResult = {
216217
sessionId: 'test-session',
217218
items: [mockInlineCompletionItemOne],
@@ -224,6 +225,12 @@ describe('RecommendationService', () => {
224225
const showGeneratingStub = sandbox.stub(activeStateController, 'showGenerating').resolves()
225226
const hideGeneratingStub = sandbox.stub(activeStateController, 'hideGenerating')
226227

228+
return { showGeneratingStub, hideGeneratingStub }
229+
}
230+
231+
it('should not show UI indicators when showUi option is false', async () => {
232+
const { showGeneratingStub, hideGeneratingStub } = setupUITest()
233+
227234
// Call with showUi: false option
228235
await service.getAllRecommendations(languageClient, mockDocument, mockPosition, mockContext, mockToken, {
229236
showUi: false,
@@ -238,17 +245,7 @@ describe('RecommendationService', () => {
238245
})
239246

240247
it('should show UI indicators when showUi option is true (default)', async () => {
241-
const mockFirstResult = {
242-
sessionId: 'test-session',
243-
items: [mockInlineCompletionItemOne],
244-
partialResultToken: undefined,
245-
}
246-
247-
sendRequestStub.resolves(mockFirstResult)
248-
249-
// Spy on the UI methods
250-
const showGeneratingStub = sandbox.stub(activeStateController, 'showGenerating').resolves()
251-
const hideGeneratingStub = sandbox.stub(activeStateController, 'hideGenerating')
248+
const { showGeneratingStub, hideGeneratingStub } = setupUITest()
252249

253250
// Call with default options (showUi: true)
254251
await service.getAllRecommendations(languageClient, mockDocument, mockPosition, mockContext, mockToken)

packages/amazonq/test/unit/app/inline/EditRendering/displayImage.test.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ describe('EditDecorationManager', function () {
9393
assert.strictEqual(removedCodeCall.args[0], manager['removedCodeDecorationType'])
9494
})
9595

96-
it('should trigger accept handler when command is executed', function () {
96+
// Helper function to setup edit suggestion test
97+
function setupEditSuggestionTest() {
9798
// Create a fake SVG image URI
9899
const svgUri = vscode.Uri.parse('file:///path/to/image.svg')
99100

@@ -113,6 +114,12 @@ describe('EditDecorationManager', function () {
113114
[{ line: 0, start: 0, end: 0 }]
114115
)
115116

117+
return { acceptHandler, rejectHandler }
118+
}
119+
120+
it('should trigger accept handler when command is executed', function () {
121+
const { acceptHandler, rejectHandler } = setupEditSuggestionTest()
122+
116123
// Find the command handler that was registered for accept
117124
const acceptCommandArgs = commandsStub.registerCommand.args.find(
118125
(args) => args[0] === 'aws.amazonq.inline.acceptEdit'
@@ -132,24 +139,7 @@ describe('EditDecorationManager', function () {
132139
})
133140

134141
it('should trigger reject handler when command is executed', function () {
135-
// Create a fake SVG image URI
136-
const svgUri = vscode.Uri.parse('file:///path/to/image.svg')
137-
138-
// Create accept and reject handlers
139-
const acceptHandler = sandbox.stub()
140-
const rejectHandler = sandbox.stub()
141-
142-
// Display the edit suggestion
143-
manager.displayEditSuggestion(
144-
editorStub as unknown as vscode.TextEditor,
145-
svgUri,
146-
0,
147-
acceptHandler,
148-
rejectHandler,
149-
'Original code',
150-
'New code',
151-
[{ line: 0, start: 0, end: 0 }]
152-
)
142+
const { acceptHandler, rejectHandler } = setupEditSuggestionTest()
153143

154144
// Find the command handler that was registered for reject
155145
const rejectCommandArgs = commandsStub.registerCommand.args.find(

packages/amazonq/test/unit/app/inline/cursorUpdateManager.test.ts

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ describe('CursorUpdateManager', () => {
129129
assert.ok(stopSpy.called)
130130
})
131131

132-
it('should send cursor update requests at intervals', () => {
132+
// Helper function to setup cursor update test
133+
function setupCursorUpdateTest() {
133134
// Setup test data
134135
const position = new vscode.Position(1, 2)
135136
const uri = 'file:///test.ts'
@@ -156,8 +157,14 @@ describe('CursorUpdateManager', () => {
156157
provideInlineCompletionItems: provideStub,
157158
}
158159

160+
return { provideStub, position, uri }
161+
}
162+
163+
it('should send cursor update requests at intervals', () => {
164+
const { provideStub } = setupCursorUpdateTest()
165+
159166
// Start the manager - we're not awaiting this since we're just setting up the test
160-
cursorUpdateManager.start()
167+
void cursorUpdateManager.start()
161168

162169
// Reset the sendRequestStub to clear the call from start()
163170
sendRequestStub.resetHistory()
@@ -173,18 +180,7 @@ describe('CursorUpdateManager', () => {
173180
})
174181

175182
it('should not send cursor update if a regular request was made recently', async () => {
176-
// Setup test data
177-
const position = new vscode.Position(1, 2)
178-
const uri = 'file:///test.ts'
179-
cursorUpdateManager.updatePosition(position, uri)
180-
181-
// Mock the active editor
182-
const mockEditor = {
183-
document: {
184-
uri: { toString: () => uri },
185-
},
186-
}
187-
sinon.stub(vscode.window, 'activeTextEditor').get(() => mockEditor as any)
183+
setupCursorUpdateTest()
188184

189185
// Start the manager
190186
await cursorUpdateManager.start()
@@ -206,32 +202,8 @@ describe('CursorUpdateManager', () => {
206202
assert.strictEqual(sendRequestStub.called, false)
207203
})
208204

209-
it.only('should not send cursor update if position has not changed since last update', async () => {
210-
// Setup test data
211-
const position = new vscode.Position(1, 2)
212-
const uri = 'file:///test.ts'
213-
cursorUpdateManager.updatePosition(position, uri)
214-
215-
// Mock the active editor
216-
const mockEditor = {
217-
document: {
218-
uri: { toString: () => uri },
219-
},
220-
}
221-
sinon.stub(vscode.window, 'activeTextEditor').get(() => mockEditor as any)
222-
223-
// Create a mock cancellation token source
224-
const mockCancellationTokenSource = {
225-
token: {} as vscode.CancellationToken,
226-
dispose: sinon.stub(),
227-
}
228-
sinon.stub(cursorUpdateManager as any, 'createCancellationTokenSource').returns(mockCancellationTokenSource)
229-
230-
// Mock the provideInlineCompletionItems method
231-
const provideStub = sinon.stub().resolves([])
232-
;(cursorUpdateManager as any).inlineCompletionProvider = {
233-
provideInlineCompletionItems: provideStub,
234-
}
205+
it('should not send cursor update if position has not changed since last update', async () => {
206+
const { provideStub } = setupCursorUpdateTest()
235207

236208
// Start the manager
237209
await cursorUpdateManager.start()
@@ -256,7 +228,7 @@ describe('CursorUpdateManager', () => {
256228

257229
// Now change the position
258230
const newPosition = new vscode.Position(1, 3)
259-
cursorUpdateManager.updatePosition(newPosition, uri)
231+
cursorUpdateManager.updatePosition(newPosition, 'file:///test.ts')
260232

261233
// Third call to sendCursorUpdate with changed position - should send update
262234
await (cursorUpdateManager as any).sendCursorUpdate()

packages/core/src/testLint/gitSecrets.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ ${mySecretAccessKey}
115115
})
116116

117117
it('ensures no git secrets are found', function () {
118+
this.timeout(10000)
118119
const result = runCmd([gitSecrets, '--scan'], { cwd: toolkitProjectDir })
119120
assert.strictEqual(result.status, 0, `Failure output: ${result.stderr.toString()}`)
120121
})

0 commit comments

Comments
 (0)