feat: expose plugin settings UI API

This commit is contained in:
2026-06-29 04:23:06 +08:00
parent 4387c6ab19
commit 380f90c5ec
9 changed files with 48 additions and 4 deletions
+15
View File
@@ -14,6 +14,7 @@ describe('VerstakPluginAPI contract', () => {
expect(typeof api.settings.write).toBe('function');
expect(typeof api.storage.data.read).toBe('function');
expect(typeof api.storage.data.write).toBe('function');
expect(typeof api.ui.openSettings).toBe('function');
expect(typeof api.capabilities.list).toBe('function');
expect(typeof api.commands.register).toBe('function');
expect(typeof api.commands.execute).toBe('function');
@@ -211,6 +212,20 @@ describe('VerstakPluginAPI contract', () => {
await expect(api.storage.data.read('missing')).resolves.toEqual({});
});
test('ui openSettings publishes the requested settings target in the mock API namespace', async () => {
const api = createMockPluginAPI('ui.plugin');
const received: unknown[] = [];
const unsubscribe = await api.events.subscribe('ui.openSettings', (event) => {
received.push(event.payload);
});
await api.ui.openSettings('ui.plugin.settings');
expect(received).toEqual([{ pluginId: 'ui.plugin', panelId: 'ui.plugin.settings' }]);
unsubscribe();
});
test('commands register, execute, and unregister', async () => {
const api = createMockPluginAPI('cmd.plugin');
+4
View File
@@ -104,6 +104,10 @@ export interface VerstakPluginAPI {
};
};
ui: {
openSettings(panelId?: string): Promise<void>;
};
capabilities: {
has(capability: string): Promise<boolean>;
get(capability: string): Promise<{ available: boolean; name?: string; pluginId?: string; status?: string }>;
+11
View File
@@ -138,6 +138,17 @@ export function createMockPluginAPI(pluginId = 'test.plugin', options: MockPlugi
}),
},
},
ui: {
openSettings: vi.fn(async (panelId?: string) => {
const event = {
name: 'ui.openSettings',
pluginId,
payload: { pluginId, panelId: panelId || '' },
timestamp: new Date().toISOString(),
};
(eventHandlers.get('ui.openSettings') || []).slice().forEach((handler) => handler(event));
}),
},
capabilities: {
has: vi.fn(async () => false),
get: vi.fn(async (name: string) => ({ available: false, name })),