fix(friend): verify and synchronize remark updates
Validate the service result before reporting friend remark changes as successful. Rejected, incomplete, or contradictory confirmations now reach callers instead of being reported as completed. Keep confirmed remarks synchronized in the identity cache and consume cross-client remark updates without exposing a new OneBot event. Local cache failures remain observable without turning an already completed remote change into a retryable failure. Preserve friend remarks exactly across restarts and add request, response, persistence, receive-pipeline, and action-level regression coverage. Fixes #303.
This commit is contained in:
17 files changed
+511
-18
No files matched your search
@@ -128,6 +128,7 @@ export interface MockBridge {
|
||||
findUidByUin: ReturnType<typeof vi.fn>;
|
||||
findUinByUid: ReturnType<typeof vi.fn>;
|
||||
findGroupMember: ReturnType<typeof vi.fn>;
|
||||
updateFriendRemark: ReturnType<typeof vi.fn>;
|
||||
forgetGroup: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
events: { emit: ReturnType<typeof vi.fn> };
|
||||
@@ -160,6 +161,7 @@ export function mockBridge(overrides: Partial<MockBridge> = {}): MockBridge {
|
||||
findUidByUin: vi.fn(() => 'cached-uid'),
|
||||
findUinByUid: vi.fn(() => 0),
|
||||
findGroupMember: vi.fn(() => null),
|
||||
updateFriendRemark: vi.fn(() => true),
|
||||
forgetGroup: vi.fn(),
|
||||
...(overrides.identity ?? {}),
|
||||
} as MockBridge['identity'],
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { subscribeLogs, type LogEntry } from '@snowluma/common/logger';
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type {
|
||||
OidbDeleteFriend,
|
||||
OidbFriendRequestAction,
|
||||
OidbSetFriendRemarkResponse,
|
||||
} from '@snowluma/proto-defs/oidb-actions/base';
|
||||
|
||||
// Post-namespace migration: FriendApi is a thin facade over the
|
||||
@@ -65,10 +66,27 @@ describe('apis/friend', () => {
|
||||
});
|
||||
|
||||
it('setRemark uses the current set command for a non-empty remark', async () => {
|
||||
const bridge = mockBridge();
|
||||
const bridge = mockBridge({
|
||||
sendRawPacket: vi.fn(async () => ({
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData: Buffer.from(protobuf_encode<OidbBase<OidbSetFriendRemarkResponse>>({
|
||||
body: {
|
||||
result: {
|
||||
target: { targetUid: 'resolved-uid', targetUin: 10001n },
|
||||
remark: 'best-friend',
|
||||
},
|
||||
},
|
||||
})),
|
||||
})),
|
||||
});
|
||||
await new FriendApi(bridge as any).setRemark(10001, 'best-friend');
|
||||
expect(bridge.sendRawPacket.mock.calls[0]![0])
|
||||
.toBe('OidbSvcTrpcTcp.0x912e_0');
|
||||
expect(bridge.identity.updateFriendRemark)
|
||||
.toHaveBeenCalledWith('resolved-uid', 10001, 'best-friend');
|
||||
});
|
||||
|
||||
it('setRemark uses the dedicated clear command for an empty remark', async () => {
|
||||
|
||||
@@ -328,6 +328,7 @@ describe('apis/group-file', () => {
|
||||
findUidByUin: vi.fn(() => 'cached-uid'),
|
||||
findUinByUid: vi.fn(() => 0),
|
||||
findGroupMember: vi.fn(() => null),
|
||||
updateFriendRemark: vi.fn(() => true),
|
||||
forgetGroup: vi.fn(),
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user