Skip to content

Commit c189df3

Browse files
committed
Ensure Graph results can only be seen if in canary mode
1 parent 277869e commit c189df3

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

extensions/ql-vscode/src/run-queries.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,21 @@ export class QueryEvaluationInfo {
206206
return false;
207207
}
208208

209-
const hasKind = !!this.metadata?.kind;
209+
const kind = this.metadata?.kind;
210+
const hasKind = !!kind;
210211
if (!hasKind) {
211212
void logger.log('Cannot produce interpreted results since the query does not have @kind metadata.');
212213
return false;
213214
}
214215

216+
// Graph queries only return interpreted results if we are in canary mode.
217+
if (kind === 'graph') {
218+
return config.isCanary();
219+
}
220+
215221
// table is the default query kind. It does not produce interpreted results.
216222
// any query kind that is not table can, in principle, produce interpreted results.
217-
const isTable = hasKind && this.metadata?.kind === 'table';
218-
return !isTable;
223+
return kind !== 'table';
219224
}
220225

221226
/**

extensions/ql-vscode/src/vscode-tests/no-workspace/helpers.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ describe('walkDirectory', () => {
407407
tmpDir.removeCallback();
408408
});
409409

410+
410411
it('should walk a directory', async () => {
411412
const file1 = path.join(dir, 'file1');
412413
const file2 = path.join(dir, 'file2');
@@ -438,6 +439,8 @@ describe('walkDirectory', () => {
438439
fs.writeFileSync(file8, 'file8');
439440
fs.writeFileSync(file9, 'file9');
440441

442+
// We don't really need to be testing all of these variants of symlinks,
443+
// but it doesn't hurt, and will help us if we ever do decide to support them.
441444
fs.symlinkSync(file6, symLinkFile7, 'file');
442445
fs.symlinkSync(dir3, symlinkDir, 'dir');
443446
fs.symlinkSync(file8, symlinkFile2, 'file');

extensions/ql-vscode/src/vscode-tests/no-workspace/run-queries.test.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,27 @@ import 'mocha';
44
import 'sinon-chai';
55
import * as sinon from 'sinon';
66
import * as chaiAsPromised from 'chai-as-promised';
7+
import { Uri } from 'vscode';
78

89
import { QueryEvaluationInfo } from '../../run-queries';
910
import { Severity, compileQuery } from '../../pure/messages';
10-
import { Uri } from 'vscode';
11+
import * as config from '../../config';
1112

1213
chai.use(chaiAsPromised);
1314
const expect = chai.expect;
1415

1516
describe('run-queries', () => {
17+
let sandbox: sinon.SinonSandbox;
18+
beforeEach(() => {
19+
sandbox = sinon.createSandbox();
20+
21+
sandbox.stub(config, 'isCanary').returns(false);
22+
});
23+
24+
afterEach(() => {
25+
sandbox.restore();
26+
});
27+
1628
it('should create a QueryEvaluationInfo', () => {
1729
const saveDir = 'query-save-dir';
1830
const info = createMockQueryInfo(true, saveDir);
@@ -38,6 +50,13 @@ describe('run-queries', () => {
3850

3951
info.metadata!.kind = 'table';
4052
expect(info.canHaveInterpretedResults()).to.eq(false);
53+
54+
// Graphs are not interpreted unless canary is set
55+
info.metadata!.kind = 'graph';
56+
expect(info.canHaveInterpretedResults()).to.eq(false);
57+
58+
(config.isCanary as sinon.SinonStub).returns(true);
59+
expect(info.canHaveInterpretedResults()).to.eq(true);
4160
});
4261

4362
describe('compile', () => {
@@ -108,7 +127,7 @@ describe('run-queries', () => {
108127
config: {
109128
timeoutSecs: 5
110129
},
111-
sendRequest: sinon.stub().returns(new Promise(resolve => {
130+
sendRequest: sandbox.stub().returns(new Promise(resolve => {
112131
resolve({
113132
messages: [
114133
{ message: 'err', severity: Severity.ERROR },
@@ -117,7 +136,7 @@ describe('run-queries', () => {
117136
});
118137
})),
119138
logger: {
120-
log: sinon.spy()
139+
log: sandbox.spy()
121140
}
122141
};
123142
}

0 commit comments

Comments
 (0)