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

@@ -22,51 +22,60 @@ const SAMPLE_EMOJI_ID = '2550419068_0_0_0_3BC06CE836D6134326EA2C1B37BF1584_0_0';
// 18 01 f3 position = 1 (front)
// 60 01 f12 = 1 ← envelope reserved (uinForm)
const ORDER_WIRE_HEX =
'08afa002100122520a17088008120a31302e302e32363230301a06392e392e32361235323535303431393036385f305f305f305f33424330364345383336443631333433323645413243314233374246313538345f305f3018016001';
'08afa002100122520a17088008120a31302e302e32363230301a06392e392e32361235323535303431393036385f305f305f305f33424330364345383336443631333433323645413243314233374246313538345f305f3018016001';
function makeSender() {
const r: SendPacketResult = {
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.alloc(0),
};
return { sendRawPacket: vi.fn(async () => r) };
const r: SendPacketResult = {
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData: Buffer.alloc(0),
};
return { sendRawPacket: vi.fn(async () => r) };
}
describe('OrderCustomFace namespace', () => {
it('declares command 0x902f sub 1 with uinForm (envelope reserved=1)', () => {
expect(OrderCustomFace.command).toBe(0x902f);
expect(OrderCustomFace.subCommand).toBe(1);
expect(OrderCustomFace.uinForm).toBe(true);
});
it('declares command 0x902f sub 1 with uinForm (envelope reserved=1)', () => {
expect(OrderCustomFace.command).toBe(0x902f);
expect(OrderCustomFace.subCommand).toBe(1);
expect(OrderCustomFace.uinForm).toBe(true);
});
it('serializes env{1024, osVersion, "9.9.26"} + emojiId + position', () => {
const out = OrderCustomFace.serialize({} as any, { emojiId: SAMPLE_EMOJI_ID, position: 1 });
expect(out.env).toMatchObject({ field1: 1024, osVersion: '10.0.26200', buildVersion: '9.9.26' });
expect(out.emojiId).toBe(SAMPLE_EMOJI_ID);
expect(out.position).toBe(1);
});
it('serializes env{1024, osVersion, "9.9.26"} + emojiId + position', () => {
const out = OrderCustomFace.serialize({} as any, { emojiId: SAMPLE_EMOJI_ID, position: 1 });
expect(out.env).toMatchObject({
field1: 1024,
osVersion: '10.0.26200',
buildVersion: '9.9.26',
});
expect(out.emojiId).toBe(SAMPLE_EMOJI_ID);
expect(out.position).toBe(1);
});
it('routes to OidbSvcTrpcTcp.0x902f_1 and reproduces the captured wire exactly', async () => {
const sender = makeSender();
await OrderCustomFace.invoke(sender, { emojiId: SAMPLE_EMOJI_ID, position: 1 });
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0x902f_1');
expect(Buffer.from(bytes as Uint8Array).toString('hex')).toBe(ORDER_WIRE_HEX);
const env = protobuf_decode<OidbBase<CustomFaceOrderBody>>(bytes as Uint8Array);
expect(env.command).toBe(0x902f);
expect(env.reserved).toBe(1);
expect(env.body?.emojiId).toBe(SAMPLE_EMOJI_ID);
expect(env.body?.position).toBe(1);
});
it('routes to OidbSvcTrpcTcp.0x902f_1 and reproduces the captured wire exactly', async () => {
const sender = makeSender();
await OrderCustomFace.invoke(sender, { emojiId: SAMPLE_EMOJI_ID, position: 1 });
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0x902f_1');
expect(Buffer.from(bytes as Uint8Array).toString('hex')).toBe(ORDER_WIRE_HEX);
const env = protobuf_decode<OidbBase<CustomFaceOrderBody>>(bytes as Uint8Array);
expect(env.command).toBe(0x902f);
expect(env.reserved).toBe(1);
expect(env.body?.emojiId).toBe(SAMPLE_EMOJI_ID);
expect(env.body?.position).toBe(1);
});
it('resolves on success (retCode 0 / empty body)', async () => {
const sender = makeSender();
await expect(OrderCustomFace.invoke(sender, { emojiId: SAMPLE_EMOJI_ID, position: 1 }))
.resolves.toBeUndefined();
});
it('resolves on success (retCode 0 / empty body)', async () => {
const sender = makeSender();
await expect(
OrderCustomFace.invoke(sender, { emojiId: SAMPLE_EMOJI_ID, position: 1 }),
).resolves.toBeUndefined();
});
it('throws when the business body carries a non-zero retCode', () => {
expect(() => OrderCustomFace.deserialize({} as any, { retCode: 5, errMsg: 'bad' }))
.toThrow();
});
it('throws when the business body carries a non-zero retCode', () => {
expect(() =>
OrderCustomFace.deserialize({} as any, { retCode: 5, errMsg: 'bad' }),
).toThrow();
});
});