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
@@ -51,6 +51,7 @@ import {
|
||||
FileUploadExtSchema,
|
||||
} from '../src/bridge/proto/highway';
|
||||
import { makeOidbBaseSchema, OidbSvcTrpcTcp0xFE5_2ResponseSchema } from '../src/bridge/proto/oidb';
|
||||
import { makeOidbEnvelope, encodeOidbEnv, decodeOidbEnv } from '../src/bridge/bridge-oidb';
|
||||
|
||||
import type {
|
||||
SendLongMsgResp,
|
||||
@@ -618,6 +619,24 @@ describe('proton ↔ legacy parity (longmsg subset)', () => {
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodeOidbEnv<T> pass-through wrapper byte-equivalent to direct codec', () => {
|
||||
// The bridge-oidb.ts module exposes encodeOidbEnv<T> / decodeOidbEnv<T>
|
||||
// as pure pass-through wrappers around protobuf_encode/decode<OidbBase<T>>.
|
||||
// Proton wrapper-binds them and substitutes each call site with the
|
||||
// monomorphized codec, so byte-output must match a direct call.
|
||||
const body: OidbSvcTrpcTcp0xFE5_2Response = {
|
||||
groups: [{ groupUin: 100, info: { groupName: 'G' } }],
|
||||
};
|
||||
const env = makeOidbEnvelope<OidbSvcTrpcTcp0xFE5_2Response>(0xFE5, 2, body, false);
|
||||
const viaWrapper = encodeOidbEnv<OidbSvcTrpcTcp0xFE5_2Response>(env);
|
||||
const viaDirect = protobuf_encode<OidbBase<OidbSvcTrpcTcp0xFE5_2Response>>(env);
|
||||
expect(hex(viaWrapper)).toBe(hex(viaDirect));
|
||||
|
||||
const back = decodeOidbEnv<OidbSvcTrpcTcp0xFE5_2Response>(viaWrapper);
|
||||
expect(back.body?.groups?.[0]?.groupUin).toBe(100);
|
||||
expect(back.body?.groups?.[0]?.info?.groupName).toBe('G');
|
||||
});
|
||||
|
||||
it('round-trips OidbBase<T> with non-trivial nested body', () => {
|
||||
const body: OidbSvcTrpcTcp0xFE5_2Response = {
|
||||
groups: [{ groupUin: 100, info: { groupName: 'G' } }],
|
||||
|
||||
Reference in new issue
Block a user