补齐桌面导航事件门禁

新增根级 Rust 函数源码提取工具

将桌面导航状态注入脚本的稳定日志边界纳入 native-shell 总检查
This commit is contained in:
2026-06-21 19:32:01 +08:00
parent 433b65e154
commit b4a1a66cd6
+59
View File
@@ -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();