Remove bridge proto schemas and parity test
Delete proto schema modules under packages/core/src/bridge/proto (action.ts, element.ts, highway.ts, longmsg.ts, message.ts, notify.ts, oidb-action.ts, oidb.ts) and the related test packages/core/tests/proton-parity.test.ts. These files contained protobuf schema definitions for the bridge layer; remove them as part of a cleanup/refactor. Update any imports or references to these modules to their new locations or replacements.
This commit is contained in:
1 parent
02bab710b8
commit
5ea1c3a961
45 files changed
+1361
-4230
No files matched your search
@@ -3,9 +3,11 @@ import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
|
||||
import type {
|
||||
OidbStrangerStatusResp,
|
||||
} from '../../src/bridge/proto/proton/oidb-actions/base';
|
||||
import type {
|
||||
OidbAiVoiceListResp,
|
||||
OidbAiVoiceResp,
|
||||
} from '../../src/bridge/proto/proton/oidb-action';
|
||||
} from '../../src/bridge/proto/proton/oidb-actions/media';
|
||||
|
||||
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
|
||||
// that the plugin substitutes at the call site with the inlined codec, so
|
||||
|
||||
@@ -44,13 +44,13 @@ vi.mock('../../src/bridge/element-builder', () => ({
|
||||
buildSendElems: buildSendElemsMock,
|
||||
}));
|
||||
|
||||
import { protoEncode } from '../../src/protobuf/decode';
|
||||
import { SendLongMsgRespSchema } from '../../src/bridge/proto/longmsg';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { SendLongMsgResp } from '../../src/bridge/proto/proton/longmsg';
|
||||
import * as forward from '../../src/bridge/actions/forward';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
function uploadResponseWithResId(resId: string) {
|
||||
const encoded = protoEncode({ result: { resId } }, SendLongMsgRespSchema);
|
||||
const encoded = protobuf_encode<SendLongMsgResp>({ result: { resId } });
|
||||
return {
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
|
||||
@@ -14,13 +14,13 @@ vi.mock('../../src/bridge/element-builder', () => ({
|
||||
buildSendElems: vi.fn(async () => []),
|
||||
}));
|
||||
|
||||
import { protoEncode } from '../../src/protobuf/decode';
|
||||
import { SendLongMsgRespSchema } from '../../src/bridge/proto/longmsg';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { SendLongMsgResp } from '../../src/bridge/proto/proton/longmsg';
|
||||
import * as forward from '../../src/bridge/actions/forward';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
function uploadResponseWithResId(resId: string) {
|
||||
const encoded = protoEncode({ result: { resId } }, SendLongMsgRespSchema);
|
||||
const encoded = protobuf_encode<SendLongMsgResp>({ result: { resId } });
|
||||
return {
|
||||
success: true,
|
||||
gotResponse: true,
|
||||
|
||||
@@ -15,8 +15,6 @@ describe('actions/friend', () => {
|
||||
beforeEach(() => {
|
||||
vi.mocked(oidb.runOidb).mockClear();
|
||||
vi.mocked(oidb.makeOidbEnvelope).mockClear();
|
||||
vi.mocked(oidb.encodeOidbEnv).mockClear();
|
||||
vi.mocked(oidb.decodeOidbEnv).mockClear();
|
||||
});
|
||||
|
||||
it('setFriendAddRequest: numeric input is treated as UIN and resolved', async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
|
||||
import type { Oidb0x8a7Resp } from '../../src/bridge/proto/proton/oidb-action';
|
||||
import type { Oidb0x8a7Resp } from '../../src/bridge/proto/proton/oidb-actions/base';
|
||||
|
||||
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
|
||||
// that the plugin substitutes at the call site with the inlined codec, so
|
||||
|
||||
@@ -5,10 +5,12 @@ import type {
|
||||
OidbGroupFileCountViewResp,
|
||||
OidbGroupFileResp,
|
||||
OidbGroupFileViewResp,
|
||||
OidbPrivateFileUploadResp,
|
||||
OidbGroupFileFolderResp,
|
||||
} from '../../src/bridge/proto/proton/oidb-actions/group-file';
|
||||
import type {
|
||||
OidbPrivateFileUploadResp,
|
||||
NTV2RichMediaResp,
|
||||
} from '../../src/bridge/proto/proton/oidb-action';
|
||||
} from '../../src/bridge/proto/proton/oidb-actions/media';
|
||||
|
||||
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
|
||||
// (substituted at the call site with the inlined codec). Mocking them on
|
||||
|
||||
@@ -15,8 +15,6 @@ 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 () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
|
||||
import type { Oidb0x9083Resp } from '../../src/bridge/proto/proton/oidb-action';
|
||||
import type { Oidb0x9083Resp } from '../../src/bridge/proto/proton/oidb-actions/base';
|
||||
|
||||
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
|
||||
// that the plugin substitutes at the call site for the inlined codec.
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
|
||||
import type {
|
||||
Oidb0x990Resp,
|
||||
Oidb0x112eResp,
|
||||
} from '../../src/bridge/proto/proton/oidb-action';
|
||||
} from '../../src/bridge/proto/proton/oidb-actions/base';
|
||||
|
||||
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
|
||||
// — the plugin substitutes them at the call site with the inlined codec,
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
|
||||
import type {
|
||||
GroupAvatarExtra,
|
||||
Oidb0x7edResp,
|
||||
Oidb0xe17Resp,
|
||||
} from '../../src/bridge/proto/proton/oidb-action';
|
||||
SetStatusReq,
|
||||
SetStatusResp,
|
||||
} from '../../src/bridge/proto/proton/oidb-actions/base';
|
||||
|
||||
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
|
||||
// (substituted at the call site with the inlined codec). Mocking them on
|
||||
@@ -71,23 +74,19 @@ describe('actions/profile', () => {
|
||||
expect(serviceCmd).toBe('trpc.qq_new_tech.status_svc.StatusService.SetStatus');
|
||||
// Decode the wire bytes back through the same schema to assert
|
||||
// every field landed in the right place.
|
||||
const { protoDecode } = await import('../../src/protobuf/decode');
|
||||
const { SetStatusReqSchema } = await import('../../src/bridge/proto/oidb-action');
|
||||
const decoded = protoDecode(body as Uint8Array, SetStatusReqSchema);
|
||||
const decoded = protobuf_decode<SetStatusReq>(body as Uint8Array);
|
||||
expect(decoded).toMatchObject({
|
||||
status: 10,
|
||||
extStatus: 2000,
|
||||
batteryStatus: 0,
|
||||
customExt: { faceId: 1234, text: '摸鱼中', faceType: 2 },
|
||||
});
|
||||
expect(decoded.batteryStatus ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it('setDiyOnlineStatus surfaces server errors via the same path as setOnlineStatus', async () => {
|
||||
const bridge = mockBridge();
|
||||
// Build a response that decodes to errCode != 0.
|
||||
const { protoEncode } = await import('../../src/protobuf/decode');
|
||||
const { SetStatusRespSchema } = await import('../../src/bridge/proto/oidb-action');
|
||||
const respBuf = Buffer.from(protoEncode({ errCode: 1, errMsg: 'denied' }, SetStatusRespSchema));
|
||||
const respBuf = Buffer.from(protobuf_encode<SetStatusResp>({ errCode: 1, errMsg: 'denied' }));
|
||||
bridge.sendRawPacket.mockResolvedValueOnce({
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: respBuf,
|
||||
} as any);
|
||||
@@ -150,9 +149,7 @@ describe('actions/profile', () => {
|
||||
expect(cmdId).toBe(3000);
|
||||
// Decode the extra blob back through the schema and assert every
|
||||
// protocol-prescribed constant lands where it should.
|
||||
const { protoDecode } = await import('../../src/protobuf/decode');
|
||||
const { GroupAvatarExtraSchema } = await import('../../src/bridge/proto/oidb-action');
|
||||
const decoded = protoDecode(extend as Uint8Array, GroupAvatarExtraSchema);
|
||||
const decoded = protobuf_decode<GroupAvatarExtra>(extend as Uint8Array);
|
||||
expect(decoded).toEqual({
|
||||
type: 101,
|
||||
groupUin: 12345,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { SendPacketResult } from '../src/protocol/packet-sender';
|
||||
import { protoDecode, protoEncode } from '../src/protobuf/decode';
|
||||
import { SendMessageRequestSchema, SendMessageResponseSchema } from '../src/bridge/proto/action';
|
||||
import { FileExtraSchema } from '../src/bridge/proto/message';
|
||||
import type { SendMessageRequest, SendMessageResponse } from '../src/bridge/proto/proton/action';
|
||||
import type { FileExtra } from '../src/bridge/proto/proton/message';
|
||||
|
||||
vi.mock('../src/bridge/element-builder', () => ({
|
||||
buildSendElems: vi.fn(async () => [{ text: { str: 'stub media elem' } }]),
|
||||
@@ -29,11 +29,12 @@ describe('Bridge private media routing', () => {
|
||||
gotResponse: true,
|
||||
errorCode: 0,
|
||||
errorMessage: '',
|
||||
responseData: Buffer.from(protoEncode({
|
||||
responseData: Buffer.from(protobuf_encode<SendMessageResponse>({
|
||||
result: 0,
|
||||
errMsg: '',
|
||||
privateSequence: 88,
|
||||
timestamp1: 1710000000,
|
||||
}, SendMessageResponseSchema)),
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -42,7 +43,7 @@ describe('Bridge private media routing', () => {
|
||||
await bridge.sendPrivateMessage(12345, [{ type: 'video', url: 'file:///tmp/clip.mp4' } as any]);
|
||||
|
||||
expect(bridge.capturedBody).toBeInstanceOf(Uint8Array);
|
||||
const request = protoDecode(bridge.capturedBody as Uint8Array, SendMessageRequestSchema);
|
||||
const request = protobuf_decode<SendMessageRequest>(bridge.capturedBody as Uint8Array);
|
||||
expect(request?.routingHead?.c2c).toMatchObject({
|
||||
uin: 12345,
|
||||
uid: 'u_peer_12345',
|
||||
@@ -67,9 +68,9 @@ describe('Bridge private media routing', () => {
|
||||
this.capturedBody = body;
|
||||
return {
|
||||
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
|
||||
responseData: Buffer.from(protoEncode({
|
||||
result: 0, privateSequence: 88, timestamp1: 1710000000,
|
||||
}, SendMessageResponseSchema)),
|
||||
responseData: Buffer.from(protobuf_encode<SendMessageResponse>({
|
||||
result: 0, errMsg: '', privateSequence: 88, timestamp1: 1710000000,
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -84,27 +85,24 @@ describe('Bridge private media routing', () => {
|
||||
fileHash: 'hash-xyz',
|
||||
});
|
||||
|
||||
const request = protoDecode(bridge.capturedBody as Uint8Array, SendMessageRequestSchema);
|
||||
const request = protobuf_decode<SendMessageRequest>(bridge.capturedBody as Uint8Array);
|
||||
|
||||
// Routing: must be trans0x211 with ccCmd=4 + uid, no c2c slot.
|
||||
expect(request?.routingHead?.trans0x211).toMatchObject({
|
||||
ccCmd: 4,
|
||||
uid: 'u_peer_xyz',
|
||||
});
|
||||
expect(request?.routingHead?.c2c).toBeUndefined();
|
||||
expect(request?.routingHead?.c2c ?? undefined).toBeUndefined();
|
||||
|
||||
// Body: msgContent carries the FileExtra; richText is absent (no
|
||||
// elems, no notOnlineFile slot — both lived on the wrong place).
|
||||
expect(request?.messageBody?.msgContent).toBeInstanceOf(Uint8Array);
|
||||
expect(request?.messageBody?.richText).toBeUndefined();
|
||||
expect(request?.messageBody?.richText ?? undefined).toBeUndefined();
|
||||
|
||||
// Decode the msgContent and verify the NotOnlineFile fields land
|
||||
// at the correct tags (Lagrange's NotOnlineFile schema, not the
|
||||
// dead FileExtraInfo one).
|
||||
const fileExtra = protoDecode(
|
||||
request!.messageBody!.msgContent as Uint8Array,
|
||||
FileExtraSchema,
|
||||
);
|
||||
const fileExtra = protobuf_decode<FileExtra>(request!.messageBody!.msgContent as Uint8Array);
|
||||
expect(fileExtra?.file).toMatchObject({
|
||||
fileUuid: 'uuid-abc-123',
|
||||
fileName: 'doc.txt',
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
// - formatEvent prints something readable in the [Event] log
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { protoEncode } from '../src/protobuf/decode';
|
||||
import { GroupReactNotifySchema } from '../src/bridge/proto/notify';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { GroupReactNotify } from '../src/bridge/proto/proton/notify';
|
||||
import { decodeEvent0x2DC } from '../src/bridge/msg-push/decoders/event-0x2dc';
|
||||
import type { MsgPushContext } from '../src/bridge/msg-push/context';
|
||||
import { IdentityService } from '../src/bridge/identity-service';
|
||||
@@ -28,7 +28,7 @@ function makeIdentity(): IdentityService {
|
||||
* a 7-byte magic prefix followed by an encoded GroupReactNotify. */
|
||||
function buildReactContent(notify: Record<string, unknown>): Uint8Array {
|
||||
const prefix = new Uint8Array([0, 0, 0, 0, 0, 0, 0]);
|
||||
const body = protoEncode(notify as never, GroupReactNotifySchema);
|
||||
const body = protobuf_encode<GroupReactNotify>(notify as GroupReactNotify);
|
||||
const out = new Uint8Array(prefix.length + body.length);
|
||||
out.set(prefix, 0);
|
||||
out.set(body, prefix.length);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
// the actual decode path inside the pipeline.
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
|
||||
vi.mock('../../src/bridge/highway/highway-client', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({ sessionId: 'fake-session' })),
|
||||
@@ -23,13 +24,8 @@ import {
|
||||
runNtv2Upload,
|
||||
type MediaSubFileUpload,
|
||||
} from '../../src/bridge/highway/pipeline';
|
||||
import { protoDecode, protoEncode } from '../../src/protobuf/decode';
|
||||
import { makeOidbBaseSchema } from '../../src/bridge/proto/oidb';
|
||||
import {
|
||||
EncodableMediaMsgInfoSchema,
|
||||
NTV2UploadRichMediaReqSchema,
|
||||
NTV2UploadRichMediaRespSchema,
|
||||
} from '../../src/bridge/proto/highway';
|
||||
import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
|
||||
import type { EncodableMediaMsgInfo, NTV2UploadRichMediaReq, NTV2UploadRichMediaResp } from '../../src/bridge/proto/proton/highway';
|
||||
|
||||
interface FakeUploadResponse {
|
||||
upload?: {
|
||||
@@ -48,8 +44,7 @@ interface FakeUploadResponse {
|
||||
}
|
||||
|
||||
function encodeOidbResponse(body: FakeUploadResponse, opts: { errorCode?: number; errorMsg?: string } = {}): Buffer {
|
||||
const baseSchema = makeOidbBaseSchema(NTV2UploadRichMediaRespSchema);
|
||||
return Buffer.from(protoEncode({
|
||||
return Buffer.from(protobuf_encode<OidbBase<NTV2UploadRichMediaResp>>({
|
||||
command: 0x11C4,
|
||||
subCommand: 100,
|
||||
errorCode: opts.errorCode ?? 0,
|
||||
@@ -58,7 +53,7 @@ function encodeOidbResponse(body: FakeUploadResponse, opts: { errorCode?: number
|
||||
body: body as unknown as Record<string, unknown>,
|
||||
errorMsg: opts.errorMsg ?? '',
|
||||
reserved: 1,
|
||||
}, baseSchema));
|
||||
} as OidbBase<NTV2UploadRichMediaResp>));
|
||||
}
|
||||
|
||||
type SendPacketResult = {
|
||||
@@ -125,8 +120,7 @@ describe('pipeline — runNtv2Upload', () => {
|
||||
|
||||
// The request roundtrips through the real OIDB envelope and carries
|
||||
// the requestId / businessType / scene fields we passed.
|
||||
const baseSchema = makeOidbBaseSchema(NTV2UploadRichMediaReqSchema);
|
||||
const decoded: any = protoDecode(requestBytes as Uint8Array, baseSchema);
|
||||
const decoded: any = protobuf_decode<OidbBase<NTV2UploadRichMediaReq>>(requestBytes as Uint8Array);
|
||||
expect(decoded.command).toBe(0x11C4);
|
||||
expect(decoded.body.reqHead.common.requestId).toBe(1);
|
||||
expect(decoded.body.reqHead.scene.businessType).toBe(1);
|
||||
@@ -141,7 +135,7 @@ describe('pipeline — runNtv2Upload', () => {
|
||||
await runNtv2Upload(baseParams({ bridge, isGroup: false, targetIdOrUid: 'recipient-uid' }));
|
||||
|
||||
const requestBytes = bridge.sendRawPacket.mock.calls[0]![1];
|
||||
const decoded: any = protoDecode(requestBytes as Uint8Array, makeOidbBaseSchema(NTV2UploadRichMediaReqSchema));
|
||||
const decoded: any = protobuf_decode<OidbBase<NTV2UploadRichMediaReq>>(requestBytes as Uint8Array);
|
||||
expect(decoded.body.reqHead.scene.sceneType).toBe(1);
|
||||
expect(decoded.body.reqHead.scene.c2c.targetUid).toBe('recipient-uid');
|
||||
});
|
||||
@@ -336,7 +330,7 @@ describe('pipeline — finalizeMediaMsgInfo', () => {
|
||||
msgInfo: { msgInfoBody: [], extBizInfo: {} },
|
||||
}, { bizType: 7, textSummary: '[image]' });
|
||||
|
||||
const decoded: any = protoDecode(out, EncodableMediaMsgInfoSchema);
|
||||
const decoded: any = protobuf_decode<EncodableMediaMsgInfo>(out);
|
||||
expect(decoded.extBizInfo.pic.bizType).toBe(7);
|
||||
expect(decoded.extBizInfo.pic.textSummary).toBe('[image]');
|
||||
});
|
||||
@@ -345,10 +339,10 @@ describe('pipeline — finalizeMediaMsgInfo', () => {
|
||||
const out = finalizeMediaMsgInfo({
|
||||
msgInfo: { msgInfoBody: [], extBizInfo: {} },
|
||||
});
|
||||
const decoded: any = protoDecode(out, EncodableMediaMsgInfoSchema);
|
||||
const decoded: any = protobuf_decode<EncodableMediaMsgInfo>(out);
|
||||
// An empty extBizInfo proto roundtrips to undefined; either way the
|
||||
// pic field never got materialised.
|
||||
expect(decoded?.extBizInfo?.pic).toBeUndefined();
|
||||
expect(decoded?.extBizInfo?.pic ?? undefined).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ import fs from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import { parseMessage } from '../src/onebot/message-parser';
|
||||
import { buildSendElems } from '../src/bridge/element-builder';
|
||||
import { MentionExtraSendSchema } from '../src/bridge/proto/action';
|
||||
import { makeOidbBaseSchema } from '../src/bridge/proto/oidb';
|
||||
import { NTV2UploadRichMediaRespSchema } from '../src/bridge/proto/highway';
|
||||
import { protoDecode, protoEncode } from '../src/protobuf/decode';
|
||||
import type { MentionExtraSend } from '../src/bridge/proto/proton/action';
|
||||
import type { OidbBase } from '../src/bridge/proto/proton/oidb';
|
||||
import type { NTV2UploadRichMediaResp } from '../src/bridge/proto/proton/highway';
|
||||
|
||||
describe('parseMessage', () => {
|
||||
describe('plain text', () => {
|
||||
@@ -188,7 +188,7 @@ describe('parseMessage', () => {
|
||||
const protoElems = await buildSendElems(elements);
|
||||
const reserve = protoElems[0].text?.pbReserve;
|
||||
expect(reserve).toBeInstanceOf(Uint8Array);
|
||||
const extra = protoDecode(reserve as Uint8Array, MentionExtraSendSchema);
|
||||
const extra = protobuf_decode<MentionExtraSend>(reserve as Uint8Array);
|
||||
expect(extra).toMatchObject({
|
||||
type: 2,
|
||||
uin: 123456,
|
||||
@@ -232,8 +232,7 @@ describe('parseMessage', () => {
|
||||
const videoPath = path.join(os.tmpdir(), `snowluma-video-test-${process.pid}-${Date.now()}.mp4`);
|
||||
fs.writeFileSync(videoPath, Buffer.from([0, 1, 2, 3]));
|
||||
|
||||
const respSchema = makeOidbBaseSchema(NTV2UploadRichMediaRespSchema);
|
||||
const responseData = protoEncode({
|
||||
const responseData = protobuf_encode<OidbBase<NTV2UploadRichMediaResp>>({
|
||||
command: 0x11EA,
|
||||
subCommand: 100,
|
||||
errorCode: 0,
|
||||
@@ -255,7 +254,7 @@ describe('parseMessage', () => {
|
||||
},
|
||||
errorMsg: '',
|
||||
reserved: 1,
|
||||
}, respSchema);
|
||||
});
|
||||
|
||||
const bridge = {
|
||||
identity: { uin: '10000' },
|
||||
|
||||
@@ -3,8 +3,6 @@ import { protobuf_encode } from '@snowluma/proton';
|
||||
import { parseMsgPush, MSG_PUSH_CMD } from '../src/bridge/msg-push';
|
||||
import { IdentityService } from '../src/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo } from '../src/bridge/qq-info';
|
||||
import { PushMsgSchema } from '../src/bridge/proto/message';
|
||||
import { GroupChangeSchema, OperatorInfoSchema } from '../src/bridge/proto/notify';
|
||||
// Proton's call-site analyzer keys off the literal type identifier
|
||||
// printed in `protobuf_encode<X>` — it walks imports by *original*
|
||||
// name (not alias). If both `import { X } from 'proto/notify'` and
|
||||
@@ -15,8 +13,9 @@ import { GroupChangeSchema, OperatorInfoSchema } from '../src/bridge/proto/notif
|
||||
// name) — we don't need to import it directly since assertions can
|
||||
// inline-extract the kind.
|
||||
import type {
|
||||
NewFriend, FriendRecall, SelfJoinInGroup,
|
||||
GroupChange, NewFriend, FriendRecall, OperatorInfo, SelfJoinInGroup,
|
||||
} from '../src/bridge/proto/proton/notify';
|
||||
import type { PushMsg } from '../src/bridge/proto/proton/message';
|
||||
import type {
|
||||
GroupMemberJoin, FriendAddEvent, QQEventVariant,
|
||||
} from '../src/bridge/events';
|
||||
@@ -26,7 +25,6 @@ import type {
|
||||
// proton import above.
|
||||
type FriendRecallEvent = Extract<QQEventVariant, { kind: 'friend_recall' }>;
|
||||
import type { PacketInfo } from '../src/protocol/types';
|
||||
import { protoEncode } from '../src/protobuf/decode';
|
||||
import { subscribeLogs } from '../src/utils/logger';
|
||||
|
||||
const SELF_UIN = '10001';
|
||||
@@ -67,21 +65,21 @@ function makeIdentity(members: GroupMemberInfo[] = []): IdentityService {
|
||||
|
||||
function makeGroupIncreasePacket(memberUid: string, operatorUid = '', fromUin = GROUP_ID): PacketInfo {
|
||||
const operatorBytes = operatorUid
|
||||
? protoEncode({ operatorField: { uid: operatorUid } } as any, OperatorInfoSchema)
|
||||
? protobuf_encode<OperatorInfo>({ operatorField: { uid: operatorUid } })
|
||||
: new Uint8Array(0);
|
||||
const content = protoEncode({
|
||||
const content = protobuf_encode<GroupChange>({
|
||||
groupUin: GROUP_ID,
|
||||
memberUid,
|
||||
operatorBytes,
|
||||
} as any, GroupChangeSchema);
|
||||
const body = protoEncode({
|
||||
});
|
||||
const body = protobuf_encode<PushMsg>({
|
||||
message: {
|
||||
responseHead: { fromUin },
|
||||
contentHead: { msgType: 33, timestamp: 1710000000 },
|
||||
body: { msgContent: content },
|
||||
},
|
||||
status: 0,
|
||||
} as any, PushMsgSchema);
|
||||
});
|
||||
|
||||
return {
|
||||
pid: 1,
|
||||
@@ -129,7 +127,7 @@ describe('parseMsgPush Event0x210 subType=38 (acknowledged-but-silent)', () => {
|
||||
// drop silently — no OneBot-level event, and — critically —
|
||||
// **no** "unknown subType=38" fallback log spam anymore.
|
||||
function makeEvent0x210Packet(subType: number, content = new Uint8Array(0)): PacketInfo {
|
||||
const body = protoEncode({
|
||||
const body = protobuf_encode<PushMsg>({
|
||||
message: {
|
||||
responseHead: { fromUin: 22222, type: 0, sigMap: 0 },
|
||||
// 528 = Event0x210
|
||||
@@ -137,7 +135,7 @@ describe('parseMsgPush Event0x210 subType=38 (acknowledged-but-silent)', () => {
|
||||
body: { msgContent: content },
|
||||
},
|
||||
status: 0,
|
||||
} as any, PushMsgSchema);
|
||||
});
|
||||
return {
|
||||
pid: 1, uin: SELF_UIN, serviceCmd: MSG_PUSH_CMD, seqId: 1,
|
||||
retCode: 0, fromClient: false, body,
|
||||
@@ -186,14 +184,14 @@ describe('parseMsgPush Event0x210 subType=38 (acknowledged-but-silent)', () => {
|
||||
// that we were previously dropping into the "unknown" fallback. ──
|
||||
|
||||
function makeEvent0x210PacketAny(subType: number, content: Uint8Array): PacketInfo {
|
||||
const body = protoEncode({
|
||||
const body = protobuf_encode<PushMsg>({
|
||||
message: {
|
||||
responseHead: { fromUin: 22222, type: 0, sigMap: 0 },
|
||||
contentHead: { msgType: 528, subType, timestamp: 1710000000 },
|
||||
body: { msgContent: content },
|
||||
},
|
||||
status: 0,
|
||||
} as any, PushMsgSchema);
|
||||
});
|
||||
return {
|
||||
pid: 1, uin: SELF_UIN, serviceCmd: MSG_PUSH_CMD, seqId: 1,
|
||||
retCode: 0, fromClient: false, body,
|
||||
@@ -313,14 +311,14 @@ describe('parseMsgPush PkgType 85 (bot self-joined a group)', () => {
|
||||
field6: 48,
|
||||
field7: '',
|
||||
});
|
||||
const body = protoEncode({
|
||||
const body = protobuf_encode<PushMsg>({
|
||||
message: {
|
||||
responseHead: { fromUin: groupId, type: 0, sigMap: 0 },
|
||||
contentHead: { msgType: 85, subType: 0, timestamp: 1710000000 },
|
||||
body: { msgContent: content },
|
||||
},
|
||||
status: 0,
|
||||
} as any, PushMsgSchema);
|
||||
});
|
||||
return {
|
||||
pid: 1, uin: SELF_UIN, serviceCmd: MSG_PUSH_CMD, seqId: 1,
|
||||
retCode: 0, fromClient: false, body,
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
// network I/O.
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import { subscribeLogs, type LogEntry } from '../src/utils/logger';
|
||||
|
||||
vi.mock('../src/bridge/highway/highway-client', () => ({
|
||||
@@ -24,22 +25,18 @@ import {
|
||||
runNtv2Upload,
|
||||
type MediaSubFileUpload,
|
||||
} from '../src/bridge/highway/pipeline';
|
||||
import { protoEncode } from '../src/protobuf/decode';
|
||||
import { makeOidbBaseSchema } from '../src/bridge/proto/oidb';
|
||||
import {
|
||||
NTV2UploadRichMediaRespSchema,
|
||||
} from '../src/bridge/proto/highway';
|
||||
import type { OidbBase } from '../src/bridge/proto/proton/oidb';
|
||||
import type { NTV2UploadRichMediaResp } from '../src/bridge/proto/proton/highway';
|
||||
import { MsgPushRegistry } from '../src/bridge/msg-push/registry';
|
||||
import type { MsgPushContext } from '../src/bridge/msg-push/context';
|
||||
import { decodeEvent0x2DC } from '../src/bridge/msg-push/decoders/event-0x2dc';
|
||||
|
||||
function encodeOidbResponse(body: unknown): Buffer {
|
||||
const baseSchema = makeOidbBaseSchema(NTV2UploadRichMediaRespSchema);
|
||||
return Buffer.from(protoEncode({
|
||||
return Buffer.from(protobuf_encode<OidbBase<NTV2UploadRichMediaResp>>({
|
||||
command: 0x11C4, subCommand: 100, errorCode: 0,
|
||||
body: body as Record<string, unknown>,
|
||||
errorMsg: '', reserved: 1,
|
||||
}, baseSchema));
|
||||
} as OidbBase<NTV2UploadRichMediaResp>));
|
||||
}
|
||||
|
||||
function fakeBridge(responseData: Buffer, uin = '12345'): any {
|
||||
|
||||
@@ -1,815 +0,0 @@
|
||||
// Proof-of-concept: verify that codec generated by @snowluma/proton's Vite
|
||||
// plugin produces wire bytes byte-identical to the legacy runtime schema
|
||||
// encoder for the same input. If this passes, the migration pattern is sound
|
||||
// for the schemas covered here.
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { protobuf_encode, protobuf_decode } from '@snowluma/proton';
|
||||
import { protoEncode, protoDecode } from '../src/protobuf/decode';
|
||||
|
||||
import {
|
||||
SendLongMsgRespSchema,
|
||||
SendLongMsgReqSchema,
|
||||
RecvLongMsgReqSchema,
|
||||
RecvLongMsgRespSchema,
|
||||
LongMsgSettingsSchema,
|
||||
LongMsgResultSchema,
|
||||
} from '../src/bridge/proto/longmsg';
|
||||
import {
|
||||
TextElemSchema,
|
||||
NotOnlineImageSchema,
|
||||
ExtraInfoSchema,
|
||||
SrcMsgSchema,
|
||||
ElemSchema,
|
||||
MsgInfoSchema,
|
||||
} from '../src/bridge/proto/element';
|
||||
import {
|
||||
ResponseHeadSchema,
|
||||
PushMsgBodySchema,
|
||||
PushMsgSchema,
|
||||
} from '../src/bridge/proto/message';
|
||||
import {
|
||||
GroupChangeSchema,
|
||||
GroupAdminSchema,
|
||||
NotifyMessageBodySchema,
|
||||
GroupReactNotifySchema,
|
||||
FriendRequestSchema,
|
||||
GroupJoinSchema,
|
||||
} from '../src/bridge/proto/notify';
|
||||
import {
|
||||
RoutingHeadSchema,
|
||||
SendMessageRequestSchema,
|
||||
SendMessageResponseSchema,
|
||||
MentionExtraSendSchema,
|
||||
MarkdownDataSchema,
|
||||
} from '../src/bridge/proto/action';
|
||||
import {
|
||||
HttpConn0x6FF501RequestSchema,
|
||||
HttpConn0x6FF501ResponseSchema,
|
||||
ReqDataHighwayHeadSchema,
|
||||
NTV2RichMediaHighwayExtSchema,
|
||||
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 {
|
||||
GetMediaListRequestSchema,
|
||||
DoQunCommentRequestSchema,
|
||||
DoQunLikeRequestSchema,
|
||||
DeleteMediasRequestSchema,
|
||||
DeleteMediasResponseSchema,
|
||||
} from '../src/bridge/proto/oidb-action';
|
||||
|
||||
import type {
|
||||
SendLongMsgResp,
|
||||
SendLongMsgReq,
|
||||
RecvLongMsgReq,
|
||||
RecvLongMsgResp,
|
||||
LongMsgSettings,
|
||||
LongMsgResult,
|
||||
} from '../src/bridge/proto/proton/longmsg';
|
||||
import type {
|
||||
TextElem,
|
||||
NotOnlineImage,
|
||||
ExtraInfo,
|
||||
SrcMsg,
|
||||
Elem,
|
||||
MsgInfo,
|
||||
} from '../src/bridge/proto/proton/element';
|
||||
import type {
|
||||
ResponseHead,
|
||||
PushMsgBody,
|
||||
PushMsg,
|
||||
} from '../src/bridge/proto/proton/message';
|
||||
import type {
|
||||
GroupChange,
|
||||
GroupAdmin,
|
||||
NotifyMessageBody,
|
||||
GroupReactNotify,
|
||||
FriendRequest as FriendRequestNotify,
|
||||
GroupJoin,
|
||||
} from '../src/bridge/proto/proton/notify';
|
||||
import type {
|
||||
RoutingHead,
|
||||
SendMessageRequest,
|
||||
SendMessageResponse,
|
||||
MentionExtraSend,
|
||||
MarkdownData,
|
||||
} from '../src/bridge/proto/proton/action';
|
||||
import type {
|
||||
HttpConn0x6FF501Request,
|
||||
HttpConn0x6FF501Response,
|
||||
ReqDataHighwayHead,
|
||||
NTV2RichMediaHighwayExt,
|
||||
FileUploadExt,
|
||||
} from '../src/bridge/proto/proton/highway';
|
||||
import type {
|
||||
OidbBase,
|
||||
OidbSvcTrpcTcp0xFE5_2Response,
|
||||
} from '../src/bridge/proto/proton/oidb';
|
||||
import type {
|
||||
GetMediaListRequest,
|
||||
DoQunCommentRequest,
|
||||
DoQunLikeRequest,
|
||||
DeleteMediasRequest,
|
||||
DeleteMediasResponse,
|
||||
} from '../src/bridge/proto/proton/oidb-action';
|
||||
|
||||
function hex(buf: Uint8Array): string {
|
||||
return Buffer.from(buf).toString('hex');
|
||||
}
|
||||
|
||||
describe('proton ↔ legacy parity (longmsg subset)', () => {
|
||||
it('encodes LongMsgSettings identically', () => {
|
||||
const data: LongMsgSettings = { field1: 1, field2: 2, field3: 3, field4: 4 };
|
||||
const legacy = protoEncode(data as any, LongMsgSettingsSchema);
|
||||
const proton = protobuf_encode<LongMsgSettings>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes SendLongMsgResp (nested message) identically', () => {
|
||||
const data: SendLongMsgResp = { result: { resId: 'res-001' } };
|
||||
const legacy = protoEncode(data as any, SendLongMsgRespSchema);
|
||||
const proton = protobuf_encode<SendLongMsgResp>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes SendLongMsgReq with bytes + nested + settings identically', () => {
|
||||
// NOTE: all numeric fields are non-zero — proton follows proto3 semantics
|
||||
// and omits default-valued fields from the wire, whereas the legacy runtime
|
||||
// encoder always writes them. Parity is therefore only expected when no
|
||||
// numeric field equals its default. See the explicit divergence test below.
|
||||
const data: SendLongMsgReq = {
|
||||
info: {
|
||||
type: 1,
|
||||
uid: { uid: 'u_test' },
|
||||
groupUin: 123456,
|
||||
payload: new Uint8Array([0xde, 0xad, 0xbe, 0xef]),
|
||||
},
|
||||
settings: { field1: 4, field2: 1, field3: 7, field4: 2 },
|
||||
};
|
||||
const legacy = protoEncode(data as any, SendLongMsgReqSchema);
|
||||
const proton = protobuf_encode<SendLongMsgReq>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes RecvLongMsgReq with bool field identically', () => {
|
||||
const data: RecvLongMsgReq = {
|
||||
info: { uid: { uid: 'u_recv' }, resId: 'r-9', acquire: true },
|
||||
settings: { field1: 4, field2: 1, field3: 7, field4: 2 },
|
||||
};
|
||||
const legacy = protoEncode(data as any, RecvLongMsgReqSchema);
|
||||
const proton = protobuf_encode<RecvLongMsgReq>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes RecvLongMsgResp (with bytes payload) identically', () => {
|
||||
const data: RecvLongMsgResp = {
|
||||
result: { resId: 'r-1', payload: new Uint8Array([1, 2, 3, 4, 5]) },
|
||||
settings: { field1: 4, field2: 1, field3: 7, field4: 2 },
|
||||
};
|
||||
const legacy = protoEncode(data as any, RecvLongMsgRespSchema);
|
||||
const proton = protobuf_encode<RecvLongMsgResp>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
// ── element.ts coverage ─────────────────────────────────────────────
|
||||
|
||||
it('encodes TextElem (only primitive bytes + strings) identically', () => {
|
||||
const data: TextElem = {
|
||||
str: 'hello',
|
||||
link: 'https://example.com',
|
||||
attr6Buf: new Uint8Array([1, 2, 3]),
|
||||
buf: new Uint8Array([0xff, 0xee]),
|
||||
};
|
||||
const legacy = protoEncode(data as any, TextElemSchema);
|
||||
const proton = protobuf_encode<TextElem>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes NotOnlineImage with nested PbReserve identically', () => {
|
||||
const data: NotOnlineImage = {
|
||||
filePath: 'pic.jpg',
|
||||
fileLen: 12345,
|
||||
picMd5: new Uint8Array([0x11, 0x22, 0x33, 0x44]),
|
||||
picHeight: 600,
|
||||
picWidth: 800,
|
||||
resId: 'res-abc',
|
||||
original: 1,
|
||||
bigUrl: 'https://q.qq.com/big/abc',
|
||||
bizType: 5,
|
||||
pbRes: {
|
||||
subType: 1,
|
||||
summary: '[picture]',
|
||||
field10: 7,
|
||||
field20: { field1: 1, field2: 'inner', field3: 2, field4: 3, field5: 4, field7: 'tail' },
|
||||
url: 'https://q.qq.com/abc',
|
||||
md5Str: 'abc123',
|
||||
},
|
||||
};
|
||||
const legacy = protoEncode(data as any, NotOnlineImageSchema);
|
||||
const proton = protobuf_encode<NotOnlineImage>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes ExtraInfo (mix of bytes + int32 + uint64) identically', () => {
|
||||
const data: ExtraInfo = {
|
||||
nick: new Uint8Array([0x41, 0x42]),
|
||||
groupCard: new Uint8Array([0x43]),
|
||||
level: 7,
|
||||
flags: 1,
|
||||
groupMask: 2,
|
||||
msgTailId: 3,
|
||||
uin: 10001n,
|
||||
msgStateFlag: 4,
|
||||
};
|
||||
const legacy = protoEncode(data as any, ExtraInfoSchema);
|
||||
const proton = protobuf_encode<ExtraInfo>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes SrcMsg with repeated_uint32 + repeated_bytes identically', () => {
|
||||
const data: SrcMsg = {
|
||||
origSeqs: [100, 200, 300, 400],
|
||||
senderUin: 10001n,
|
||||
time: 1234567890,
|
||||
flag: 1,
|
||||
elemsRaw: [new Uint8Array([1, 2]), new Uint8Array([3, 4]), new Uint8Array([5, 6])],
|
||||
type: 1,
|
||||
toUin: 20002n,
|
||||
};
|
||||
const legacy = protoEncode(data as any, SrcMsgSchema);
|
||||
const proton = protobuf_encode<SrcMsg>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes Elem (oneOf-style union) identically across multiple shapes', () => {
|
||||
const textOnly: Elem = { text: { str: 'hi', link: 'lnk' } };
|
||||
expect(hex(protobuf_encode<Elem>(textOnly))).toBe(hex(protoEncode(textOnly as any, ElemSchema)));
|
||||
|
||||
const faceOnly: Elem = { face: { index: 42, buf: new Uint8Array([1, 2, 3]) } };
|
||||
expect(hex(protobuf_encode<Elem>(faceOnly))).toBe(hex(protoEncode(faceOnly as any, ElemSchema)));
|
||||
|
||||
const generalFlags: Elem = { generalFlags: { uin: 10001n, longTextFlag: 1, longTextResId: 'rs' } };
|
||||
expect(hex(protobuf_encode<Elem>(generalFlags))).toBe(hex(protoEncode(generalFlags as any, ElemSchema)));
|
||||
});
|
||||
|
||||
it('encodes MsgInfo with repeated_message + deeply nested ExtBizInfo identically', () => {
|
||||
const data: MsgInfo = {
|
||||
msgInfoBody: [
|
||||
{
|
||||
index: {
|
||||
info: { fileSize: 1024, fileHash: 'sha-1', fileSha1: 'sha-2', fileName: 'a.png', type: { type: 1, picFormat: 2, videoFormat: 3, voiceFormat: 4 }, width: 100, height: 200, time: 99, original: 1 },
|
||||
fileUuid: 'uuid-1', storeId: 5, uploadTime: 1000, ttl: 86400, subType: 1,
|
||||
},
|
||||
picture: {
|
||||
urlPath: '/p/1',
|
||||
ext: { originalParameter: 'op', bigParameter: 'bp', thumbParameter: 'tp' },
|
||||
domain: 'q.qq.com',
|
||||
},
|
||||
fileExist: true,
|
||||
},
|
||||
],
|
||||
extBizInfo: {
|
||||
pic: {
|
||||
bizType: 5, textSummary: '[pic]',
|
||||
extData: { subType: 2, textSummary: 'sum' },
|
||||
fromScene: 1, toScene: 2, oldFileId: 999,
|
||||
},
|
||||
busiType: 3,
|
||||
},
|
||||
};
|
||||
const legacy = protoEncode(data as any, MsgInfoSchema);
|
||||
const proton = protobuf_encode<MsgInfo>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
// ── message.ts coverage ─────────────────────────────────────────────
|
||||
|
||||
it('encodes ResponseHead (nested forward + grp) identically', () => {
|
||||
const data: ResponseHead = {
|
||||
fromUin: 10001, fromUid: 'u_a', type: 1, sigMap: 2, toUin: 20002, toUid: 'u_b',
|
||||
forward: { friendName: 'Alice' },
|
||||
grp: { groupUin: 555, memberName: 'Bob', groupName: 'TestGroup' },
|
||||
};
|
||||
const legacy = protoEncode(data as any, ResponseHeadSchema);
|
||||
const proton = protobuf_encode<ResponseHead>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes PushMsgBody (with RichText holding Elem[]) identically', () => {
|
||||
const data: PushMsgBody = {
|
||||
responseHead: { fromUin: 1, toUin: 2, type: 1, sigMap: 3, fromUid: 'a', toUid: 'b' },
|
||||
contentHead: { msgType: 1, subType: 1, divSeq: 1, msgId: 99, sequence: 100, timestamp: 1234567890 },
|
||||
body: {
|
||||
richText: {
|
||||
elems: [
|
||||
{ text: { str: 'hi ' } },
|
||||
{ text: { str: 'world', link: 'lnk' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
const legacy = protoEncode(data as any, PushMsgBodySchema);
|
||||
const proton = protobuf_encode<PushMsgBody>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes PushMsg (top-level) identically', () => {
|
||||
const data: PushMsg = {
|
||||
message: {
|
||||
responseHead: { fromUin: 1, toUin: 2, type: 1, sigMap: 1, fromUid: 'a', toUid: 'b' },
|
||||
contentHead: { msgType: 1, subType: 1, divSeq: 1, msgId: 1, sequence: 1, timestamp: 1 },
|
||||
body: { richText: { elems: [{ text: { str: 'x' } }] } },
|
||||
},
|
||||
status: 1,
|
||||
};
|
||||
const legacy = protoEncode(data as any, PushMsgSchema);
|
||||
const proton = protobuf_encode<PushMsg>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
// ── longmsg.ts: full migration (Content / Action / Result) ─────────
|
||||
|
||||
it('encodes LongMsgResult (repeated Action → Content → PushMsgBody[]) identically', () => {
|
||||
const inner: PushMsgBody = {
|
||||
responseHead: { fromUin: 1, toUin: 2, type: 1, sigMap: 1, fromUid: 'a', toUid: 'b' },
|
||||
contentHead: { msgType: 1, subType: 1, divSeq: 1, msgId: 1, sequence: 1, timestamp: 1 },
|
||||
body: { richText: { elems: [{ text: { str: 'forwarded' } }] } },
|
||||
};
|
||||
const data: LongMsgResult = {
|
||||
action: [
|
||||
{
|
||||
actionCommand: 'MultiMsg',
|
||||
actionData: { msgBody: [inner, inner] },
|
||||
},
|
||||
],
|
||||
};
|
||||
const legacy = protoEncode(data as any, LongMsgResultSchema);
|
||||
const proton = protobuf_encode<LongMsgResult>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
// ── notify.ts coverage ──────────────────────────────────────────────
|
||||
|
||||
it('encodes GroupChange identically', () => {
|
||||
const data: GroupChange = {
|
||||
groupUin: 555,
|
||||
flag: 1,
|
||||
memberUid: 'u_x',
|
||||
decreaseType: 130,
|
||||
operatorBytes: new Uint8Array([1, 2, 3]),
|
||||
increaseType: 1,
|
||||
};
|
||||
const legacy = protoEncode(data as any, GroupChangeSchema);
|
||||
const proton = protobuf_encode<GroupChange>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes GroupAdmin (extraEnable variant) identically', () => {
|
||||
const data: GroupAdmin = {
|
||||
groupUin: 777, flag: 1, isPromote: true,
|
||||
body: { extraEnable: { adminUid: 'u_admin', isPromote: true } },
|
||||
};
|
||||
const legacy = protoEncode(data as any, GroupAdminSchema);
|
||||
const proton = protobuf_encode<GroupAdmin>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes NotifyMessageBody (recall variant with repeated RecallMessage) identically', () => {
|
||||
const data: NotifyMessageBody = {
|
||||
type: 17,
|
||||
groupUin: 555,
|
||||
recall: {
|
||||
operatorUid: 'u_op',
|
||||
recallMessages: [
|
||||
{ sequence: 1, time: 100, random: 42, type: 1, flag: 1, authorUid: 'u_a' },
|
||||
{ sequence: 2, time: 200, random: 43, type: 1, flag: 1, authorUid: 'u_a' },
|
||||
],
|
||||
groupType: 1, opType: 2,
|
||||
tipInfo: { tip: 'recalled' },
|
||||
},
|
||||
msgSequence: 99,
|
||||
};
|
||||
const legacy = protoEncode(data as any, NotifyMessageBodySchema);
|
||||
const proton = protobuf_encode<NotifyMessageBody>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes GroupReactNotify (deeply nested) identically', () => {
|
||||
const data: GroupReactNotify = {
|
||||
groupUin: 555n,
|
||||
field13: 35,
|
||||
groupReactionData: {
|
||||
data: {
|
||||
data: {
|
||||
groupReactionTarget: { seq: 12345n },
|
||||
groupReactionDataContent: { code: '128516', count: 1, operatorUid: 'u_op', type: 1 },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const legacy = protoEncode(data as any, GroupReactNotifySchema);
|
||||
const proton = protobuf_encode<GroupReactNotify>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes FriendRequest identically', () => {
|
||||
const data: FriendRequestNotify = {
|
||||
info: { targetUid: 'u_me', sourceUid: 'u_them', newSource: 'qrcode', message: 'hello!', source: 'web' },
|
||||
};
|
||||
const legacy = protoEncode(data as any, FriendRequestSchema);
|
||||
const proton = protobuf_encode<FriendRequestNotify>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes GroupJoin identically', () => {
|
||||
const data: GroupJoin = {
|
||||
groupUin: 555, field2: 1, targetUid: 'u_them', field4: 1,
|
||||
field6: 1, field7: 'reason', field8: 1, field9: new Uint8Array([0xaa]),
|
||||
};
|
||||
const legacy = protoEncode(data as any, GroupJoinSchema);
|
||||
const proton = protobuf_encode<GroupJoin>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
// ── action.ts coverage ─────────────────────────────────────────────
|
||||
|
||||
it('encodes RoutingHead (c2c variant) identically', () => {
|
||||
const data: RoutingHead = { c2c: { uin: 10001, uid: 'u_a' } };
|
||||
const legacy = protoEncode(data as any, RoutingHeadSchema);
|
||||
const proton = protobuf_encode<RoutingHead>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes RoutingHead (group variant) identically', () => {
|
||||
const data: RoutingHead = { grp: { groupCode: 555n } };
|
||||
const legacy = protoEncode(data as any, RoutingHeadSchema);
|
||||
const proton = protobuf_encode<RoutingHead>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes SendMessageRequest (group with two text elements) identically', () => {
|
||||
const data: SendMessageRequest = {
|
||||
routingHead: { grp: { groupCode: 555n } },
|
||||
contentHead: { type: 1, subType: 1, c2cCmd: 11 },
|
||||
messageBody: {
|
||||
richText: {
|
||||
elems: [
|
||||
{ text: { str: 'hi ' } },
|
||||
{ text: { str: 'world', link: 'lnk' } },
|
||||
],
|
||||
},
|
||||
},
|
||||
clientSequence: 1,
|
||||
random: 12345,
|
||||
syncCookie: new Uint8Array([0xaa, 0xbb]),
|
||||
via: 1,
|
||||
dataStatist: 1,
|
||||
multiSendSeq: 1,
|
||||
};
|
||||
const legacy = protoEncode(data as any, SendMessageRequestSchema);
|
||||
const proton = protobuf_encode<SendMessageRequest>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes SendMessageResponse identically', () => {
|
||||
const data: SendMessageResponse = {
|
||||
result: 1, errMsg: 'ok', timestamp1: 1234567890,
|
||||
field10: 1, groupSequence: 100, timestamp2: 1234567891, privateSequence: 200,
|
||||
};
|
||||
const legacy = protoEncode(data as any, SendMessageResponseSchema);
|
||||
const proton = protobuf_encode<SendMessageResponse>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes MentionExtraSend identically', () => {
|
||||
const data: MentionExtraSend = { type: 2, uin: 10001, field5: 1, uid: 'u_a' };
|
||||
const legacy = protoEncode(data as any, MentionExtraSendSchema);
|
||||
const proton = protobuf_encode<MentionExtraSend>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes MarkdownData identically', () => {
|
||||
const data: MarkdownData = { content: '**bold** _italic_' };
|
||||
const legacy = protoEncode(data as any, MarkdownDataSchema);
|
||||
const proton = protobuf_encode<MarkdownData>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
// ── highway.ts coverage ────────────────────────────────────────────
|
||||
|
||||
it('encodes HttpConn0x6FF501Request (high-numbered field tag 0x501) identically', () => {
|
||||
const data: HttpConn0x6FF501Request = {
|
||||
httpConn: {
|
||||
field1: 1, field2: 2, field3: 16, field4: 1, field6: 3,
|
||||
serviceTypes: [1, 5, 10, 21],
|
||||
field9: 2, field10: 9, field11: 8, ver: '1.0.1',
|
||||
},
|
||||
};
|
||||
const legacy = protoEncode(data as any, HttpConn0x6FF501RequestSchema);
|
||||
const proton = protobuf_encode<HttpConn0x6FF501Request>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes HttpConn0x6FF501Response (with repeated server infos) identically', () => {
|
||||
const data: HttpConn0x6FF501Response = {
|
||||
httpConn: {
|
||||
sigSession: new Uint8Array([1, 2, 3]),
|
||||
sessionKey: new Uint8Array([4, 5, 6]),
|
||||
serverInfos: [
|
||||
{ serviceType: 1, serverAddrs: [{ type: 1, ip: 0x01020304, port: 8080, area: 1 }] },
|
||||
{ serviceType: 2, serverAddrs: [{ type: 1, ip: 0x05060708, port: 8081, area: 2 }] },
|
||||
],
|
||||
},
|
||||
};
|
||||
const legacy = protoEncode(data as any, HttpConn0x6FF501ResponseSchema);
|
||||
const proton = protobuf_encode<HttpConn0x6FF501Response>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes ReqDataHighwayHead (multiple nested messages) identically', () => {
|
||||
const data: ReqDataHighwayHead = {
|
||||
msgBaseHead: {
|
||||
version: 1, uin: '10001', command: 'PicUp.DataUp', seq: 1, retryTimes: 1,
|
||||
appId: 1600001604, dataFlag: 16, commandId: 1003,
|
||||
},
|
||||
msgSegHead: {
|
||||
serviceId: 1, filesize: 100n, dataOffset: 50n, dataLength: 100,
|
||||
retCode: 1, serviceTicket: new Uint8Array([1, 2, 3]), flag: 1,
|
||||
md5: new Uint8Array([4, 5, 6]), fileMd5: new Uint8Array([7, 8, 9]),
|
||||
cacheAddr: 1, cachePort: 80,
|
||||
},
|
||||
bytesReqExtendInfo: new Uint8Array([0xab, 0xcd]),
|
||||
timestamp: 1234567890n,
|
||||
msgLoginSigHead: { loginSigType: 8, appId: 1600001604 },
|
||||
};
|
||||
const legacy = protoEncode(data as any, ReqDataHighwayHeadSchema);
|
||||
const proton = protobuf_encode<ReqDataHighwayHead>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes NTV2RichMediaHighwayExt (repeated_bytes hash) identically', () => {
|
||||
const data: NTV2RichMediaHighwayExt = {
|
||||
fileUuid: 'uuid-1',
|
||||
uKey: 'key-1',
|
||||
network: { ipv4s: [{ domain: { isEnable: true, ip: '127.0.0.1' }, port: 80 }] },
|
||||
blockSize: 1048576,
|
||||
hash: { fileSha1: [new Uint8Array([1, 2]), new Uint8Array([3, 4])] },
|
||||
};
|
||||
const legacy = protoEncode(data as any, NTV2RichMediaHighwayExtSchema);
|
||||
const proton = protobuf_encode<NTV2RichMediaHighwayExt>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes FileUploadExt (high-numbered tags 100/200/400/600/700) identically', () => {
|
||||
const data: FileUploadExt = {
|
||||
unknown1: 100,
|
||||
unknown2: 1,
|
||||
unknown3: 1,
|
||||
entry: {
|
||||
busiBuff: {
|
||||
busId: 102,
|
||||
senderUin: 10001n,
|
||||
receiverUin: 555n,
|
||||
groupCode: 555n,
|
||||
},
|
||||
fileEntry: {
|
||||
fileSize: 12345n,
|
||||
md5: new Uint8Array([0x11, 0x22]),
|
||||
checkKey: new Uint8Array([0x33, 0x44]),
|
||||
md5S2: new Uint8Array([0x55]),
|
||||
fileId: 'file-1',
|
||||
uploadKey: new Uint8Array([0x66]),
|
||||
},
|
||||
clientInfo: {
|
||||
clientType: 3, appId: '100', terminalType: 3, clientVer: '1.1.1', unknown: 4,
|
||||
},
|
||||
fileNameInfo: { fileName: 'a.bin' },
|
||||
host: {
|
||||
hosts: [
|
||||
{ url: { unknown: 1, host: 'upload.qq.com' }, port: 80 },
|
||||
],
|
||||
},
|
||||
},
|
||||
unknown200: 1,
|
||||
};
|
||||
const legacy = protoEncode(data as any, FileUploadExtSchema);
|
||||
const proton = protobuf_encode<FileUploadExt>(data);
|
||||
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('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' } }],
|
||||
};
|
||||
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)', () => {
|
||||
// proto3 wire format says fields equal to their default value MUST NOT be
|
||||
// emitted. Proton follows that; the legacy runtime encoder always emits.
|
||||
// Either form is round-trippable through a conforming proto3 reader — the
|
||||
// missing field decodes as its default. This test pins that behaviour.
|
||||
const data: LongMsgSettings = { field1: 0, field2: 0, field3: 0, field4: 0 };
|
||||
const legacy = protoEncode(data as any, LongMsgSettingsSchema);
|
||||
const proton = protobuf_encode<LongMsgSettings>(data);
|
||||
expect(hex(proton)).toBe(''); // nothing on the wire
|
||||
expect(legacy.length).toBeGreaterThan(0); // legacy emits all zeros
|
||||
// Legacy emits explicit zero values; a proto3-conforming reader sees them
|
||||
// back when decoding. (Decoding the empty wire returns null because the
|
||||
// legacy decoder treats an empty buffer as "no message at all" — that's
|
||||
// also semantically equivalent to "all-default values" in proto3.)
|
||||
expect(protoDecode(legacy, LongMsgSettingsSchema)).toMatchObject({
|
||||
field1: 0, field2: 0, field3: 0, field4: 0,
|
||||
});
|
||||
});
|
||||
|
||||
// ── round-trip via decode ───────────────────────────────────────────
|
||||
|
||||
it('round-trips SendLongMsgResp through proton encode → legacy decode', () => {
|
||||
const data: SendLongMsgResp = { result: { resId: 'rt-1' } };
|
||||
const encoded = protobuf_encode<SendLongMsgResp>(data);
|
||||
const decoded = protoDecode(encoded, SendLongMsgRespSchema);
|
||||
expect(decoded?.result?.resId).toBe('rt-1');
|
||||
});
|
||||
|
||||
it('round-trips SendLongMsgResp through legacy encode → proton decode', () => {
|
||||
const data: SendLongMsgResp = { result: { resId: 'rt-2' } };
|
||||
const encoded = protoEncode(data as any, SendLongMsgRespSchema);
|
||||
const decoded = protobuf_decode<SendLongMsgResp>(encoded);
|
||||
expect(decoded.result?.resId).toBe('rt-2');
|
||||
});
|
||||
|
||||
// ── Group album TRPC envelopes (PR #31) ─────────────────────────────
|
||||
//
|
||||
// Raw TRPC packets — not OIDB-wrapped — that the group-album actions
|
||||
// ship to `QunAlbum.trpc.qzone.webapp_qun_*`. Field names are mostly
|
||||
// positional (`field1`/`field2`/...) because the upstream protocol
|
||||
// doesn't expose semantic names; the byte-for-byte parity below is
|
||||
// what guarantees the migration preserved every numbered field.
|
||||
|
||||
// NOTE: every numeric/bytes field below is non-zero / non-empty —
|
||||
// proton follows proto3 semantics and skips default-valued fields on
|
||||
// the wire, while the legacy runtime encoder writes them all. Byte
|
||||
// parity therefore only holds when no field equals its default. The
|
||||
// actual production callers in `actions/group-album.ts` *do* pass
|
||||
// some zero-valued fields (e.g. `field1: 0`), which means the
|
||||
// post-migration packet drops a few leading zero tags — semantically
|
||||
// equivalent to a proto3-conforming reader, see the explicit
|
||||
// divergence test earlier in this file.
|
||||
|
||||
it('encodes GetMediaListRequest (nested ReqInfo + extMap) identically', () => {
|
||||
const data: GetMediaListRequest = {
|
||||
field1: 1, // proto3 non-default
|
||||
field2: new Uint8Array([0xab]),
|
||||
field3: new Uint8Array([0xcd]),
|
||||
reqInfo: { groupId: '555', albumId: 'alb-1', field3: 7, attachInfo: 'cursor', field5: 'tag' },
|
||||
traceId: '_1700000000_12345',
|
||||
extMap: [{ key: 'fc-appid', value: '100' }],
|
||||
};
|
||||
const legacy = protoEncode(data as any, GetMediaListRequestSchema);
|
||||
const proton = protobuf_encode<GetMediaListRequest>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes DoQunCommentRequest (deeply nested anonymous-in-legacy schemas) identically', () => {
|
||||
const data: DoQunCommentRequest = {
|
||||
field1: 8527,
|
||||
field2: new Uint8Array([0x01]),
|
||||
field3: new Uint8Array([0x02]),
|
||||
body: {
|
||||
groupId: '555',
|
||||
field3: 2,
|
||||
reqBody: {
|
||||
field1: { field3: 3, field4: 'h' },
|
||||
field2: { field1: { uin: '10001' } },
|
||||
field5: {
|
||||
field1: {
|
||||
field2: {
|
||||
field1: 1, field2: 'a', lloc: 'lloc-x',
|
||||
field4: 'b', field6: 'c', field7: 1, field8: 1, field9: 1,
|
||||
field14: 1, field15: 1, field17: 1,
|
||||
},
|
||||
},
|
||||
albumId: 'alb-1',
|
||||
field5: 1,
|
||||
},
|
||||
},
|
||||
field5: {
|
||||
field2: { uin: '10001' },
|
||||
field3: { field1: 1, field2: 'hello', field3: 'd', field4: 'e', field5: 1, field6: 'f' },
|
||||
clientKey: 'ck-1',
|
||||
},
|
||||
},
|
||||
traceId: '_1700000000_12345',
|
||||
extMap: [{ key: 'fc-appid', value: '100' }],
|
||||
};
|
||||
const legacy = protoEncode(data as any, DoQunCommentRequestSchema);
|
||||
const proton = protobuf_encode<DoQunCommentRequest>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes DoQunLikeRequest (with bigint time/batchId) identically', () => {
|
||||
const data: DoQunLikeRequest = {
|
||||
field1: 5495,
|
||||
field2: 'h5_test',
|
||||
field3: 'h5_test',
|
||||
body: {
|
||||
type: 2,
|
||||
like: { id: '421_1_0_555|alb|42', status: 1 }, // non-default
|
||||
publish: {
|
||||
cellCommon: { time: 1700000000000n, feedId: '422_0_42' },
|
||||
cellUserInfo: { user: { uin: '10001' } },
|
||||
cellMedia: { albumId: 'alb', batchId: 42n },
|
||||
cellQunInfo: { qunId: '555' },
|
||||
},
|
||||
clientKey: 'ck',
|
||||
},
|
||||
extMap: [{ key: 'fc-appid', value: '100' }],
|
||||
};
|
||||
const legacy = protoEncode(data as any, DoQunLikeRequestSchema);
|
||||
const proton = protobuf_encode<DoQunLikeRequest>(data);
|
||||
expect(hex(proton)).toBe(hex(legacy));
|
||||
});
|
||||
|
||||
it('encodes DeleteMediasRequest + decodes DeleteMediasResponse identically', () => {
|
||||
const req: DeleteMediasRequest = {
|
||||
field1: 8694, field2: 'h5_test', field3: 'h5_test',
|
||||
body: { groupId: '555', albumId: 'alb', lloc: 'lloc-x' },
|
||||
traceId: 'tr-1',
|
||||
extMap: [{ key: 'fc-appid', value: '100' }],
|
||||
};
|
||||
expect(hex(protobuf_encode<DeleteMediasRequest>(req)))
|
||||
.toBe(hex(protoEncode(req as any, DeleteMediasRequestSchema)));
|
||||
|
||||
// Response: encode with legacy, decode with proton, fields stay aligned.
|
||||
const respBytes = protoEncode({ field1: 8694, field2: 10023, field3: 'no right delete' } as any, DeleteMediasResponseSchema);
|
||||
const decoded = protobuf_decode<DeleteMediasResponse>(respBytes);
|
||||
expect(decoded.field1).toBe(8694);
|
||||
expect(decoded.field2).toBe(10023);
|
||||
expect(decoded.field3).toBe('no right delete');
|
||||
});
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import type { OidbBase } from '../../src/bridge/proto/proton/oidb';
|
||||
import type {
|
||||
OidbClientKeyResp,
|
||||
OidbGetPskeyResp,
|
||||
} from '../../src/bridge/proto/proton/oidb-action';
|
||||
} from '../../src/bridge/proto/proton/oidb-actions/base';
|
||||
|
||||
// `encodeOidbEnv` / `decodeOidbEnv` are proton-bound pass-through wrappers
|
||||
// — the plugin substitutes them at the call site with the inlined codec,
|
||||
|
||||
Reference in new issue
Block a user