Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Server } from '@aws/language-server-runtimes/server-interface'
import { TestFeatures } from '@aws/language-server-runtimes/testing'
import sinon from 'ts-sinon'
import { LocalProjectContextServer } from './localProjectContextServer'

describe('LocalProjectContextServer', () => {
let features: TestFeatures
let server: Server
let disposeServer: () => void

beforeEach(() => {
features = new TestFeatures()
server = LocalProjectContextServer()
disposeServer = server(features)
})

afterEach(() => {
sinon.restore()
disposeServer()
features.dispose()
})

it('should skip init when isDefaultConfig is true', async () => {
// Mock the service manager methods
const mockServiceManager = {
addDidChangeConfigurationListener: sinon.stub().resolves(),
}
sinon
.stub(
require('../../shared/amazonQServiceManager/AmazonQTokenServiceManager'),
'getOrThrowBaseTokenServiceManager'
)
.returns(mockServiceManager)
sinon.stub(require('../../shared/utils'), 'isUsingIAMAuth').returns(false)

await features.initialize(server)

// Get the configuration listener that was registered
const configListener = mockServiceManager.addDidChangeConfigurationListener.firstCall.args[0]

// Call it with default config
await configListener({ isDefaultConfig: true })

sinon.assert.calledWith(
features.logging.log,
'Skipping local project context initialization for default config'
)
})

it('should call init when isDefaultConfig is false', async () => {
// Mock the service manager methods
const mockServiceManager = {
addDidChangeConfigurationListener: sinon.stub().resolves(),
}
sinon
.stub(
require('../../shared/amazonQServiceManager/AmazonQTokenServiceManager'),
'getOrThrowBaseTokenServiceManager'
)
.returns(mockServiceManager)
sinon.stub(require('../../shared/utils'), 'isUsingIAMAuth').returns(false)

await features.initialize(server)

// Get the configuration listener that was registered
const configListener = mockServiceManager.addDidChangeConfigurationListener.firstCall.args[0]

// Call it with non-default config
await configListener({
isDefaultConfig: false,
projectContext: { enableLocalIndexing: true },
})

sinon.assert.calledWith(features.logging.log, sinon.match(/Setting project context indexing enabled to/))
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ export const LocalProjectContextServer =
const updateConfigurationHandler = async (updatedConfig: AmazonQWorkspaceConfig) => {
logging.log('Updating configuration of local context server')
try {
if (updatedConfig.isDefaultConfig === true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add tests for this use case

logging.log('Skipping local project context initialization for default config')
return
}

localProjectContextEnabled = updatedConfig.projectContext?.enableLocalIndexing === true
if (process.env.DISABLE_INDEXING_LIBRARY === 'true') {
logging.log('Skipping local project context initialization')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ interface CodeWhispererConfigSection {
sendUserWrittenCodeMetrics: boolean
}

export type AmazonQWorkspaceConfig = QConfigSection & CodeWhispererConfigSection
export type AmazonQWorkspaceConfig = QConfigSection &
CodeWhispererConfigSection & {
isDefaultConfig?: boolean
}

/**
* Attempts to fetch the workspace configurations set in:
Expand Down Expand Up @@ -184,6 +187,7 @@ export async function getAmazonQRelatedWorkspaceConfigs(
return {
...qConfig,
...codeWhispererConfig,
isDefaultConfig: false,
}
}

Expand Down Expand Up @@ -212,6 +216,7 @@ export const defaultAmazonQWorkspaceConfigFactory = (): AmazonQWorkspaceConfig =
indexCacheDirPath: undefined,
},
},
isDefaultConfig: true,
}
}

Expand Down
Loading