Files
Genarrative/apps/ai-game-creator-shell/tests/designProjectRestore.test.tsx
T
lhk229 832f1e8b59
Project CI / Repository checks (pull_request) Successful in 2m17s
Project CI / Frontend tests (pull_request) Successful in 3m8s
Project CI / Backend tests (pull_request) Successful in 7m46s
Project CI / Native shell tests (pull_request) Successful in 19m52s
修复策划项目重开运行态恢复
持久化策划项目 design 运行模式并在重开时恢复 design/game 工作台。

补充旧策划会话兼容判断、前端夹具和恢复回归测试。
2026-09-12 06:41:49 +00:00

83 lines
2.9 KiB
TypeScript

// @vitest-environment jsdom
import { act, cleanup, renderHook } from '@testing-library/react';
import { afterEach, expect, it, vi } from 'vitest';
import { createGameCreationAppManifest } from '../../../packages/shared/src/contracts/gameCreationApp';
import { useHomeProjectCreation } from '../src/features/app-shell/useHomeProjectCreation';
afterEach(() => {
cleanup();
delete window.__TAURI__;
});
const projectPath = 'C:/test/design-project';
const manifest = createGameCreationAppManifest('test-project', '策划项目');
function setup(invoke: ReturnType<typeof vi.fn>) {
window.__TAURI__ = { core: { invoke } } as unknown as typeof window.__TAURI__;
return renderHook(() =>
useHomeProjectCreation({
setStatus: vi.fn(),
setLauncherView: vi.fn(),
setAgentChatProjectPath: vi.fn(),
rememberRecentWorkspace: vi.fn(),
}),
);
}
it.each(['design', 'game', null] as const)(
'restores %s before publishing the project context',
async (mode) => {
let resolveMode!: (value: { activeRuntime: string } | null) => void;
const modePromise = new Promise<{ activeRuntime: string } | null>(
(resolve) => {
resolveMode = resolve;
},
);
const invoke = vi.fn(async (command: string) => {
if (command === 'inspect_local_project_directory')
return { exists: true, isDirectory: true, isGameCreatorProject: true };
if (command === 'get_local_game_manifest') return manifest;
if (command === 'get_local_game_project_revision') return { revision: 1 };
if (command === 'get_design_agent_runtime_mode') return modePromise;
throw new Error(command);
});
const { result } = setup(invoke);
let opening!: Promise<void>;
await act(async () => {
opening = result.current.openProject(projectPath, 'open');
});
expect(result.current.currentProjectContext).toBeNull();
await act(async () => {
resolveMode(mode ? { activeRuntime: mode } : null);
await opening;
});
expect(result.current.currentProjectContext?.startMode).toBe(
mode === 'design' ? 'planning' : null,
);
},
);
it('persists design mode before entering a newly created planning project', async () => {
const invoke = vi.fn(async (command: string) => {
if (command === 'create_automatic_local_game_project')
return { projectPath, manifest };
if (command === 'set_design_agent_runtime_mode')
return { activeRuntime: 'design' };
if (command === 'get_local_game_project_revision') return { revision: 1 };
throw new Error(command);
});
const { result } = setup(invoke);
await act(async () => {
await result.current.createHomeDraftAutomatically(
{ creationType: 'game', prompt: '测试', attachments: [] },
'planning',
);
});
expect(invoke).toHaveBeenCalledWith('set_design_agent_runtime_mode', {
projectPath,
activeRuntime: 'design',
});
expect(result.current.currentProjectContext?.startMode).toBe('planning');
});