From 08b8d0d1677c6cc657358a24e0d653d885dc4622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Thu, 1 Oct 2026 21:12:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=90=AF=E5=8A=A8=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E7=B3=BB=E7=BB=9F=E5=8F=98=E4=BD=93=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E7=9A=84=E8=B4=9F=E5=90=91=E6=96=AD=E8=A8=80=E7=AB=9E=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 先等系统变体经 unhandledrejection 抛出(并校验抛出物带 Rust 原文),再断言登录页没有该文案 - 原写法在首个 waitFor tick 就因 queryByText 返回 null 而通过,没真正验证拒绝落地后的文案 --- .../tests/appSurface/auth.suite.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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(); } });