Ensure Graph results can only be seen if in canary mode

This commit is contained in:
Andrew Eisenberg
2022-02-25 17:19:43 -08:00
parent 277869ebca
commit c189df3fd6
3 changed files with 33 additions and 6 deletions

View File

@@ -206,16 +206,21 @@ export class QueryEvaluationInfo {
return false;
}
const hasKind = !!this.metadata?.kind;
const kind = this.metadata?.kind;
const hasKind = !!kind;
if (!hasKind) {
void logger.log('Cannot produce interpreted results since the query does not have @kind metadata.');
return false;
}
// Graph queries only return interpreted results if we are in canary mode.
if (kind === 'graph') {
return config.isCanary();
}
// table is the default query kind. It does not produce interpreted results.
// any query kind that is not table can, in principle, produce interpreted results.
const isTable = hasKind && this.metadata?.kind === 'table';
return !isTable;
return kind !== 'table';
}
/**

View File

@@ -407,6 +407,7 @@ describe('walkDirectory', () => {
tmpDir.removeCallback();
});
it('should walk a directory', async () => {
const file1 = path.join(dir, 'file1');
const file2 = path.join(dir, 'file2');
@@ -438,6 +439,8 @@ describe('walkDirectory', () => {
fs.writeFileSync(file8, 'file8');
fs.writeFileSync(file9, 'file9');
// We don't really need to be testing all of these variants of symlinks,
// but it doesn't hurt, and will help us if we ever do decide to support them.
fs.symlinkSync(file6, symLinkFile7, 'file');
fs.symlinkSync(dir3, symlinkDir, 'dir');
fs.symlinkSync(file8, symlinkFile2, 'file');

View File

@@ -4,15 +4,27 @@ import 'mocha';
import 'sinon-chai';
import * as sinon from 'sinon';
import * as chaiAsPromised from 'chai-as-promised';
import { Uri } from 'vscode';
import { QueryEvaluationInfo } from '../../run-queries';
import { Severity, compileQuery } from '../../pure/messages';
import { Uri } from 'vscode';
import * as config from '../../config';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('run-queries', () => {
let sandbox: sinon.SinonSandbox;
beforeEach(() => {
sandbox = sinon.createSandbox();
sandbox.stub(config, 'isCanary').returns(false);
});
afterEach(() => {
sandbox.restore();
});
it('should create a QueryEvaluationInfo', () => {
const saveDir = 'query-save-dir';
const info = createMockQueryInfo(true, saveDir);
@@ -38,6 +50,13 @@ describe('run-queries', () => {
info.metadata!.kind = 'table';
expect(info.canHaveInterpretedResults()).to.eq(false);
// Graphs are not interpreted unless canary is set
info.metadata!.kind = 'graph';
expect(info.canHaveInterpretedResults()).to.eq(false);
(config.isCanary as sinon.SinonStub).returns(true);
expect(info.canHaveInterpretedResults()).to.eq(true);
});
describe('compile', () => {
@@ -108,7 +127,7 @@ describe('run-queries', () => {
config: {
timeoutSecs: 5
},
sendRequest: sinon.stub().returns(new Promise(resolve => {
sendRequest: sandbox.stub().returns(new Promise(resolve => {
resolve({
messages: [
{ message: 'err', severity: Severity.ERROR },
@@ -117,7 +136,7 @@ describe('run-queries', () => {
});
})),
logger: {
log: sinon.spy()
log: sandbox.spy()
}
};
}