diff --git a/apps/ai-game-creator-shell/tests/appSurface/home.suite.ts b/apps/ai-game-creator-shell/tests/appSurface/home.suite.ts index d897eb29b..800a6ce7d 100644 --- a/apps/ai-game-creator-shell/tests/appSurface/home.suite.ts +++ b/apps/ai-game-creator-shell/tests/appSurface/home.suite.ts @@ -2544,6 +2544,7 @@ export function registerHomeProjectCreationTests() { 'failed-direct-project', '直连失败项目', ); + const persistedMessages: Array> = []; const invoke = vi.fn( async (command: string, args?: Record) => { if (command === 'get_local_game_manifest') { @@ -2552,7 +2553,11 @@ export function registerHomeProjectCreationTests() { } if (command === 'read_direct_project_history_slice') { expect(args).toEqual({ projectPath, limit: 20 }); - return { items: [], hasMore: false, firstItemId: null }; + return { + items: [...persistedMessages], + hasMore: false, + firstItemId: null, + }; } if (command === 'append_local_permission_log') { return {}; @@ -2601,13 +2606,38 @@ export function registerHomeProjectCreationTests() { await screen.findAllByText('项目权限策略拒绝了本次调用'), ).not.toBeNull(); expect(screen.queryAllByText(/permissionRejected/)).toHaveLength(0); - // 入队没成立:只发一次命令,失败之后不自动重试、也不重放。 + // 入队没成立:被拒消息不得留下任何历史条目,也不得被乐观渲染成已成立的用户消息。 + expect(persistedMessages).toHaveLength(0); + expect(screen.queryAllByText('生成一个游戏')).toHaveLength(0); + expect( + invoke.mock.calls.filter( + ([command]) => command === 'append_local_conversation_message', + ), + ).toHaveLength(0); + // 入队没成立:只发一次命令,失败之后不自动重试。 expect( invoke.mock.calls.filter( ([command]) => command === 'enqueue_direct_codex_turn', ), ).toHaveLength(1); cleanup(); + + // 重进项目:被拒消息不得从历史里被重放,拒绝文案也不该被当成历史条目。 + render( + React.createElement(App, { + initialProjectPath: projectPath, + initialProjectManifest: manifest, + }), + ); + await waitFor(() => { + expect(screen.queryAllByText('生成一个游戏')).toHaveLength(0); + }); + expect(screen.queryAllByText('项目权限策略拒绝了本次调用')).toHaveLength(0); + expect( + invoke.mock.calls.filter( + ([command]) => command === 'enqueue_direct_codex_turn', + ), + ).toHaveLength(1); }); }