Files
Genarrative/apps/ai-game-creator-shell/tests/homeWebPreflight.test.tsx
T
kdletters 1d6cbd4b67
Project CI / AI game creator shell Rust crates (push) Successful in 1m29s
Project CI / AI game creator shell Rust smoke (push) Successful in 1m57s
Project CI / Backend tests (push) Successful in 3m57s
Project CI / Frontend tests (push) Successful in 2m0s
Project CI / Native shell tests (push) Successful in 6m5s
Project CI / Repository checks (push) Failing after 42s
Project CI / AI game creator shell Rust lane 2/2 (push) Successful in 8m49s
Project CI / AI game creator shell Rust lane 1/2 (push) Successful in 8m54s
Project CI / AI game creator shell web tests (push) Successful in 1m40s
外壳状态栏退役,状态改由浮层提示承载
- 首页输入框下方与项目组页面头部那行状态栏退役:status 不再由页面渲染,统一由外壳浮层承载(WorkspaceLauncher 合成粘性状态与一次性提示,渲染 notice ?? statusNotice)
- 进行中进度与失败结论走粘性浮层(sticky: true,不自动收起,切页回来仍可见);成功与取消回显走一次性浮层(成功/取消 2.6 秒、失败 6 秒收起),一次性提示优先显示,收起后粘性状态继续显示
- 粘性状态只挂首页与项目组两个页面,进项目工作台、模板库、帮助页不再飘在界面上;运行/预览提示与取消回显不受该限制
- RunNoticeToast/RunNotice 更名为 LauncherNoticeToast/LauncherNotice,新增 sticky 与 neutral 色调,挂点改为 data-launcher-notice-toast,长文案容器限宽 min(680px, 100vw - 2rem) 并换行
- 收起回调只从 ref 读,不再写进 effect 依赖:此前外壳每次重渲染都会换一个内联箭头函数,把收起计时重新起算,长驻页面上的提示可能永远收不回去
- useHomeProjectCreation 三处取消(非空文件夹确认弹窗、打开项目选目录、新建项目选目录)改为清空状态并弹一次性浮层回显「已取消」,不再往页面上那行写文字
- 删除 HomeView 的 status prop 与状态行节点、ProjectsPage 的 status prop 与 .launcher-project-page-status 节点及对应 CSS 规则
- launcherNoticeToast 用例补粘性不收起、父组件重渲染不重新计时、取消回显短时收起;launcherNoticeShellWiring 用例补进行中状态与取消回显都只走浮层、首页不留那一行、粘性状态不进项目工作台
- appSurface/home.suite 三处取消断言改断浮层挂点;homeWebPreflight 与 designProjectRestore 的 hook 夹具补 showTransientNotice
- 技术方案与 decision-log 记录该口径与边界:首页带按钮的「已创建的工作区」提示仍留在页面上
2026-09-29 19:35:49 +08:00

108 lines
3.8 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 { HOME_WEB_PREFLIGHT_FAILURE } from '../src/features/app-shell/homeWebPreflight';
import { useHomeProjectCreation } from '../src/features/app-shell/useHomeProjectCreation';
afterEach(() => {
cleanup();
delete window.__TAURI__;
});
function mount(preflight: () => Promise<unknown>) {
const calls: string[] = [];
const invoke = vi.fn(async (command: string) => {
if (command !== 'capture_analytics_context') calls.push(command);
if (command === 'preflight_web_game_creation') return preflight();
if (command === 'suggest_automatic_project_name') return '预检项目';
if (command === 'create_automatic_local_game_project')
return {
projectPath: 'C:/test/preflight-game',
manifestPath: 'C:/test/preflight-game/.agent/manifest.json',
manifest: createGameCreationAppManifest('preflight-game', '预检项目'),
};
if (command === 'get_local_game_project_revision') return { revision: 1 };
if (command === 'set_design_agent_runtime_mode')
return { activeRuntime: 'design' };
return null;
});
window.__TAURI__ = { core: { invoke } } as unknown as typeof window.__TAURI__;
const hook = renderHook(() =>
useHomeProjectCreation({
setStatus: vi.fn(),
showTransientNotice: vi.fn(),
setLauncherView: vi.fn(),
setAgentChatProjectPath: vi.fn(),
rememberRecentWorkspace: vi.fn(),
}),
);
return { ...hook, calls, invoke };
}
it('awaits the real home preflight before naming or creating a game', async () => {
let ready!: (value: unknown) => void;
const pending = new Promise((resolve) => {
ready = resolve;
});
const { result, calls } = mount(() => pending);
let creation!: Promise<string>;
await act(async () => {
creation = result.current.createHomeDraftAutomatically(
{ creationType: 'game', prompt: '做一个小游戏', attachments: [] },
'direct-build',
);
});
expect(calls).toEqual(['preflight_web_game_creation']);
await act(async () => {
ready({ status: 'ready' });
await creation;
});
expect(calls.slice(0, 3)).toEqual([
'preflight_web_game_creation',
'suggest_automatic_project_name',
'create_automatic_local_game_project',
]);
expect(result.current.currentProjectContext?.creationType).toBe('game');
});
it.each([false, true])(
'blocks naming, creation, and first generation when preflight fails (throws=%s)',
async (throws) => {
const { result, calls } = mount(async () => {
if (throws) throw new Error('private host path');
return { status: 'blocked' };
});
let status = '';
await act(async () => {
status = await result.current.createHomeDraftAutomatically(
{ creationType: 'game', prompt: '做一个小游戏', attachments: [] },
'direct-build',
);
});
expect(status).toBe(HOME_WEB_PREFLIGHT_FAILURE);
expect(calls).toEqual(['preflight_web_game_creation']);
expect(result.current.currentProjectContext).toBeNull();
expect(status).not.toContain('private');
},
);
it.each(['game', 'doc'] as const)(
'does not require the Web preflight for %s planning',
async (creationType) => {
const { result, calls } = mount(async () => {
throw new Error('must not run');
});
await act(async () => {
await result.current.createHomeDraftAutomatically(
{ creationType, prompt: '策划需求', attachments: [] },
'planning',
);
});
expect(calls).not.toContain('preflight_web_game_creation');
expect(calls).not.toContain('suggest_automatic_project_name');
expect(calls).toContain('create_automatic_local_game_project');
},
);