From d2626e0ad820b1dbed2e1cfa6c1930be54ee29a7 Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Mon, 30 Dec 2024 17:09:43 -0800 Subject: [PATCH] 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. --- .github/workflows/job-compile-and-test.yml | 8 ++++++++ Extension/.scripts/common.ts | 3 +++ .../tests/copilotProviders.test.ts | 18 +++++++++++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.github/workflows/job-compile-and-test.yml b/.github/workflows/job-compile-and-test.yml index 2b3998d499..1756d29869 100644 --- a/.github/workflows/job-compile-and-test.yml +++ b/.github/workflows/job-compile-and-test.yml @@ -42,6 +42,14 @@ jobs: run: yarn test working-directory: Extension + # These tests don't require the binary. + # On Linux, it is failing (before the tests actually run) with: Test run terminated with signal SIGSEGV. + # But it works on Linux during the E2E test. + - name: Run SingleRootProject tests + if: ${{ inputs.platform != 'linux' }} + run: yarn test --scenario=SingleRootProject --skipCheckBinaries + working-directory: Extension + # NOTE : We can't run the test that require the native binary files # yet -- there will be an update soon that allows the tester to # acquire them on-the-fly diff --git a/Extension/.scripts/common.ts b/Extension/.scripts/common.ts index 490d464c2c..598ff97e8f 100644 --- a/Extension/.scripts/common.ts +++ b/Extension/.scripts/common.ts @@ -334,6 +334,9 @@ export async function checkDTS() { } export async function checkBinaries() { + if ($switches.includes('--skipCheckBinaries')) { + return false; + } let failing = false; 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; diff --git a/Extension/test/scenarios/SingleRootProject/tests/copilotProviders.test.ts b/Extension/test/scenarios/SingleRootProject/tests/copilotProviders.test.ts index 626ed287c0..31b7615a4f 100644 --- a/Extension/test/scenarios/SingleRootProject/tests/copilotProviders.test.ts +++ b/Extension/test/scenarios/SingleRootProject/tests/copilotProviders.test.ts @@ -10,6 +10,7 @@ import * as sinon from 'sinon'; import * as vscode from 'vscode'; import * as util from '../../../../src/common'; import { DefaultClient, GetIncludesResult } from '../../../../src/LanguageServer/client'; +import { ClientCollection } from '../../../../src/LanguageServer/clientCollection'; import { CopilotApi, CopilotTrait } from '../../../../src/LanguageServer/copilotProviders'; import * as extension from '../../../../src/LanguageServer/extension'; import * as lmTool from '../../../../src/LanguageServer/lmTool'; @@ -19,18 +20,19 @@ import * as telemetry from '../../../../src/telemetry'; describe('copilotProviders Tests', () => { let moduleUnderTest: any; let mockCopilotApi: sinon.SinonStubbedInstance; - let getActiveClientStub: sinon.SinonStub; + let getClientsStub: sinon.SinonStub; let activeClientStub: sinon.SinonStubbedInstance; let vscodeGetExtensionsStub: sinon.SinonStub; let callbackPromise: Promise<{ entries: vscode.Uri[]; traits?: CopilotTrait[] }> | undefined; let vscodeExtension: vscode.Extension; let telemetryStub: sinon.SinonStub; - const includedFiles = process.platform === 'win32' ? + const includedFiles: string[] = process.platform === 'win32' ? ['c:\\system\\include\\vector', 'c:\\system\\include\\string', 'C:\\src\\my_project\\foo.h'] : ['/system/include/vector', '/system/include/string', '/home/src/my_project/foo.h']; - const rootUri = vscode.Uri.file(process.platform === 'win32' ? 'C:\\src\\my_project' : '/home/src/my_project'); - const expectedInclude = process.platform === 'win32' ? 'file:///c%3A/src/my_project/foo.h' : 'file:///home/src/my_project/foo.h'; + const rootUri: vscode.Uri = vscode.Uri.file(process.platform === 'win32' ? 'C:\\src\\my_project' : '/home/src/my_project'); + const expectedInclude: string = process.platform === 'win32' ? 'file:///c%3A/src/my_project/foo.h' : 'file:///home/src/my_project/foo.h'; + 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'); beforeEach(() => { proxyquire.noPreserveCache(); // Tells proxyquire to not fetch the module from cache @@ -70,7 +72,9 @@ describe('copilotProviders Tests', () => { }; activeClientStub = sinon.createStubInstance(DefaultClient); - getActiveClientStub = sinon.stub(extension, 'getActiveClient').returns(activeClientStub); + const clientsStub = sinon.createStubInstance(ClientCollection); + getClientsStub = sinon.stub(extension, 'getClients').returns(clientsStub); + clientsStub.getClientFor.returns(activeClientStub); activeClientStub.getIncludes.resolves({ includedFiles: [] }); telemetryStub = sinon.stub(telemetry, 'logCopilotEvent').returns(); }); @@ -90,7 +94,7 @@ describe('copilotProviders Tests', () => { if (_providerId.languageId === 'cpp') { const tokenSource = new vscode.CancellationTokenSource(); try { - callbackPromise = callback(vscode.Uri.parse('file:///test-extension-path'), { flags: flags ?? {} }, tokenSource.token); + callbackPromise = callback(sourceFileUri, { flags: flags ?? {} }, tokenSource.token); } finally { tokenSource.dispose(); } @@ -129,7 +133,7 @@ describe('copilotProviders Tests', () => { ok(vscodeGetExtensionsStub.calledOnce, 'vscode.extensions.getExtension should be called once'); 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'); - ok(getActiveClientStub.callCount !== 0, 'getActiveClient should be called'); + ok(getClientsStub.callCount !== 0, 'getClients should be called'); ok(callbackPromise, 'callbackPromise should be defined'); ok(result, 'result should be defined'); ok(result.entries.length === 1, 'result.entries should have 1 included file');