54d0fb75ea
新增 GDExtension 自动引导、GDScript 执行和实例隔离缓存 接入 AGC 插件开关、Runner、Agent 工具与权限审计 完善执行回执确认、不确定状态阻断及卸载恢复 补齐 Windows 分发资源、定向测试与实机验收文档
92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import {
|
|
setAgcPluginProjectPath,
|
|
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.each(['agc-cocos-editor', 'agc-unity-editor', 'agc-godot-editor'])(
|
|
'支持的编辑器插件按原入口启动:%s',
|
|
async (pluginId) => {
|
|
const invoke = vi.fn(async (command: string) =>
|
|
command === 'list_agc_plugins'
|
|
? [
|
|
{
|
|
id: pluginId,
|
|
enabled: true,
|
|
hasRuntime: true,
|
|
status: 'stopped',
|
|
},
|
|
]
|
|
: {},
|
|
);
|
|
vi.stubGlobal('window', { __TAURI__: { core: { invoke } } });
|
|
await startAvailableAgcPlugin(pluginId);
|
|
expect(invoke).toHaveBeenLastCalledWith('start_agc_plugin', {
|
|
id: pluginId,
|
|
});
|
|
},
|
|
);
|
|
|
|
it('快速切换项目时旧 cleanup 不能晚于新项目设置抵达宿主', async () => {
|
|
const received: Array<string | null> = [];
|
|
let finishFirst: () => void = () => undefined;
|
|
const invoke = vi.fn(
|
|
async (_command: string, params: { projectPath: string | null }) => {
|
|
if (params.projectPath === 'C:/A')
|
|
await new Promise<void>((resolve) => {
|
|
finishFirst = resolve;
|
|
});
|
|
received.push(params.projectPath);
|
|
},
|
|
);
|
|
vi.stubGlobal('window', { __TAURI__: { core: { invoke } } });
|
|
const first = setAgcPluginProjectPath('C:/A');
|
|
const cleanup = setAgcPluginProjectPath(null);
|
|
const second = setAgcPluginProjectPath('C:/B');
|
|
await vi.waitFor(() => expect(invoke).toHaveBeenCalledTimes(1));
|
|
finishFirst();
|
|
await Promise.all([first, cleanup, second]);
|
|
expect(received).toEqual(['C:/A', null, 'C:/B']);
|
|
});
|
|
});
|