fix(onebot): return profile like user details

Restore the interaction user lists returned by get_profile_like and keep self and other-user lookups consistent with the current client behavior.

Resolve missing account identities when needed, surface lookup failures, and update the public action catalog with the completed response shape. Add regression coverage for request selection, response decoding, identity enrichment, and malformed results.

Fixes #349
This commit is contained in:
DrSmoothl committed 2026-08-11 23:46:46 +08:00
1 parent b38db6715f
commit 8ded1065d4
9 files changed
+717 -70

No files matched your search

@@ -9,6 +9,7 @@ import { GetLike } from '../../../src/oidb-services/profile/get-like';
function makeDeps(opts: {
cachedSelfUid?: string | null;
resolveUserUid?: (uin: number) => Promise<string>;
findUinByUid?: (uid: string) => number | null;
responseBody?: Oidb0x7edResp;
} = {}) {
const responseData = opts.responseBody !== undefined
@@ -17,35 +18,44 @@ function makeDeps(opts: {
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
return {
sendRawPacket: vi.fn(async () => r),
identity: { uin: '10001', selfUid: opts.cachedSelfUid ?? null } as any,
identity: {
uin: '10001',
selfUid: opts.cachedSelfUid ?? null,
findUinByUid: vi.fn(opts.findUinByUid ?? (() => null)),
} as any,
resolveUserUid: vi.fn(opts.resolveUserUid ?? (async (uin: number) => `uid-of-${uin}`)),
};
}
describe('GetLike namespace', () => {
it('declares 0x7ED_12', () => {
it('uses the self and other-user subcommands selected by the native client', () => {
const deps = makeDeps({ cachedSelfUid: 'self-uid' });
expect(GetLike.command).toBe(0x7ED);
expect(GetLike.subCommand).toBe(12);
expect(GetLike.resolveSubCommand({}, deps)).toBe(13);
expect(GetLike.resolveSubCommand({ userId: 0 }, deps)).toBe(13);
expect(GetLike.resolveSubCommand({ userId: 10001 }, deps)).toBe(13);
expect(GetLike.resolveSubCommand({ userId: 20002 }, deps)).toBe(12);
});
describe('invoke (target uid resolution)', () => {
it('uses cached self uid when userId is omitted', async () => {
const deps = makeDeps({
cachedSelfUid: 'cached-self',
responseBody: { userLikeInfos: [{ uid: 'cached-self', time: 0n, favoriteInfo: {}, voteInfo: {} }] },
responseBody: { userLikeInfos: [{ uid: 'cached-self', time: 0, favoriteInfo: {}, voteInfo: {} }] },
});
await GetLike.invoke(deps, {});
expect(deps.resolveUserUid).not.toHaveBeenCalled();
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const [serviceCmd, bytes] = deps.sendRawPacket.mock.calls[0]!;
expect(serviceCmd).toBe('OidbSvcTrpcTcp.0x7ed_13');
const env = protobuf_decode<OidbBase<Oidb0x7edReq>>(bytes);
expect(env.body?.targetUid).toBe('cached-self');
expect(env.body?.targetUids).toEqual(['cached-self']);
});
it('falls back to resolveUserUid for self when cache is empty', async () => {
const deps = makeDeps({
cachedSelfUid: null,
resolveUserUid: vi.fn(async () => 'fresh-self') as any,
responseBody: { userLikeInfos: [{ uid: 'fresh-self', time: 0n, favoriteInfo: {}, voteInfo: {} }] },
responseBody: { userLikeInfos: [{ uid: 'fresh-self', time: 0, favoriteInfo: {}, voteInfo: {} }] },
});
await GetLike.invoke(deps, {});
expect(deps.resolveUserUid).toHaveBeenCalledWith(10001);
@@ -53,10 +63,21 @@ describe('GetLike namespace', () => {
it('resolves other users via resolveUserUid', async () => {
const deps = makeDeps({
responseBody: { userLikeInfos: [{ uid: 'uid-of-99999', time: 0n, favoriteInfo: {}, voteInfo: {} }] },
responseBody: { userLikeInfos: [{ uid: 'uid-of-99999', time: 0, favoriteInfo: {}, voteInfo: {} }] },
});
await GetLike.invoke(deps, { userId: 99999 });
expect(deps.resolveUserUid).toHaveBeenCalledWith(99999);
expect(deps.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x7ed_12');
});
it('treats an explicit self uin as a self query', async () => {
const deps = makeDeps({
cachedSelfUid: 'cached-self',
responseBody: { userLikeInfos: [{ uid: 'cached-self', time: 0 }] },
});
await GetLike.invoke(deps, { userId: 10001 });
expect(deps.resolveUserUid).not.toHaveBeenCalled();
expect(deps.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x7ed_13');
});
it('throws when self uin is invalid and cache is empty', async () => {
@@ -67,21 +88,22 @@ describe('GetLike namespace', () => {
});
describe('serialize', () => {
it('always sets basic=1, vote=1, favorite=1 (full breakdown query)', async () => {
it('requests the profile-backed vote list', async () => {
const deps = makeDeps({
responseBody: { userLikeInfos: [{ uid: 'u', time: 0n, favoriteInfo: {}, voteInfo: {} }] },
responseBody: { userLikeInfos: [{ uid: 'u', time: 0, favoriteInfo: {}, voteInfo: {} }] },
});
await GetLike.invoke(deps, { userId: 1 });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<Oidb0x7edReq>>(bytes);
expect(env.body?.basic).toBe(1);
expect(env.body?.vote).toBe(1);
expect(env.body?.favorite).toBe(1);
expect(env.body?.favorite ?? 0).toBe(0);
expect(env.body?.userProfile).toBe(1);
});
it('threads start / limit through to the request', async () => {
const deps = makeDeps({
responseBody: { userLikeInfos: [{ uid: 'u', time: 0n, favoriteInfo: {}, voteInfo: {} }] },
responseBody: { userLikeInfos: [{ uid: 'u', time: 0, favoriteInfo: {}, voteInfo: {} }] },
});
await GetLike.invoke(deps, { userId: 1, start: 5, limit: 50 });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
@@ -92,7 +114,7 @@ describe('GetLike namespace', () => {
it('defaults start=0 / limit=10', async () => {
const deps = makeDeps({
responseBody: { userLikeInfos: [{ uid: 'u', time: 0n, favoriteInfo: {}, voteInfo: {} }] },
responseBody: { userLikeInfos: [{ uid: 'u', time: 0, favoriteInfo: {}, voteInfo: {} }] },
});
await GetLike.invoke(deps, { userId: 1 });
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
@@ -104,20 +126,74 @@ describe('GetLike namespace', () => {
describe('deserialize', () => {
it('shapes favorite + vote info with the expected key names', () => {
const out = GetLike.deserialize({} as any, {
const deps = makeDeps({
findUinByUid: uid => uid === 'vote-user' ? 12345 : null,
});
const out = GetLike.deserialize(deps, {
userLikeInfos: [{
uid: 'u', time: 1700000000n,
favoriteInfo: { totalCount: 5, lastTime: 1n, newCount: 1 },
voteInfo: { totalCount: 7, newCount: 2, lastTime: 2n },
uid: 'u', time: 1700000000,
favoriteInfo: {
totalCount: 5,
lastTime: 1,
todayCount: 1,
userInfos: [{ uid: 'favorite-user', nick: '收藏者', count: 3 }],
},
voteInfo: {
totalCount: 7,
newCount: 2,
newNearbyCount: 1,
lastVisitTime: 2,
userInfos: [{
uid: 'vote-user',
src: 4,
latestTime: 3,
count: 2,
giftCount: 1,
customId: 5,
lastCharged: 6,
availableCount: 7,
todayVotedCount: 8,
nick: '点赞者',
gender: 1,
age: 20,
isFriend: true,
isVip: true,
isSvip: false,
}],
},
}],
});
expect(out.uid).toBe('u');
expect(out.time).toBe(1700000000);
expect(out.favoriteInfo).toEqual({
total_count: 5, last_time: 1, today_count: 1, userInfos: [],
total_count: 5,
last_time: 1,
today_count: 1,
userInfos: [expect.objectContaining({ uid: 'favorite-user', nick: '收藏者', count: 3 })],
});
expect(out.voteInfo).toEqual({
total_count: 7, new_count: 2, new_nearby_count: 0, last_visit_time: 2, userInfos: [],
total_count: 7,
new_count: 2,
new_nearby_count: 1,
last_visit_time: 2,
userInfos: [expect.objectContaining({
uid: 'vote-user',
uin: 12345,
src: 4,
latestTime: 3,
count: 2,
giftCount: 1,
customId: 5,
lastCharged: 6,
bAvailableCnt: 7,
bTodayVotedCnt: 8,
nick: '点赞者',
gender: 1,
age: 20,
isFriend: true,
isvip: true,
isSvip: false,
})],
});
});
@@ -126,8 +202,14 @@ describe('GetLike namespace', () => {
expect(() => GetLike.deserialize({} as any, { userLikeInfos: [] })).toThrow('get profile like info empty');
});
it('throws when a returned user item has no uid', () => {
expect(() => GetLike.deserialize(makeDeps(), {
userLikeInfos: [{ uid: 'u', voteInfo: { userInfos: [{ nick: 'broken' }] } }],
})).toThrow('get profile like user uid missing');
});
it('defaults all count fields to 0 when omitted', () => {
const out = GetLike.deserialize({} as any, { userLikeInfos: [{ uid: 'u', time: 0n }] });
const out = GetLike.deserialize(makeDeps(), { userLikeInfos: [{ uid: 'u', time: 0 }] });
expect(out.favoriteInfo.total_count).toBe(0);
expect(out.voteInfo.total_count).toBe(0);
});