diff --git a/apps/ai-game-creator-shell/tests/homeProjectNamingAsync.test.tsx b/apps/ai-game-creator-shell/tests/homeProjectNamingAsync.test.tsx index 73c964683..c23103b50 100644 --- a/apps/ai-game-creator-shell/tests/homeProjectNamingAsync.test.tsx +++ b/apps/ai-game-creator-shell/tests/homeProjectNamingAsync.test.tsx @@ -318,3 +318,50 @@ it('never starts automatic naming for the 做方案 flow', async () => { await naming.promise; }); }); + +it('does not hijack the project the user already moved to when the AI name lands', async () => { + const naming = deferred(); + const { result, refreshRecentWorkspace } = mount({ + naming: naming.promise, + conditionalRename: async () => ({ + renamed: true, + manifest: createGameCreationAppManifest(PROJECT_ID, SUGGESTED_NAME), + revision: 1, + }), + }); + + await act(async () => { + await createAutomatically(result); + }); + + // 用户已经切到另一个工作区(看门狗解围后打开别项目走的是同一条「上下文已被别人接管」判据)。 + await act(async () => { + result.current.setCurrentProjectContext({ + projectPath: 'C:/test/other-project', + projectName: '另一个项目', + projectKind: 'web', + manifest: createGameCreationAppManifest('other-project', '另一个项目'), + projectRevision: 3, + creationType: null, + startMode: null, + initialPrompt: '', + attachments: [], + recentRunStatus: null, + recentRunStopReason: null, + createdAt: 1, + }); + }); + + await act(async () => { + naming.resolve(SUGGESTED_NAME); + await naming.promise; + }); + + // 后台改名不能把用户当前所在的项目上下文换成刚建好的那个工作区。 + expect(result.current.currentProjectContext?.projectPath).toBe( + 'C:/test/other-project', + ); + expect(result.current.currentProjectContext?.projectName).toBe('另一个项目'); + // 但刚刚建好的工作区确实改名了:最近项目行照旧按目录重检。 + expect(refreshRecentWorkspace).toHaveBeenCalledWith(PROJECT_PATH); +});