Skip to content

Commit d2626e0

Browse files
authored
Re-enable the SingleRootProject tests with check-in tests and fix the getIncludes test failure (#13084)
* Fix getIncludes call with E2E test. * Add a --skipCheckBinaries arg.
1 parent 42c6d99 commit d2626e0

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Diff for: .github/workflows/job-compile-and-test.yml

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ jobs:
4242
run: yarn test
4343
working-directory: Extension
4444

45+
# These tests don't require the binary.
46+
# On Linux, it is failing (before the tests actually run) with: Test run terminated with signal SIGSEGV.
47+
# But it works on Linux during the E2E test.
48+
- name: Run SingleRootProject tests
49+
if: ${{ inputs.platform != 'linux' }}
50+
run: yarn test --scenario=SingleRootProject --skipCheckBinaries
51+
working-directory: Extension
52+
4553
# NOTE : We can't run the test that require the native binary files
4654
# yet -- there will be an update soon that allows the tester to
4755
# acquire them on-the-fly

Diff for: Extension/.scripts/common.ts

+3
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ export async function checkDTS() {
334334
}
335335

336336
export async function checkBinaries() {
337+
if ($switches.includes('--skipCheckBinaries')) {
338+
return false;
339+
}
337340
let failing = false;
338341
failing = !await assertAnyFile(['bin/cpptools.exe', 'bin/cpptools']) && (quiet || warn(`The native binary files are not present. You should either build or install the native binaries\n\n.`)) || failing;
339342

Diff for: Extension/test/scenarios/SingleRootProject/tests/copilotProviders.test.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as sinon from 'sinon';
1010
import * as vscode from 'vscode';
1111
import * as util from '../../../../src/common';
1212
import { DefaultClient, GetIncludesResult } from '../../../../src/LanguageServer/client';
13+
import { ClientCollection } from '../../../../src/LanguageServer/clientCollection';
1314
import { CopilotApi, CopilotTrait } from '../../../../src/LanguageServer/copilotProviders';
1415
import * as extension from '../../../../src/LanguageServer/extension';
1516
import * as lmTool from '../../../../src/LanguageServer/lmTool';
@@ -19,18 +20,19 @@ import * as telemetry from '../../../../src/telemetry';
1920
describe('copilotProviders Tests', () => {
2021
let moduleUnderTest: any;
2122
let mockCopilotApi: sinon.SinonStubbedInstance<CopilotApi>;
22-
let getActiveClientStub: sinon.SinonStub;
23+
let getClientsStub: sinon.SinonStub;
2324
let activeClientStub: sinon.SinonStubbedInstance<DefaultClient>;
2425
let vscodeGetExtensionsStub: sinon.SinonStub;
2526
let callbackPromise: Promise<{ entries: vscode.Uri[]; traits?: CopilotTrait[] }> | undefined;
2627
let vscodeExtension: vscode.Extension<unknown>;
2728
let telemetryStub: sinon.SinonStub;
2829

29-
const includedFiles = process.platform === 'win32' ?
30+
const includedFiles: string[] = process.platform === 'win32' ?
3031
['c:\\system\\include\\vector', 'c:\\system\\include\\string', 'C:\\src\\my_project\\foo.h'] :
3132
['/system/include/vector', '/system/include/string', '/home/src/my_project/foo.h'];
32-
const rootUri = vscode.Uri.file(process.platform === 'win32' ? 'C:\\src\\my_project' : '/home/src/my_project');
33-
const expectedInclude = process.platform === 'win32' ? 'file:///c%3A/src/my_project/foo.h' : 'file:///home/src/my_project/foo.h';
33+
const rootUri: vscode.Uri = vscode.Uri.file(process.platform === 'win32' ? 'C:\\src\\my_project' : '/home/src/my_project');
34+
const expectedInclude: string = process.platform === 'win32' ? 'file:///c%3A/src/my_project/foo.h' : 'file:///home/src/my_project/foo.h';
35+
const sourceFileUri: vscode.Uri = vscode.Uri.file(process.platform === 'win32' ? 'file:///c%3A/src/my_project/foo.cpp' : 'file:///home/src/my_project/foo.cpp');
3436

3537
beforeEach(() => {
3638
proxyquire.noPreserveCache(); // Tells proxyquire to not fetch the module from cache
@@ -70,7 +72,9 @@ describe('copilotProviders Tests', () => {
7072
};
7173

7274
activeClientStub = sinon.createStubInstance(DefaultClient);
73-
getActiveClientStub = sinon.stub(extension, 'getActiveClient').returns(activeClientStub);
75+
const clientsStub = sinon.createStubInstance(ClientCollection);
76+
getClientsStub = sinon.stub(extension, 'getClients').returns(clientsStub);
77+
clientsStub.getClientFor.returns(activeClientStub);
7478
activeClientStub.getIncludes.resolves({ includedFiles: [] });
7579
telemetryStub = sinon.stub(telemetry, 'logCopilotEvent').returns();
7680
});
@@ -90,7 +94,7 @@ describe('copilotProviders Tests', () => {
9094
if (_providerId.languageId === 'cpp') {
9195
const tokenSource = new vscode.CancellationTokenSource();
9296
try {
93-
callbackPromise = callback(vscode.Uri.parse('file:///test-extension-path'), { flags: flags ?? {} }, tokenSource.token);
97+
callbackPromise = callback(sourceFileUri, { flags: flags ?? {} }, tokenSource.token);
9498
} finally {
9599
tokenSource.dispose();
96100
}
@@ -129,7 +133,7 @@ describe('copilotProviders Tests', () => {
129133

130134
ok(vscodeGetExtensionsStub.calledOnce, 'vscode.extensions.getExtension should be called once');
131135
ok(mockCopilotApi.registerRelatedFilesProvider.calledWithMatch(sinon.match({ extensionId: 'test-extension-id', languageId: sinon.match.in(['c', 'cpp', 'cuda-cpp']) })), 'registerRelatedFilesProvider should be called with the correct providerId and languageId');
132-
ok(getActiveClientStub.callCount !== 0, 'getActiveClient should be called');
136+
ok(getClientsStub.callCount !== 0, 'getClients should be called');
133137
ok(callbackPromise, 'callbackPromise should be defined');
134138
ok(result, 'result should be defined');
135139
ok(result.entries.length === 1, 'result.entries should have 1 included file');

0 commit comments

Comments
 (0)