@@ -16,23 +16,45 @@ import { MetricName, Span } from 'aws-core-vscode/telemetry'
16
16
import sinon from 'sinon'
17
17
import { CodeWhispererSettings } from 'aws-core-vscode/codewhisperer'
18
18
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
+ }
20
34
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
+
23
44
const workspace = getWorkspaceFolder ( folder . path )
24
45
sinon
25
46
. stub ( CodeWhispererSettings . instance , 'getDevCommandWorkspaceConfigurations' )
26
47
. returns ( devfileEnabled ? { [ workspace . uri . fsPath ] : true } : { } )
27
48
28
- await testPrepareRepoData ( workspace , expectedRepoSize )
49
+ await testPrepareRepoData ( workspace , expectedFiles )
29
50
}
30
51
31
52
const testPrepareRepoData = async (
32
53
workspace : vscode . WorkspaceFolder ,
33
- expectedRepoSize : number ,
54
+ expectedFiles : string [ ] ,
34
55
expectedTelemetryMetrics ?: Array < { metricName : MetricName ; value : any } >
35
56
) => {
57
+ expectedFiles . sort ( ( a , b ) => a . localeCompare ( b ) )
36
58
const telemetry = new TelemetryHelper ( )
37
59
const result = await prepareRepoData ( [ workspace . uri . fsPath ] , [ workspace ] , telemetry , {
38
60
record : ( ) => { } ,
@@ -41,13 +63,18 @@ const testPrepareRepoData = async (
41
63
assert . strictEqual ( Buffer . isBuffer ( result . zipFileBuffer ) , true )
42
64
// checksum is not the same across different test executions because some unique random folder names are generated
43
65
assert . strictEqual ( result . zipFileChecksum . length , 44 )
44
- assert . strictEqual ( telemetry . repositorySize , expectedRepoSize )
45
66
46
67
if ( expectedTelemetryMetrics ) {
47
- expectedTelemetryMetrics . forEach ( ( metric ) => {
68
+ for ( const metric of expectedTelemetryMetrics ) {
48
69
assertTelemetry ( metric . metricName , metric . value )
49
- } )
70
+ }
50
71
}
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 )
51
78
}
52
79
53
80
describe ( 'file utils' , ( ) => {
@@ -62,25 +89,27 @@ describe('file utils', () => {
62
89
await folder . write ( 'file2.md' , 'test content' )
63
90
const workspace = getWorkspaceFolder ( folder . path )
64
91
65
- await testPrepareRepoData ( workspace , 24 )
92
+ await testPrepareRepoData ( workspace , [ './file1.md' , './file2.md' ] )
66
93
} )
67
94
68
95
it ( 'prepareRepoData ignores denied file extensions' , async function ( ) {
69
96
const folder = await TestFolder . create ( )
70
97
await folder . write ( 'file.mp4' , 'test content' )
71
98
const workspace = getWorkspaceFolder ( folder . path )
72
99
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
+ )
76
105
} )
77
106
78
107
it ( 'should ignore devfile.yaml when setting is disabled' , async function ( ) {
79
- await testDevfilePrepareRepo ( 12 , false )
108
+ await testDevfilePrepareRepo ( false )
80
109
} )
81
110
82
111
it ( 'should include devfile.yaml when setting is enabled' , async function ( ) {
83
- await testDevfilePrepareRepo ( 16 , true )
112
+ await testDevfilePrepareRepo ( true )
84
113
} )
85
114
86
115
// Test the logic that allows the customer to modify root source folder
0 commit comments