refactor(oidb): migrate profile.ts OIDB cmds to namespaces

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.
This commit is contained in:
DrSmoothl committed 2026-05-22 23:29:55 +08:00
1 parent ff2b902cbd
commit a38f7ea26e
14 files changed
+760 -154

No files matched your search

+12 -2
View File
@@ -47,6 +47,12 @@ export interface OidbCallSpec<TReq, TResp, TParams, TResult> {
resolveSubCommand?(params: TParams): number;
/** Set OIDB envelope `reserved = 1` (UIN-form variant, see makeOidbEnvelope's isUid). */
uinForm?: boolean;
/** Override the default `OidbSvcTrpcTcp.0xNNNN_N` wire name. A few
* cmds route through different SSO names (e.g. 0xE17_0 lives at
* `MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0`); supply a function
* that takes the resolved `(cmd, subCmd)` and returns the actual
* wire name. Omit for the default scheme. */
wireName?(command: number, subCommand: number): string;
/** Business params → wire-shaped request body. */
serialize(params: TParams): TReq;
/** Wire-shaped response body → business result. */
@@ -88,7 +94,9 @@ export async function invokeOidb<TReq, TResp, TParams, TResult>(
const reqBody = spec.serialize(params);
const env = makeOidbEnvelope(spec.command, subCommand, reqBody, spec.uinForm ?? false);
const reqBytes = spec.encode(env);
const wireName = `OidbSvcTrpcTcp.0x${spec.command.toString(16)}_${subCommand}`;
const wireName = spec.wireName
? spec.wireName(spec.command, subCommand)
: `OidbSvcTrpcTcp.0x${spec.command.toString(16)}_${subCommand}`;
const result = await sender.sendRawPacket(wireName, reqBytes, timeoutMs);
if (!result.success) throw new Error(result.errorMessage || 'packet send failed');
@@ -127,7 +135,9 @@ export function buildOidbRequest<TReq, TResp, TParams, TResult>(
const reqBody = spec.serialize(params);
const env = makeOidbEnvelope(spec.command, subCommand, reqBody, spec.uinForm ?? false);
const bytes = spec.encode(env);
const wireName = `OidbSvcTrpcTcp.0x${spec.command.toString(16)}_${subCommand}`;
const wireName = spec.wireName
? spec.wireName(spec.command, subCommand)
: `OidbSvcTrpcTcp.0x${spec.command.toString(16)}_${subCommand}`;
return { wireName, bytes };
}