diff --git a/scripts/check-native-shells.mjs b/scripts/check-native-shells.mjs index 015573825..300b2bdcc 100644 --- a/scripts/check-native-shells.mjs +++ b/scripts/check-native-shells.mjs @@ -2152,6 +2152,32 @@ function extractFunctionSource(source, functionName) { throw new Error(`unterminated function body ${functionName}`); } +function extractRustFunctionSource(source, functionName) { + const start = source.indexOf(`fn ${functionName}`); + if (start === -1) { + throw new Error(`unable to read Rust function ${functionName}`); + } + + const openBrace = source.indexOf('{', start); + if (openBrace === -1) { + throw new Error(`unable to read Rust function body ${functionName}`); + } + + let depth = 0; + for (let index = openBrace; index < source.length; index += 1) { + if (source[index] === '{') { + depth += 1; + } else if (source[index] === '}') { + depth -= 1; + if (depth === 0) { + return source.slice(start, index + 1); + } + } + } + + throw new Error(`unterminated Rust function body ${functionName}`); +} + function extractTsStringObject(source, exportName) { const match = source.match( new RegExp(`export const ${exportName}\\s*=\\s*\\{([\\s\\S]*?)\\}\\s*as const;`), @@ -3710,6 +3736,36 @@ function assertWechatShareGridFailureBoundaries() { } } +function assertDesktopNavigationEventBoundaries() { + const desktopShellNavigationSource = fs.readFileSync( + 'apps/desktop-shell/src-tauri/src/shell/navigation.rs', + 'utf8', + ); + const desktopNavigationStateScriptSource = extractRustFunctionSource( + desktopShellNavigationSource, + 'desktop_navigation_state_script', + ); + + if ( + !desktopNavigationStateScriptSource.includes( + "console.warn('desktop navigation state sync failed')", + ) + ) { + throw new Error( + 'desktop shell navigation state diagnostics must log a stable label', + ); + } + if ( + desktopNavigationStateScriptSource.includes( + "console.warn('desktop navigation state sync failed', error)", + ) + ) { + throw new Error( + 'desktop shell navigation state diagnostics must not log native error objects', + ); + } +} + function assertHostBridgeLayerLayout() { for (const [label, values] of [ ['wechat host bridge files expectation', expectedWechatHostBridgeFiles], @@ -3980,6 +4036,9 @@ assertWechatWebViewPageEventBoundaries(); console.log('[check:native-shells] wechat-share-grid-failure-boundaries'); assertWechatShareGridFailureBoundaries(); +console.log('[check:native-shells] desktop-navigation-event-boundaries'); +assertDesktopNavigationEventBoundaries(); + console.log('[check:native-shells] h5-host-bridge-event-subscription-gates'); assertH5HostBridgeEventSubscriptionGates();