diff --git a/apps/ai-game-creator-shell/tests/appSurface/auth.suite.ts b/apps/ai-game-creator-shell/tests/appSurface/auth.suite.ts index b8c37b473..76d997050 100644 --- a/apps/ai-game-creator-shell/tests/appSurface/auth.suite.ts +++ b/apps/ai-game-creator-shell/tests/appSurface/auth.suite.ts @@ -271,6 +271,11 @@ export function registerAuthTests() { it('keeps transport details out of the login copy by throwing system variants through', async () => { const uninstall = installUnhandledRejectionBridge(); + const reasons: unknown[] = []; + const onRejection = (event: Event) => { + reasons.push((event as Event & { reason?: unknown }).reason); + }; + window.addEventListener('unhandledrejection', onRejection); try { const invoke = vi.fn(async (command: string) => { if (command === 'read_client_auth_state') { @@ -287,12 +292,16 @@ export function registerAuthTests() { renderAuthSurface(invoke); await loginWithCode(); - await waitFor(() => - expect(screen.queryByText(/无法连接登录服务/u)).toBeNull(), - ); + // 先等系统变体真的经 unhandledrejection 抛出,再断言它没落到登录页文案。 + await waitFor(() => expect(reasons).toHaveLength(1)); + expect(reasons[0]).toMatchObject({ + message: '无法连接登录服务,请确认配套后端或 API 代理已启动后重试', + }); + expect(screen.queryByText(/无法连接登录服务/u)).toBeNull(); expect(document.body.textContent).not.toContain('ECONNREFUSED'); await screen.findByRole('main', { name: '登录' }); } finally { + window.removeEventListener('unhandledrejection', onRejection); uninstall(); } });