@@ -4,14 +4,16 @@ import * as sinon from 'sinon';
44import { CancellationToken , extensions , QuickPickItem , Uri , window } from 'vscode' ;
55import 'mocha' ;
66import * as fs from 'fs-extra' ;
7+ import * as os from 'os' ;
78import * as yaml from 'js-yaml' ;
89
9- import { runRemoteQuery } from '../../run-remote-query' ;
10+ import { QlPack , runRemoteQuery } from '../../run-remote-query' ;
1011import { Credentials } from '../../authentication' ;
1112import { CliVersionConstraint , CodeQLCliServer } from '../../cli' ;
1213import { CodeQLExtensionInterface } from '../../extension' ;
1314import { setRemoteControllerRepo , setRemoteRepositoryLists } from '../../config' ;
1415import { UserCancellationException } from '../../commandRunner' ;
16+ import { lte } from 'semver' ;
1517
1618describe ( 'Remote queries' , function ( ) {
1719 const baseDir = path . join ( __dirname , '../../../src/vscode-tests/cli-integration' ) ;
@@ -104,7 +106,7 @@ describe('Remote queries', function() {
104106 fs . existsSync ( path . join ( compiledPackDir , 'codeql-pack.lock.yml' ) )
105107 ) . to . be . true ;
106108 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' ) ;
109+ verifyQlPack ( path . join ( compiledPackDir , 'qlpack.yml' ) , 'in-pack.ql' , 'github/remote-query-pack' , '0.0.0' , await pathSerializationBroken ( ) ) ;
108110
109111 // dependencies
110112 const libraryDir = path . join ( compiledPackDir , '.codeql/libraries/codeql' ) ;
@@ -145,7 +147,7 @@ describe('Remote queries', function() {
145147 printDirectoryContents ( compiledPackDir ) ;
146148 expect ( fs . existsSync ( path . join ( compiledPackDir , 'in-pack.ql' ) ) ) . to . be . true ;
147149 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' ) ;
150+ verifyQlPack ( path . join ( compiledPackDir , 'qlpack.yml' ) , 'in-pack.ql' , 'codeql-remote/query' , '0.0.0' , await pathSerializationBroken ( ) ) ;
149151
150152 // depending on the cli version, we should have one of these files
151153 expect (
@@ -200,7 +202,7 @@ describe('Remote queries', function() {
200202 expect ( fs . existsSync ( path . join ( compiledPackDir , 'otherfolder/lib.qll' ) ) ) . to . be . true ;
201203 expect ( fs . existsSync ( path . join ( compiledPackDir , 'subfolder/in-pack.ql' ) ) ) . to . be . true ;
202204 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' ) ;
205+ verifyQlPack ( path . join ( compiledPackDir , 'qlpack.yml' ) , 'subfolder/in-pack.ql' , 'github/remote-query-pack' , '0.0.0' , await pathSerializationBroken ( ) ) ;
204206
205207 // depending on the cli version, we should have one of these files
206208 expect (
@@ -236,8 +238,13 @@ describe('Remote queries', function() {
236238 }
237239 } ) ;
238240
239- function verifyQlPack ( qlpackPath : string , queryPath : string , packName : string , packVersion : string ) {
240- const qlPack = yaml . safeLoad ( fs . readFileSync ( qlpackPath , 'utf8' ) ) ;
241+ function verifyQlPack ( qlpackPath : string , queryPath : string , packName : string , packVersion : string , pathSerializationBroken : boolean ) {
242+ const qlPack = yaml . safeLoad ( fs . readFileSync ( qlpackPath , 'utf8' ) ) as QlPack ;
243+
244+ if ( pathSerializationBroken ) {
245+ // the path serialization is broken, so we force it to be the path in the pack to be same as the query path
246+ qlPack . defaultSuite ! [ 1 ] . query = queryPath ;
247+ }
241248
242249 // don't check the build metadata since it is variable
243250 delete ( qlPack as any ) . buildMetadata ;
@@ -257,6 +264,15 @@ describe('Remote queries', function() {
257264 } ) ;
258265 }
259266
267+ /**
268+ * In version 2.7.2 and earlier, relative paths were not serialized correctly inside the qlpack.yml file.
269+ * So, ignore part of the test for these versions.
270+ *
271+ * @returns true if path serialization is broken in this run
272+ */
273+ async function pathSerializationBroken ( ) {
274+ return lte ( ( await cli . getVersion ( ) ) , '2.7.2' ) && os . platform ( ) === 'win32' ;
275+ }
260276 function getFile ( file : string ) : Uri {
261277 return Uri . file ( path . join ( baseDir , file ) ) ;
262278 }
0 commit comments