diff --git a/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/utils/SkillsPreferencesUtilsTest.java b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/utils/SkillsPreferencesUtilsTest.java new file mode 100644 index 00000000..87898243 --- /dev/null +++ b/com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/utils/SkillsPreferencesUtilsTest.java @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +package com.microsoft.copilot.eclipse.ui.utils; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; +import org.mockito.Mockito; + +import com.microsoft.copilot.eclipse.core.Constants; +import com.microsoft.copilot.eclipse.core.CopilotCore; +import com.microsoft.copilot.eclipse.core.FeatureFlags; +import com.microsoft.copilot.eclipse.ui.CopilotUi; + +class SkillsPreferencesUtilsTest { + + @Test + void testIsSkillsEnabled_previewDisabledAndPreferenceEnabled_returnsTrue() { + IPreferenceStore preferenceStore = mock(IPreferenceStore.class); + CopilotUi uiPlugin = mock(CopilotUi.class); + // Keep preview disabled to prevent it from becoming a Skills prerequisite again. + CopilotCore corePlugin = mock(CopilotCore.class); + FeatureFlags featureFlags = mock(FeatureFlags.class); + when(uiPlugin.getPreferenceStore()).thenReturn(preferenceStore); + when(preferenceStore.getBoolean(Constants.ENABLE_SKILLS)).thenReturn(true); + when(corePlugin.getFeatureFlags()).thenReturn(featureFlags); + when(featureFlags.isClientPreviewFeatureEnabled()).thenReturn(false); + + try (MockedStatic copilotUi = Mockito.mockStatic(CopilotUi.class); + MockedStatic copilotCore = Mockito.mockStatic(CopilotCore.class)) { + copilotUi.when(CopilotUi::getPlugin).thenReturn(uiPlugin); + copilotCore.when(CopilotCore::getPlugin).thenReturn(corePlugin); + + assertTrue(PreferencesUtils.isSkillsEnabled()); + } + } + + @Test + void testIsSkillsEnabled_preferenceDisabled_returnsFalse() { + IPreferenceStore preferenceStore = mock(IPreferenceStore.class); + CopilotUi uiPlugin = mock(CopilotUi.class); + when(uiPlugin.getPreferenceStore()).thenReturn(preferenceStore); + when(preferenceStore.getBoolean(Constants.ENABLE_SKILLS)).thenReturn(false); + + try (MockedStatic copilotUi = Mockito.mockStatic(CopilotUi.class)) { + copilotUi.when(CopilotUi::getPlugin).thenReturn(uiPlugin); + + assertFalse(PreferencesUtils.isSkillsEnabled()); + } + } +} diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/ChatPreferencesPage.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/ChatPreferencesPage.java index 0b0ce6ff..bff5641f 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/ChatPreferencesPage.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/preferences/ChatPreferencesPage.java @@ -21,7 +21,6 @@ import com.microsoft.copilot.eclipse.core.Constants; import com.microsoft.copilot.eclipse.core.CopilotCore; -import com.microsoft.copilot.eclipse.core.FeatureFlags; import com.microsoft.copilot.eclipse.ui.CopilotUi; /** @@ -54,18 +53,14 @@ public void createFieldEditors() { addNote(parent, Messages.preferences_page_watched_files_note_content); addSeparator(parent); - if (isClientPreviewFeatureEnabled()) { - // Add Enable Skills toggle - Composite skillsComposite = createSectionComposite(parent, gdf); + Composite skillsComposite = createSectionComposite(parent, gdf); + BooleanFieldEditor skillsField = new BooleanFieldEditor(Constants.ENABLE_SKILLS, + Messages.preferences_page_skills_enabled, SWT.WRAP, skillsComposite); + applyFieldWidthHint(skillsField, skillsComposite); + addField(skillsField); - BooleanFieldEditor skillsField = new BooleanFieldEditor(Constants.ENABLE_SKILLS, - Messages.preferences_page_skills_enabled, SWT.WRAP, skillsComposite); - applyFieldWidthHint(skillsField, skillsComposite); - addField(skillsField); - - addNote(parent, Messages.preferences_page_skills_enabled_note_content); - addSeparator(parent); - } + addNote(parent, Messages.preferences_page_skills_enabled_note_content); + addSeparator(parent); // Add Agent Max Requests field Composite agentMaxRequestsComposite = createSectionComposite(parent, gdf); @@ -138,9 +133,4 @@ private void addSeparator(Composite parent) { gridData.horizontalSpan = 2; separator.setLayoutData(gridData); } - - private boolean isClientPreviewFeatureEnabled() { - FeatureFlags flags = CopilotCore.getPlugin().getFeatureFlags(); - return flags != null && flags.isClientPreviewFeatureEnabled(); - } } \ No newline at end of file diff --git a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/utils/PreferencesUtils.java b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/utils/PreferencesUtils.java index 20f0285d..587cca39 100644 --- a/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/utils/PreferencesUtils.java +++ b/com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/utils/PreferencesUtils.java @@ -9,7 +9,6 @@ import com.microsoft.copilot.eclipse.core.Constants; import com.microsoft.copilot.eclipse.core.CopilotCore; -import com.microsoft.copilot.eclipse.core.FeatureFlags; import com.microsoft.copilot.eclipse.core.chat.CustomInstructionsChatLoadScope; import com.microsoft.copilot.eclipse.ui.CopilotUi; import com.microsoft.copilot.eclipse.ui.preferences.AutoApprovePreferencePage; @@ -38,16 +37,12 @@ public static String[] getAllPreferenceIds() { } /** - * Returns whether the skills feature is enabled. Skills require both the user preference - * {@link Constants#ENABLE_SKILLS} to be set and the client preview feature flag to be enabled. + * Returns whether the skills feature is enabled. * * @return {@code true} if skills are enabled, {@code false} otherwise */ public static boolean isSkillsEnabled() { - CopilotCore plugin = CopilotCore.getPlugin(); - FeatureFlags flags = plugin != null ? plugin.getFeatureFlags() : null; - return CopilotUi.getPlugin().getPreferenceStore().getBoolean(Constants.ENABLE_SKILLS) - && flags != null && flags.isClientPreviewFeatureEnabled(); + return CopilotUi.getPlugin().getPreferenceStore().getBoolean(Constants.ENABLE_SKILLS); } /**