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
72 lines
2.8 KiB
TypeScript
72 lines
2.8 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
|
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
|
runOidb: vi.fn(async () => new Uint8Array()),
|
|
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
|
encodeOidbEnv: vi.fn(() => new Uint8Array()),
|
|
decodeOidbEnv: vi.fn(() => ({ body: {} })),
|
|
}));
|
|
|
|
import * as oidb from '../../src/bridge/bridge-oidb';
|
|
import * as msg from '../../src/bridge/actions/group-message';
|
|
import { mockBridge } from './_helpers';
|
|
|
|
describe('actions/group-message', () => {
|
|
beforeEach(() => {
|
|
vi.mocked(oidb.runOidb).mockClear();
|
|
vi.mocked(oidb.makeOidbEnvelope).mockClear();
|
|
vi.mocked(oidb.encodeOidbEnv).mockClear();
|
|
vi.mocked(oidb.decodeOidbEnv).mockClear();
|
|
});
|
|
|
|
it('recallGroupMessage sends to SsoGroupRecallMsg with the group sequence', async () => {
|
|
const bridge = mockBridge();
|
|
await msg.recallGroupMessage(bridge as any, 12345, 999);
|
|
expect(bridge.sendRawPacket).toHaveBeenCalledOnce();
|
|
const [serviceCmd] = bridge.sendRawPacket.mock.calls[0]!;
|
|
expect(serviceCmd).toBe('trpc.msg.msg_svc.MsgService.SsoGroupRecallMsg');
|
|
});
|
|
|
|
it('recallGroupMessage throws when sendRawPacket reports failure', async () => {
|
|
const bridge = mockBridge({
|
|
sendRawPacket: vi.fn(async () => ({
|
|
success: false,
|
|
gotResponse: false,
|
|
errorCode: -1,
|
|
errorMessage: 'network down',
|
|
responseData: null,
|
|
})) as any,
|
|
});
|
|
await expect(msg.recallGroupMessage(bridge as any, 12345, 999))
|
|
.rejects.toThrow(/network down/);
|
|
});
|
|
|
|
it('recallPrivateMessage resolves the target UID before dispatch', async () => {
|
|
const bridge = mockBridge();
|
|
await msg.recallPrivateMessage(bridge as any, 10001, 100, 200, 123, 1700000000);
|
|
expect(bridge.resolveUserUid).toHaveBeenCalledWith(10001);
|
|
const [serviceCmd] = bridge.sendRawPacket.mock.calls[0]!;
|
|
expect(serviceCmd).toBe('trpc.msg.msg_svc.MsgService.SsoC2CRecallMsg');
|
|
});
|
|
|
|
it('markGroupMessageRead and markPrivateMessageRead both hit SsoReadedReport', async () => {
|
|
const bridge = mockBridge();
|
|
await msg.markGroupMessageRead(bridge as any, 12345, 50);
|
|
await msg.markPrivateMessageRead(bridge as any, 10001, 60);
|
|
expect(bridge.sendRawPacket).toHaveBeenCalledTimes(2);
|
|
const cmds = bridge.sendRawPacket.mock.calls.map((c: any) => c[0]);
|
|
expect(cmds).toEqual([
|
|
'trpc.msg.msg_svc.MsgService.SsoReadedReport',
|
|
'trpc.msg.msg_svc.MsgService.SsoReadedReport',
|
|
]);
|
|
});
|
|
|
|
it('setGroupEssence picks _1 for enable and _2 for disable', async () => {
|
|
const bridge = mockBridge();
|
|
await msg.setGroupEssence(bridge as any, 12345, 5, 7, true);
|
|
await msg.setGroupEssence(bridge as any, 12345, 5, 7, false);
|
|
const cmds = vi.mocked(oidb.runOidb).mock.calls.map(c => c[1]);
|
|
expect(cmds).toEqual(['OidbSvcTrpcTcp.0xeac_1', 'OidbSvcTrpcTcp.0xeac_2']);
|
|
});
|
|
});
|