From 1a16e8babc94bf921074d5609abb90345fa85260 Mon Sep 17 00:00:00 2001 From: kdletters Date: Sat, 20 Jun 2026 22:44:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E5=8F=A3=E7=A7=BB=E5=8A=A8=E5=A3=B3?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=8A=E6=96=AD=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移动壳文件 HostBridge 失败日志只记录稳定标签 更新文件失败测试避免断言原生错误对象外泄 扩展移动壳配置门禁禁止文件日志打印原生 error 对象 --- apps/mobile-shell/scripts/check-config.mjs | 8 ++++++++ apps/mobile-shell/src/host-bridge/files.test.ts | 10 ---------- apps/mobile-shell/src/host-bridge/files.ts | 4 ++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/apps/mobile-shell/scripts/check-config.mjs b/apps/mobile-shell/scripts/check-config.mjs index 47e8717b4..4c6703aef 100644 --- a/apps/mobile-shell/scripts/check-config.mjs +++ b/apps/mobile-shell/scripts/check-config.mjs @@ -2368,6 +2368,14 @@ for (const snippet of [ } } +if (filesSource.includes('console.warn(`mobile HostBridge file failed for ${label}`, error)')) { + throw new Error('mobile shell file diagnostics must not log native error objects'); +} + +if (!filesSource.includes('console.warn(`mobile HostBridge file failed for ${label}`)')) { + throw new Error('mobile shell file diagnostics must use stable label-only logging'); +} + if ( !dispatchSource.includes('exportMobileHostBridgeTextFile(request)') || !dispatchSource.includes('importMobileHostBridgeTextFile(request)') || diff --git a/apps/mobile-shell/src/host-bridge/files.test.ts b/apps/mobile-shell/src/host-bridge/files.test.ts index fb52703d8..12ef4219a 100644 --- a/apps/mobile-shell/src/host-bridge/files.test.ts +++ b/apps/mobile-shell/src/host-bridge/files.test.ts @@ -222,7 +222,6 @@ describe('mobile HostBridge file actions', () => { expect(shareAsyncMock).not.toHaveBeenCalled(); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for sharing.available', - error, ); warnSpy.mockRestore(); }); @@ -252,7 +251,6 @@ describe('mobile HostBridge file actions', () => { ]); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for sharing.open', - error, ); warnSpy.mockRestore(); }); @@ -329,7 +327,6 @@ describe('mobile HostBridge file actions', () => { }); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for document_picker.open', - error, ); warnSpy.mockRestore(); }); @@ -357,7 +354,6 @@ describe('mobile HostBridge file actions', () => { }); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for file.read_text', - expect.any(Error), ); warnSpy.mockRestore(); }); @@ -386,7 +382,6 @@ describe('mobile HostBridge file actions', () => { }); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for file.read_base64', - expect.any(Error), ); warnSpy.mockRestore(); }); @@ -414,7 +409,6 @@ describe('mobile HostBridge file actions', () => { }); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for file.read_base64', - expect.any(Error), ); warnSpy.mockRestore(); }); @@ -498,7 +492,6 @@ describe('mobile HostBridge file actions', () => { expect(imageLibraryMock).not.toHaveBeenCalled(); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for image.library_permission', - error, ); warnSpy.mockRestore(); }); @@ -520,7 +513,6 @@ describe('mobile HostBridge file actions', () => { }); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for image.library_open', - error, ); warnSpy.mockRestore(); }); @@ -537,7 +529,6 @@ describe('mobile HostBridge file actions', () => { expect(cameraMock).not.toHaveBeenCalled(); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for image.camera_permission', - error, ); warnSpy.mockRestore(); }); @@ -559,7 +550,6 @@ describe('mobile HostBridge file actions', () => { }); expect(warnSpy).toHaveBeenCalledWith( 'mobile HostBridge file failed for image.camera_open', - error, ); warnSpy.mockRestore(); }); diff --git a/apps/mobile-shell/src/host-bridge/files.ts b/apps/mobile-shell/src/host-bridge/files.ts index 3b44ca19f..f1e85ab95 100644 --- a/apps/mobile-shell/src/host-bridge/files.ts +++ b/apps/mobile-shell/src/host-bridge/files.ts @@ -51,8 +51,8 @@ import { } from './filePayloads'; import { invalidRequest, ok } from './protocol'; -function logMobileHostBridgeFileFailure(label: string, error: unknown) { - console.warn(`mobile HostBridge file failed for ${label}`, error); +function logMobileHostBridgeFileFailure(label: string, _error: unknown) { + console.warn(`mobile HostBridge file failed for ${label}`); } type MobileDocumentPickerOptions = Parameters<