Avoid running remote queries on v2.6.3 cli or earlier
Also: - Fix the count of copied files - A few typos - Ensure the correct settings are applied for remote queries before running tests.
This commit is contained in:
@@ -822,12 +822,15 @@ export class CodeQLCliServer implements Disposable {
|
||||
|
||||
async packPacklist(dir: string, includeQueries: boolean): Promise<string[]> {
|
||||
const args = includeQueries ? [dir] : ['--no-include-queries', dir];
|
||||
const results = await this.runJsonCodeQlCliCommand(['pack', 'packlist'], args, 'Generating the pack list');
|
||||
// since 2.7.1, packlist returns an object with a "paths" property that is a list of packs.
|
||||
// previous versions return a list of packs.
|
||||
const results: { paths: string[] } | string[] = await this.runJsonCodeQlCliCommand(['pack', 'packlist'], args, 'Generating the pack list');
|
||||
|
||||
if (await this.cliConstraints.usesNewPackPacklistLayout()) {
|
||||
return (results as { paths: string[] }).paths;
|
||||
// Once we no longer need to support 2.7.0 or earlier, we can remove this and assume all versions return an object.
|
||||
if ('paths' in results) {
|
||||
return results.paths;
|
||||
} else {
|
||||
return results as string[];
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1130,9 +1133,9 @@ export class CliVersionConstraint {
|
||||
public static CLI_VERSION_WITH_NO_PRECOMPILE = new SemVer('2.7.1');
|
||||
|
||||
/**
|
||||
* CLI version where `pack packlist` layout changed from array to object
|
||||
* CLI version where remote queries are supported.
|
||||
*/
|
||||
public static CLI_VERSION_PACK_PACKLIST_LAYOUT_CHANGE = new SemVer('2.7.1');
|
||||
public static CLI_VERSION_REMOTE_QUERIES = new SemVer('2.6.3');
|
||||
|
||||
constructor(private readonly cli: CodeQLCliServer) {
|
||||
/**/
|
||||
@@ -1174,7 +1177,8 @@ export class CliVersionConstraint {
|
||||
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NO_PRECOMPILE);
|
||||
}
|
||||
|
||||
async usesNewPackPacklistLayout() {
|
||||
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_PACK_PACKLIST_LAYOUT_CHANGE);
|
||||
async supportsRemoteQueries() {
|
||||
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -314,6 +314,10 @@ export function getRemoteRepositoryLists(): Record<string, string[]> | undefined
|
||||
return REMOTE_REPO_LISTS.getValue<Record<string, string[]>>() || undefined;
|
||||
}
|
||||
|
||||
export async function setRemoteRepositoryLists(lists: Record<string, string[]> | undefined) {
|
||||
await REMOTE_REPO_LISTS.updateValue(lists, ConfigurationTarget.Global);
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the "controller" repository that you want to use with the "Run Remote query" command.
|
||||
* Note: This command is only available for internal users.
|
||||
|
||||
@@ -98,18 +98,27 @@ async function generateQueryPack(cliServer: cli.CodeQLCliServer, queryFile: stri
|
||||
|
||||
// also copy the lock file (either new name or old name) and the query file itself. These are not included in the packlist.
|
||||
[path.join(originalPackRoot, 'qlpack.lock.yml'), path.join(originalPackRoot, 'codeql-pack.lock.yml'), queryFile]
|
||||
.forEach(aboslutePath => {
|
||||
if (aboslutePath) {
|
||||
toCopy.push(aboslutePath);
|
||||
.forEach(absolutePath => {
|
||||
if (absolutePath) {
|
||||
toCopy.push(absolutePath);
|
||||
}
|
||||
});
|
||||
void logger.log(`Copying ${toCopy.length} files to ${queryPackDir}`);
|
||||
|
||||
let copiedCount = 0;
|
||||
await fs.copy(originalPackRoot, queryPackDir, {
|
||||
filter: (file: string) =>
|
||||
// copy file if it is in the packlist, or it is a parent directory of a file in the packlist
|
||||
!!toCopy.find(f => f === file || f.startsWith(file + path.sep)
|
||||
)
|
||||
!!toCopy.find(f => {
|
||||
const matches = f === file || f.startsWith(file + path.sep);
|
||||
if (matches) {
|
||||
copiedCount++;
|
||||
}
|
||||
return matches;
|
||||
})
|
||||
});
|
||||
|
||||
void logger.log(`Copied ${copiedCount} files to ${queryPackDir}`);
|
||||
|
||||
language = await findLanguage(cliServer, Uri.file(targetQueryFileName));
|
||||
|
||||
} else {
|
||||
@@ -173,6 +182,11 @@ export async function runRemoteQuery(
|
||||
progress: ProgressCallback,
|
||||
token: CancellationToken
|
||||
): Promise<void | string> {
|
||||
if (!(await cliServer.cliConstraints.supportsRemoteQueries())) {
|
||||
throw new Error(`Remote queries are not supported by this version of CodeQL. Please upgrade to v${cli.CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES
|
||||
} or later.`);
|
||||
}
|
||||
|
||||
const { remoteQueryDir, queryPackDir } = await createRemoteQueriesTempDirectory();
|
||||
try {
|
||||
if (!uri?.fsPath.endsWith('.ql')) {
|
||||
@@ -214,7 +228,6 @@ export async function runRemoteQuery(
|
||||
}
|
||||
|
||||
if (!repositories || repositories.length === 0) {
|
||||
// No error message needed, since `getRepositories` already displays one.
|
||||
throw new UserCancellationException('No repositories to query.');
|
||||
}
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@ import * as yaml from 'js-yaml';
|
||||
|
||||
import { runRemoteQuery } from '../../run-remote-query';
|
||||
import { Credentials } from '../../authentication';
|
||||
import { CodeQLCliServer } from '../../cli';
|
||||
import { CliVersionConstraint, CodeQLCliServer } from '../../cli';
|
||||
import { CodeQLExtensionInterface } from '../../extension';
|
||||
import { setRemoteControllerRepo } from '../../config';
|
||||
import { setRemoteControllerRepo, setRemoteRepositoryLists } from '../../config';
|
||||
import { UserCancellationException } from '../../commandRunner';
|
||||
|
||||
describe('Remote queries', function() {
|
||||
describe.only('Remote queries', function() {
|
||||
const baseDir = path.join(__dirname, '../../../src/vscode-tests/cli-integration');
|
||||
|
||||
let sandbox: sinon.SinonSandbox;
|
||||
@@ -27,7 +27,8 @@ describe('Remote queries', function() {
|
||||
let progress: sinon.SinonSpy;
|
||||
let showQuickPickSpy: sinon.SinonStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
// use `function` so we have access to `this`
|
||||
beforeEach(async function() {
|
||||
sandbox = sinon.createSandbox();
|
||||
|
||||
const extension = await extensions.getExtension<CodeQLExtensionInterface | Record<string, never>>('GitHub.vscode-codeql')!.activate();
|
||||
@@ -36,6 +37,12 @@ describe('Remote queries', function() {
|
||||
} else {
|
||||
throw new Error('Extension not initialized. Make sure cli is downloaded and installed properly.');
|
||||
}
|
||||
|
||||
if (!(await cli.cliConstraints.supportsRemoteQueries())) {
|
||||
console.log(`Remote queries are not supported on CodeQL CLI v${CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES
|
||||
}. Skipping this test.`);
|
||||
this.skip();
|
||||
}
|
||||
credentials = {} as unknown as Credentials;
|
||||
token = {
|
||||
isCancellationRequested: false
|
||||
@@ -48,7 +55,8 @@ describe('Remote queries', function() {
|
||||
.onSecondCall().resolves('javascript' as unknown as QuickPickItem);
|
||||
|
||||
// always run in the vscode-codeql repo
|
||||
void setRemoteControllerRepo('github/vscode-codeql');
|
||||
await setRemoteControllerRepo('github/vscode-codeql');
|
||||
await setRemoteRepositoryLists({ 'vscode-codeql': ['github/vscode-codeql'] });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user