From 27e1880e1f070029e94e2d3c8b3bc66f58a55083 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Fri, 15 Nov 2024 09:37:40 -0800 Subject: [PATCH 1/3] fix flaky crossfileContextUtil.test --- .../util/crossFileContextUtil.test.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/amazonq/test/unit/codewhisperer/util/crossFileContextUtil.test.ts b/packages/amazonq/test/unit/codewhisperer/util/crossFileContextUtil.test.ts index a3cfbbe35e7..dae3bcf88ca 100644 --- a/packages/amazonq/test/unit/codewhisperer/util/crossFileContextUtil.test.ts +++ b/packages/amazonq/test/unit/codewhisperer/util/crossFileContextUtil.test.ts @@ -38,6 +38,7 @@ describe('crossFileContextUtil', function () { describe('fetchSupplementalContextForSrc', function () { beforeEach(async function () { tempFolder = (await createTestWorkspaceFolder()).uri.fsPath + sinon.restore() }) afterEach(async function () { @@ -50,10 +51,12 @@ describe('crossFileContextUtil', function () { const myCurrentEditor = await toTextEditor('', 'TargetFile.java', tempFolder, { preview: false, }) + + await assertTabCount(2) + const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken) assert.ok(actual) - assert.ok(actual.supplementalContextItems.length === 3) - + assert.strictEqual(actual.supplementalContextItems.length, 3) assert.strictEqual(actual.supplementalContextItems[0].content.split('\n').length, 50) assert.strictEqual(actual.supplementalContextItems[1].content.split('\n').length, 50) assert.strictEqual(actual.supplementalContextItems[2].content.split('\n').length, 50) @@ -64,6 +67,9 @@ describe('crossFileContextUtil', function () { const myCurrentEditor = await toTextEditor('', 'TargetFile.java', tempFolder, { preview: false, }) + + await assertTabCount(2) + sinon.stub(FeatureConfigProvider.instance, 'getProjectContextGroup').returns('t1') sinon .stub(LspController.instance, 'queryInlineProjectContext') @@ -78,7 +84,7 @@ describe('crossFileContextUtil', function () { const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken) assert.ok(actual) - assert.ok(actual.supplementalContextItems.length === 4) + assert.strictEqual(actual.supplementalContextItems.length, 4) assert.strictEqual(actual?.strategy, 'codemap') assert.deepEqual(actual?.supplementalContextItems[0], { content: 'foo', @@ -96,6 +102,9 @@ describe('crossFileContextUtil', function () { const myCurrentEditor = await toTextEditor('', 'TargetFile.java', tempFolder, { preview: false, }) + + await assertTabCount(2) + sinon.stub(FeatureConfigProvider.instance, 'getProjectContextGroup').returns('t2') sinon .stub(LspController.instance, 'queryInlineProjectContext') @@ -130,7 +139,7 @@ describe('crossFileContextUtil', function () { const actual = await crossFile.fetchSupplementalContextForSrc(myCurrentEditor, fakeCancellationToken) assert.ok(actual) - assert.ok(actual.supplementalContextItems.length === 5) + assert.strictEqual(actual.supplementalContextItems.length, 5) assert.strictEqual(actual?.strategy, 'bm25') assert.deepEqual(actual?.supplementalContextItems[0], { From 6dd448ee950fbbba563b573edec0395f1a6e6529 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Fri, 15 Nov 2024 09:50:07 -0800 Subject: [PATCH 2/3] a --- .../test/unit/codewhisperer/util/crossFileContextUtil.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/amazonq/test/unit/codewhisperer/util/crossFileContextUtil.test.ts b/packages/amazonq/test/unit/codewhisperer/util/crossFileContextUtil.test.ts index dae3bcf88ca..372aa566396 100644 --- a/packages/amazonq/test/unit/codewhisperer/util/crossFileContextUtil.test.ts +++ b/packages/amazonq/test/unit/codewhisperer/util/crossFileContextUtil.test.ts @@ -38,7 +38,6 @@ describe('crossFileContextUtil', function () { describe('fetchSupplementalContextForSrc', function () { beforeEach(async function () { tempFolder = (await createTestWorkspaceFolder()).uri.fsPath - sinon.restore() }) afterEach(async function () { From d281665cf1821b304dab01264d8f5569f1e90db2 Mon Sep 17 00:00:00 2001 From: Will Lo Date: Fri, 15 Nov 2024 10:04:17 -0800 Subject: [PATCH 3/3] patch --- .../unit/codewhisperer/util/supplemetalContextUtil.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/amazonq/test/unit/codewhisperer/util/supplemetalContextUtil.test.ts b/packages/amazonq/test/unit/codewhisperer/util/supplemetalContextUtil.test.ts index 9e45180a758..25f3ce1a585 100644 --- a/packages/amazonq/test/unit/codewhisperer/util/supplemetalContextUtil.test.ts +++ b/packages/amazonq/test/unit/codewhisperer/util/supplemetalContextUtil.test.ts @@ -7,7 +7,7 @@ import assert from 'assert' import * as vscode from 'vscode' import * as sinon from 'sinon' import * as crossFile from 'aws-core-vscode/codewhisperer' -import { TestFolder } from 'aws-core-vscode/test' +import { TestFolder, assertTabCount } from 'aws-core-vscode/test' import { FeatureConfigProvider } from 'aws-core-vscode/codewhisperer' import { toTextEditor } from 'aws-core-vscode/test' @@ -39,6 +39,8 @@ describe('supplementalContextUtil', function () { preview: false, }) + await assertTabCount(4) + const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken) assert.ok(actual?.supplementalContextItems.length === 3) }) @@ -53,6 +55,8 @@ describe('supplementalContextUtil', function () { preview: false, }) + await assertTabCount(4) + const actual = await crossFile.fetchSupplementalContext(editor, fakeCancellationToken) assert.ok(actual?.supplementalContextItems.length === 0) })