@@ -16,23 +16,45 @@ import { MetricName, Span } from 'aws-core-vscode/telemetry'
1616import sinon from 'sinon'
1717import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'
1818
19- const testDevfilePrepareRepo = async ( expectedRepoSize : number , devfileEnabled : boolean ) => {
19+ import AdmZip from 'adm-zip'
20+
21+ const testDevfilePrepareRepo = async ( devfileEnabled : boolean ) => {
22+ const files : Record < string , string > = {
23+ 'file.md' : 'test content' ,
24+ // only include when execution is enabled
25+ 'devfile.yaml' : 'test' ,
26+ // .git folder is always dropped (because of vscode global exclude rules)
27+ '.git/ref' : '####' ,
28+ // .gitignore should always be included
29+ '.gitignore' : 'node_models/*' ,
30+ // non code files only when dev execution is enabled
31+ 'abc.jar' : 'jar-content' ,
32+ 'data/logo.ico' : 'binary-content' ,
33+ }
2034 const folder = await TestFolder . create ( )
21- await folder . write ( 'devfile.yaml' , 'test' )
22- await folder . write ( 'file.md' , 'test content' )
35+
36+ for ( const [ fileName , content ] of Object . entries ( files ) ) {
37+ await folder . write ( fileName , content )
38+ }
39+
40+ const expectedFiles = ! devfileEnabled
41+ ? [ './file.md' , './.gitignore' ]
42+ : [ './devfile.yaml' , './file.md' , './.gitignore' , './abc.jar' , 'data/logo.ico' ]
43+
2344 const workspace = getWorkspaceFolder ( folder . path )
2445 sinon
2546 . stub ( CodeWhispererSettings . instance , 'getDevCommandWorkspaceConfigurations' )
2647 . returns ( devfileEnabled ? { [ workspace . uri . fsPath ] : true } : { } )
2748
28- await testPrepareRepoData ( workspace , expectedRepoSize )
49+ await testPrepareRepoData ( workspace , expectedFiles )
2950}
3051
3152const testPrepareRepoData = async (
3253 workspace : vscode . WorkspaceFolder ,
33- expectedRepoSize : number ,
54+ expectedFiles : string [ ] ,
3455 expectedTelemetryMetrics ?: Array < { metricName : MetricName ; value : any } >
3556) => {
57+ expectedFiles . sort ( ( a , b ) => a . localeCompare ( b ) )
3658 const telemetry = new TelemetryHelper ( )
3759 const result = await prepareRepoData ( [ workspace . uri . fsPath ] , [ workspace ] , telemetry , {
3860 record : ( ) => { } ,
@@ -41,13 +63,18 @@ const testPrepareRepoData = async (
4163 assert . strictEqual ( Buffer . isBuffer ( result . zipFileBuffer ) , true )
4264 // checksum is not the same across different test executions because some unique random folder names are generated
4365 assert . strictEqual ( result . zipFileChecksum . length , 44 )
44- assert . strictEqual ( telemetry . repositorySize , expectedRepoSize )
4566
4667 if ( expectedTelemetryMetrics ) {
47- expectedTelemetryMetrics . forEach ( ( metric ) => {
68+ for ( const metric of expectedTelemetryMetrics ) {
4869 assertTelemetry ( metric . metricName , metric . value )
49- } )
70+ }
5071 }
72+
73+ // Unzip the buffer and compare the entry names
74+ const zip = new AdmZip ( result . zipFileBuffer )
75+ const actualZipEntries = zip . getEntries ( ) . map ( ( entry ) => entry . entryName )
76+ actualZipEntries . sort ( ( a , b ) => a . localeCompare ( b ) )
77+ assert . deepStrictEqual ( actualZipEntries , expectedFiles )
5178}
5279
5380describe ( 'file utils' , ( ) => {
@@ -62,25 +89,27 @@ describe('file utils', () => {
6289 await folder . write ( 'file2.md' , 'test content' )
6390 const workspace = getWorkspaceFolder ( folder . path )
6491
65- await testPrepareRepoData ( workspace , 24 )
92+ await testPrepareRepoData ( workspace , [ './file1.md' , './file2.md' ] )
6693 } )
6794
6895 it ( 'prepareRepoData ignores denied file extensions' , async function ( ) {
6996 const folder = await TestFolder . create ( )
7097 await folder . write ( 'file.mp4' , 'test content' )
7198 const workspace = getWorkspaceFolder ( folder . path )
7299
73- await testPrepareRepoData ( workspace , 0 , [
74- { metricName : 'amazonq_bundleExtensionIgnored' , value : { filenameExt : 'mp4' , count : 1 } } ,
75- ] )
100+ await testPrepareRepoData (
101+ workspace ,
102+ [ ] ,
103+ [ { metricName : 'amazonq_bundleExtensionIgnored' , value : { filenameExt : 'mp4' , count : 1 } } ]
104+ )
76105 } )
77106
78107 it ( 'should ignore devfile.yaml when setting is disabled' , async function ( ) {
79- await testDevfilePrepareRepo ( 12 , false )
108+ await testDevfilePrepareRepo ( false )
80109 } )
81110
82111 it ( 'should include devfile.yaml when setting is enabled' , async function ( ) {
83- await testDevfilePrepareRepo ( 16 , true )
112+ await testDevfilePrepareRepo ( true )
84113 } )
85114
86115 // Test the logic that allows the customer to modify root source folder
0 commit comments