From 4937c60c49e3f24ef20afc5ce711ef35f6da2b01 Mon Sep 17 00:00:00 2001 From: Laxman Reddy Aileni Date: Tue, 17 Nov 2026 01:50:19 +0000 Subject: [PATCH 1/2] fix(amazonq): process a new directory with the workspace folder that its handler found When workspace context is on, addNewDirectories now processes a new or renamed directory with the workspace folder that the didCreateFiles or didRenameFiles handler found for it. Adds tests. --- .../workspaceContext/artifactManager.test.ts | 63 +++++++++++++++++++ .../workspaceContext/artifactManager.ts | 15 ++--- .../workspaceContextServer.ts | 2 +- 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.test.ts diff --git a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.test.ts b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.test.ts new file mode 100644 index 0000000000..0ac8ba6750 --- /dev/null +++ b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.test.ts @@ -0,0 +1,63 @@ +import * as sinon from 'sinon' +import { URI } from 'vscode-uri' +import { Logging, Workspace, WorkspaceFolder } from '@aws/language-server-runtimes/server-interface' +import { ArtifactManager } from './artifactManager' +import * as util from './util' + +describe('ArtifactManager', () => { + const logging = { + log: () => {}, + info: () => {}, + warn: () => {}, + error: () => {}, + debug: () => {}, + } as unknown as Logging + const proj: WorkspaceFolder = { uri: URI.file('/work/proj').toString(), name: 'proj' } + const projOther: WorkspaceFolder = { uri: URI.file('/work/proj-other').toString(), name: 'proj-other' } + + let artifactManager: ArtifactManager + let processDirectory: sinon.SinonStub + + beforeEach(() => { + // Two workspace folders + artifactManager = new ArtifactManager({} as Workspace, logging, [proj, projOther]) + // The directory processing reads the disk, so these tests check only the workspace folder that it gets + processDirectory = sinon.stub(artifactManager, 'processDirectory').resolves(new Map()) + sinon.stub(artifactManager as any, 'processFilesByLanguage').resolves([]) + }) + + afterEach(() => { + sinon.restore() + }) + + describe('addNewDirectories', () => { + it('processes a new directory with the workspace folder that the caller found', async () => { + await artifactManager.addNewDirectories([URI.file('/work/proj-other/src')], projOther) + + sinon.assert.calledOnceWithExactly(processDirectory, projOther, '/work/proj-other/src', 'src') + }) + + it('processes a new directory with a workspace folder whose URI has an uppercase drive letter', async () => { + const driveFolder: WorkspaceFolder = { uri: 'file:///C:/work/proj', name: 'proj' } + + await artifactManager.addNewDirectories([URI.parse('file:///C:/work/proj/lib')], driveFolder) + + sinon.assert.calledOnceWithExactly(processDirectory, driveFolder, '/C:/work/proj/lib', 'lib') + }) + }) + + describe('handleRename', () => { + it('processes a renamed directory with the workspace folder of its new path', async () => { + sinon.stub(util, 'isDirectory').returns(true) + sinon.stub(util, 'isEmptyDirectory').returns(false) + + await artifactManager.handleRename( + projOther, + URI.file('/work/proj-other/old').toString(), + URI.file('/work/proj-other/src').toString() + ) + + sinon.assert.calledOnceWithExactly(processDirectory, projOther, '/work/proj-other/src', 'src') + }) + }) +}) diff --git a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.ts b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.ts index dfedb0c913..d19642a1d7 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.ts @@ -94,7 +94,11 @@ export class ArtifactManager { return zipFileMetadata } - async addNewDirectories(newDirectories: URI[]): Promise { + /** + * Processes the files of new directories as part of `workspaceFolder`, the workspace folder that the file event + * handler found for them + */ + async addNewDirectories(newDirectories: URI[], workspaceFolder: WorkspaceFolder): Promise { let zipFileMetadata: FileMetadata[] = [] const fileSizeDetails: FileSizeDetails = { includedFileCount: 0, @@ -104,13 +108,6 @@ export class ArtifactManager { } for (const directory of newDirectories) { - const workspaceFolder = this.workspaceFolders.find(ws => directory.path.startsWith(URI.parse(ws.uri).path)) - - if (!workspaceFolder) { - // No workspace folder found for directory, it will not be processed - continue - } - try { const workspacePath = URI.parse(workspaceFolder.uri).path const relativePath = path.relative(workspacePath, directory.path) @@ -317,7 +314,7 @@ export class ArtifactManager { let filesMetadata: FileMetadata[] = [] if (isDirectory(newUri)) { if (!isEmptyDirectory(newUri)) { - filesMetadata = await this.addNewDirectories([URI.parse(newUri)]) + filesMetadata = await this.addNewDirectories([URI.parse(newUri)], workspaceFolder) } } else { filesMetadata = [await this.processNewFile(workspaceFolder, newUri)] diff --git a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/workspaceContextServer.ts b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/workspaceContextServer.ts index 6361b87c44..f25bc89a8e 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/workspaceContextServer.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/workspaceContextServer.ts @@ -432,7 +432,7 @@ export const WorkspaceContextServer = (): Server => features => { if (isDir && isEmptyDirectory(file.uri)) { continue } else if (isDir) { - filesMetadata = await artifactManager.addNewDirectories([URI.parse(file.uri)]) + filesMetadata = await artifactManager.addNewDirectories([URI.parse(file.uri)], workspaceFolder) } else { filesMetadata = [await artifactManager.processNewFile(workspaceFolder, file.uri)] } From 7aeae9ae05f26e89db29e6598e7f50d4b5f49f1f Mon Sep 17 00:00:00 2001 From: Laxman Reddy Aileni Date: Wed, 18 Nov 2026 03:26:49 +0000 Subject: [PATCH 2/2] test(amazonq): check the workspace folder that a new directory is processed with Checks that processFilesByLanguage gets the workspace folder that the file handler found and the relative path, for a new directory, a workspace folder with a drive letter, and a renamed directory. --- .../workspaceContext/artifactManager.test.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.test.ts b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.test.ts index 0ac8ba6750..3fb3db379c 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.test.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/workspaceContext/artifactManager.test.ts @@ -17,13 +17,14 @@ describe('ArtifactManager', () => { let artifactManager: ArtifactManager let processDirectory: sinon.SinonStub + let processFilesByLanguage: sinon.SinonStub beforeEach(() => { // Two workspace folders artifactManager = new ArtifactManager({} as Workspace, logging, [proj, projOther]) // The directory processing reads the disk, so these tests check only the workspace folder that it gets processDirectory = sinon.stub(artifactManager, 'processDirectory').resolves(new Map()) - sinon.stub(artifactManager as any, 'processFilesByLanguage').resolves([]) + processFilesByLanguage = sinon.stub(artifactManager as any, 'processFilesByLanguage').resolves([]) }) afterEach(() => { @@ -35,6 +36,14 @@ describe('ArtifactManager', () => { await artifactManager.addNewDirectories([URI.file('/work/proj-other/src')], projOther) sinon.assert.calledOnceWithExactly(processDirectory, projOther, '/work/proj-other/src', 'src') + // The files of the directory are zipped as part of the same folder, under the same relative path + sinon.assert.calledOnceWithExactly( + processFilesByLanguage, + projOther, + sinon.match.object, + sinon.match.map, + 'src' + ) }) it('processes a new directory with a workspace folder whose URI has an uppercase drive letter', async () => { @@ -43,6 +52,13 @@ describe('ArtifactManager', () => { await artifactManager.addNewDirectories([URI.parse('file:///C:/work/proj/lib')], driveFolder) sinon.assert.calledOnceWithExactly(processDirectory, driveFolder, '/C:/work/proj/lib', 'lib') + sinon.assert.calledOnceWithExactly( + processFilesByLanguage, + driveFolder, + sinon.match.object, + sinon.match.map, + 'lib' + ) }) }) @@ -58,6 +74,13 @@ describe('ArtifactManager', () => { ) sinon.assert.calledOnceWithExactly(processDirectory, projOther, '/work/proj-other/src', 'src') + sinon.assert.calledOnceWithExactly( + processFilesByLanguage, + projOther, + sinon.match.object, + sinon.match.map, + 'src' + ) }) }) })