Files
Genarrative/apps/ai-game-creator-shell/tests/designWorkspaceDebug.test.tsx
T
k88936 25c5ecdf6e
Project CI / AI game creator shell Rust crates (pull_request) Successful in 2m58s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 6m34s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 5m29s
Project CI / Backend tests (pull_request) Failing after 4m38s
Project CI / Frontend tests (pull_request) Successful in 3m33s
Project CI / Repository checks (pull_request) Failing after 4m4s
Project CI / AI game creator shell web tests (pull_request) Successful in 3m13s
Project CI / Native shell tests (pull_request) Successful in 6m35s
测试:全仓测试统一 Tauri 运行时替身安装点
- 78 处内联 window.__TAURI__ 赋值改为 installTauriRuntime,覆盖 appSurface 之外的 37 个测试文件
- 31 处 delete window.__TAURI__ / window.__TAURI__ = undefined 复位改为 resetTauriRuntime
- 删除 recentProjectsHook、projectCreationDirectory、projectResourceLiveIntegration、useProjectResourceCardPreviews、resourceVersionReplacementModel、unityProjectOpen 里的本地 asTauriInvoke / asTauriListen 适配器与相关类型别名
- designProjectRestore 的 setup 参数由 ReturnType<typeof vi.fn> 收窄为具体 invoke 签名
- 迁移后仅 tests/tauriRuntimeFake.ts 直接读写 window.__TAURI__
2026-10-03 20:19:45 +08:00

121 lines
3.7 KiB
TypeScript

// @vitest-environment jsdom
import {
act,
cleanup,
fireEvent,
render,
screen,
waitFor,
within,
} from '@testing-library/react';
import React from 'react';
import { afterEach, expect, it, vi } from 'vitest';
import { DesignWorkspacePanel } from '../src/features/project-workspace/DesignWorkspacePanel';
import { installTauriRuntime, resetTauriRuntime } from './tauriRuntimeFake';
vi.mock('../src/components/ChatMarkdownMessage', () => ({
ChatMarkdownMessage: () => null,
}));
afterEach(() => {
cleanup();
vi.unstubAllEnvs();
resetTauriRuntime();
});
it('shows imported references after a workspace event without reloading the design session', async () => {
let imported = false;
let onUpdate:
| ((event: { payload: { projectPath: string; kind: string } }) => void)
| undefined;
const invoke = vi.fn(async (command: string) => {
if (command === 'is_design_agent_debug_enabled') return false;
if (command === 'hydrate_design_agent_session') return null;
if (command === 'list_design_workspace')
return imported
? [
{ path: 'references', kind: 'directory' },
{ path: 'references/需求.md', kind: 'file' },
]
: [];
if (command === 'read_design_workspace_file') return '# 导入的需求';
throw new Error(`Unexpected command: ${command}`);
});
installTauriRuntime({
core: { invoke },
event: {
listen: vi.fn(async (_name, callback) => {
onUpdate = callback;
return () => undefined;
}),
},
});
render(<DesignWorkspacePanel projectPath="imported-project" />);
await waitFor(() => expect(onUpdate).toBeDefined());
await waitFor(() =>
expect(invoke).toHaveBeenCalledWith('list_design_workspace', {
projectPath: 'imported-project',
}),
);
imported = true;
act(() =>
onUpdate!({
payload: { projectPath: 'imported-project', kind: 'workspace' },
}),
);
fireEvent.click(await screen.findByRole('button', { name: '需求.md' }));
await waitFor(() =>
expect(invoke).toHaveBeenCalledWith('read_design_workspace_file', {
projectPath: 'imported-project',
path: 'references/需求.md',
}),
);
expect(
invoke.mock.calls.filter(
([command]) => command === 'hydrate_design_agent_session',
),
).toHaveLength(1);
});
it('prepares debug fixtures from the header and refreshes the phase and files without a manual refresh', async () => {
let prepared = false;
const invoke = vi.fn(async (command: string) => {
if (command === 'is_design_agent_debug_enabled') {
return true;
}
if (command === 'debug_fast_forward_design_session') {
prepared = true;
return { activeRuntime: 'design' };
}
if (command === 'hydrate_design_agent_session') {
return { session: { currentPhase: prepared ? 'consultant' : 'concept' } };
}
if (command === 'list_design_workspace') {
return prepared ? [{ path: 'debug.md', kind: 'file', size: 10 }] : [];
}
throw new Error(`Unexpected command: ${command}`);
});
installTauriRuntime({ core: { invoke } });
render(<DesignWorkspacePanel projectPath="test-project" />);
await waitFor(() =>
expect(
screen
.getByRole('button', { name: '刷新策划工作区' })
.hasAttribute('disabled'),
).toBe(false),
);
const header = screen
.getByRole('heading', { name: '概念设计' })
.closest('header')!;
fireEvent.click(
within(header).getByRole('button', { name: '快速准备做成游戏测试' }),
);
await screen.findByRole('heading', { name: '顾问' });
await screen.findByRole('button', { name: 'debug.md' });
expect(invoke).toHaveBeenCalledWith('debug_fast_forward_design_session', {
projectPath: 'test-project',
targetPhase: 'consultant',
});
});