import { afterEach, describe, expect, it, vi } from 'vitest'; import { startAvailableAgcPlugin } from '../src/services/pluginHost'; afterEach(() => vi.unstubAllGlobals()); describe('插件自动启动使用后端能力投影', () => { it.each( [ [], [ { id: 'agc-cocos-editor', enabled: false, hasRuntime: true, status: 'stopped', }, ], [ { id: 'agc-cocos-editor', enabled: true, hasRuntime: false, status: 'package', }, ], [ { id: 'agc-cocos-editor', enabled: true, hasRuntime: true, status: 'invalid', }, ], ].map((plugins) => ({ plugins })), )('隐藏、禁用或不可执行的插件不启动(%j)', async ({ plugins }) => { const invoke = vi.fn(async () => plugins); vi.stubGlobal('window', { __TAURI__: { core: { invoke } } }); await startAvailableAgcPlugin('agc-cocos-editor'); expect(invoke).toHaveBeenCalledTimes(1); expect(invoke).toHaveBeenCalledWith('list_agc_plugins'); }); it('支持的 Cocos 插件继续按原入口启动', async () => { const invoke = vi.fn(async (command: string) => command === 'list_agc_plugins' ? [ { id: 'agc-cocos-editor', enabled: true, hasRuntime: true, status: 'stopped', }, ] : {}, ); vi.stubGlobal('window', { __TAURI__: { core: { invoke } } }); await startAvailableAgcPlugin('agc-cocos-editor'); expect(invoke).toHaveBeenLastCalledWith('start_agc_plugin', { id: 'agc-cocos-editor', }); }); });