Skip to content

Commit 9477316

Browse files
fix - Should not initialize empty mcp_tools_status (#1058)
1 parent 0a4fd01 commit 9477316

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/preferences/LanguageServerSettingManagerTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.microsoft.copilot.eclipse.ui.preferences;
22

3+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
34
import static org.junit.jupiter.api.Assertions.assertEquals;
45
import static org.junit.jupiter.api.Assertions.assertFalse;
56
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -216,4 +217,22 @@ void testUpdateStrictSslSetting() {
216217
assertFalse(capturedSettings.getHttp().isProxyStrictSsl());
217218
}
218219

220+
@Test
221+
void testInitializeMcpToolsStatusWhenEmpty() {
222+
// arrange
223+
when(mockPreferenceStore.getBoolean(Constants.AUTO_SHOW_COMPLETION)).thenReturn(true);
224+
when(mockPreferenceStore.getString(Constants.PROXY_KERBEROS_SP)).thenReturn(null);
225+
when(mockPreferenceStore.getString(Constants.GITHUB_ENTERPRISE)).thenReturn(null);
226+
when(mockPreferenceStore.getString(Constants.MCP)).thenReturn(null);
227+
when(mockPreferenceStore.getString(Constants.MCP_TOOLS_STATUS)).thenReturn("");
228+
229+
// act
230+
LanguageServerSettingManager manager = new LanguageServerSettingManager(mockLsConnection, mockProxyService,
231+
mockPreferenceStore);
232+
assertDoesNotThrow(manager::initializeMcpToolsStatus);
233+
234+
// assert
235+
verify(mockPreferenceStore, times(1)).getString(Constants.MCP_TOOLS_STATUS);
236+
verify(mockLsConnection, times(0)).updateMcpToolsStatus(any());
237+
}
219238
}

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/CopilotPreferenceInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void initializeDefaultPreferences() {
4343
}
4444
}
4545
""");
46-
pref.setDefault(Constants.MCP_TOOLS_STATUS, "");
46+
pref.setDefault(Constants.MCP_TOOLS_STATUS, "{}");
4747
pref.setDefault(Constants.QUICK_START_VERSION, 0);
4848
}
4949
}

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/LanguageServerSettingManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.google.gson.Gson;
99
import com.google.gson.reflect.TypeToken;
10+
import org.apache.commons.lang3.StringUtils;
1011
import org.eclipse.core.net.proxy.IProxyChangeEvent;
1112
import org.eclipse.core.net.proxy.IProxyChangeListener;
1213
import org.eclipse.core.net.proxy.IProxyData;
@@ -179,6 +180,10 @@ public void initializeMcpToolsStatus() {
179180
* {"server1":{"tool1":true,"tool2":false},"server2":{"tool1":true}}
180181
*/
181182
private void updateMcpToolsStatus(String mcpToolsStatus) {
183+
if (StringUtils.isBlank(mcpToolsStatus)) {
184+
return;
185+
}
186+
182187
try {
183188
Gson gson = new Gson();
184189
Map<String, Map<String, Boolean>> toolStatusMap = gson.fromJson(mcpToolsStatus,

0 commit comments

Comments
 (0)