5 of profile.ts's methods were thin OIDB wrappers — migrated to the
new namespace pattern. The 5 non-OIDB methods (setOnlineStatus /
setDiyOnlineStatus / setAvatar / setGroupAvatar / fetchCustomFace)
stay on the facade unchanged — they hit `trpc.qq_new_tech.*`,
Highway, or `Faceroam.OpReq` directly and aren't in scope for the
OIDB-namespace refactor.
New namespaces (each with focused Pick<BridgeContext, …> deps):
- SetProfile (0x112A_2) — needs identity for uin
- SetSelfLongNick (0x112A_2) — same cmd different proto, ditto
- SetInputStatus (0xCD4_1) — needs resolveUserUid
- GetLike (0x7ED_12) — needs identity + resolveUserUid
- GetUnidirectionalFriendList (0xE17_0) — needs identity; non-standard
wire name handled via the new
wireName override on OidbCallSpec
Infrastructure tweak:
- OidbCallSpec gains an optional `wireName(cmd, sub) → string`. Most
cmds use the default `OidbSvcTrpcTcp.0xNNNN_N` scheme; 0xe17_0
routes through `MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0`.
Test mock updates:
- profile.test.ts moves the migrated cmds onto bridge.sendRawPacket
mock (the new path bypasses the bridge-oidb runOidb mock). Non-OIDB
cmds (setOnlineStatus, setAvatar, etc.) keep their existing mocks.
- 36 new namespace-level tests in @snowluma/bridge covering serialize
branches, deserialize edge cases, deps resolution, and e2e wire
routing.
Verification:
- pnpm -r typecheck: green
- @snowluma/bridge: 12 files / 118 tests
- @snowluma/core: 33 files / 302 tests
Wire shape unchanged across migrated cmds — same bytes produced.
55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { protobuf_decode } from '@snowluma/proton';
|
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
|
import type { Oidb0xcd4Req } from '@snowluma/proto-defs/oidb-actions/base';
|
|
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
|
|
|
import { SetInputStatus } from '../../../src/oidb-services/profile/set-input-status';
|
|
|
|
function makeDeps(uid: string | null = 'resolved-uid') {
|
|
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
|
|
return {
|
|
sendRawPacket: vi.fn(async () => r),
|
|
resolveUserUid: vi.fn(async () => uid as string),
|
|
};
|
|
}
|
|
|
|
describe('SetInputStatus namespace', () => {
|
|
it('declares 0xCD4_1', () => {
|
|
expect(SetInputStatus.command).toBe(0xCD4);
|
|
expect(SetInputStatus.subCommand).toBe(1);
|
|
});
|
|
|
|
describe('invoke', () => {
|
|
it('routes to OidbSvcTrpcTcp.0xcd4_1', async () => {
|
|
const deps = makeDeps();
|
|
await SetInputStatus.invoke(deps, { userId: 10001, eventType: 1 });
|
|
expect(deps.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0xcd4_1');
|
|
});
|
|
|
|
it('resolves the target uid before encoding', async () => {
|
|
const deps = makeDeps();
|
|
await SetInputStatus.invoke(deps, { userId: 10001, eventType: 1 });
|
|
expect(deps.resolveUserUid).toHaveBeenCalledWith(10001);
|
|
});
|
|
|
|
it('packages uid + chatType=0 + eventType into reqBody', async () => {
|
|
const deps = makeDeps('alice-uid');
|
|
await SetInputStatus.invoke(deps, { userId: 10001, eventType: 7 });
|
|
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
|
const env = protobuf_decode<OidbBase<Oidb0xcd4Req>>(bytes);
|
|
expect(env.body?.reqBody?.uid).toBe('alice-uid');
|
|
// chatType=0 is proto3 default — omitted on the wire, comes back as null/undefined.
|
|
expect(env.body?.reqBody?.chatType ?? 0).toBe(0);
|
|
expect(env.body?.reqBody?.eventType).toBe(7);
|
|
});
|
|
|
|
it('throws when the target uid cannot be resolved', async () => {
|
|
const deps = makeDeps(null);
|
|
await expect(SetInputStatus.invoke(deps, { userId: 10001, eventType: 1 }))
|
|
.rejects.toThrow('target uid not found');
|
|
expect(deps.sendRawPacket).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|