diff --git a/scripts/check-native-shells.mjs b/scripts/check-native-shells.mjs index 172eb2c89..4ae46e55e 100644 --- a/scripts/check-native-shells.mjs +++ b/scripts/check-native-shells.mjs @@ -1164,6 +1164,27 @@ function assertH5HostBridgePayloadBoundaries() { 'H5 HostBridge facade must normalize haptics.impact payloads with the shared style boundary', ); } + if ( + !h5HostBridgeSource.includes( + 'colorScheme: normalizeHostBridgeColorScheme(result?.colorScheme),', + ) + ) { + throw new Error( + 'H5 HostBridge facade must normalize appearance.getColorScheme results with the shared color scheme boundary', + ); + } + if ( + !h5HostBridgeSource.includes( + 'const connectionType = normalizeHostBridgeConnectionType(\n payload?.connectionType ?? payload?.nativeType,\n );', + ) || + !h5HostBridgeSource.includes( + 'listener(normalizeHostNetworkStatus(payload));', + ) + ) { + throw new Error( + 'H5 HostBridge facade must normalize network.status results and network.statusChanged events with shared network boundaries', + ); + } if ( !h5HostBridgeSource.includes( 'const normalizedTitle = normalizeHostBridgeAppTitle(title);', diff --git a/src/services/host-bridge/hostBridge.test.ts b/src/services/host-bridge/hostBridge.test.ts index 2a829f3ac..54bfd6ad6 100644 --- a/src/services/host-bridge/hostBridge.test.ts +++ b/src/services/host-bridge/hostBridge.test.ts @@ -598,6 +598,43 @@ describe('hostBridge', () => { }); }); + test('原生 App 宿主配色结果进入 H5 前先归一化', async () => { + const invoke = vi.fn( + async (_command: string, args?: Record) => { + const request = (args as { request: { id: string; method: string } }) + .request; + return { + bridge: 'GenarrativeHostBridge', + version: 1, + id: request.id, + ok: true, + result: { + colorScheme: 'sepia', + }, + }; + }, + ); + window.history.replaceState( + null, + '', + nativeAppPath(['appearance.getColorScheme']), + ); + window.__TAURI__ = { + core: { + invoke: asTauriInvoke(invoke), + }, + }; + + await expect(getHostAppearanceColorScheme()).resolves.toEqual({ + colorScheme: 'unknown', + }); + expect(invoke).toHaveBeenCalledWith('host_bridge_request', { + request: expect.objectContaining({ + method: 'appearance.getColorScheme', + }), + }); + }); + test('从真实宿主 runtime 回读能力并通知订阅者', async () => { const listener = vi.fn(); const unsubscribe = subscribeHostRuntimeChange(listener);