Two bugs collapsed fetch_emoji_like into a perma-empty list with status=ok and no error output: 1. Req fields 4 and 5 were swapped (emojiType on field 4 / emojiId on field 5). The sibling 0x9082 OidbGroupReaction has field 4 = code (string) and field 5 = type (uint), and 0x9083 mirrors that layout — verified against LagrangeDev/LagrangeV2 `Internal/Packets/Service/SetGroupReaction.cs`. With our swap the wire types also mismatched (varint vs length-delim), so the server protobuf decoder dropped both fields and returned an empty list without ever surfacing an error. 2. Resp `inner.userInfo` was declared as a single message, but the server emits one entry per liker (repeated). Even after fixing the req, multi-user responses would have collapsed into the last entry. Map the decoded array on the InteractionApi side and filter uin=0 placeholders. Test now mocks two users to exercise the repeated path.
102 lines
4.4 KiB
TypeScript
102 lines
4.4 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { protobuf_encode } from '@snowluma/proton';
|
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
|
import type { Oidb0x9083Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
|
|
|
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
|
|
// that the plugin substitutes at the call site for the inlined codec.
|
|
// That means production calls to them NEVER hit the imported function —
|
|
// mocking them on the module object is a no-op. The only mockable point
|
|
// is `runOidb` (non-generic, untouched by proton) returning real bytes
|
|
// that the production-side codec actually decodes. `makeOidbEnvelope` is
|
|
// a pure TS helper, so its mock works for introspection.
|
|
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
|
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
|
'@snowluma/bridge/bridge-oidb',
|
|
);
|
|
return {
|
|
...actual,
|
|
runOidb: vi.fn(async () => new Uint8Array()),
|
|
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
|
};
|
|
});
|
|
|
|
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
|
import { InteractionApi } from '../../src/bridge/apis/interaction';
|
|
import { mockBridge } from './_helpers';
|
|
|
|
describe('apis/interaction', () => {
|
|
beforeEach(() => {
|
|
vi.mocked(oidb.runOidb).mockReset();
|
|
vi.mocked(oidb.runOidb).mockResolvedValue(new Uint8Array());
|
|
vi.mocked(oidb.makeOidbEnvelope).mockClear();
|
|
});
|
|
|
|
it('sendPoke group: groupUin set, friendUin=0', async () => {
|
|
const bridge = mockBridge();
|
|
await new InteractionApi(bridge as any).sendPoke(true, 12345, 67890);
|
|
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
|
expect(body).toMatchObject({ uin: 67890, groupUin: 12345, friendUin: 0 });
|
|
});
|
|
|
|
it('sendPoke friend: friendUin set, groupUin=0, targetUin defaults to peer', async () => {
|
|
const bridge = mockBridge();
|
|
await new InteractionApi(bridge as any).sendPoke(false, 67890);
|
|
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
|
expect(body).toMatchObject({ uin: 67890, groupUin: 0, friendUin: 67890 });
|
|
});
|
|
|
|
it('sendLike forwards target + count to 0x7e5_104', async () => {
|
|
const bridge = mockBridge();
|
|
await new InteractionApi(bridge as any).sendLike(10001, 3);
|
|
const [, cmd] = vi.mocked(oidb.runOidb).mock.calls[0]!;
|
|
expect(cmd).toBe('OidbSvcTrpcTcp.0x7e5_104');
|
|
const body = vi.mocked(oidb.makeOidbEnvelope).mock.calls[0]![2];
|
|
expect(body).toMatchObject({ targetUin: 10001, count: 3 });
|
|
});
|
|
|
|
it('setReaction picks _1 for set and _2 for unset', async () => {
|
|
const bridge = mockBridge();
|
|
const api = new InteractionApi(bridge as any);
|
|
await api.setReaction(12345, 99, '128516', true);
|
|
await api.setReaction(12345, 99, '128516', false);
|
|
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1]);
|
|
expect(cmds).toEqual(['OidbSvcTrpcTcp.0x9082_1', 'OidbSvcTrpcTcp.0x9082_2']);
|
|
});
|
|
|
|
it('setEssence picks _1 for enable and _2 for disable', async () => {
|
|
const bridge = mockBridge();
|
|
const api = new InteractionApi(bridge as any);
|
|
await api.setEssence(12345, 99, 0, true);
|
|
await api.setEssence(12345, 99, 0, false);
|
|
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1]);
|
|
expect(cmds).toEqual(['OidbSvcTrpcTcp.0xeac_1', 'OidbSvcTrpcTcp.0xeac_2']);
|
|
});
|
|
|
|
it('getEmojiLikes decodes user list, base64-encodes cookie, and reports isLast', async () => {
|
|
const bridge = mockBridge();
|
|
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
|
protobuf_encode<OidbBase<Oidb0x9083Resp>>({
|
|
body: {
|
|
inner: { userInfo: [{ uin: 10001n }, { uin: 20002n }] },
|
|
cookie: new Uint8Array([0xCA, 0xFE]),
|
|
} as any,
|
|
}),
|
|
);
|
|
const out = await new InteractionApi(bridge as any).getEmojiLikes(12345, 99, '128516');
|
|
expect(out.users).toEqual([{ uin: 10001 }, { uin: 20002 }]);
|
|
expect(out.cookie).toBe(Buffer.from([0xCA, 0xFE]).toString('base64'));
|
|
expect(out.isLast).toBe(false);
|
|
});
|
|
|
|
it('getEmojiLikes reports isLast=true when no cookie comes back', async () => {
|
|
const bridge = mockBridge();
|
|
vi.mocked(oidb.runOidb).mockResolvedValueOnce(
|
|
protobuf_encode<OidbBase<Oidb0x9083Resp>>({ body: {} }),
|
|
);
|
|
const out = await new InteractionApi(bridge as any).getEmojiLikes(12345, 99, '128516');
|
|
expect(out.users).toEqual([]);
|
|
expect(out.isLast).toBe(true);
|
|
});
|
|
});
|