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

+66 -3
View File
@@ -173,22 +173,35 @@ describe('apis/profile', () => {
it('getProfileLike (self): resolves self UID, returns formatted favorite + vote info', async () => {
const bridge = mockBridge();
bridge.identity.findUinByUid.mockImplementation(
(uid: string) => uid === 'liker-uid' ? 20002 : 0,
);
bridge.sendRawPacket.mockResolvedValueOnce({
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<Oidb0x7edResp>>({
body: {
userLikeInfos: [{
uid: 'u',
time: 1700000000n,
favoriteInfo: { totalCount: 5, lastTime: 1n, newCount: 1 },
voteInfo: { totalCount: 7, newCount: 2, lastTime: 2n },
time: 1700000000,
favoriteInfo: { totalCount: 5, lastTime: 1, todayCount: 1 },
voteInfo: {
totalCount: 7,
newCount: 2,
newNearbyCount: 1,
lastVisitTime: 2,
userInfos: [{ uid: 'liker-uid', nick: '点赞者', count: 3 }],
},
}],
} as any,
})),
});
const out = await new ProfileApi(bridge as any).getLike();
expect(bridge.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x7ed_13');
expect(out.favoriteInfo.total_count).toBe(5);
expect(out.voteInfo.total_count).toBe(7);
expect(out.voteInfo.userInfos).toEqual([
expect.objectContaining({ uid: 'liker-uid', uin: 20002, nick: '点赞者', count: 3 }),
]);
});
it('getProfileLike throws on empty result', async () => {
@@ -200,6 +213,56 @@ describe('apis/profile', () => {
await expect(new ProfileApi(bridge as any).getLike()).rejects.toThrow(/empty/);
});
it('getProfileLike resolves uncached liker uins from their profiles', async () => {
const bridge = mockBridge();
bridge.identity.findUinByUid.mockReturnValue(null);
const fetchUserProfileByUid = vi.fn(async (uid: string) => ({
uid,
uin: 30003,
nickname: '陌生点赞者',
}));
(bridge.apis.contacts as any).fetchUserProfileByUid = fetchUserProfileByUid;
bridge.sendRawPacket.mockResolvedValueOnce({
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<Oidb0x7edResp>>({
body: {
userLikeInfos: [{
uid: 'self-uid',
voteInfo: { userInfos: [{ uid: 'stranger-uid', nick: '陌生点赞者' }] },
}],
},
})),
});
const out = await new ProfileApi(bridge as any).getLike();
expect(fetchUserProfileByUid).toHaveBeenCalledOnce();
expect(fetchUserProfileByUid).toHaveBeenCalledWith('stranger-uid');
expect(out.voteInfo.userInfos[0]?.uin).toBe(30003);
});
it('getProfileLike surfaces failures while resolving uncached liker uins', async () => {
const bridge = mockBridge();
bridge.identity.findUinByUid.mockReturnValue(null);
(bridge.apis.contacts as any).fetchUserProfileByUid = vi.fn(async () => {
throw new Error('profile lookup failed');
});
bridge.sendRawPacket.mockResolvedValueOnce({
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<Oidb0x7edResp>>({
body: {
userLikeInfos: [{
uid: 'self-uid',
voteInfo: { userInfos: [{ uid: 'stranger-uid' }] },
}],
},
})),
});
await expect(new ProfileApi(bridge as any).getLike())
.rejects.toThrow('profile lookup failed');
});
it('getUnidirectionalFriendList parses the embedded JSON body', async () => {
const bridge = mockBridge();
bridge.sendRawPacket.mockResolvedValueOnce({