From 606604258626e11b7c1bc86c696e11a286bbe092 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Mon, 8 Apr 2024 21:32:09 +0000 Subject: [PATCH 1/5] Turns out these patterns do not terminate that branch of the walk See https://github.com/micromatch/anymatch for context --- .../pyright-internal/src/common/chokidarFileWatcherProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pyright-internal/src/common/chokidarFileWatcherProvider.ts b/packages/pyright-internal/src/common/chokidarFileWatcherProvider.ts index 78f7ae647..4bede8c2f 100644 --- a/packages/pyright-internal/src/common/chokidarFileWatcherProvider.ts +++ b/packages/pyright-internal/src/common/chokidarFileWatcherProvider.ts @@ -44,7 +44,7 @@ export class ChokidarFileWatcherProvider implements FileWatcherProvider { watcherOptions.usePolling = false; } - const excludes: string[] = ['**/node_modules', '**/__pycache__', '**/.*']; + const excludes: string[] = ['**/node_modules/**', '**/__pycache__/**', '**/.*']; if (_isMacintosh || _isLinux) { if (paths.some((path) => path === '' || path === '/')) { excludes.push('/dev/**'); From b0e8efeb86b69ead521fac70c2d29b0bb603eeaf Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 9 Apr 2024 18:42:26 +0000 Subject: [PATCH 2/5] Just trying crazy stuff to see what works. No idea why I can't observe the failure --- packages/pyright-internal/src/tests/languageServer.test.ts | 2 +- .../pyright-internal/src/tests/lsp/languageServerTestUtils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/pyright-internal/src/tests/languageServer.test.ts b/packages/pyright-internal/src/tests/languageServer.test.ts index 1d99a7096..47fbc1488 100644 --- a/packages/pyright-internal/src/tests/languageServer.test.ts +++ b/packages/pyright-internal/src/tests/languageServer.test.ts @@ -182,7 +182,7 @@ describe(`Basic language server tests`, () => { await openFile(info, 'marker'); // Wait for the diagnostics to publish - const diagnostics = await waitForDiagnostics(info); + const diagnostics = await waitForDiagnostics(info, 10000, 6); assert.equal(diagnostics[0]!.diagnostics.length, 6); // Make sure the error has a special rule diff --git a/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts b/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts index 94900f7be..9d19d700d 100644 --- a/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts +++ b/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts @@ -265,10 +265,10 @@ function createServerConnection(testServerData: CustomLSP.TestServerStartOptions return connection; } -export async function waitForDiagnostics(info: PyrightServerInfo, timeout = 10000) { +export async function waitForDiagnostics(info: PyrightServerInfo, timeout = 10000, count?: number) { const deferred = createDeferred(); const disposable = info.diagnosticsEvent((params) => { - if (params.diagnostics.length > 0) { + if (count === undefined ? params.diagnostics.length > 0 : params.diagnostics.length === count) { deferred.resolve(); } }); From bc6ac2eab6a9cda74272303a40624640baed46c8 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 9 Apr 2024 18:53:38 +0000 Subject: [PATCH 3/5] Mismatched timeouts --- packages/pyright-internal/src/tests/languageServer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pyright-internal/src/tests/languageServer.test.ts b/packages/pyright-internal/src/tests/languageServer.test.ts index 47fbc1488..d2ec39ef7 100644 --- a/packages/pyright-internal/src/tests/languageServer.test.ts +++ b/packages/pyright-internal/src/tests/languageServer.test.ts @@ -189,5 +189,5 @@ describe(`Basic language server tests`, () => { assert.equal(diagnostics[0].diagnostics[1].code, 'pyright[reportUnusedImport]'); assert.equal(diagnostics[0].diagnostics[3].code, 'ruff[F401]'); assert.equal(diagnostics[0].diagnostics[5].code, 'ruff[F401]'); - }); + }, 10000); }); From 7a458431eba496682b6e27ebc9b4ccc702d01cbf Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 9 Apr 2024 20:26:03 +0000 Subject: [PATCH 4/5] Again. --- packages/pyright-internal/src/tests/languageServer.test.ts | 2 +- .../src/tests/lsp/languageServerTestUtils.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/pyright-internal/src/tests/languageServer.test.ts b/packages/pyright-internal/src/tests/languageServer.test.ts index d2ec39ef7..16d058573 100644 --- a/packages/pyright-internal/src/tests/languageServer.test.ts +++ b/packages/pyright-internal/src/tests/languageServer.test.ts @@ -183,7 +183,7 @@ describe(`Basic language server tests`, () => { // Wait for the diagnostics to publish const diagnostics = await waitForDiagnostics(info, 10000, 6); - assert.equal(diagnostics[0]!.diagnostics.length, 6); + assert.equal(diagnostics[0]!.diagnostics.length, 0); // Make sure the error has a special rule assert.equal(diagnostics[0].diagnostics[1].code, 'pyright[reportUnusedImport]'); diff --git a/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts b/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts index 9d19d700d..2c83e6222 100644 --- a/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts +++ b/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts @@ -267,18 +267,21 @@ function createServerConnection(testServerData: CustomLSP.TestServerStartOptions export async function waitForDiagnostics(info: PyrightServerInfo, timeout = 10000, count?: number) { const deferred = createDeferred(); + const responses: number[] = []; const disposable = info.diagnosticsEvent((params) => { + responses.push(params.diagnostics.length); if (count === undefined ? params.diagnostics.length > 0 : params.diagnostics.length === count) { deferred.resolve(); } }); - const timer = setTimeout(() => deferred.reject('Timed out waiting for diagnostics'), timeout); + const timer = setTimeout(() => deferred.resolve(), timeout); try { await deferred.promise; } finally { clearTimeout(timer); disposable.dispose(); } + console.error('RECEIVED THE FOLLOWING DIAGNOSTICS:', responses); return info.diagnostics; } From 365972df386074e7a84c4ccc8e445645806ece8e Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 9 Apr 2024 20:57:46 +0000 Subject: [PATCH 5/5] Reduce, get back to the spirit of the original implementation --- .../src/tests/languageServer.test.ts | 4 ++-- .../src/tests/lsp/languageServerTestUtils.ts | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/pyright-internal/src/tests/languageServer.test.ts b/packages/pyright-internal/src/tests/languageServer.test.ts index 16d058573..bdc623954 100644 --- a/packages/pyright-internal/src/tests/languageServer.test.ts +++ b/packages/pyright-internal/src/tests/languageServer.test.ts @@ -182,8 +182,8 @@ describe(`Basic language server tests`, () => { await openFile(info, 'marker'); // Wait for the diagnostics to publish - const diagnostics = await waitForDiagnostics(info, 10000, 6); - assert.equal(diagnostics[0]!.diagnostics.length, 0); + const diagnostics = await waitForDiagnostics(info, 6); + assert.equal(diagnostics[0]!.diagnostics.length, 6); // Make sure the error has a special rule assert.equal(diagnostics[0].diagnostics[1].code, 'pyright[reportUnusedImport]'); diff --git a/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts b/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts index 2c83e6222..695938a09 100644 --- a/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts +++ b/packages/pyright-internal/src/tests/lsp/languageServerTestUtils.ts @@ -265,23 +265,30 @@ function createServerConnection(testServerData: CustomLSP.TestServerStartOptions return connection; } -export async function waitForDiagnostics(info: PyrightServerInfo, timeout = 10000, count?: number) { +export async function waitForDiagnostics(info: PyrightServerInfo, expectedCount: number, timeout = 10000) { const deferred = createDeferred(); - const responses: number[] = []; + // Replit(dstewart): We've got a bit of an issue with the Windows CI job. + // A bit of a Schrodinger's bug situation, since adding console.log seems + // to add just enough latency to cause the tests to pass. I presume that + // what we're seeing is we're getting two responses, first with 3 responses, + // then immediately after one with six responses. + const responseLengths: number[] = []; const disposable = info.diagnosticsEvent((params) => { - responses.push(params.diagnostics.length); - if (count === undefined ? params.diagnostics.length > 0 : params.diagnostics.length === count) { + if (params.diagnostics.length > 0) { + responseLengths.push(params.diagnostics.length); + } + if (params.diagnostics.length === expectedCount) { deferred.resolve(); } }); - const timer = setTimeout(() => deferred.resolve(), timeout); + const timer = setTimeout(() => deferred.reject('Timed out waiting for diagnostics'), timeout); try { await deferred.promise; + assert.equal(responseLengths.length, 1, 'We had more than one result! ' + JSON.stringify(responseLengths)); } finally { clearTimeout(timer); disposable.dispose(); } - console.error('RECEIVED THE FOLLOWING DIAGNOSTICS:', responses); return info.diagnostics; }