@@ -13,7 +13,7 @@ import { CodeQLExtensionInterface } from '../../extension';
1313import { setRemoteControllerRepo , setRemoteRepositoryLists } from '../../config' ;
1414import { UserCancellationException } from '../../commandRunner' ;
1515
16- describe ( 'Remote queries' , function ( ) {
16+ describe . only ( 'Remote queries' , function ( ) {
1717 const baseDir = path . join ( __dirname , '../../../src/vscode-tests/cli-integration' ) ;
1818
1919 let sandbox : sinon . SinonSandbox ;
@@ -80,8 +80,7 @@ describe('Remote queries', function() {
8080 const queryPackDir = path . join ( queryPackRootDir , 'query-pack' ) ;
8181 printDirectoryContents ( queryPackDir ) ;
8282
83- // in-pack.ql renamed to query.ql
84- expect ( fs . existsSync ( path . join ( queryPackDir , 'query.ql' ) ) ) . to . be . true ;
83+ expect ( fs . existsSync ( path . join ( queryPackDir , 'in-pack.ql' ) ) ) . to . be . true ;
8584 expect ( fs . existsSync ( path . join ( queryPackDir , 'lib.qll' ) ) ) . to . be . true ;
8685 expect ( fs . existsSync ( path . join ( queryPackDir , 'qlpack.yml' ) ) ) . to . be . true ;
8786
@@ -96,7 +95,7 @@ describe('Remote queries', function() {
9695 const compiledPackDir = path . join ( queryPackDir , '.codeql/pack/github/remote-query-pack/0.0.0/' ) ;
9796 printDirectoryContents ( compiledPackDir ) ;
9897
99- expect ( fs . existsSync ( path . join ( compiledPackDir , 'query .ql' ) ) ) . to . be . true ;
98+ expect ( fs . existsSync ( path . join ( compiledPackDir , 'in-pack .ql' ) ) ) . to . be . true ;
10099 expect ( fs . existsSync ( path . join ( compiledPackDir , 'lib.qll' ) ) ) . to . be . true ;
101100 expect ( fs . existsSync ( path . join ( compiledPackDir , 'qlpack.yml' ) ) ) . to . be . true ;
102101 // depending on the cli version, we should have one of these files
@@ -105,6 +104,7 @@ describe('Remote queries', function() {
105104 fs . existsSync ( path . join ( compiledPackDir , 'codeql-pack.lock.yml' ) )
106105 ) . to . be . true ;
107106 expect ( fs . existsSync ( path . join ( compiledPackDir , 'not-in-pack.ql' ) ) ) . to . be . false ;
107+ verifyQlPack ( path . join ( compiledPackDir , 'qlpack.yml' ) , 'in-pack.ql' , 'github/remote-query-pack' , '0.0.0' ) ;
108108
109109 // dependencies
110110 const libraryDir = path . join ( compiledPackDir , '.codeql/libraries/codeql' ) ;
@@ -129,8 +129,8 @@ describe('Remote queries', function() {
129129
130130 const queryPackDir = path . join ( queryPackRootDir , 'query-pack' ) ;
131131 printDirectoryContents ( queryPackDir ) ;
132- // in-pack.ql renamed to query.ql
133- expect ( fs . existsSync ( path . join ( queryPackDir , 'query .ql' ) ) ) . to . be . true ;
132+
133+ expect ( fs . existsSync ( path . join ( queryPackDir , 'in-pack .ql' ) ) ) . to . be . true ;
134134 expect ( fs . existsSync ( path . join ( queryPackDir , 'qlpack.yml' ) ) ) . to . be . true ;
135135 // depending on the cli version, we should have one of these files
136136 expect (
@@ -143,8 +143,10 @@ describe('Remote queries', function() {
143143 // the compiled pack
144144 const compiledPackDir = path . join ( queryPackDir , '.codeql/pack/codeql-remote/query/0.0.0/' ) ;
145145 printDirectoryContents ( compiledPackDir ) ;
146- expect ( fs . existsSync ( path . join ( compiledPackDir , 'query .ql' ) ) ) . to . be . true ;
146+ expect ( fs . existsSync ( path . join ( compiledPackDir , 'in-pack .ql' ) ) ) . to . be . true ;
147147 expect ( fs . existsSync ( path . join ( compiledPackDir , 'qlpack.yml' ) ) ) . to . be . true ;
148+ verifyQlPack ( path . join ( compiledPackDir , 'qlpack.yml' ) , 'in-pack.ql' , 'codeql-remote/query' , '0.0.0' ) ;
149+
148150 // depending on the cli version, we should have one of these files
149151 expect (
150152 fs . existsSync ( path . join ( compiledPackDir , 'qlpack.lock.yml' ) ) ||
@@ -165,6 +167,60 @@ describe('Remote queries', function() {
165167 expect ( packNames ) . to . deep . equal ( [ 'javascript-all' , 'javascript-upgrades' ] ) ;
166168 } ) ;
167169
170+ it ( 'should run a remote query that is nested inside a qlpack' , async ( ) => {
171+ const fileUri = getFile ( 'data-remote-qlpack-nested/subfolder/in-pack.ql' ) ;
172+
173+ const queryPackRootDir = ( await runRemoteQuery ( cli , credentials , fileUri , true , progress , token ) ) ! ;
174+
175+ // to retrieve the list of repositories
176+ expect ( showQuickPickSpy ) . to . have . been . calledOnce ;
177+
178+ // check a few files that we know should exist and others that we know should not
179+
180+ // the tarball to deliver to the server
181+ printDirectoryContents ( queryPackRootDir ) ;
182+ expect ( fs . readdirSync ( queryPackRootDir ) . find ( f => f . startsWith ( 'qlpack-' ) && f . endsWith ( '-generated.tgz' ) ) ) . not . to . be . undefined ;
183+
184+ const queryPackDir = path . join ( queryPackRootDir , 'query-pack' ) ;
185+ printDirectoryContents ( queryPackDir ) ;
186+
187+ expect ( fs . existsSync ( path . join ( queryPackDir , 'subfolder/in-pack.ql' ) ) ) . to . be . true ;
188+ expect ( fs . existsSync ( path . join ( queryPackDir , 'qlpack.yml' ) ) ) . to . be . true ;
189+ // depending on the cli version, we should have one of these files
190+ expect (
191+ fs . existsSync ( path . join ( queryPackDir , 'qlpack.lock.yml' ) ) ||
192+ fs . existsSync ( path . join ( queryPackDir , 'codeql-pack.lock.yml' ) )
193+ ) . to . be . true ;
194+ expect ( fs . existsSync ( path . join ( queryPackDir , 'otherfolder/lib.qll' ) ) ) . to . be . true ;
195+ expect ( fs . existsSync ( path . join ( queryPackDir , 'not-in-pack.ql' ) ) ) . to . be . false ;
196+
197+ // the compiled pack
198+ const compiledPackDir = path . join ( queryPackDir , '.codeql/pack/github/remote-query-pack/0.0.0/' ) ;
199+ printDirectoryContents ( compiledPackDir ) ;
200+ expect ( fs . existsSync ( path . join ( compiledPackDir , 'otherfolder/lib.qll' ) ) ) . to . be . true ;
201+ expect ( fs . existsSync ( path . join ( compiledPackDir , 'subfolder/in-pack.ql' ) ) ) . to . be . true ;
202+ expect ( fs . existsSync ( path . join ( compiledPackDir , 'qlpack.yml' ) ) ) . to . be . true ;
203+ verifyQlPack ( path . join ( compiledPackDir , 'qlpack.yml' ) , 'subfolder/in-pack.ql' , 'github/remote-query-pack' , '0.0.0' ) ;
204+
205+ // depending on the cli version, we should have one of these files
206+ expect (
207+ fs . existsSync ( path . join ( compiledPackDir , 'qlpack.lock.yml' ) ) ||
208+ fs . existsSync ( path . join ( compiledPackDir , 'codeql-pack.lock.yml' ) )
209+ ) . to . be . true ;
210+ expect ( fs . existsSync ( path . join ( compiledPackDir , 'not-in-pack.ql' ) ) ) . to . be . false ;
211+ // should have generated a correct qlpack file
212+ const qlpackContents : any = yaml . safeLoad ( fs . readFileSync ( path . join ( compiledPackDir , 'qlpack.yml' ) , 'utf8' ) ) ;
213+ expect ( qlpackContents . name ) . to . equal ( 'github/remote-query-pack' ) ;
214+ expect ( qlpackContents . version ) . to . equal ( '0.0.0' ) ;
215+ expect ( qlpackContents . dependencies ?. [ 'codeql/javascript-all' ] ) . to . equal ( '*' ) ;
216+
217+ // dependencies
218+ const libraryDir = path . join ( compiledPackDir , '.codeql/libraries/codeql' ) ;
219+ printDirectoryContents ( libraryDir ) ;
220+ const packNames = fs . readdirSync ( libraryDir ) . sort ( ) ;
221+ expect ( packNames ) . to . deep . equal ( [ 'javascript-all' , 'javascript-upgrades' ] ) ;
222+ } ) ;
223+
168224 it ( 'should cancel a run before uploading' , async ( ) => {
169225 const fileUri = getFile ( 'data-remote-no-qlpack/in-pack.ql' ) ;
170226
@@ -180,15 +236,37 @@ describe('Remote queries', function() {
180236 }
181237 } ) ;
182238
239+ function verifyQlPack ( qlpackPath : string , queryPath : string , packName : string , packVersion : string ) {
240+ const qlPack = yaml . safeLoad ( fs . readFileSync ( qlpackPath , 'utf8' ) ) ;
241+
242+ // don't check the build metadata since it is variable
243+ delete ( qlPack as any ) . buildMetadata ;
244+
245+ expect ( qlPack ) . to . deep . equal ( {
246+ name : packName ,
247+ version : packVersion ,
248+ dependencies : {
249+ 'codeql/javascript-all' : '*' ,
250+ } ,
251+ library : false ,
252+ defaultSuite : [ {
253+ description : 'Query suite for remote query' ,
254+ query : queryPath ,
255+ } ]
256+ } ) ;
257+ }
258+
183259 function getFile ( file : string ) : Uri {
184260 return Uri . file ( path . join ( baseDir , file ) ) ;
185261 }
186262
187263 function printDirectoryContents ( dir : string ) {
188- console . log ( `DIR ${ dir } ` ) ;
189- if ( ! fs . existsSync ( dir ) ) {
190- console . log ( `DIR ${ dir } does not exist` ) ;
191- }
192- fs . readdirSync ( dir ) . sort ( ) . forEach ( f => console . log ( ` ${ f } ` ) ) ;
264+ dir ;
265+ // uncomment to debug
266+ // console.log(`DIR ${dir}`);
267+ // if (!fs.existsSync(dir)) {
268+ // console.log(`DIR ${dir} does not exist`);
269+ // }
270+ // fs.readdirSync(dir).sort().forEach(f => console.log(` ${f}`));
193271 }
194272} ) ;
0 commit comments