Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherry pick 6084 #6091

Merged
merged 1 commit into from
Nov 8, 2024
Merged
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
18 changes: 14 additions & 4 deletions agent/src/AgentWorkspaceConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('AgentWorkspaceConfiguration', () => {
"cody.debug": {
"verbose": true
},
"cody.advanced.hasNativeWebview": false,
"cody.autocomplete.advanced.provider": "anthropic",
"cody.experimental": {
"tracing": true
Expand Down Expand Up @@ -54,6 +55,9 @@ describe('AgentWorkspaceConfiguration', () => {
verboseDebug: true,
codebase: 'test-repo',
customConfigurationJson: customConfigJson,
customConfiguration: {
'cody.debug.additional': true,
},
}

beforeEach(() => {
Expand All @@ -70,7 +74,7 @@ describe('AgentWorkspaceConfiguration', () => {
expect(config.get('cody.customHeaders')).toEqual({ 'X-Test': 'test' })
expect(config.get('cody.telemetry.level')).toBe('agent')
// clientName undefined because custom JSON specified telemetry with level alone.
expect(config.get('cody.telemetry.clientName')).toBeUndefined()
expect(config.get('cody.telemetry.clientName')).toBe('test-client')
expect(config.get('cody.autocomplete.enabled')).toBe(true)
expect(config.get('cody.autocomplete.advanced.provider')).toBe('anthropic')
expect(config.get('cody.autocomplete.advanced.model')).toBe('claude-2')
Expand Down Expand Up @@ -108,7 +112,7 @@ describe('AgentWorkspaceConfiguration', () => {
},
running: true,
},
hasNativeWebview: true,
hasNativeWebview: false,
},
autocomplete: {
advanced: {
Expand All @@ -123,12 +127,14 @@ describe('AgentWorkspaceConfiguration', () => {
},
debug: {
verbose: true,
additional: true,
},
experimental: {
tracing: true,
},
serverEndpoint: 'https://sourcegraph.test',
telemetry: {
clientName: 'test-client',
level: 'agent',
},
})
Expand Down Expand Up @@ -167,7 +173,7 @@ describe('AgentWorkspaceConfiguration', () => {

it('handles agent capabilities correctly', () => {
expect(config.get('cody.advanced.agent.capabilities.storage')).toBe(true)
expect(config.get('cody.advanced.hasNativeWebview')).toBe(true)
expect(config.get('cody.advanced.hasNativeWebview')).toBe(false)
})

it('returns default value for unknown sections', () => {
Expand Down Expand Up @@ -236,7 +242,11 @@ describe('AgentWorkspaceConfiguration', () => {

it('updates nested configuration object', async () => {
await config.update('cody.debug', { verbose: false, newSetting: true })
expect(config.get('cody.debug')).toEqual({ verbose: false, newSetting: true })
expect(config.get('cody.debug')).toEqual({
verbose: false,
newSetting: true,
additional: true,
})
expect(config.get('cody.debug.newSetting')).toEqual(true)
})

Expand Down
21 changes: 14 additions & 7 deletions agent/src/AgentWorkspaceConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,26 @@ export class AgentWorkspaceConfiguration implements vscode.WorkspaceConfiguratio
},
}

function mergeWithBaseConfig(config: any) {
for (const [key, value] of Object.entries(config)) {
if (typeof value === 'object') {
const existing = _.get(baseConfig, key) ?? {}
const merged = _.merge(existing, value)
_.set(baseConfig, key, merged)
} else {
_.set(baseConfig, key, value)
}
}
}

const customConfiguration = config?.customConfiguration
if (customConfiguration) {
for (const [key, value] of Object.entries(customConfiguration)) {
_.set(baseConfig, key, value)
}
mergeWithBaseConfig(customConfiguration)
}

const fromCustomConfigurationJson = config?.customConfigurationJson
if (fromCustomConfigurationJson) {
const configJson = JSON.parse(fromCustomConfigurationJson)
for (const [key, value] of Object.entries(configJson)) {
_.set(baseConfig, key, value)
}
mergeWithBaseConfig(JSON.parse(fromCustomConfigurationJson))
}

const fromBaseConfig = _.get(baseConfig, section)
Expand Down
Loading