@@ -188,6 +188,91 @@ describe('EditDecorationManager', function () {
188188 } )
189189} )
190190
191+ describe ( 'displaySvgDecoration cursor distance auto-discard' , function ( ) {
192+ let sandbox : sinon . SinonSandbox
193+ let editorStub : sinon . SinonStubbedInstance < vscode . TextEditor >
194+ let languageClientStub : any
195+ let sessionStub : any
196+ let itemStub : any
197+
198+ beforeEach ( function ( ) {
199+ sandbox = sinon . createSandbox ( )
200+ const commonStubs = createCommonStubs ( sandbox )
201+ editorStub = commonStubs . editorStub
202+
203+ languageClientStub = {
204+ sendNotification : sandbox . stub ( ) ,
205+ }
206+
207+ sessionStub = {
208+ sessionId : 'test-session' ,
209+ requestStartTime : Date . now ( ) ,
210+ firstCompletionDisplayLatency : 100 ,
211+ }
212+
213+ itemStub = {
214+ itemId : 'test-item' ,
215+ insertText : 'test content' ,
216+ }
217+ } )
218+
219+ afterEach ( function ( ) {
220+ sandbox . restore ( )
221+ } )
222+
223+ it ( 'should send discard telemetry and return early when edit is 10+ lines away from cursor' , async function ( ) {
224+ // Set cursor at line 5
225+ editorStub . selection = {
226+ active : new vscode . Position ( 5 , 0 ) ,
227+ } as any
228+
229+ // Try to display edit at line 20 (15 lines away)
230+ await displaySvgDecoration (
231+ editorStub as unknown as vscode . TextEditor ,
232+ vscode . Uri . parse ( 'data:image/svg+xml;base64,test' ) ,
233+ 20 ,
234+ 'new code' ,
235+ [ ] ,
236+ sessionStub ,
237+ languageClientStub ,
238+ itemStub
239+ )
240+
241+ // Verify discard telemetry was sent
242+ sinon . assert . calledOnce ( languageClientStub . sendNotification )
243+ const call = languageClientStub . sendNotification . getCall ( 0 )
244+ assert . strictEqual ( call . args [ 0 ] , 'aws/logInlineCompletionSessionResults' )
245+ assert . strictEqual ( call . args [ 1 ] . sessionId , 'test-session' )
246+ assert . strictEqual ( call . args [ 1 ] . completionSessionResult [ 'test-item' ] . discarded , true )
247+ } )
248+
249+ it ( 'should proceed normally when edit is within 10 lines of cursor' , async function ( ) {
250+ // Set cursor at line 5
251+ editorStub . selection = {
252+ active : new vscode . Position ( 5 , 0 ) ,
253+ } as any
254+
255+ // Mock required dependencies for normal flow
256+ sandbox . stub ( vscode . workspace , 'onDidChangeTextDocument' ) . returns ( { dispose : sandbox . stub ( ) } )
257+ sandbox . stub ( vscode . window , 'onDidChangeTextEditorSelection' ) . returns ( { dispose : sandbox . stub ( ) } )
258+
259+ // Try to display edit at line 10 (5 lines away)
260+ await displaySvgDecoration (
261+ editorStub as unknown as vscode . TextEditor ,
262+ vscode . Uri . parse ( 'data:image/svg+xml;base64,test' ) ,
263+ 10 ,
264+ 'new code' ,
265+ [ ] ,
266+ sessionStub ,
267+ languageClientStub ,
268+ itemStub
269+ )
270+
271+ // Verify no discard telemetry was sent (function should proceed normally)
272+ sinon . assert . notCalled ( languageClientStub . sendNotification )
273+ } )
274+ } )
275+
191276describe ( 'displaySvgDecoration cursor distance auto-reject' , function ( ) {
192277 let sandbox : sinon . SinonSandbox
193278 let editorStub : sinon . SinonStubbedInstance < vscode . TextEditor >
0 commit comments