@@ -125,7 +125,7 @@ Resources:
125125 // Verify that suggested resources are from the expected set
126126 for ( const item of result ) {
127127 expect ( item . insertText ) . toBeDefined ( ) ;
128- expect ( item . insertText ) . toContain ( 'relatedResourceLogicalId :' ) ;
128+ expect ( item . insertText ) . toContain ( 'RelatedToS3BucketLogicalId :' ) ;
129129 expect ( item . insertText ) . toContain ( 'Type:' ) ;
130130 expect ( item . range ) . toBeDefined ( ) ;
131131 expect ( item . range . start ) . toEqual ( mockParams . position ) ;
@@ -164,7 +164,7 @@ Resources:
164164 expect ( result ) . toBeDefined ( ) ;
165165 expect ( Array . isArray ( result ) ) . toBe ( true ) ;
166166 // Should only include AWS::IAM::Role (not the existing S3 and Lambda)
167- expect ( result ) . toEqual ( [ 'AWS::IAM::Role' ] ) ;
167+ expect ( result ) . toEqual ( [ { type : 'AWS::IAM::Role' , relatedTo : 'AWS::S3::Bucket' } ] ) ;
168168 } ) ;
169169
170170 test ( 'should rank suggestions by frequency' , ( ) => {
@@ -181,21 +181,21 @@ Resources:
181181 expect ( result ) . toBeDefined ( ) ;
182182 expect ( Array . isArray ( result ) ) . toBe ( true ) ;
183183 // AWS::IAM::Role should be first (appears in all 3), others alphabetically
184- expect ( result [ 0 ] ) . toBe ( 'AWS::IAM::Role' ) ;
184+ expect ( result [ 0 ] . type ) . toBe ( 'AWS::IAM::Role' ) ;
185185 } ) ;
186186 } ) ;
187187
188188 describe ( 'generateInlineCompletionItems' , ( ) => {
189189 test ( 'should limit suggestions to top 5' , ( ) => {
190190 const manyResourceTypes = [
191- 'AWS::IAM::Role' ,
192- 'AWS::CloudFront::Distribution' ,
193- 'AWS::API::Gateway' ,
194- 'AWS::EC2::SecurityGroup' ,
195- 'AWS::RDS::DBInstance' ,
196- 'AWS::DynamoDB::Table' ,
197- 'AWS::SNS::Topic' ,
198- 'AWS::SQS::Queue' ,
191+ { type : 'AWS::IAM::Role' , relatedTo : 'AWS::S3::Bucket' } ,
192+ { type : 'AWS::CloudFront::Distribution' , relatedTo : 'AWS::S3::Bucket' } ,
193+ { type : 'AWS::API::Gateway' , relatedTo : 'AWS::Lambda::Function' } ,
194+ { type : 'AWS::EC2::SecurityGroup' , relatedTo : 'AWS::EC2::Instance' } ,
195+ { type : 'AWS::RDS::DBInstance' , relatedTo : 'AWS::EC2::Instance' } ,
196+ { type : 'AWS::DynamoDB::Table' , relatedTo : 'AWS::Lambda::Function' } ,
197+ { type : 'AWS::SNS::Topic' , relatedTo : 'AWS::Lambda::Function' } ,
198+ { type : 'AWS::SQS::Queue' , relatedTo : 'AWS::Lambda::Function' } ,
199199 ] ;
200200
201201 const result = ( provider as any ) . generateInlineCompletionItems ( manyResourceTypes , mockParams , mockContext ) ;
@@ -206,7 +206,10 @@ Resources:
206206 } ) ;
207207
208208 test ( 'should create proper completion items structure' , ( ) => {
209- const resourceTypes = [ 'AWS::IAM::Role' , 'AWS::CloudFront::Distribution' ] ;
209+ const resourceTypes = [
210+ { type : 'AWS::IAM::Role' , relatedTo : 'AWS::S3::Bucket' } ,
211+ { type : 'AWS::CloudFront::Distribution' , relatedTo : 'AWS::S3::Bucket' } ,
212+ ] ;
210213
211214 const result = ( provider as any ) . generateInlineCompletionItems ( resourceTypes , mockParams , mockContext ) ;
212215
@@ -215,7 +218,7 @@ Resources:
215218
216219 for ( const item of result ) {
217220 expect ( item . insertText ) . toBeDefined ( ) ;
218- expect ( item . insertText ) . toContain ( 'relatedResourceLogicalId :' ) ;
221+ expect ( item . insertText ) . toContain ( 'RelatedToS3BucketLogicalId :' ) ;
219222 expect ( item . range ) . toBeDefined ( ) ;
220223 expect ( item . range . start ) . toEqual ( mockParams . position ) ;
221224 expect ( item . range . end ) . toEqual ( mockParams . position ) ;
@@ -235,34 +238,48 @@ Resources:
235238 describe ( 'generatePropertySnippet' , ( ) => {
236239 test ( 'should generate basic property snippet' , ( ) => {
237240 const resourceType = 'AWS::S3::Bucket' ;
241+ const relatedToType = 'AWS::Lambda::Function' ;
238242
239243 const result = ( provider as any ) . generatePropertySnippet (
240244 resourceType ,
241- mockContext . documentType ,
245+ relatedToType ,
242246 mockParams ,
247+ undefined ,
243248 ) ;
244249
245250 expect ( result ) . toBeDefined ( ) ;
246- expect ( result ) . toContain ( 'relatedResourceLogicalId :' ) ;
251+ expect ( result ) . toContain ( 'RelatedToLambdaFunctionLogicalId :' ) ;
247252 expect ( result ) . toContain ( 'Type: AWS::S3::Bucket' ) ;
248253 } ) ;
249254
250255 test ( 'should handle different resource types' , ( ) => {
251- const testCases = [ 'AWS::Lambda::Function' , 'AWS::IAM::Role' , 'AWS::EC2::Instance' , 'AWS::RDS::DBInstance' ] ;
256+ const testCases = [
257+ { resourceType : 'AWS::Lambda::Function' , relatedTo : 'AWS::S3::Bucket' } ,
258+ { resourceType : 'AWS::IAM::Role' , relatedTo : 'AWS::Lambda::Function' } ,
259+ { resourceType : 'AWS::EC2::Instance' , relatedTo : 'AWS::IAM::Role' } ,
260+ { resourceType : 'AWS::RDS::DBInstance' , relatedTo : 'AWS::EC2::Instance' } ,
261+ ] ;
252262
253- for ( const resourceType of testCases ) {
263+ for ( const { resourceType, relatedTo } of testCases ) {
254264 const result = ( provider as any ) . generatePropertySnippet (
255265 resourceType ,
256- mockContext . documentType ,
266+ relatedTo ,
257267 mockParams ,
268+ undefined ,
258269 ) ;
259- expect ( result ) . toContain ( 'relatedResourceLogicalId:' ) ;
270+ const expectedLogicalId = `RelatedTo${ relatedTo
271+ . split ( '::' )
272+ . slice ( 1 )
273+ . join ( '' )
274+ . replaceAll ( / [ ^ a - z A - Z 0 - 9 ] / g, '' ) } LogicalId`;
275+ expect ( result ) . toContain ( `${ expectedLogicalId } :` ) ;
260276 expect ( result ) . toContain ( `Type: ${ resourceType } ` ) ;
261277 }
262278 } ) ;
263279
264280 test ( 'should include required properties when schema has required fields' , ( ) => {
265281 const resourceType = 'AWS::S3::Bucket' ;
282+ const relatedToType = 'AWS::Lambda::Function' ;
266283
267284 // Mock schema with required properties
268285 const mockSchema = {
@@ -275,11 +292,12 @@ Resources:
275292
276293 const result = ( provider as any ) . generatePropertySnippet (
277294 resourceType ,
278- mockContext . documentType ,
295+ relatedToType ,
279296 mockParams ,
297+ undefined ,
280298 ) ;
281299
282- expect ( result ) . toContain ( 'relatedResourceLogicalId :' ) ;
300+ expect ( result ) . toContain ( 'RelatedToLambdaFunctionLogicalId :' ) ;
283301 expect ( result ) . toContain ( `Type: ${ resourceType } ` ) ;
284302 expect ( result ) . toContain ( 'Properties:' ) ;
285303 expect ( result ) . toContain ( 'BucketName: ' ) ;
@@ -290,6 +308,7 @@ Resources:
290308
291309 test ( 'should generate properly indented YAML snippets with cursor context' , ( ) => {
292310 const resourceType = 'AWS::IAM::Role' ;
311+ const relatedToType = 'AWS::S3::Bucket' ;
293312 const mockSchema = {
294313 required : [ 'AssumeRolePolicyDocument' ] ,
295314 } ;
@@ -316,25 +335,28 @@ Resources:
316335 ' BucketName: test' ,
317336 ' ' ,
318337 ] ,
338+ documentType : 'YAML' ,
319339 } ;
320340 mockDocumentManager . get . returns ( mockDocument as any ) ;
321341 mockDocumentManager . getEditorSettingsForDocument . returns ( { tabSize : 2 , insertSpaces : true } as any ) ;
322342
323343 const result = ( provider as any ) . generatePropertySnippet (
324344 resourceType ,
325- mockContext . documentType ,
345+ relatedToType ,
326346 mockParams ,
347+ mockDocument ,
327348 ) ;
328349
329350 // Verify proper YAML structure with cursor context indentation
330- expect ( result ) . toContain ( 'relatedResourceLogicalId :' ) ;
351+ expect ( result ) . toContain ( 'RelatedToS3BucketLogicalId :' ) ;
331352 expect ( result ) . toContain ( ' Type: AWS::IAM::Role' ) ; // 4 spaces (2 existing + 2 more)
332353 expect ( result ) . toContain ( ' Properties:' ) ; // 4 spaces (2 existing + 2 more)
333354 expect ( result ) . toContain ( ' AssumeRolePolicyDocument: ' ) ; // 6 spaces (2 existing + 4 more)
334355 } ) ;
335356
336357 test ( 'should generate properly indented JSON snippets with cursor context' , ( ) => {
337358 const resourceType = 'AWS::IAM::Role' ;
359+ const relatedToType = 'AWS::S3::Bucket' ;
338360 const mockSchema = {
339361 required : [ 'AssumeRolePolicyDocument' ] ,
340362 } ;
@@ -361,20 +383,20 @@ Resources:
361383 ' },' ,
362384 ' ' ,
363385 ] ,
386+ documentType : 'JSON' ,
364387 } ;
365388 mockDocumentManager . get . returns ( mockDocument as any ) ;
366389 mockDocumentManager . getEditorSettingsForDocument . returns ( { tabSize : 2 , insertSpaces : true } as any ) ;
367390
368- const jsonContext = { ...mockContext , documentType : 'JSON' } ;
369-
370391 const result = ( provider as any ) . generatePropertySnippet (
371392 resourceType ,
372- jsonContext . documentType ,
393+ relatedToType ,
373394 mockParams ,
395+ mockDocument ,
374396 ) ;
375397
376398 // Verify proper JSON structure with cursor context indentation
377- expect ( result ) . toContain ( '"relatedResourceLogicalId ": {' ) ;
399+ expect ( result ) . toContain ( '"RelatedToS3BucketLogicalId ": {' ) ;
378400 expect ( result ) . toContain ( ' "Type": "AWS::IAM::Role"' ) ; // 4 spaces (2 existing + 2 more)
379401 expect ( result ) . toContain ( ' "Properties": {' ) ; // 4 spaces (2 existing + 2 more)
380402 expect ( result ) . toContain ( ' "AssumeRolePolicyDocument": ""' ) ; // 6 spaces (2 existing + 4 more)
0 commit comments