diff --git a/packages/napcat-onebot/action/group/DelEssenceMsg.ts b/packages/napcat-onebot/action/group/DelEssenceMsg.ts index 51788c82b..0b18a70e0 100644 --- a/packages/napcat-onebot/action/group/DelEssenceMsg.ts +++ b/packages/napcat-onebot/action/group/DelEssenceMsg.ts @@ -48,7 +48,7 @@ export default class DelEssenceMsg extends OneBotAction const data = this.core.apis.GroupApi.essenceLRU.getValue(+payload.message_id); if (!data) throw new Error('消息不存在'); const { msg_seq, msg_random, group_id } = JSON.parse(data) as { msg_seq: string, msg_random: string, group_id: string; }; - return await this.core.apis.GroupApi.removeGroupEssenceBySeq(group_id, msg_seq, msg_random); + return await this.core.apis.GroupApi.removeGroupEssenceBySeq(group_id, msg_random, msg_seq); } return await this.core.apis.GroupApi.removeGroupEssence( msg.Peer.peerUid, diff --git a/packages/napcat-test/delEssenceMsg.test.ts b/packages/napcat-test/delEssenceMsg.test.ts new file mode 100644 index 000000000..e09e91ce5 --- /dev/null +++ b/packages/napcat-test/delEssenceMsg.test.ts @@ -0,0 +1,53 @@ +// StreamBasic must be evaluated before OneBotAction: the two modules import each other, +// and loading OneBotAction first leaves BasicStream extending an uninitialized binding. +import '../napcat-onebot/action/stream/StreamBasic'; +import { afterEach, describe, expect, test, vi } from 'vitest'; +import { MessageUnique } from '../napcat-common/src/message-unique'; +import DelEssenceMsg from '../napcat-onebot/action/group/DelEssenceMsg'; + +function createAction (essenceLRUValue: string | undefined) { + const removeGroupEssenceBySeq = vi.fn().mockResolvedValue({ result: 0 }); + const action = new DelEssenceMsg( + undefined as never, + { + apis: { + GroupApi: { + essenceLRU: { getValue: vi.fn().mockReturnValue(essenceLRUValue) }, + removeGroupEssenceBySeq, + }, + }, + } as never + ); + return { action, removeGroupEssenceBySeq }; +} + +describe('delete_essence_msg argument order', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + test('passes msg_random before msg_seq for explicitly supplied parameters', async () => { + const { action, removeGroupEssenceBySeq } = createAction(undefined); + + await action._handle({ group_id: '33', msg_seq: '11', msg_random: '22' }); + + // GroupApi.removeGroupEssenceBySeq(groupCode, msgRandom, msgSeq) + expect(removeGroupEssenceBySeq).toHaveBeenCalledWith('33', '22', '11'); + }); + + test('passes msg_random before msg_seq for the essence LRU fallback', async () => { + // get_essence_msg_list stores this payload under a synthetic message_id when the + // original message can no longer be resolved from the local message cache. + const { action, removeGroupEssenceBySeq } = createAction(JSON.stringify({ + msg_seq: '11', + msg_random: '22', + group_id: '33', + })); + vi.spyOn(MessageUnique, 'getMsgIdAndPeerByShortId').mockReturnValue(undefined); + + await action._handle({ message_id: 12345 }); + + // GroupApi.removeGroupEssenceBySeq(groupCode, msgRandom, msgSeq) + expect(removeGroupEssenceBySeq).toHaveBeenCalledWith('33', '22', '11'); + }); +});