feat(proton): add proton/oidb.ts with generic OidbBase<T> envelope
Phase 1 of the OIDB migration: stages the proton-side type definitions
and pins their wire equivalence to the legacy makeOidbBaseSchema()
runtime factory. No call sites are switched yet — that lands in
phase 2 along with the proton/oidb-action.ts schema mirror and the
runOidb refactor.
The legacy bridge/proto/oidb.ts exports a `makeOidbBaseSchema(body)`
factory function that synthesizes the OidbSvcTrpcTcpBase envelope
ProtoSchema at runtime. Proton is compile-time, so the natural form
is the generic interface
OidbBase<T> { command, subCommand, errorCode, body: T, errorMsg,
properties, reserved }
which the plugin monomorphizes per-instantiation. This is exactly the
"generic template with generic-instantiated field" usage that this
package's earlier edge-case fixes #2 and #3 were designed to support,
and the new parity test pins that they actually work on the real
shape (a fully populated OidbSvcTrpcTcp0xFE5_2Response with nested
groupOwner/customInfo).
Also added:
- OidbProperty (for the envelope.properties repeated field)
- OidbBaseMeta — envelope-only view for fire-and-check OIDB calls
that just need to peek at errorCode without decoding the body
- All 8 concrete schemas from oidb.ts (FriendList, GroupList,
GroupMemberList, GroupRequest families)
Verification:
- 2 new parity tests
* OidbBase<OidbSvcTrpcTcp0xFE5_2Response> ↔ makeOidbBaseSchema
byte equivalence
* round-trip encode → decode preserves nested body
- 602+2 = 604 core tests pass (network-manager file still env-fails
on missing native binary)
- tsc --noEmit clean
This commit is contained in:
2 files changed
+234
No files matched your search
@@ -50,6 +50,7 @@ import {
|
||||
NTV2RichMediaHighwayExtSchema,
|
||||
FileUploadExtSchema,
|
||||
} from '../src/bridge/proto/highway';
|
||||
import { makeOidbBaseSchema, OidbSvcTrpcTcp0xFE5_2ResponseSchema } from '../src/bridge/proto/oidb';
|
||||
|
||||
import type {
|
||||
SendLongMsgResp,
|
||||
@@ -94,6 +95,10 @@ import type {
|
||||
NTV2RichMediaHighwayExt,
|
||||
FileUploadExt,
|
||||
} from '../src/bridge/proto/proton/highway';
|
||||
import type {
|
||||
OidbBase,
|
||||
OidbSvcTrpcTcp0xFE5_2Response,
|
||||
} from '../src/bridge/proto/proton/oidb';
|
||||
|
||||
function hex(buf: Uint8Array): string {
|
||||
return Buffer.from(buf).toString('hex');
|
||||
@@ -579,6 +584,55 @@ describe('proton ↔ legacy parity (longmsg subset)', () => {
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
// ── oidb.ts coverage (OidbBase<T> generic envelope) ────────────────
|
||||
|
||||
it('encodes OidbBase<OidbSvcTrpcTcp0xFE5_2Response> identically to makeOidbBaseSchema', () => {
|
||||
// This is the exact pattern runOidb uses for the OIDB envelope. Proton's
|
||||
// OidbBase<T> generic interface should monomorphize to a codec that is
|
||||
// byte-equivalent to the legacy makeOidbBaseSchema(InnerSchema) factory.
|
||||
// The inner Body type used here is a real schema (group-list response).
|
||||
const body: OidbSvcTrpcTcp0xFE5_2Response = {
|
||||
groups: [
|
||||
{
|
||||
groupUin: 555,
|
||||
info: {
|
||||
groupOwner: { uid: 'u_owner' },
|
||||
createdTime: 1234567890, memberMax: 100, memberCount: 50,
|
||||
groupName: 'TestGroup', description: 'desc', question: 'q?',
|
||||
announcement: 'announcement',
|
||||
},
|
||||
customInfo: { remark: 'remark' },
|
||||
},
|
||||
],
|
||||
};
|
||||
const envelope = {
|
||||
command: 0xFE5,
|
||||
subCommand: 2,
|
||||
errorCode: 1, // non-zero so it isn't proto3-omitted
|
||||
body,
|
||||
errorMsg: 'ok',
|
||||
reserved: 1,
|
||||
};
|
||||
const legacy = protoEncode(envelope as any, makeOidbBaseSchema(OidbSvcTrpcTcp0xFE5_2ResponseSchema));
|
||||
const proton = protobuf_encode<OidbBase<OidbSvcTrpcTcp0xFE5_2Response>>(envelope);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('round-trips OidbBase<T> with non-trivial nested body', () => {
|
||||
const body: OidbSvcTrpcTcp0xFE5_2Response = {
|
||||
groups: [{ groupUin: 100, info: { groupName: 'G' } }],
|
||||
};
|
||||
const envelope: OidbBase<OidbSvcTrpcTcp0xFE5_2Response> = {
|
||||
command: 0xFE5, subCommand: 2, errorCode: 1, body, errorMsg: 'ok', reserved: 1,
|
||||
};
|
||||
const encoded = protobuf_encode<OidbBase<OidbSvcTrpcTcp0xFE5_2Response>>(envelope);
|
||||
const decoded = protobuf_decode<OidbBase<OidbSvcTrpcTcp0xFE5_2Response>>(encoded);
|
||||
expect(decoded.command).toBe(0xFE5);
|
||||
expect(decoded.errorCode).toBe(1);
|
||||
expect(decoded.body?.groups?.[0]?.groupUin).toBe(100);
|
||||
expect(decoded.body?.groups?.[0]?.info?.groupName).toBe('G');
|
||||
});
|
||||
|
||||
// ── Documented divergence: proto3 default-value omission ────────────
|
||||
|
||||
it('proton omits default-valued numeric fields (legacy emits them)', () => {
|
||||
|
||||
Reference in new issue
Block a user