fix(protocol): enforce message element contracts end to end

Replace the open message bag with a validated discriminated union and preflight complete messages before uploads or sends. Return BAD_REQUEST for invalid or unsendable segments instead of dropping fields, sending partial content, or silently changing private messages.
This commit is contained in:
DrSmoothl committed 2026-07-10 13:47:06 +08:00
1 parent aff6ad9179
commit 01688c7567
24 files changed
+1883 -417

No files matched your search

@@ -40,4 +40,21 @@ describe('sendPrivateMessage temp-session gate (passive-only)', () => {
sendPrivateMessage(ref, 1001, [{ type: 'text', data: { text: 'hi' } }], false, 700),
).rejects.toThrow(/passive-only|temp session/i);
});
it('rejects text + file before sending a partial temp-session message', async () => {
const store = new TempSessionStore();
store.record(1001, 700);
const ref = refWith(store);
await expect(sendPrivateMessage(ref, 1001, [
{ type: 'text', data: { text: 'must not be sent' } },
{ type: 'file', data: { file_id: 'friend-file-id' } },
], false, 700)).rejects.toMatchObject({
code: 'UNSENDABLE_TYPE',
elementType: 'file',
});
expect((ref.bridge.apis.message as { sendGroupTempMessage: ReturnType<typeof vi.fn> }).sendGroupTempMessage)
.not.toHaveBeenCalled();
});
});