fix(onebot): keep synthetic sequences out of history
Distinguish QQ-authoritative message sequences from local message IDs so group files and reply placeholders cannot become history anchors or be reused by protocol actions. Filter QQ null roam records and migrate previously stored synthetic rows. Fixes #254
This commit is contained in:
17 files changed
+758
-45
No files matched your search
@@ -188,6 +188,7 @@ describe('backfillReplyTarget', () => {
|
||||
expect(store.storeEvent).toHaveBeenCalledWith(
|
||||
targetId, true, 700, 123, GROUP_MESSAGE_EVENT,
|
||||
expect.objectContaining({ message_id: targetId, message_type: 'group', user_id: 800 }),
|
||||
{ sequenceAuthoritative: false },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -207,6 +208,7 @@ describe('backfillReplyTarget', () => {
|
||||
expect(store.storeEvent).toHaveBeenCalledWith(
|
||||
targetId, true, 700, 123, GROUP_MESSAGE_EVENT,
|
||||
expect.objectContaining({ message_id: targetId, message_type: 'group' }),
|
||||
{ sequenceAuthoritative: false },
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -145,6 +145,7 @@ describe('registerEventPipeline', () => {
|
||||
expect(metaCalls[0].meta.isGroup).toBe(false);
|
||||
expect(metaCalls[0].meta.targetId).toBe(PEER_UIN);
|
||||
expect(metaCalls[0].meta.sequence).toBe(11);
|
||||
expect(metaCalls[0].meta.sequenceAuthoritative).toBe(true);
|
||||
expect(metaCalls[0].meta.random).toBe(555);
|
||||
|
||||
expect(dispatchCalls).toHaveLength(1);
|
||||
|
||||
@@ -16,6 +16,7 @@ function fakeMeta(overrides: Partial<MessageMeta> = {}): MessageMeta {
|
||||
isGroup: true,
|
||||
targetId: 100,
|
||||
sequence: 555,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: 'group_message',
|
||||
clientSequence: 0,
|
||||
random: 0,
|
||||
@@ -648,6 +649,19 @@ describe('extended-actions / set_/complete_/cancel_group_todo', () => {
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 100 });
|
||||
});
|
||||
|
||||
it('rejects a local-only message id without calling the group todo protocol', async () => {
|
||||
const setGroupTodo = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({ setGroupTodo });
|
||||
const ctx = fakeCtx(bridge, {
|
||||
getMessageMeta: () => fakeMeta({ sequence: 0, sequenceAuthoritative: false }),
|
||||
});
|
||||
|
||||
const res = await makeHandler(ctx).handle('set_group_todo', { group_id: 100, message_id: 1 });
|
||||
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 100 });
|
||||
expect(setGroupTodo).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects missing params', async () => {
|
||||
const r1 = await makeHandler(fakeCtx(fakeBridge())).handle('set_group_todo', { message_id: 1 });
|
||||
const r2 = await makeHandler(fakeCtx(fakeBridge())).handle('set_group_todo', { group_id: 1 });
|
||||
@@ -656,6 +670,26 @@ describe('extended-actions / set_/complete_/cancel_group_todo', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('extended-actions / set_group_reaction', () => {
|
||||
it('rejects a local-only message id without calling the reaction protocol', async () => {
|
||||
const setGroupReaction = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({ setGroupReaction });
|
||||
const ctx = fakeCtx(bridge, {
|
||||
getMessageMeta: () => fakeMeta({ sequence: 0, sequenceAuthoritative: false }),
|
||||
});
|
||||
|
||||
const res = await makeHandler(ctx).handle('set_group_reaction', {
|
||||
group_id: 100,
|
||||
message_id: 1,
|
||||
code: '66',
|
||||
is_set: true,
|
||||
});
|
||||
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 100 });
|
||||
expect(setGroupReaction).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Tier 2: nc_get_user_status ───
|
||||
|
||||
describe('extended-actions / nc_get_user_status', () => {
|
||||
|
||||
@@ -63,6 +63,7 @@ describe('history direction plumbing', () => {
|
||||
isGroup: true,
|
||||
targetId: GROUP_ID,
|
||||
sequence: 500,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: GROUP_MESSAGE_EVENT,
|
||||
clientSequence: 0,
|
||||
random: 0,
|
||||
@@ -91,6 +92,7 @@ describe('history direction plumbing', () => {
|
||||
isGroup: false,
|
||||
targetId: FRIEND_ID,
|
||||
sequence: 700,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: PRIVATE_MESSAGE_EVENT,
|
||||
clientSequence: 0,
|
||||
random: 0,
|
||||
@@ -124,6 +126,15 @@ describe('history direction plumbing', () => {
|
||||
message_id: 1,
|
||||
message_seq: 900,
|
||||
});
|
||||
messageStore.storeEvent(2, true, GROUP_ID, 1799283572, GROUP_MESSAGE_EVENT, {
|
||||
post_type: 'message_sent',
|
||||
message_type: 'group',
|
||||
group_id: GROUP_ID,
|
||||
message_id: 2,
|
||||
message_seq: 1799283572,
|
||||
user_id: SELF_ID,
|
||||
message: [{ type: 'file', data: { file_id: 'gfid-local' } }],
|
||||
}, { sequenceAuthoritative: false });
|
||||
const ref = {
|
||||
selfId: SELF_ID,
|
||||
bridge: {
|
||||
@@ -136,6 +147,31 @@ describe('history direction plumbing', () => {
|
||||
const messages = await getGroupHistory(ref, GROUP_ID, 0, 20, false);
|
||||
|
||||
expect(messages.map((message) => message.message_seq)).toEqual([899, 900]);
|
||||
expect(fetchHistory).toHaveBeenCalledWith(GROUP_ID, 900, 20, SELF_ID, true);
|
||||
});
|
||||
|
||||
it('does not use an explicitly requested local-only id as a server history anchor', async () => {
|
||||
const fetchHistory = vi.fn(async () => [groupMessage(1799283572)]);
|
||||
messageStore.storeEvent(2, true, GROUP_ID, 1799283572, GROUP_MESSAGE_EVENT, {
|
||||
post_type: 'message_sent',
|
||||
message_type: 'group',
|
||||
group_id: GROUP_ID,
|
||||
message_id: 2,
|
||||
message_seq: 1799283572,
|
||||
user_id: SELF_ID,
|
||||
message: [{ type: 'file', data: { file_id: 'gfid-local' } }],
|
||||
}, { sequenceAuthoritative: false });
|
||||
const ref = {
|
||||
selfId: SELF_ID,
|
||||
bridge: {
|
||||
apis: { message: { getGroupHistory: fetchHistory } },
|
||||
},
|
||||
messageStore,
|
||||
converterCtx,
|
||||
} as any;
|
||||
|
||||
await expect(getGroupHistory(ref, GROUP_ID, 2, 20, false)).resolves.toEqual([]);
|
||||
expect(fetchHistory).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects a private anchor from a different friend conversation', async () => {
|
||||
@@ -144,6 +180,7 @@ describe('history direction plumbing', () => {
|
||||
isGroup: false,
|
||||
targetId: 987654321,
|
||||
sequence: 800,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: PRIVATE_MESSAGE_EVENT,
|
||||
clientSequence: 0,
|
||||
random: 0,
|
||||
|
||||
@@ -2,7 +2,8 @@ import { describe, expect, it, vi } from 'vitest';
|
||||
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
|
||||
import { ApiHandler, type ApiActionContext } from '../src/api-handler';
|
||||
import type { OneBotInstanceContext } from '../src/instance-context';
|
||||
import { sendGroupMessage } from '../src/modules/message-actions';
|
||||
import { deleteMessage, sendGroupMessage, setEssenceMessage } from '../src/modules/message-actions';
|
||||
import type { MessageMeta } from '../src/types';
|
||||
|
||||
function instanceContext(sendGroup: ReturnType<typeof vi.fn>): OneBotInstanceContext {
|
||||
const bridge = {
|
||||
@@ -95,3 +96,33 @@ describe('outbound message validation at the Action boundary', () => {
|
||||
expect(bridgeSend).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('server-sequence action validation', () => {
|
||||
const localOnlyMeta: MessageMeta = {
|
||||
isGroup: true,
|
||||
targetId: 12345,
|
||||
sequence: 0,
|
||||
sequenceAuthoritative: false,
|
||||
eventName: 'group_message',
|
||||
clientSequence: 0,
|
||||
random: 0,
|
||||
timestamp: 0,
|
||||
};
|
||||
|
||||
it('does not recall a message that has only a local id', async () => {
|
||||
const recallGroup = vi.fn();
|
||||
const bridge = { apis: { message: { recallGroup } } } as unknown as BridgeInterface;
|
||||
|
||||
await expect(deleteMessage(bridge, localOnlyMeta)).rejects.toThrow('no authoritative QQ sequence');
|
||||
expect(recallGroup).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not mark a message that has only a local id as essence', async () => {
|
||||
const setEssence = vi.fn();
|
||||
const bridge = { apis: { interaction: { setEssence } } } as unknown as BridgeInterface;
|
||||
const store = { findMeta: () => localOnlyMeta } as any;
|
||||
|
||||
await expect(setEssenceMessage(bridge, store, 1, true)).rejects.toThrow('no authoritative QQ sequence');
|
||||
expect(setEssence).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -3,6 +3,7 @@ import { MessageStore } from '../src/message-store';
|
||||
import { hashMessageIdInt32, GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../src/message-id';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
|
||||
describe('MessageStore', () => {
|
||||
const testDbPath = path.join('data', 'test', 'messages-test.db');
|
||||
@@ -39,6 +40,7 @@ describe('MessageStore', () => {
|
||||
isGroup: true,
|
||||
targetId: groupId,
|
||||
sequence,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: GROUP_MESSAGE_EVENT,
|
||||
clientSequence: 0,
|
||||
random: 0,
|
||||
@@ -61,6 +63,7 @@ describe('MessageStore', () => {
|
||||
isGroup: false,
|
||||
targetId: senderUin,
|
||||
sequence,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: PRIVATE_MESSAGE_EVENT,
|
||||
clientSequence: 0,
|
||||
random: 0,
|
||||
@@ -105,6 +108,7 @@ describe('MessageStore', () => {
|
||||
isGroup: true,
|
||||
targetId: sessionId,
|
||||
sequence,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: GROUP_MESSAGE_EVENT,
|
||||
clientSequence: 0,
|
||||
random: 0,
|
||||
@@ -117,6 +121,7 @@ describe('MessageStore', () => {
|
||||
isGroup: false,
|
||||
targetId: sessionId,
|
||||
sequence,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: PRIVATE_MESSAGE_EVENT,
|
||||
clientSequence: 0,
|
||||
random: 0,
|
||||
@@ -170,6 +175,7 @@ describe('MessageStore', () => {
|
||||
isGroup: true,
|
||||
targetId: 123456,
|
||||
sequence: 100,
|
||||
sequenceAuthoritative: true,
|
||||
eventName: GROUP_MESSAGE_EVENT,
|
||||
clientSequence: 1,
|
||||
random: 12345,
|
||||
@@ -218,6 +224,159 @@ describe('MessageStore', () => {
|
||||
|
||||
expect(messages.map((message) => message.message_seq)).toEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it('excludes unconfirmed sequences from replies and history anchors (#254)', () => {
|
||||
const groupId = 123456;
|
||||
store.storeEvent(1, true, groupId, 9748, GROUP_MESSAGE_EVENT, {
|
||||
post_type: 'message',
|
||||
message_type: 'group',
|
||||
group_id: groupId,
|
||||
group_name: 'Test group',
|
||||
message_id: 1,
|
||||
message_seq: 9748,
|
||||
});
|
||||
store.storeEvent(2, true, groupId, 1799283572, GROUP_MESSAGE_EVENT, {
|
||||
post_type: 'message_sent',
|
||||
message_type: 'group',
|
||||
group_id: groupId,
|
||||
message_id: 2,
|
||||
message_seq: 1799283572,
|
||||
message: [{ type: 'file', data: { file: 'test.bin' } }],
|
||||
}, { sequenceAuthoritative: false });
|
||||
|
||||
expect(store.findLatestAuthoritativeSequence(true, groupId)).toBe(9748);
|
||||
expect(store.listSessionEvents(true, groupId).map((message) => message.message_seq)).toEqual([9748]);
|
||||
expect(store.resolveReplySequence(true, groupId, 2)).toBeNull();
|
||||
expect(store.findMeta(2)).toMatchObject({
|
||||
sequence: 1799283572,
|
||||
sequenceAuthoritative: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('migrates legacy synthetic group-file and reply-backfill sequences (#254)', () => {
|
||||
const groupId = 123456;
|
||||
store.close();
|
||||
|
||||
const legacy = new DatabaseSync(testDbPath);
|
||||
legacy.exec(`
|
||||
DROP TABLE messages;
|
||||
CREATE TABLE messages (
|
||||
message_hash INTEGER PRIMARY KEY,
|
||||
is_group INTEGER NOT NULL,
|
||||
session_id INTEGER NOT NULL,
|
||||
sequence INTEGER NOT NULL,
|
||||
event_name TEXT NOT NULL,
|
||||
client_sequence INTEGER NOT NULL DEFAULT 0,
|
||||
random INTEGER NOT NULL DEFAULT 0,
|
||||
timestamp INTEGER NOT NULL DEFAULT 0,
|
||||
data TEXT
|
||||
)
|
||||
`);
|
||||
const insert = legacy.prepare(`
|
||||
INSERT INTO messages
|
||||
(message_hash, is_group, session_id, sequence, event_name, client_sequence, random, timestamp, data)
|
||||
VALUES (?, 1, ?, ?, ?, 0, ?, ?, ?)
|
||||
`);
|
||||
const insertPrivate = legacy.prepare(`
|
||||
INSERT INTO messages
|
||||
(message_hash, is_group, session_id, sequence, event_name, client_sequence, random, timestamp, data)
|
||||
VALUES (?, 0, ?, ?, ?, 0, ?, ?, ?)
|
||||
`);
|
||||
insert.run(1, groupId, 9748, GROUP_MESSAGE_EVENT, 0, 1700000000, JSON.stringify({
|
||||
time: 1700000000,
|
||||
post_type: 'message',
|
||||
message_type: 'group',
|
||||
group_id: groupId,
|
||||
message_id: 1,
|
||||
message_seq: 9748,
|
||||
user_id: 222,
|
||||
message: [{ type: 'text', data: { text: 'real' } }],
|
||||
}));
|
||||
insert.run(2, groupId, 1799283572, GROUP_MESSAGE_EVENT, 1799283572, 1700000100, JSON.stringify({
|
||||
time: 1700000100,
|
||||
post_type: 'message_sent',
|
||||
message_type: 'group',
|
||||
group_id: groupId,
|
||||
message_id: 2,
|
||||
message_seq: 1799283572,
|
||||
user_id: 10001,
|
||||
message: [{ type: 'file', data: { file: 'test.bin' } }],
|
||||
}));
|
||||
insert.run(3, groupId, 1813530543, GROUP_MESSAGE_EVENT, 0, 1700000200, JSON.stringify({
|
||||
time: 1700000200,
|
||||
post_type: 'message',
|
||||
message_type: 'group',
|
||||
group_id: groupId,
|
||||
message_id: 3,
|
||||
message_seq: 1813530543,
|
||||
user_id: 0,
|
||||
message: [{ type: 'text', data: { text: '[引用消息]' } }],
|
||||
}));
|
||||
insert.run(4, groupId, 9732, GROUP_MESSAGE_EVENT, 0, 0, JSON.stringify({
|
||||
time: 0,
|
||||
post_type: 'message',
|
||||
message_type: 'group',
|
||||
group_id: groupId,
|
||||
message_id: 4,
|
||||
message_seq: 9732,
|
||||
user_id: 0,
|
||||
message: [{ type: 'text', data: { text: '[已删除]' } }],
|
||||
}));
|
||||
insert.run(5, groupId, 1813530544, GROUP_MESSAGE_EVENT, 0, 1700000300, JSON.stringify({
|
||||
time: 1700000300,
|
||||
post_type: 'message',
|
||||
message_type: 'group',
|
||||
group_id: groupId,
|
||||
message_id: 5,
|
||||
message_seq: 1813530544,
|
||||
user_id: 800,
|
||||
message: [{ type: 'text', data: { text: 'quoted inline content' } }],
|
||||
sender: {
|
||||
user_id: 800,
|
||||
nickname: '',
|
||||
card: '',
|
||||
role: 'member',
|
||||
sex: 'unknown',
|
||||
age: 0,
|
||||
},
|
||||
anonymous: null,
|
||||
}));
|
||||
insertPrivate.run(6, 555, 800, PRIVATE_MESSAGE_EVENT, 1234, 1700000400, JSON.stringify({
|
||||
time: 1700000400,
|
||||
post_type: 'message',
|
||||
message_type: 'private',
|
||||
sub_type: 'friend',
|
||||
message_id: 6,
|
||||
message_seq: 800,
|
||||
user_id: 555,
|
||||
message: [{ type: 'text', data: { text: 'real private message' } }],
|
||||
sender: { user_id: 555, nickname: 'Alice', sex: 'unknown', age: 0 },
|
||||
}));
|
||||
insertPrivate.run(7, 555, 1813530545, PRIVATE_MESSAGE_EVENT, 0, 1700000500, JSON.stringify({
|
||||
time: 1700000500,
|
||||
post_type: 'message',
|
||||
message_type: 'private',
|
||||
sub_type: 'friend',
|
||||
message_id: 7,
|
||||
message_seq: 1813530545,
|
||||
user_id: 555,
|
||||
message: [{ type: 'text', data: { text: 'quoted private content' } }],
|
||||
sender: { user_id: 555, nickname: '', sex: 'unknown', age: 0 },
|
||||
}));
|
||||
legacy.close();
|
||||
|
||||
store = new MessageStore(testDbPath);
|
||||
|
||||
expect(store.findLatestAuthoritativeSequence(true, groupId)).toBe(9748);
|
||||
expect(store.listSessionEvents(true, groupId).map((message) => message.message_seq)).toEqual([9748]);
|
||||
expect(store.findMeta(2)).toMatchObject({ sequenceAuthoritative: false });
|
||||
expect(store.findMeta(3)).toMatchObject({ sequenceAuthoritative: false });
|
||||
expect(store.findMeta(4)).toMatchObject({ sequenceAuthoritative: false });
|
||||
expect(store.findMeta(5)).toMatchObject({ sequenceAuthoritative: false });
|
||||
expect(store.findLatestAuthoritativeSequence(false, 555)).toBe(800);
|
||||
expect(store.findMeta(6)).toMatchObject({ sequenceAuthoritative: true });
|
||||
expect(store.findMeta(7)).toMatchObject({ sequenceAuthoritative: false });
|
||||
});
|
||||
});
|
||||
|
||||
describe('listReadSessions', () => {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
|
||||
import type { OneBotInstanceContext } from '../src/instance-context';
|
||||
import { MessageStore } from '../src/message-store';
|
||||
import { sendGroupMessage } from '../src/modules/message-actions';
|
||||
|
||||
function fakeBridge(overrides: Partial<BridgeInterface> = {}): BridgeInterface {
|
||||
@@ -29,12 +30,17 @@ function fakeBridge(overrides: Partial<BridgeInterface> = {}): BridgeInterface {
|
||||
});
|
||||
}
|
||||
|
||||
function makeCtx(bridge: BridgeInterface): OneBotInstanceContext {
|
||||
function makeCtx(bridge: BridgeInterface, messageStore?: MessageStore): OneBotInstanceContext {
|
||||
const store = messageStore
|
||||
?? ({ findEvent: () => null, resolveReplySequence: () => 0 } as any);
|
||||
return {
|
||||
uin: '10001',
|
||||
selfId: 10001,
|
||||
bridge,
|
||||
messageStore: { findEvent: () => null, resolveReplySequence: () => 0 } as any,
|
||||
cacheMessageMeta: vi.fn(),
|
||||
messageStore: store,
|
||||
cacheMessageMeta: messageStore
|
||||
? (messageId, meta) => messageStore.storeMeta(messageId, meta)
|
||||
: vi.fn(),
|
||||
mediaStore: {} as any,
|
||||
musicSignUrl: '',
|
||||
} as unknown as OneBotInstanceContext;
|
||||
@@ -75,6 +81,133 @@ describe('send_group_msg with {type:"file"} segment', () => {
|
||||
expect(fileId).toBe('gfid-abc');
|
||||
});
|
||||
|
||||
it('keeps an OIDB-only group file id separate from a QQ server sequence (#254)', async () => {
|
||||
const messageStore = new MessageStore(':memory:');
|
||||
try {
|
||||
const publish = vi.fn(async (_groupId: number, _fileId: string) => undefined);
|
||||
const bridge = fakeBridge({
|
||||
identity: { nickname: 'Bot' },
|
||||
apis: {
|
||||
message: { sendGroup: vi.fn() },
|
||||
groupFile: { publish },
|
||||
} as any,
|
||||
resolveUserUid: vi.fn(),
|
||||
} as any);
|
||||
const ctx = makeCtx(bridge, messageStore);
|
||||
|
||||
const result = await sendGroupMessage(ctx, 12345, [{
|
||||
type: 'file', data: { file_id: 'gfid-abc', name: 'doc.txt', size: 123 },
|
||||
}] as any, false);
|
||||
|
||||
expect(result.messageId).not.toBe(0);
|
||||
expect(messageStore.findMeta(result.messageId)).toMatchObject({
|
||||
sequence: 0,
|
||||
sequenceAuthoritative: false,
|
||||
});
|
||||
expect(messageStore.findEvent(result.messageId)).toMatchObject({ message_seq: 0 });
|
||||
expect(messageStore.findLatestAuthoritativeSequence(true, 12345)).toBeNull();
|
||||
} finally {
|
||||
messageStore.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects replying to an OIDB-only group file id as a QQ sequence (#254)', async () => {
|
||||
const messageStore = new MessageStore(':memory:');
|
||||
try {
|
||||
const sendGroup = vi.fn(async (_groupId: number, _elements: any[]) => goodReceipt);
|
||||
const publish = vi.fn(async (_groupId: number, _fileId: string) => undefined);
|
||||
const bridge = fakeBridge({
|
||||
identity: { nickname: 'Bot' },
|
||||
apis: {
|
||||
message: { sendGroup },
|
||||
groupFile: { publish },
|
||||
} as any,
|
||||
resolveUserUid: vi.fn(),
|
||||
} as any);
|
||||
const ctx = makeCtx(bridge, messageStore);
|
||||
|
||||
const file = await sendGroupMessage(ctx, 12345, [{
|
||||
type: 'file', data: { file_id: 'gfid-abc', name: 'doc.txt', size: 123 },
|
||||
}] as any, false);
|
||||
|
||||
await expect(sendGroupMessage(ctx, 12345, [
|
||||
{ type: 'reply', data: { id: file.messageId } },
|
||||
{ type: 'text', data: { text: 'received' } },
|
||||
] as any, false)).rejects.toMatchObject({
|
||||
code: 'INVALID_FIELD',
|
||||
elementType: 'reply',
|
||||
});
|
||||
expect(sendGroup).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
messageStore.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects a local-only reply id even when its full event was not cached', async () => {
|
||||
const messageStore = new MessageStore(':memory:');
|
||||
try {
|
||||
const sendGroup = vi.fn(async (_groupId: number, _elements: any[]) => goodReceipt);
|
||||
const bridge = fakeBridge({
|
||||
apis: { message: { sendGroup } } as any,
|
||||
resolveUserUid: vi.fn(),
|
||||
} as any);
|
||||
const ctx = makeCtx(bridge, messageStore);
|
||||
messageStore.storeMeta(77, {
|
||||
isGroup: true,
|
||||
targetId: 12345,
|
||||
sequence: 0,
|
||||
sequenceAuthoritative: false,
|
||||
eventName: 'group_message',
|
||||
clientSequence: 0,
|
||||
random: 42,
|
||||
timestamp: 1700000000,
|
||||
});
|
||||
|
||||
await expect(sendGroupMessage(ctx, 12345, [
|
||||
{ type: 'reply', data: { id: 77 } },
|
||||
{ type: 'text', data: { text: 'received' } },
|
||||
] as any, false)).rejects.toMatchObject({ code: 'INVALID_FIELD', elementType: 'reply' });
|
||||
expect(sendGroup).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
messageStore.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not apply local-only reply metadata from another group', async () => {
|
||||
const messageStore = new MessageStore(':memory:');
|
||||
try {
|
||||
const sendGroup = vi.fn(async (_groupId: number, _elements: any[]) => goodReceipt);
|
||||
const bridge = fakeBridge({
|
||||
identity: { nickname: 'Bot' },
|
||||
apis: { message: { sendGroup } } as any,
|
||||
resolveUserUid: vi.fn(),
|
||||
} as any);
|
||||
const ctx = makeCtx(bridge, messageStore);
|
||||
messageStore.storeMeta(77, {
|
||||
isGroup: true,
|
||||
targetId: 99999,
|
||||
sequence: 0,
|
||||
sequenceAuthoritative: false,
|
||||
eventName: 'group_message',
|
||||
clientSequence: 0,
|
||||
random: 42,
|
||||
timestamp: 1700000000,
|
||||
});
|
||||
|
||||
await sendGroupMessage(ctx, 12345, [
|
||||
{ type: 'reply', data: { id: 77 } },
|
||||
{ type: 'text', data: { text: 'direct sequence' } },
|
||||
] as any, false);
|
||||
|
||||
expect(sendGroup).toHaveBeenCalledWith(12345, [
|
||||
{ type: 'reply', replySeq: 77 },
|
||||
{ type: 'text', text: 'direct sequence' },
|
||||
]);
|
||||
} finally {
|
||||
messageStore.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('mixed text + file splits across two sends (text via elems[], file via OIDB)', async () => {
|
||||
const sendGroupMessage_bridge = vi.fn(async (_gid: number, _elements: any[]) => goodReceipt);
|
||||
const publish = vi.fn(async (_groupId: number, _fileId: string) => undefined);
|
||||
|
||||
Reference in new issue
Block a user