This commit is contained in:
DrSmoothl committed 2026-10-12 15:43:34 +08:00
1 parent effeb66554
commit 7c0519f75f
977 files changed
+198426 -158324

No files matched your search

@@ -6,88 +6,113 @@ import { SetFriendCategory } from '../../../src/oidb-services/contacts/set-frien
import { env, s, v } from '../_pb-oracle';
function packet(errorCode = 0, errorMessage = ''): SendPacketResult {
return {
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<OidbEmpty>>({
command: 0x1255,
subCommand: 0,
errorCode,
errorMsg: errorMessage,
})),
};
return {
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData: Buffer.from(
protobuf_encode<OidbBase<OidbEmpty>>({
command: 0x1255,
subCommand: 0,
errorCode,
errorMsg: errorMessage,
}),
),
};
}
describe('SetFriendCategory namespace', () => {
it('uses the client command and UIN-form envelope confirmed by the native worker', () => {
expect(SetFriendCategory.command).toBe(0x1255);
expect(SetFriendCategory.subCommand).toBe(0);
expect(SetFriendCategory.uinForm).toBe(true);
});
it('serializes the friend UID and category ID with the verified field layout', async () => {
const sendRawPacket = vi.fn(async () => packet());
await SetFriendCategory.invoke({ sendRawPacket }, {
uid: 'u_friend',
categoryId: 7,
it('uses the client command and UIN-form envelope confirmed by the native worker', () => {
expect(SetFriendCategory.command).toBe(0x1255);
expect(SetFriendCategory.subCommand).toBe(0);
expect(SetFriendCategory.uinForm).toBe(true);
});
expect(sendRawPacket).toHaveBeenCalledOnce();
const [command, bytes] = sendRawPacket.mock.calls[0]!;
expect(command).toBe('OidbSvcTrpcTcp.0x1255_0');
expect(Buffer.from(bytes).toString('hex')).toBe(
env(0x1255, 0, [...s(1, 'u_friend'), ...v(2, 7)], true),
);
});
it('serializes the friend UID and category ID with the verified field layout', async () => {
const sendRawPacket = vi.fn(async () => packet());
it('accepts the idempotent success code used by the QQ client', async () => {
const sendRawPacket = vi.fn(async () => packet(2_001_002));
await SetFriendCategory.invoke(
{ sendRawPacket },
{
uid: 'u_friend',
categoryId: 7,
},
);
await expect(SetFriendCategory.invoke({ sendRawPacket }, {
uid: 'u_friend',
categoryId: 7,
})).resolves.toBeUndefined();
});
expect(sendRawPacket).toHaveBeenCalledOnce();
const [command, bytes] = sendRawPacket.mock.calls[0]!;
expect(command).toBe('OidbSvcTrpcTcp.0x1255_0');
expect(Buffer.from(bytes).toString('hex')).toBe(
env(0x1255, 0, [...s(1, 'u_friend'), ...v(2, 7)], true),
);
});
it('accepts the idempotent result when the packet layer reports it directly', async () => {
const sendRawPacket = vi.fn(async (): Promise<SendPacketResult> => ({
success: false,
gotResponse: true,
errorCode: 2_001_002,
errorMessage: 'already applied',
responseData: null,
}));
it('accepts the idempotent success code used by the QQ client', async () => {
const sendRawPacket = vi.fn(async () => packet(2_001_002));
await expect(SetFriendCategory.invoke({ sendRawPacket }, {
uid: 'u_friend',
categoryId: 7,
})).resolves.toBeUndefined();
});
await expect(
SetFriendCategory.invoke(
{ sendRawPacket },
{
uid: 'u_friend',
categoryId: 7,
},
),
).resolves.toBeUndefined();
});
it('surfaces explicit server rejections', async () => {
const sendRawPacket = vi.fn(async () => packet(42, 'denied'));
it('accepts the idempotent result when the packet layer reports it directly', async () => {
const sendRawPacket = vi.fn(async (): Promise<SendPacketResult> => ({
success: false,
gotResponse: true,
errorCode: 2_001_002,
errorMessage: 'already applied',
responseData: null,
}));
await expect(SetFriendCategory.invoke({ sendRawPacket }, {
uid: 'u_friend',
categoryId: 7,
})).rejects.toThrow(/42.*denied/);
});
await expect(
SetFriendCategory.invoke(
{ sendRawPacket },
{
uid: 'u_friend',
categoryId: 7,
},
),
).resolves.toBeUndefined();
});
it('does not mistake a transport failure with code zero for success', async () => {
const sendRawPacket = vi.fn(async (): Promise<SendPacketResult> => ({
success: false,
gotResponse: true,
errorCode: 0,
errorMessage: 'packet send failed',
responseData: null,
}));
it('surfaces explicit server rejections', async () => {
const sendRawPacket = vi.fn(async () => packet(42, 'denied'));
await expect(SetFriendCategory.invoke({ sendRawPacket }, {
uid: 'u_friend',
categoryId: 7,
})).rejects.toThrow('packet send failed');
});
await expect(
SetFriendCategory.invoke(
{ sendRawPacket },
{
uid: 'u_friend',
categoryId: 7,
},
),
).rejects.toThrow(/42.*denied/);
});
it('does not mistake a transport failure with code zero for success', async () => {
const sendRawPacket = vi.fn(async (): Promise<SendPacketResult> => ({
success: false,
gotResponse: true,
errorCode: 0,
errorMessage: 'packet send failed',
responseData: null,
}));
await expect(
SetFriendCategory.invoke(
{ sendRawPacket },
{
uid: 'u_friend',
categoryId: 7,
},
),
).rejects.toThrow('packet send failed');
});
});