fix(protocol): treat a successful group kick as success

QQ reports a per-member kick outcome in the command body. A zero
outcome means the member was removed; treat that as success instead
of a false failure. Still reject a non-zero outcome so callers do
not see success when the kick did not take effect.

Fixes #413
This commit is contained in:
DrSmoothl committed 2026-08-22 11:12:58 +08:00
1 parent 39e6b45b81
commit 6782fd9cb3
6 files changed
+144 -24

No files matched your search

+23 -11
View File
@@ -14,6 +14,7 @@ import type {
OidbGroupDetailRequest,
OidbGroupRequestAction,
OidbKickMember,
OidbKickMemberResponse,
OidbLeaveGroup,
OidbMuteAll,
OidbMuteMember,
@@ -125,18 +126,30 @@ describe('apis/group-admin', () => {
});
});
it('kickMember rejects a server business error instead of reporting success (#298)', async () => {
it('kickMember treats a zero per-member result as success (#413)', async () => {
const bridge = mockBridge();
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
Buffer.from(
'222008b960121be7bea4e4b8bbe697a0e6b395e8a2abe7a7bbe587bae7bea4e8818a',
'hex',
),
protobuf_encode<OidbBase<OidbKickMemberResponse>>({
body: { groupUin: 12345, results: [{ result: 0, uid: 'u_abcdefghijklmnopqrstuv' }] },
}),
));
await expect(
new GroupAdminApi(bridge as any).kickMember(12345, 67890, false),
).rejects.toThrow('群主无法被移出群聊');
).resolves.toBeUndefined();
});
it('kickMember rejects a server business error instead of reporting success (#298)', async () => {
const bridge = mockBridge();
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
protobuf_encode<OidbBase<OidbKickMemberResponse>>({
body: { groupUin: 12345, results: [{ result: 1, uid: 'u_abcdefghijklmnopqrstuv' }] },
}),
));
await expect(
new GroupAdminApi(bridge as any).kickMember(12345, 67890, false),
).rejects.toThrow('kick member failed: result=1');
});
it('kickMembers resolves each UID in parallel', async () => {
@@ -155,15 +168,14 @@ describe('apis/group-admin', () => {
it('kickMembers rejects the same command-level business error', async () => {
const bridge = mockBridge();
bridge.sendRawPacket.mockResolvedValueOnce(packResponse(
Buffer.from(
'222008b960121be7bea4e4b8bbe697a0e6b395e8a2abe7a7bbe587bae7bea4e8818a',
'hex',
),
protobuf_encode<OidbBase<OidbKickMemberResponse>>({
body: { groupUin: 12345, results: [{ result: 1, uid: 'u_abcdefghijklmnopqrstuv' }] },
}),
));
await expect(
new GroupAdminApi(bridge as any).kickMembers(12345, [67890], false),
).rejects.toThrow('群主无法被移出群聊');
).rejects.toThrow('kick members failed: result=1');
});
it('leave sends 0x1097_1, emits a self group_member_leave, and forgets the group (#133)', async () => {