Skip to content

Commit 7874a34

Browse files
Add tests for runRemoteQuery when in live results mode
1 parent 52f993f commit 7874a34

2 files changed

Lines changed: 105 additions & 1 deletion

File tree

extensions/ql-vscode/src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,7 @@ const LIVE_RESULTS = new Setting('liveResults', REMOTE_QUERIES_SETTING);
397397
export function isVariantAnalysisLiveResultsEnabled(): boolean {
398398
return !!LIVE_RESULTS.getValue<boolean>();
399399
}
400+
401+
export async function setVariantAnalysisLiveResultsEnabled(enabled: boolean) {
402+
await LIVE_RESULTS.updateValue(enabled, ConfigurationTarget.Global);
403+
}

extensions/ql-vscode/src/vscode-tests/cli-integration/remote-queries/run-remote-query.test.ts

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import { QlPack, runRemoteQuery } from '../../../remote-queries/run-remote-query
1010
import { Credentials } from '../../../authentication';
1111
import { CliVersionConstraint, CodeQLCliServer } from '../../../cli';
1212
import { CodeQLExtensionInterface } from '../../../extension';
13-
import { setRemoteControllerRepo, setRemoteRepositoryLists } from '../../../config';
13+
import { setRemoteControllerRepo, setRemoteRepositoryLists, setVariantAnalysisLiveResultsEnabled } from '../../../config';
1414
import { UserCancellationException } from '../../../commandRunner';
15+
import * as ghApiClient from '../../../remote-queries/gh-api/gh-api-client';
1516
import { lte } from 'semver';
17+
import { VariantAnalysis } from '../../../remote-queries/gh-api/variant-analysis';
1618

1719
describe('Remote queries', function() {
1820
const baseDir = path.join(__dirname, '../../../../src/vscode-tests/cli-integration');
@@ -58,6 +60,9 @@ describe('Remote queries', function() {
5860
// always run in the vscode-codeql repo
5961
await setRemoteControllerRepo('github/vscode-codeql');
6062
await setRemoteRepositoryLists({ 'vscode-codeql': ['github/vscode-codeql'] });
63+
64+
// Consider live results disabled unless specifically enabled in a test
65+
await setVariantAnalysisLiveResultsEnabled(false);
6166
});
6267

6368
afterEach(() => {
@@ -259,6 +264,101 @@ describe('Remote queries', function() {
259264
}
260265
});
261266

267+
it('should run a variant analysis that is part of a qlpack', async () => {
268+
await setVariantAnalysisLiveResultsEnabled(true);
269+
270+
const dummyVariantAnalysis: VariantAnalysis = {
271+
id: 123,
272+
controller_repo: {
273+
id: 64,
274+
name: 'pickles',
275+
full_name: 'github/pickles',
276+
private: false,
277+
},
278+
actor_id: 27,
279+
query_language: 'javascript',
280+
query_pack_url: 'https://example.com/foo',
281+
status: 'in_progress',
282+
};
283+
const submitVariantAnalysisStub = sandbox.stub(ghApiClient, 'submitVariantAnalysis').resolves(dummyVariantAnalysis);
284+
285+
const fileUri = getFile('data-remote-qlpack/in-pack.ql');
286+
287+
const querySubmissionResult = await runRemoteQuery(cli, credentials, fileUri, true, progress, token);
288+
expect(querySubmissionResult).to.be.ok;
289+
290+
expect(submitVariantAnalysisStub).to.have.been.calledOnce;
291+
});
292+
293+
it('should run a remote query that is not part of a qlpack', async () => {
294+
await setVariantAnalysisLiveResultsEnabled(true);
295+
296+
const dummyVariantAnalysis: VariantAnalysis = {
297+
id: 123,
298+
controller_repo: {
299+
id: 64,
300+
name: 'pickles',
301+
full_name: 'github/pickles',
302+
private: false,
303+
},
304+
actor_id: 27,
305+
query_language: 'javascript',
306+
query_pack_url: 'https://example.com/foo',
307+
status: 'in_progress',
308+
};
309+
const submitVariantAnalysisStub = sandbox.stub(ghApiClient, 'submitVariantAnalysis').resolves(dummyVariantAnalysis);
310+
311+
const fileUri = getFile('data-remote-no-qlpack/in-pack.ql');
312+
313+
const querySubmissionResult = await runRemoteQuery(cli, credentials, fileUri, true, progress, token);
314+
expect(querySubmissionResult).to.be.ok;
315+
316+
expect(submitVariantAnalysisStub).to.have.been.calledOnce;
317+
});
318+
319+
it('should run a remote query that is nested inside a qlpack', async () => {
320+
await setVariantAnalysisLiveResultsEnabled(true);
321+
322+
const dummyVariantAnalysis: VariantAnalysis = {
323+
id: 123,
324+
controller_repo: {
325+
id: 64,
326+
name: 'pickles',
327+
full_name: 'github/pickles',
328+
private: false,
329+
},
330+
actor_id: 27,
331+
query_language: 'javascript',
332+
query_pack_url: 'https://example.com/foo',
333+
status: 'in_progress',
334+
};
335+
const submitVariantAnalysisStub = sandbox.stub(ghApiClient, 'submitVariantAnalysis').resolves(dummyVariantAnalysis);
336+
337+
const fileUri = getFile('data-remote-qlpack-nested/subfolder/in-pack.ql');
338+
339+
const querySubmissionResult = await runRemoteQuery(cli, credentials, fileUri, true, progress, token);
340+
expect(querySubmissionResult).to.be.ok;
341+
342+
expect(submitVariantAnalysisStub).to.have.been.calledOnce;
343+
});
344+
345+
it('should cancel a run before uploading', async () => {
346+
await setVariantAnalysisLiveResultsEnabled(true);
347+
348+
const fileUri = getFile('data-remote-no-qlpack/in-pack.ql');
349+
350+
const promise = runRemoteQuery(cli, credentials, fileUri, true, progress, token);
351+
352+
token.isCancellationRequested = true;
353+
354+
try {
355+
await promise;
356+
assert.fail('should have thrown');
357+
} catch (e) {
358+
expect(e).to.be.instanceof(UserCancellationException);
359+
}
360+
});
361+
262362
function verifyQlPack(qlpackPath: string, queryPath: string, packVersion: string, pathSerializationBroken: boolean) {
263363
const qlPack = yaml.load(fs.readFileSync(qlpackPath, 'utf8')) as QlPack;
264364

0 commit comments

Comments
 (0)