4a46f89c9b
客户端新增随包提供的插件宿主和 Cocos Creator 集成:识别并导入 Cocos 项目,通过内置桥接操作已打开的编辑器,无需安装项目 MCP 扩展。DirectProject 现在公开 36 个独立 cocos_* 工具,保留通用 JavaScript 执行入口。 - 通用插件 SDK、命令/能力/面板注册、编辑器适配器和跨进程内置插件开关。 - Cocos 场景、节点、组件、Prefab、UI、Layout/Widget、资源、保存、撤销、日志与预览调试;目录和实现由 JS/native 共用。 - 编辑事务回读、失败回滚、后续手动修改保护及不确定结果禁止重放;预览截图通过 MCP image 返回。 - DirectProject 跳过无关专业 Agent 历史,将项目打开和历史读取中的同步 I/O 移出窗口线程,消除 Cocos 执行与项目文件锁的错误耦合。 验证: - 合并 master 后:类型/配置检查、编码检查、Rust 格式检查和提交钩子通过。 - 合并 master 后:Cocos 项目打开、插件面板和开发启动定向测试 10 通过、2 跳过;DirectProject MCP 测试 17 通过、1 项真实 Creator opt-in 忽略;插件宿主测试 9/9。 - 插件行为测试 17/17;native 测试 20/20,4 项 opt-in 测试默认忽略。 - 真实 Creator 3.8.8 的 36/36 操作 smoke,以及客户端 MCP tools/list、tools/call、UI/撤销和预览截图,在功能实现阶段已验证通过;本次 master 合并后未重复真实 GUI smoke。 验证边界:发行安装包和远端 CI 尚未验收。 Reviewed-on: #338 Co-authored-by: kdletters <kdletters@qq.com> Co-committed-by: kdletters <kdletters@qq.com>
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { act, renderHook } from '@testing-library/react';
|
|
import { afterEach, expect, test, vi } from 'vitest';
|
|
|
|
import { createGameCreationAppManifest } from '../../../packages/shared/src/contracts/gameCreationApp';
|
|
import { useHomeProjectCreation } from '../src/features/app-shell/useHomeProjectCreation';
|
|
|
|
afterEach(() => {
|
|
delete window.__TAURI__;
|
|
});
|
|
|
|
test('打开 Cocos 目录走导入入口,不创建 Web 脚手架或发送初始消息', async () => {
|
|
const manifest = {
|
|
...createGameCreationAppManifest('cocos-project', 'Cocos 项目'),
|
|
cocosProjectRoot: '.',
|
|
};
|
|
const invoke = vi.fn(async (command: string) => {
|
|
if (command === 'inspect_local_project_directory') {
|
|
return {
|
|
exists: true,
|
|
isDirectory: true,
|
|
isGameCreatorProject: false,
|
|
isGodotProject: false,
|
|
godotProjectRoot: null,
|
|
isCocosProject: true,
|
|
cocosProjectRoot: '.',
|
|
projectName: 'Cocos 项目',
|
|
recentRunStatus: null,
|
|
recentRunStopReason: null,
|
|
};
|
|
}
|
|
if (command === 'import_local_cocos_project') {
|
|
return { projectPath: 'C:/projects/cocos', manifest };
|
|
}
|
|
if (command === 'get_local_game_project_revision') return { revision: 0 };
|
|
if (command === 'get_design_agent_runtime_mode') {
|
|
return { activeRuntime: 'game' };
|
|
}
|
|
throw new Error(`意外调用:${command}`);
|
|
});
|
|
window.__TAURI__ = { core: { invoke } };
|
|
const setLauncherView = vi.fn();
|
|
const { result } = renderHook(() =>
|
|
useHomeProjectCreation({
|
|
setStatus: vi.fn(),
|
|
setLauncherView,
|
|
setAgentChatProjectPath: vi.fn(),
|
|
rememberRecentWorkspace: vi.fn(),
|
|
}),
|
|
);
|
|
|
|
await act(() => result.current.openProject('C:/projects/cocos', 'open'));
|
|
|
|
expect(invoke).toHaveBeenCalledWith('import_local_cocos_project', {
|
|
projectPath: 'C:/projects/cocos',
|
|
projectId: expect.any(String),
|
|
name: 'cocos',
|
|
});
|
|
expect(result.current.currentProjectContext).toMatchObject({
|
|
projectKind: 'cocos',
|
|
projectPath: 'C:/projects/cocos',
|
|
initialPrompt: '',
|
|
startMode: null,
|
|
manifest,
|
|
});
|
|
expect(setLauncherView).toHaveBeenCalledWith('project-development');
|
|
expect(invoke).toHaveBeenCalledWith('get_design_agent_runtime_mode', {
|
|
projectPath: 'C:/projects/cocos',
|
|
});
|
|
expect(
|
|
invoke.mock.calls.some(
|
|
([command]) => command === 'init_local_game_project',
|
|
),
|
|
).toBe(false);
|
|
});
|