Fix failing tests on windows
1. Acknowledge that the CLI has a bug for path serialization on <=2.7.2. Avoid testing the query path on that version. 2. Fix calculation of root path on windows.
This commit is contained in:
@@ -17,12 +17,12 @@ interface Config {
|
|||||||
language?: string;
|
language?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface QlPack {
|
export interface QlPack {
|
||||||
name: string;
|
name: string;
|
||||||
version: string;
|
version: string;
|
||||||
dependencies: { [key: string]: string };
|
dependencies: { [key: string]: string };
|
||||||
defaultSuite?: Record<string, unknown>[];
|
defaultSuite?: Record<string, unknown>[];
|
||||||
defaultSuiteFile?: Record<string, unknown>;
|
defaultSuiteFile?: string;
|
||||||
}
|
}
|
||||||
interface RepoListQuickPickItem extends QuickPickItem {
|
interface RepoListQuickPickItem extends QuickPickItem {
|
||||||
repoList: string[];
|
repoList: string[];
|
||||||
@@ -195,7 +195,7 @@ async function findPackRoot(queryFile: string): Promise<string> {
|
|||||||
let dir = path.dirname(queryFile);
|
let dir = path.dirname(queryFile);
|
||||||
while (!(await fs.pathExists(path.join(dir, 'qlpack.yml')))) {
|
while (!(await fs.pathExists(path.join(dir, 'qlpack.yml')))) {
|
||||||
dir = path.dirname(dir);
|
dir = path.dirname(dir);
|
||||||
if (dir === '/') {
|
if (isFileSystemRoot(dir)) {
|
||||||
// there is no qlpack.yml in this direcory or any parent directory.
|
// there is no qlpack.yml in this direcory or any parent directory.
|
||||||
// just use the query file's directory as the pack root.
|
// just use the query file's directory as the pack root.
|
||||||
return path.dirname(queryFile);
|
return path.dirname(queryFile);
|
||||||
@@ -205,6 +205,11 @@ async function findPackRoot(queryFile: string): Promise<string> {
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isFileSystemRoot(dir: string): boolean {
|
||||||
|
const pathObj = path.parse(dir);
|
||||||
|
return pathObj.root === dir && pathObj.base === '';
|
||||||
|
}
|
||||||
|
|
||||||
async function createRemoteQueriesTempDirectory() {
|
async function createRemoteQueriesTempDirectory() {
|
||||||
const remoteQueryDir = await tmp.dir({ dir: tmpDir.name, unsafeCleanup: true });
|
const remoteQueryDir = await tmp.dir({ dir: tmpDir.name, unsafeCleanup: true });
|
||||||
const queryPackDir = path.join(remoteQueryDir.path, 'query-pack');
|
const queryPackDir = path.join(remoteQueryDir.path, 'query-pack');
|
||||||
@@ -445,7 +450,7 @@ async function fixDefaultSuite(queryPackDir: string, packRelativePath: string):
|
|||||||
qlpack.defaultSuite = [{
|
qlpack.defaultSuite = [{
|
||||||
description: 'Query suite for remote query'
|
description: 'Query suite for remote query'
|
||||||
}, {
|
}, {
|
||||||
query: packRelativePath.replace('\\', '/')
|
query: packRelativePath.replace(/\\/g, '/')
|
||||||
}];
|
}];
|
||||||
await fs.writeFile(packPath, yaml.safeDump(qlpack));
|
await fs.writeFile(packPath, yaml.safeDump(qlpack));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,16 @@ import * as sinon from 'sinon';
|
|||||||
import { CancellationToken, extensions, QuickPickItem, Uri, window } from 'vscode';
|
import { CancellationToken, extensions, QuickPickItem, Uri, window } from 'vscode';
|
||||||
import 'mocha';
|
import 'mocha';
|
||||||
import * as fs from 'fs-extra';
|
import * as fs from 'fs-extra';
|
||||||
|
import * as os from 'os';
|
||||||
import * as yaml from 'js-yaml';
|
import * as yaml from 'js-yaml';
|
||||||
|
|
||||||
import { runRemoteQuery } from '../../run-remote-query';
|
import { QlPack, runRemoteQuery } from '../../run-remote-query';
|
||||||
import { Credentials } from '../../authentication';
|
import { Credentials } from '../../authentication';
|
||||||
import { CliVersionConstraint, CodeQLCliServer } from '../../cli';
|
import { CliVersionConstraint, CodeQLCliServer } from '../../cli';
|
||||||
import { CodeQLExtensionInterface } from '../../extension';
|
import { CodeQLExtensionInterface } from '../../extension';
|
||||||
import { setRemoteControllerRepo, setRemoteRepositoryLists } from '../../config';
|
import { setRemoteControllerRepo, setRemoteRepositoryLists } from '../../config';
|
||||||
import { UserCancellationException } from '../../commandRunner';
|
import { UserCancellationException } from '../../commandRunner';
|
||||||
|
import { lte } from 'semver';
|
||||||
|
|
||||||
describe('Remote queries', function() {
|
describe('Remote queries', function() {
|
||||||
const baseDir = path.join(__dirname, '../../../src/vscode-tests/cli-integration');
|
const baseDir = path.join(__dirname, '../../../src/vscode-tests/cli-integration');
|
||||||
@@ -104,7 +106,7 @@ describe('Remote queries', function() {
|
|||||||
fs.existsSync(path.join(compiledPackDir, 'codeql-pack.lock.yml'))
|
fs.existsSync(path.join(compiledPackDir, 'codeql-pack.lock.yml'))
|
||||||
).to.be.true;
|
).to.be.true;
|
||||||
expect(fs.existsSync(path.join(compiledPackDir, 'not-in-pack.ql'))).to.be.false;
|
expect(fs.existsSync(path.join(compiledPackDir, 'not-in-pack.ql'))).to.be.false;
|
||||||
verifyQlPack(path.join(compiledPackDir, 'qlpack.yml'), 'in-pack.ql', 'github/remote-query-pack', '0.0.0');
|
verifyQlPack(path.join(compiledPackDir, 'qlpack.yml'), 'in-pack.ql', 'github/remote-query-pack', '0.0.0', await pathSerializationBroken());
|
||||||
|
|
||||||
// dependencies
|
// dependencies
|
||||||
const libraryDir = path.join(compiledPackDir, '.codeql/libraries/codeql');
|
const libraryDir = path.join(compiledPackDir, '.codeql/libraries/codeql');
|
||||||
@@ -145,7 +147,7 @@ describe('Remote queries', function() {
|
|||||||
printDirectoryContents(compiledPackDir);
|
printDirectoryContents(compiledPackDir);
|
||||||
expect(fs.existsSync(path.join(compiledPackDir, 'in-pack.ql'))).to.be.true;
|
expect(fs.existsSync(path.join(compiledPackDir, 'in-pack.ql'))).to.be.true;
|
||||||
expect(fs.existsSync(path.join(compiledPackDir, 'qlpack.yml'))).to.be.true;
|
expect(fs.existsSync(path.join(compiledPackDir, 'qlpack.yml'))).to.be.true;
|
||||||
verifyQlPack(path.join(compiledPackDir, 'qlpack.yml'), 'in-pack.ql', 'codeql-remote/query', '0.0.0');
|
verifyQlPack(path.join(compiledPackDir, 'qlpack.yml'), 'in-pack.ql', 'codeql-remote/query', '0.0.0', await pathSerializationBroken());
|
||||||
|
|
||||||
// depending on the cli version, we should have one of these files
|
// depending on the cli version, we should have one of these files
|
||||||
expect(
|
expect(
|
||||||
@@ -200,7 +202,7 @@ describe('Remote queries', function() {
|
|||||||
expect(fs.existsSync(path.join(compiledPackDir, 'otherfolder/lib.qll'))).to.be.true;
|
expect(fs.existsSync(path.join(compiledPackDir, 'otherfolder/lib.qll'))).to.be.true;
|
||||||
expect(fs.existsSync(path.join(compiledPackDir, 'subfolder/in-pack.ql'))).to.be.true;
|
expect(fs.existsSync(path.join(compiledPackDir, 'subfolder/in-pack.ql'))).to.be.true;
|
||||||
expect(fs.existsSync(path.join(compiledPackDir, 'qlpack.yml'))).to.be.true;
|
expect(fs.existsSync(path.join(compiledPackDir, 'qlpack.yml'))).to.be.true;
|
||||||
verifyQlPack(path.join(compiledPackDir, 'qlpack.yml'), 'subfolder/in-pack.ql', 'github/remote-query-pack', '0.0.0');
|
verifyQlPack(path.join(compiledPackDir, 'qlpack.yml'), 'subfolder/in-pack.ql', 'github/remote-query-pack', '0.0.0', await pathSerializationBroken());
|
||||||
|
|
||||||
// depending on the cli version, we should have one of these files
|
// depending on the cli version, we should have one of these files
|
||||||
expect(
|
expect(
|
||||||
@@ -236,8 +238,13 @@ describe('Remote queries', function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function verifyQlPack(qlpackPath: string, queryPath: string, packName: string, packVersion: string) {
|
function verifyQlPack(qlpackPath: string, queryPath: string, packName: string, packVersion: string, pathSerializationBroken: boolean) {
|
||||||
const qlPack = yaml.safeLoad(fs.readFileSync(qlpackPath, 'utf8'));
|
const qlPack = yaml.safeLoad(fs.readFileSync(qlpackPath, 'utf8')) as QlPack;
|
||||||
|
|
||||||
|
if (pathSerializationBroken) {
|
||||||
|
// the path serialization is broken, so we force it to be the path in the pack to be same as the query path
|
||||||
|
qlPack.defaultSuite![1].query = queryPath;
|
||||||
|
}
|
||||||
|
|
||||||
// don't check the build metadata since it is variable
|
// don't check the build metadata since it is variable
|
||||||
delete (qlPack as any).buildMetadata;
|
delete (qlPack as any).buildMetadata;
|
||||||
@@ -257,6 +264,15 @@ describe('Remote queries', function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In version 2.7.2 and earlier, relative paths were not serialized correctly inside the qlpack.yml file.
|
||||||
|
* So, ignore part of the test for these versions.
|
||||||
|
*
|
||||||
|
* @returns true if path serialization is broken in this run
|
||||||
|
*/
|
||||||
|
async function pathSerializationBroken() {
|
||||||
|
return lte((await cli.getVersion()), '2.7.2') && os.platform() === 'win32';
|
||||||
|
}
|
||||||
function getFile(file: string): Uri {
|
function getFile(file: string): Uri {
|
||||||
return Uri.file(path.join(baseDir, file));
|
return Uri.file(path.join(baseDir, file));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user