Some testing

This commit is contained in:
Douwe Osinga
2025-09-30 16:46:13 -04:00
parent 890321b398
commit 0cf10d1709
5 changed files with 19 additions and 64 deletions
@@ -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) => {
@@ -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) => {
@@ -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<string, string> = {
goosed: await window.electron.getBinaryPath('goosed'),
+3 -1
View File
@@ -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',
},
],
};
+1 -3
View File
@@ -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 {