Forward scored query metadata property for canary users

This commit is contained in:
Henry Mercer
2021-01-21 16:16:11 +00:00
committed by Henry Mercer
parent ae6be79c51
commit f741deb48b
4 changed files with 11 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ import { promisify } from 'util';
import { CancellationToken, Disposable } from 'vscode';
import { BQRSInfo, DecodedBqrsChunk } from './pure/bqrs-cli-types';
import * as config from './config';
import { CliConfig } from './config';
import { DistributionProvider, FindDistributionResultKind } from './distribution';
import { assertNever } from './pure/helpers-pure';
@@ -573,7 +574,7 @@ export class CodeQLCliServer implements Disposable {
return await this.runJsonCodeQlCliCommand<DecodedBqrsChunk>(['bqrs', 'decode'], subcommandArgs, 'Reading bqrs data');
}
async interpretBqrs(metadata: { kind: string; id: string }, resultsPath: string, interpretedResultsPath: string, sourceInfo?: SourceInfo): Promise<sarif.Log> {
async interpretBqrs(metadata: { kind: string; id: string; scored?: string }, resultsPath: string, interpretedResultsPath: string, sourceInfo?: SourceInfo): Promise<sarif.Log> {
const args = [
`-t=kind=${metadata.kind}`,
`-t=id=${metadata.id}`,
@@ -585,6 +586,9 @@ export class CodeQLCliServer implements Disposable {
// grouping client-side.
'--no-group-results',
];
if (config.isCanary() && metadata.scored !== undefined) {
args.push(`-t=scored=${metadata.scored}`);
}
if (sourceInfo !== undefined) {
args.push(
'--source-archive', sourceInfo.sourceArchive,

View File

@@ -34,6 +34,7 @@ export interface QueryMetadata {
description?: string;
id?: string;
kind?: string;
scored?: string;
}
export interface PreviousExecution {

View File

@@ -173,7 +173,7 @@ export async function interpretResults(
if (metadata === undefined) {
throw new Error('Can\'t interpret results without query metadata');
}
let { kind, id } = metadata;
let { kind, id, scored } = metadata;
if (kind === undefined) {
throw new Error('Can\'t interpret results without query metadata including kind');
}
@@ -182,5 +182,5 @@ export async function interpretResults(
// SARIF format does, so in the absence of one, we use a dummy id.
id = 'dummy-id';
}
return await server.interpretBqrs({ kind, id }, resultsPath, interpretedResultsPath, sourceInfo);
return await server.interpretBqrs({ kind, id, scored }, resultsPath, interpretedResultsPath, sourceInfo);
}

View File

@@ -152,7 +152,8 @@ describe('CompletedQuery', () => {
const sourceInfo = {};
const metadata = {
kind: 'my-kind',
id: 'my-id' as string | undefined
id: 'my-id' as string | undefined,
scored: undefined
};
const results1 = await interpretResults(
mockServer,
@@ -183,7 +184,7 @@ describe('CompletedQuery', () => {
);
expect(results2).to.eq('1234');
expect(spy).to.have.been.calledWith(
{ kind: 'my-kind', id: 'dummy-id' },
{ kind: 'my-kind', id: 'dummy-id', scored: undefined },
resultsPath, interpretedResultsPath, sourceInfo
);