From 46e505f4baa289ba4aa02f5ace3b51a4bddea1ee Mon Sep 17 00:00:00 2001 From: Shxiao Date: Wed, 23 Sep 2026 11:08:42 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E5=87=BA=E7=B2=BE=E5=8D=8E?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=97=B6=20msg=5Frandom=20=E4=B8=8E=20msg=5F?= =?UTF-8?q?seq=20=E5=8F=82=E6=95=B0=E9=A1=BA=E5=BA=8F=E9=94=99=E8=AF=AF=20?= =?UTF-8?q?(#2064)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/group/DelEssenceMsg.ts | 2 +- packages/napcat-test/delEssenceMsg.test.ts | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 packages/napcat-test/delEssenceMsg.test.ts 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'); + }); +});