fix(onebot): match group invitations to the correct request

Report distinct invitations separately and approve only the request that belongs to the account and inviter. Reject ambiguous approvals and resolve the sender of invitations from outside the contact list.

Refs #612
This commit is contained in:
DrSmoothl committed 2026-10-31 18:28:05 +08:00
1 parent d8763c98db
commit 299fa85a74
16 files changed
+429 -142

No files matched your search

+42 -4
View File
@@ -12,7 +12,7 @@ const APIS_ROUTING: Record<string, string> = {
fetchGroupRequests: 'contacts',
fetchGroupRequestsByUid: 'contacts',
fetchDownloadRKeys: 'contacts',
getGroupInviteCardSequence: 'contacts',
groupInvites: 'contacts',
findGroupInviteCardGroupBySequence: 'contacts',
};
@@ -205,7 +205,7 @@ describe('onebot/modules/request-actions / handleGroupAddRequest', () => {
filtered: false,
}),
]),
getGroupInviteCardSequence: vi.fn(() => null),
groupInvites: { getSelfInviteNotice: vi.fn(() => undefined) },
apis: { groupAdmin: { setAddRequest } } as any,
});
@@ -232,7 +232,7 @@ describe('onebot/modules/request-actions / handleGroupAddRequest', () => {
]
: [],
),
getGroupInviteCardSequence: vi.fn(() => null),
groupInvites: { getSelfInviteNotice: vi.fn(() => undefined) },
apis: { groupAdmin: { setAddRequest } } as any,
});
@@ -246,7 +246,7 @@ describe('onebot/modules/request-actions / handleGroupAddRequest', () => {
it('surfaces "not found" only when neither inbox has the request', async () => {
const bridge = fakeBridge({
fetchGroupRequestsByUid: vi.fn(async () => []),
getGroupInviteCardSequence: vi.fn(() => null),
groupInvites: { getSelfInviteNotice: vi.fn(() => undefined) },
apis: { groupAdmin: { setAddRequest: vi.fn(async () => {}) } } as any,
});
await expect(handleGroupAddRequest(bridge, 'invite:999:u_i', true, 'ok')).rejects.toThrow(
@@ -254,6 +254,44 @@ describe('onebot/modules/request-actions / handleGroupAddRequest', () => {
);
});
it('never picks one of two different pending invitations with the same legacy flag', async () => {
const setAddRequest = vi.fn();
const bridge = fakeBridge({
groupInvites: { getSelfInviteNotice: vi.fn(() => undefined) },
fetchGroupRequestsByUid: vi.fn(async (filtered: boolean) =>
filtered ? [] : [fakeRequest({ sequence: 123 }), fakeRequest({ sequence: 124 })],
),
apis: { groupAdmin: { setAddRequest } },
});
await expect(handleGroupAddRequest(bridge, 'invite:999:u_i', true, '')).rejects.toThrow(
'multiple pending group requests',
);
expect(setAddRequest).not.toHaveBeenCalled();
});
it('skips processed requests when approving a legacy notice', async () => {
const setAddRequest = vi.fn();
const bridge = fakeBridge({
groupInvites: { getSelfInviteNotice: vi.fn(() => undefined) },
fetchGroupRequestsByUid: vi.fn(async (filtered: boolean) =>
filtered
? []
: [fakeRequest({ sequence: 123, state: 2 }), fakeRequest({ sequence: 124 })],
),
apis: { groupAdmin: { setAddRequest } },
});
await handleGroupAddRequest(bridge, 'invite:999:u_i', true, '');
expect(setAddRequest).toHaveBeenCalledExactlyOnceWith(
999,
124,
7,
true,
'',
false,
undefined,
);
});
it('does not treat an inviter QQ number as a request sequence (#213)', async () => {
const setAddRequest = vi.fn(async () => {});
const bridge = fakeBridge({