锁定微信原生页跳转失败提示

H5 HostBridge 微信小程序跳转失败不再透出原生 errMsg

HostBridge 测试覆盖微信跳转失败稳定提示

native shell 总门禁反查微信跳转失败边界
This commit is contained in:
2026-06-20 13:43:48 +08:00
parent 1cf9e6bcc6
commit fba6fb75fb
3 changed files with 64 additions and 1 deletions
+25
View File
@@ -1027,6 +1027,10 @@ function assertH5HostBridgePayloadBoundaries() {
'src/services/host-bridge/hostBridge.ts',
'utf8',
);
const h5HostBridgeTestSource = fs.readFileSync(
'src/services/host-bridge/hostBridge.test.ts',
'utf8',
);
const nativeRequestCapabilities = extractTsStringArray(
sharedContractSource,
'HOST_BRIDGE_METHODS',
@@ -1117,6 +1121,27 @@ function assertH5HostBridgePayloadBoundaries() {
'H5 HostBridge facade must reject unsafe native app navigation targets before sending navigation.openNativePage',
);
}
if (
!h5HostBridgeSource.includes(
"'[host-bridge] wechat mini program navigation failed'",
) ||
!h5HostBridgeSource.includes('reject(new Error(errorMessage));') ||
h5HostBridgeSource.includes('reject(new Error(error?.errMsg || errorMessage));')
) {
throw new Error(
'H5 HostBridge facade must not expose wx.miniProgram.navigateTo native failures',
);
}
for (const snippet of [
'hides wechat mini program navigation native failure details',
"errMsg: 'navigateTo:fail private native detail'",
"rejects.toThrow(\n '请在微信小程序内完成登录',",
"rejects.not.toThrow(\n 'private native detail',",
]) {
if (!h5HostBridgeTestSource.includes(snippet)) {
throw new Error(`H5 HostBridge navigation failure test must include ${snippet}`);
}
}
if (
!h5HostBridgeSource.includes(
'absolutizeHostSharePayloadUrls(params),',
@@ -767,6 +767,40 @@ describe('hostBridge', () => {
await expect(requestWechatMiniProgramPhoneLogin()).resolves.toBe(true);
});
test('hides wechat mini program navigation native failure details', async () => {
const consoleError = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined);
const navigationError = {
errMsg: 'navigateTo:fail private native detail',
};
const navigateTo = vi.fn((options) => {
options.fail?.(navigationError);
});
window.history.replaceState(
null,
'',
'/?clientRuntime=wechat_mini_program',
);
window.wx = {
miniProgram: {
navigateTo,
},
};
await expect(requestHostLogin()).rejects.toThrow(
'请在微信小程序内完成登录',
);
await expect(requestHostLogin()).rejects.not.toThrow(
'private native detail',
);
expect(consoleError).toHaveBeenCalledWith(
'[host-bridge] wechat mini program navigation failed',
navigationError,
);
consoleError.mockRestore();
});
test('通过微信小程序原生页请求支付', async () => {
const navigateTo = vi.fn((options) => {
options.success?.();
+5 -1
View File
@@ -496,7 +496,11 @@ export async function navigateWechatMiniProgramPage(
resolve();
},
fail(error) {
reject(new Error(error?.errMsg || errorMessage));
console.error(
'[host-bridge] wechat mini program navigation failed',
error,
);
reject(new Error(errorMessage));
},
});
});