From b4a1a66cd6eb6808ce37ec6fac38e237b268a6f7 Mon Sep 17 00:00:00 2001 From: kdletters Date: Sun, 21 Jun 2026 19:32:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E9=BD=90=E6=A1=8C=E9=9D=A2=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E4=BA=8B=E4=BB=B6=E9=97=A8=E7=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增根级 Rust 函数源码提取工具 将桌面导航状态注入脚本的稳定日志边界纳入 native-shell 总检查 --- scripts/check-native-shells.mjs | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) 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();