From 0cf10d1709eada035f3604a465a74c7b4d7d794d Mon Sep 17 00:00:00 2001 From: Douwe Osinga Date: Tue, 30 Sep 2025 16:46:13 -0400 Subject: [PATCH] Some testing --- .../settings/extensions/ExtensionsSection.tsx | 33 +++++++------------ .../settings/extensions/utils.test.ts | 31 ++--------------- .../components/settings/extensions/utils.ts | 11 ------- ui/desktop/src/recipe/validation.test.ts | 4 ++- ui/desktop/src/utils/providerUtils.ts | 4 +-- 5 files changed, 19 insertions(+), 64 deletions(-) diff --git a/ui/desktop/src/components/settings/extensions/ExtensionsSection.tsx b/ui/desktop/src/components/settings/extensions/ExtensionsSection.tsx index c51a46b7cf..a61d84a197 100644 --- a/ui/desktop/src/components/settings/extensions/ExtensionsSection.tsx +++ b/ui/desktop/src/components/settings/extensions/ExtensionsSection.tsx @@ -9,7 +9,6 @@ import { createExtensionConfig, ExtensionFormData, extensionToFormData, - extractExtensionConfig, getDefaultFormData, } from './utils'; @@ -82,33 +81,25 @@ export default function ExtensionsSection({ await getExtensions(true); // Force refresh - this will update the context }, [getExtensions]); - const handleExtensionToggle = async (extension: FixedExtensionEntry) => { + const handleExtensionToggle = async (extensionConfig: FixedExtensionEntry) => { if (customToggle) { - await customToggle(extension); + await customToggle(extensionConfig); return true; } // If extension is enabled, we are trying to toggle if off, otherwise on - const toggleDirection = extension.enabled ? 'toggleOff' : 'toggleOn'; - const extensionConfig = extractExtensionConfig(extension); + const toggleDirection = extensionConfig.enabled ? 'toggleOff' : 'toggleOn'; - // eslint-disable-next-line no-useless-catch - try { - await toggleExtension({ - toggle: toggleDirection, - extensionConfig: extensionConfig, - addToConfig: addExtension, - toastOptions: { silent: false }, - sessionId: sessionId, - }); + await toggleExtension({ + toggle: toggleDirection, + extensionConfig: extensionConfig, + addToConfig: addExtension, + toastOptions: { silent: false }, + sessionId: sessionId, + }); - await fetchExtensions(); // Refresh the list after successful toggle - return true; // Indicate success - } catch (error) { - // Don't refresh the extension list on failure - this allows our visual state rollback to work - // The actual state in the config hasn't changed anyway - throw error; // Re-throw to let the ExtensionItem component know it failed - } + await fetchExtensions(); + return true; }; const handleConfigureClick = (extension: FixedExtensionEntry) => { diff --git a/ui/desktop/src/components/settings/extensions/utils.test.ts b/ui/desktop/src/components/settings/extensions/utils.test.ts index 6b16b43f76..dce8ea94ce 100644 --- a/ui/desktop/src/components/settings/extensions/utils.test.ts +++ b/ui/desktop/src/components/settings/extensions/utils.test.ts @@ -6,7 +6,6 @@ import { createExtensionConfig, splitCmdAndArgs, combineCmdAndArgs, - extractExtensionConfig, replaceWithShims, removeShims, extractCommand, @@ -185,7 +184,7 @@ describe('Extension Utils', () => { expect(formData).toEqual({ name: 'developer', - description: '', + description: 'developer', type: 'builtin', cmd: undefined, endpoint: undefined, @@ -286,7 +285,7 @@ describe('Extension Utils', () => { it('should create builtin extension config', () => { const formData = { name: 'developer', - description: '', + description: 'developer', type: 'builtin' as const, cmd: '', endpoint: '', @@ -301,6 +300,7 @@ describe('Extension Utils', () => { expect(config).toEqual({ type: 'builtin', name: 'developer', + description: 'developer', timeout: 300, }); }); @@ -342,31 +342,6 @@ describe('Extension Utils', () => { }); }); - describe('extractExtensionConfig', () => { - it('should extract extension config from fixed entry', () => { - const fixedEntry: FixedExtensionEntry = { - type: 'stdio', - name: 'test-extension', - description: 'test-extension', - cmd: 'python', - args: ['script.py'], - enabled: true, - timeout: 300, - }; - - const config = extractExtensionConfig(fixedEntry); - - expect(config).toEqual({ - type: 'stdio', - name: 'test-extension', - cmd: 'python', - args: ['script.py'], - enabled: true, - timeout: 300, - }); - }); - }); - describe('replaceWithShims', () => { beforeEach(() => { mockElectron.getBinaryPath.mockImplementation((binary: string) => { diff --git a/ui/desktop/src/components/settings/extensions/utils.ts b/ui/desktop/src/components/settings/extensions/utils.ts index 7feb0dd469..66d335768a 100644 --- a/ui/desktop/src/components/settings/extensions/utils.ts +++ b/ui/desktop/src/components/settings/extensions/utils.ts @@ -186,17 +186,6 @@ export function combineCmdAndArgs(cmd: string, args: string[]): string { return [cmd, ...args].join(' '); } -/** - * Extracts the ExtensionConfig from a FixedExtensionEntry object - * @param fixedEntry - The FixedExtensionEntry object - * @returns The ExtensionConfig portion of the object - */ -export function extractExtensionConfig(fixedEntry: FixedExtensionEntry): ExtensionConfig { - // todo: enabled not used? - const { ...extensionConfig } = fixedEntry; - return extensionConfig; -} - export async function replaceWithShims(cmd: string) { const binaryPathMap: Record = { goosed: await window.electron.getBinaryPath('goosed'), diff --git a/ui/desktop/src/recipe/validation.test.ts b/ui/desktop/src/recipe/validation.test.ts index 39b6334655..c50a7886c1 100644 --- a/ui/desktop/src/recipe/validation.test.ts +++ b/ui/desktop/src/recipe/validation.test.ts @@ -184,9 +184,9 @@ describe('Recipe Validation', () => { ...validRecipe, extensions: [ { - // Only required fields for builtin extension type: 'builtin', name: 'developer', + description: 'description', }, ], }; @@ -554,10 +554,12 @@ describe('Recipe Validation', () => { { type: 'builtin', name: 'developer', + description: 'developer', }, { type: 'builtin', name: 'computercontroller', + description: 'computercontroller', }, ], }; diff --git a/ui/desktop/src/utils/providerUtils.ts b/ui/desktop/src/utils/providerUtils.ts index 4ded559a00..8f6a8f1547 100644 --- a/ui/desktop/src/utils/providerUtils.ts +++ b/ui/desktop/src/utils/providerUtils.ts @@ -3,7 +3,6 @@ import { syncBundledExtensions, addToAgentOnStartup, } from '../components/settings/extensions'; -import { extractExtensionConfig } from '../components/settings/extensions/utils'; import type { ExtensionConfig, FixedExtensionEntry } from '../components/ConfigContext'; import { addSubRecipesToAgent } from '../recipe/add_sub_recipe_on_agent'; import { @@ -272,8 +271,7 @@ export const initializeSystem = async ( options?.setIsExtensionsLoading?.(true); - const extensionLoadingPromises = enabledExtensions.map(async (extensionEntry) => { - const extensionConfig = extractExtensionConfig(extensionEntry); + const extensionLoadingPromises = enabledExtensions.map(async (extensionConfig) => { const extensionName = extensionConfig.name; try {