M5: BridgeController 激活闸门 setActive(双 Web 基础件)

- BridgeController 加 active 状态 + setActive/isActive:
  - 非激活:onLoadIntercept 拦截 yy:// 但不分发(入站忽略)、dispatch 直接返回(出站抑制)
  - 保证双 Web 下"同时只有一个 Web 执行桥接口",且去激活端不会收到 native 推送
- 去激活顺序约定:先 callHandler(appservice,'2')(彼时仍激活),再 setActive(false)
- 单测新增 inactive_gate_suppresses_outbound_and_inbound;scripts/test.sh 通过
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
lanterngamescn
2026-06-25 23:25:49 +08:00
parent f190fe69e3
commit a865ac766b
2 changed files with 40 additions and 0 deletions
+20
View File
@@ -188,6 +188,26 @@ export default function bridgeTest() {
expect(bridge.getRegistry().has('a')).assertFalse();
});
it('inactive_gate_suppresses_outbound_and_inbound', 0, () => {
const fake = new FakeWebController();
const bridge = new BridgeController(fake);
bridge.onPageEnd();
let got = '';
bridge.registerHandler('echo', (data, cb) => { got = data; cb('R'); });
// 去激活:出站抑制
bridge.setActive(false);
bridge.callHandler('appservice', '2');
expect(fake.scripts.length).assertEqual(0);
// 去激活:入站忽略——yy:// 仍拦截(返回 true)但不 flush
const intercepted = bridge.onLoadIntercept('yy://__queue__/');
expect(intercepted).assertTrue();
expect(fake.scripts.length).assertEqual(0);
// 重新激活:恢复出站
bridge.setActive(true);
bridge.callHandler('appservice', '1');
expect(fake.scripts.some((s) => s.includes('appservice'))).assertTrue();
});
it('default_handler_unregistered_no_throw', 0, () => {
const fake = new FakeWebController();
const bridge = new BridgeController(fake);