feat(protocol): define strict first-slice wire contracts

This commit is contained in:
2026-09-05 02:06:46 +08:00
parent a173d410e0
commit 0a7951ba32
11 changed files with 851 additions and 0 deletions
@@ -34,6 +34,13 @@ test('decodeFrame:带 app 字段的单层业务包(服务器实测格式)', ()
assert.equal(r.kind === 'message' && r.message.rpc, 'kick_server');
});
test('decodeFrame:拒绝把双层 data 信封误当服务器业务包', () => {
const nested = JSON.stringify({
data: { route: 'agent', rpc: 'kick_server', data: { msg: '检查到新版本' } },
});
assert.deepEqual(decodeFrame(nested), { kind: 'ignore' });
});
test('decodeFrame:无法解析的帧安全忽略', () => {
assert.deepEqual(decodeFrame('not json'), { kind: 'ignore' });
assert.deepEqual(decodeFrame(JSON.stringify({ foo: 1 })), { kind: 'ignore' });