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:
24 files changed
+1883
-417
No files matched your search
@@ -104,7 +104,7 @@ describe('send_group_msg with {type:"file"} segment', () => {
|
||||
expect(fileFileId).toBe('gfid-xyz');
|
||||
});
|
||||
|
||||
it('file segment without file_id is skipped (with a warn-level log)', async () => {
|
||||
it('rejects the whole message when a file segment has neither file_id nor url', async () => {
|
||||
const sendGroupMessage_bridge = vi.fn(async (_gid: number, _elements: any[]) => goodReceipt);
|
||||
const publish = vi.fn();
|
||||
const upload = vi.fn();
|
||||
@@ -117,12 +117,15 @@ describe('send_group_msg with {type:"file"} segment', () => {
|
||||
} as any);
|
||||
const ctx = makeCtx(bridge);
|
||||
|
||||
await sendGroupMessage(ctx, 12345, [
|
||||
await expect(sendGroupMessage(ctx, 12345, [
|
||||
{ type: 'text', data: { text: 'with bad file segment' } },
|
||||
{ type: 'file', data: {} }, // no file_id and no url
|
||||
] as any, false);
|
||||
] as any, false)).rejects.toMatchObject({
|
||||
code: 'MISSING_FIELD',
|
||||
elementType: 'file',
|
||||
});
|
||||
|
||||
expect(sendGroupMessage_bridge).toHaveBeenCalledOnce();
|
||||
expect(sendGroupMessage_bridge).not.toHaveBeenCalled();
|
||||
expect(publish).not.toHaveBeenCalled();
|
||||
expect(upload).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user