|
| 1 | +package com.microsoft.copilot.eclipse.core.chat.service; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 5 | +import static org.mockito.ArgumentMatchers.any; |
| 6 | +import static org.mockito.Mockito.when; |
| 7 | + |
| 8 | +import java.lang.reflect.Field; |
| 9 | +import java.util.List; |
| 10 | +import java.util.concurrent.CompletableFuture; |
| 11 | + |
| 12 | +import org.junit.jupiter.api.BeforeEach; |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 15 | +import org.mockito.Mock; |
| 16 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 17 | + |
| 18 | +import com.microsoft.copilot.eclipse.core.CopilotCore; |
| 19 | +import com.microsoft.copilot.eclipse.core.chat.BuiltInChatMode; |
| 20 | +import com.microsoft.copilot.eclipse.core.lsp.CopilotLanguageServerConnection; |
| 21 | +import com.microsoft.copilot.eclipse.core.lsp.protocol.ConversationMode; |
| 22 | +import com.microsoft.copilot.eclipse.core.lsp.protocol.ConversationModesParams; |
| 23 | + |
| 24 | +@ExtendWith(MockitoExtension.class) |
| 25 | +class BuiltInChatModeServiceTests { |
| 26 | + |
| 27 | + @Mock |
| 28 | + private CopilotLanguageServerConnection mockConnection; |
| 29 | + |
| 30 | + private BuiltInChatModeService builtInChatModeService; |
| 31 | + |
| 32 | + @BeforeEach |
| 33 | + void setUp() throws Exception { |
| 34 | + builtInChatModeService = new BuiltInChatModeService(); |
| 35 | + |
| 36 | + CopilotCore plugin = new CopilotCore(); |
| 37 | + Field languageServerField = CopilotCore.class.getDeclaredField("copilotLanguageServer"); |
| 38 | + languageServerField.setAccessible(true); |
| 39 | + languageServerField.set(plugin, mockConnection); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void testLoadBuiltInModes_inlineAgentSkippedFromAgentModes() { |
| 44 | + ConversationMode agentMode = createBuiltInMode("Agent", "Agent", "Agent", |
| 45 | + "Advanced agent mode with access to tools and capabilities"); |
| 46 | + ConversationMode inlineAgentMode = createBuiltInMode("InlineAgent", "Agent", "InlineAgent", |
| 47 | + "Agent mode with a restricted tool set for inline editing"); |
| 48 | + |
| 49 | + when(mockConnection.listConversationModes(any(ConversationModesParams.class))) |
| 50 | + .thenReturn(CompletableFuture.completedFuture(new ConversationMode[] { agentMode, inlineAgentMode })); |
| 51 | + |
| 52 | + List<BuiltInChatMode> builtInModes = builtInChatModeService.loadBuiltInModes().join(); |
| 53 | + |
| 54 | + assertEquals(1, builtInModes.size()); |
| 55 | + |
| 56 | + BuiltInChatMode builtInMode = builtInModes.get(0); |
| 57 | + assertNotNull(builtInMode); |
| 58 | + assertEquals("Agent", builtInMode.getId()); |
| 59 | + assertEquals("Agent", builtInMode.getDisplayName()); |
| 60 | + assertEquals("Agent", builtInMode.getKind()); |
| 61 | + } |
| 62 | + |
| 63 | + private ConversationMode createBuiltInMode(String id, String name, String kind, String description) { |
| 64 | + ConversationMode mode = new ConversationMode(); |
| 65 | + mode.setId(id); |
| 66 | + mode.setName(name); |
| 67 | + mode.setKind(kind); |
| 68 | + mode.setBuiltIn(true); |
| 69 | + mode.setDescription(description); |
| 70 | + return mode; |
| 71 | + } |
| 72 | +} |
0 commit comments