Skip to content
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
Original file line number Diff line number Diff line change
@@ -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 {
Comment thread
jdneo marked this conversation as resolved.

@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> copilotUi = Mockito.mockStatic(CopilotUi.class);
MockedStatic<CopilotCore> 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> copilotUi = Mockito.mockStatic(CopilotUi.class)) {
copilotUi.when(CopilotUi::getPlugin).thenReturn(uiPlugin);

assertFalse(PreferencesUtils.isSkillsEnabled());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Loading