feat(proton): finish OIDB migration — runOidb on protobuf_encode<OidbBase<T>>
Closes the OIDB phase of the proton migration. Every consumer that
talked to the OIDB service through the old runtime
`makeOidbBaseSchema()` factory now goes through the compile-time
generic `OidbBase<T>` instead — proton monomorphizes the codec per
call-site instantiation.
@snowluma/proton — two analyzer fixes uncovered by the migration:
1. Skip queuing call-site type-args that reference an *enclosing
generic function's* type parameter for monomorphization. Before
this, a wrapper like
export function encodeOidbEnv<T>(env: OidbBase<T>): Uint8Array {
return protobuf_encode<OidbBase<T>>(env);
}
would cause the analyzer to mint a literal `OidbBase__T` registry
entry with `body.typeName = 'T'`, which the post-walk wire-type
guard then tripped on. The enclosing-scope type params are tracked
on a stack as the walker descends into FunctionDeclaration,
FunctionExpression, ArrowFunction, MethodDeclaration nodes; matching
call sites are skipped (the wrapper-binding path is still
responsible for materialising concrete codecs at downstream call
sites).
2. Register *explicitly* empty interfaces (`interface X {}`) as
zero-field proto messages. OIDB has a handful of these
('this call has no meaningful response body' placeholders —
Oidb0xeb7Resp, Oidb0xcd4Resp, Oidb0x112aResp, Oidb0x8a0Resp,
Oidb0xf16Resp, OidbClientKeyReq). Proto3 wire allows zero-field
messages, and downstream code does `protobuf_decode<OidbBase<X>>`
where X is one of these — the wire-type guard would otherwise trip
on the missing `X` registration. Interfaces that have members but
no pb-marked fields are still NOT registered.
@snowluma/core — the OIDB-layer refactor itself:
bridge-oidb.ts ditches the runtime ProtoSchema factory and exposes:
- makeOidbEnvelope<T>(oidbCmd, subCmd, body, isUid) pure helper
- encodeOidbEnv<T>(env) pass-through
- decodeOidbEnv<T>(bytes) pass-through
- runOidb(bridge, cmd, envelopeBytes) non-generic raw
`encodeOidbEnv` / `decodeOidbEnv` are pure pass-through generic
wrappers — proton wrapper-binds them and substitutes every call site
with the inlined `protobuf_encode_OidbBase__X` / `protobuf_decode_…`
function. `runOidb` is non-generic (proton leaves it alone) so it can
be mocked in tests. `makeOidbEnvelope` is plain TS — also mockable for
introspection.
56 `runOidb` call sites across 11 files migrated to the new API:
- bridge-contacts.ts, actions/extras.ts, actions/friend.ts,
actions/group-admin.ts, actions/group-file.ts,
actions/group-message.ts, actions/interaction.ts,
actions/misc.ts, actions/profile.ts, web-actions/cookies.ts,
highway/pipeline.ts
pipeline.ts also drops `makeOidbBaseSchema(NTV2UploadRichMediaReqSchema)`
and the residual `protoEncode({...}, EncodableMediaMsgInfoSchema)` —
both go through proton now.
Tests:
- 8 test files migrated from `vi.mocked(decodeOidbEnv).mockReturnValueOnce`
to `vi.mocked(runOidb).mockResolvedValueOnce(protobuf_encode<OidbBase<X>>({body: …}))`
— the proton substitution means the old mock layer is bypassed at
build time, so the only mockable point is the bytes layer at `runOidb`.
- 2 new parity tests pinning `OidbBase<T>` ↔ legacy
`makeOidbBaseSchema(InnerSchema)` byte equivalence.
Verification:
- @snowluma/proton: 95/95 tests pass, tsc --noEmit clean
- @snowluma/core: 605/605 tests pass (network-manager.test.ts
fails to load due to a missing darwin-arm64 native binary in this
environment — pre-existing), tsc --noEmit clean
This commit is contained in:
25 files changed
+1144
-977
No files matched your search
@@ -4,17 +4,19 @@
|
||||
|
||||
import type { Bridge } from '../bridge';
|
||||
import { protoDecode, protoEncode } from '../../protobuf/decode';
|
||||
import { runOidb } from '../bridge-oidb';
|
||||
import { runOidb, makeOidbEnvelope, encodeOidbEnv, decodeOidbEnv } from '../bridge-oidb';
|
||||
import {
|
||||
MiniAppShareReqSchema,
|
||||
MiniAppShareRespSchema,
|
||||
Oidb0x112eReqSchema,
|
||||
Oidb0x112eRespSchema,
|
||||
Oidb0x990ReqSchema,
|
||||
Oidb0x990RespSchema,
|
||||
Oidb0xeb7ReqSchema,
|
||||
Oidb0xeb7RespSchema,
|
||||
} from '../proto/oidb-action';
|
||||
import type {
|
||||
Oidb0x112eReq,
|
||||
Oidb0x112eResp,
|
||||
Oidb0x990Req,
|
||||
Oidb0x990Resp,
|
||||
Oidb0xeb7Req,
|
||||
Oidb0xeb7Resp,
|
||||
} from '../proto/proton/oidb-action';
|
||||
|
||||
export async function translateEn2Zh(
|
||||
bridge: Bridge,
|
||||
@@ -30,12 +32,9 @@ export async function translateEn2Zh(
|
||||
tag12: 1,
|
||||
};
|
||||
|
||||
const result = await runOidb<any>(bridge, {
|
||||
cmd: 'OidbSvcTrpcTcp.0x990_2',
|
||||
oidbCmd: 0x990, subCmd: 2,
|
||||
request: { schema: Oidb0x990ReqSchema, value: req },
|
||||
response: { schema: Oidb0x990RespSchema },
|
||||
});
|
||||
const env = makeOidbEnvelope<Oidb0x990Req>(0x990, 2, req);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x990_2', encodeOidbEnv<Oidb0x990Req>(env));
|
||||
const result = decodeOidbEnv<Oidb0x990Resp>(respBytes).body;
|
||||
|
||||
const resp = result?.translateResp;
|
||||
if (!resp) {
|
||||
@@ -122,12 +121,9 @@ export async function clickInlineKeyboardButton(
|
||||
unknown9: 1,
|
||||
};
|
||||
|
||||
const result = await runOidb<any>(bridge, {
|
||||
cmd: 'OidbSvcTrpcTcp.0x112e_1',
|
||||
oidbCmd: 0x112E, subCmd: 1,
|
||||
request: { schema: Oidb0x112eReqSchema, value: req },
|
||||
response: { schema: Oidb0x112eRespSchema },
|
||||
});
|
||||
const env = makeOidbEnvelope<Oidb0x112eReq>(0x112E, 1, req);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0x112e_1', encodeOidbEnv<Oidb0x112eReq>(env));
|
||||
const result = decodeOidbEnv<Oidb0x112eResp>(respBytes).body;
|
||||
|
||||
if (!result) {
|
||||
throw new Error('click inline keyboard button result empty');
|
||||
@@ -155,10 +151,8 @@ export async function sendGroupSign(
|
||||
},
|
||||
};
|
||||
|
||||
await runOidb<any>(bridge, {
|
||||
cmd: 'OidbSvcTrpcTcp.0xEB7_1',
|
||||
oidbCmd: 0xEB7, subCmd: 1,
|
||||
request: { schema: Oidb0xeb7ReqSchema, value: req },
|
||||
response: { schema: Oidb0xeb7RespSchema },
|
||||
});
|
||||
const env = makeOidbEnvelope<Oidb0xeb7Req>(0xEB7, 1, req);
|
||||
const respBytes = await runOidb(bridge, 'OidbSvcTrpcTcp.0xEB7_1', encodeOidbEnv<Oidb0xeb7Req>(env));
|
||||
// Decode just to maintain the original behaviour of "consume the response".
|
||||
decodeOidbEnv<Oidb0xeb7Resp>(respBytes);
|
||||
}
|
||||
Reference in new issue
Block a user