From 76b87f6b27c52469d6a95482be5750abb9b89afe Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 19 May 2026 08:28:11 +0800 Subject: [PATCH] feat(proton): migrate group-album actions (PR #31) to proton codec MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #31 landed 4 TRPC group-album actions on the legacy runtime schema encoder. Migrate them to the compile-time codec, matching the pattern established by the OIDB migration: TS interfaces in `proto/proton/oidb-action.ts` are monomorphized at build time and each `protoEncode/Decode` call site now calls `protobuf_encode` / `protobuf_decode` directly. - Add 33 proton interfaces for the new TRPC envelopes (GetMediaList, DoQunComment, DoQunLike, DeleteMedias, plus all nested types) — inline anonymous schemas in legacy lifted to named interfaces. - Migrate `actions/group-album.ts` to the proton API; drop the `(resp as any)` casts now that decoded responses are typed. - Add 4 wire-byte parity tests for the new envelopes; non-default field values throughout so byte equivalence holds (proto3 omission of defaults is the documented divergence). - Drop dead `GroupAvatarUploadExtSchema` from `proto/highway.ts` and unused `import * as console from "node:console"` in `web/group-album.ts` — leftovers from the original PR review. core: 609/609 tests pass, typecheck clean. --- .../core/src/bridge/actions/group-album.ts | 99 ++++--- packages/core/src/bridge/proto/highway.ts | 15 +- .../src/bridge/proto/proton/oidb-action.ts | 280 ++++++++++++++++++ packages/core/src/bridge/web/group-album.ts | 1 - packages/core/tests/proton-parity.test.ts | 124 ++++++++ 5 files changed, 463 insertions(+), 56 deletions(-) diff --git a/packages/core/src/bridge/actions/group-album.ts b/packages/core/src/bridge/actions/group-album.ts index 2856905a..75c8e135 100644 --- a/packages/core/src/bridge/actions/group-album.ts +++ b/packages/core/src/bridge/actions/group-album.ts @@ -1,16 +1,23 @@ -// Group album actions via TRPC protocol +// Group album actions via TRPC protocol. +// +// Unlike the OIDB action family, these endpoints speak raw TRPC +// (service command `QunAlbum.trpc.qzone.webapp_qun_*`) without an +// `OidbBase` envelope. We hit `bridge.sendRawPacket` directly with +// proton-encoded bodies and decode the responses through proton's +// monomorphized codecs. import type { Bridge } from '../bridge'; -import { protoEncode, protoDecode } from '@/protobuf/decode'; -import { GetMediaListRequestSchema, - GetMediaListResponseSchema, - DoQunCommentRequestSchema, - DoQunCommentResponseSchema, - DoQunLikeRequestSchema, - DoQunLikeResponseSchema, - DeleteMediasRequestSchema, - DeleteMediasResponseSchema -} from '../proto/oidb-action'; +import { protobuf_encode, protobuf_decode } from '@snowluma/proton'; +import type { + GetMediaListRequest, + GetMediaListResponse, + DoQunCommentRequest, + DoQunCommentResponse, + DoQunLikeRequest, + DoQunLikeResponse, + DeleteMediasRequest, + DeleteMediasResponse, +} from '../proto/proton/oidb-action'; export interface GroupAlbumMediaResult { mediaList: any[]; @@ -47,7 +54,7 @@ export async function getGroupAlbumMediaList( ): Promise { const traceId = `_${Date.now()}_${Math.floor(Math.random() * 100000)}`; - const body = protoEncode({ + const body = protobuf_encode({ field1: 0, field2: new Uint8Array(0), field3: new Uint8Array(0), @@ -60,7 +67,7 @@ export async function getGroupAlbumMediaList( }, traceId: traceId, extMap: [{ key: 'fc-appid', value: '100' }], - }, GetMediaListRequestSchema); + }); const result = await bridge.sendRawPacket( 'QunAlbum.trpc.qzone.webapp_qun_media.QunMedia.GetMediaList', @@ -72,15 +79,15 @@ export async function getGroupAlbumMediaList( throw new Error(result.errorMessage || 'failed to get album media list'); } - const resp = protoDecode(result.responseData, GetMediaListResponseSchema); + const resp = protobuf_decode(result.responseData); - if (!resp || (resp as any).field1 !== 0) { - throw new Error(`fetch album media list error: retCode ${(resp as any)?.field1 || 'unknown'}`); + if (resp.field1 !== 0) { + throw new Error(`fetch album media list error: retCode ${resp.field1 ?? 'unknown'}`); } - const data = (resp as any).data || {}; - const mediaList = data.mediaList || []; - const nextAttachInfo = data.nextAttachInfo || ''; + const data = resp.data ?? {}; + const mediaList = data.mediaList ?? []; + const nextAttachInfo = data.nextAttachInfo ?? ''; return convertBigIntToString({ mediaList, @@ -101,7 +108,7 @@ export async function commentGroupAlbumMedia( const clientKey = Date.now().toString(); const uin = bridge.identity.uin; - const body = protoEncode({ + const body = protobuf_encode({ field1: 8527, field2: new Uint8Array(0), field3: new Uint8Array(0), @@ -137,7 +144,7 @@ export async function commentGroupAlbumMedia( }, traceId, extMap: [{ key: 'fc-appid', value: '100' }], - }, DoQunCommentRequestSchema); + }); const result = await bridge.sendRawPacket( 'QunAlbum.trpc.qzone.webapp_qun_operation.FeedsWriter.DoQunComment', @@ -149,21 +156,21 @@ export async function commentGroupAlbumMedia( throw new Error(result.errorMessage || 'failed to comment on album media'); } - const resp = protoDecode(result.responseData, DoQunCommentResponseSchema); + const resp = protobuf_decode(result.responseData); - const resCode = (resp as any)?.field1; - if (!resp || (resCode !== 0 && resCode !== 8527 && !(resp as any).comment)) { - throw new Error(`comment album media error: retCode ${resCode || 'unknown'}`); + const resCode = resp.field1; + if (resCode !== 0 && resCode !== 8527 && !resp.comment) { + throw new Error(`comment album media error: retCode ${resCode ?? 'unknown'}`); } - const commentData = (resp as any).comment?.data || {}; + const commentData = resp.comment?.data ?? {}; return convertBigIntToString({ - id: commentData.id || '', - user: { uin: commentData.user?.uin || '' }, - content: commentData.content || [], - time: commentData.time || '0', - clientKey: commentData.clientKey || '', + id: commentData.id ?? '', + user: { uin: commentData.user?.uin ?? '' }, + content: commentData.content ?? [], + time: commentData.time ?? '0', + clientKey: commentData.clientKey ?? '', }); } @@ -188,7 +195,7 @@ export async function likeGroupAlbumMedia( id = `421_1_0_${groupId}|${albumId}|${batchId}`; } - const body = protoEncode({ + const body = protobuf_encode({ field1: 5495, field2: "h5_test", field3: "h5_test", @@ -214,7 +221,7 @@ export async function likeGroupAlbumMedia( clientKey }, extMap: [{ key: 'fc-appid', value: '100' }], - }, DoQunLikeRequestSchema); + }); const result = await bridge.sendRawPacket( 'QunAlbum.trpc.qzone.webapp_qun_operation.FeedsWriter.DoQunLike', @@ -226,14 +233,14 @@ export async function likeGroupAlbumMedia( throw new Error(result.errorMessage || 'failed to like album media'); } - const resp = protoDecode(result.responseData, DoQunLikeResponseSchema); - const resCode = (resp as any)?.field1; + const resp = protobuf_decode(result.responseData); + const resCode = resp.field1; - if (!resp || resCode !== 5495) { - throw new Error(`like album media error: retCode ${resCode || 'unknown'}`); + if (resCode !== 5495) { + throw new Error(`like album media error: retCode ${resCode ?? 'unknown'}`); } - return (resp as any).body?.like || {}; + return convertBigIntToString(resp.body?.like ?? {}); } export async function deleteGroupAlbumMedia( @@ -245,7 +252,7 @@ export async function deleteGroupAlbumMedia( const uin = bridge.identity.uin; const clientKey = `${uin}_${Date.now()}_${Math.floor(Math.random() * 100000)}`; - const body = protoEncode({ + const body = protobuf_encode({ field1: 8694, field2: "h5_test", field3: "h5_test", @@ -256,7 +263,7 @@ export async function deleteGroupAlbumMedia( }, traceId: clientKey, extMap: [{ key: 'fc-appid', value: '100' }], - }, DeleteMediasRequestSchema); + }); const result = await bridge.sendRawPacket( 'QunAlbum.trpc.qzone.webapp_qun_media.QunMedia.DeleteMedias', @@ -268,13 +275,13 @@ export async function deleteGroupAlbumMedia( throw new Error(result.errorMessage || 'failed to delete album media'); } - const resp = protoDecode(result.responseData, DeleteMediasResponseSchema); - const resCode = (resp as any)?.field1; - const errCode = (resp as any)?.field2; - const errMsg = (resp as any)?.field3; + const resp = protobuf_decode(result.responseData); + const resCode = resp.field1; + const errCode = resp.field2; + const errMsg = resp.field3; - if (!resp || resCode !== 8694 || errCode) { - throw new Error(`delete album media error [${errCode || 'unknown'}]: ${errMsg || 'unknown'}`); + if (resCode !== 8694 || errCode) { + throw new Error(`delete album media error [${errCode ?? 'unknown'}]: ${errMsg ?? 'unknown'}`); } return { success: true }; diff --git a/packages/core/src/bridge/proto/highway.ts b/packages/core/src/bridge/proto/highway.ts index f61f30bf..11a583e7 100644 --- a/packages/core/src/bridge/proto/highway.ts +++ b/packages/core/src/bridge/proto/highway.ts @@ -335,12 +335,9 @@ export const NTV2UploadRichMediaRespSchema = { upload: { field: 2, type: 'message' as const, schema: NTV2UploadRespBodySchema }, } satisfies ProtoSchema; -// --- Group Avatar Upload Extend --- - -export const GroupAvatarUploadExtSchema = { - field1: { field: 1, type: 'uint32' as const }, - groupId: { field: 2, type: 'uint64' as const }, - field3: { field: 3, type: 'bytes' as const }, - field5: { field: 5, type: 'uint32' as const }, - field6: { field: 6, type: 'uint32' as const }, -} satisfies ProtoSchema; +// (The legacy `GroupAvatarUploadExtSchema` definition that briefly +// lived here in PR #31 was removed: it was a residual artifact of an +// alternative `setGroupAvatar` implementation that got dropped during +// review — the canonical Lagrange-derived `GroupAvatarExtraSchema` +// further up this file is the one `actions/profile.setGroupAvatar` +// actually uses.) diff --git a/packages/core/src/bridge/proto/proton/oidb-action.ts b/packages/core/src/bridge/proto/proton/oidb-action.ts index 3d8b00e7..1aede706 100644 --- a/packages/core/src/bridge/proto/proton/oidb-action.ts +++ b/packages/core/src/bridge/proto/proton/oidb-action.ts @@ -1277,3 +1277,283 @@ export interface GroupAvatarExtra { field5?: pb<5, uint_32>; // observed value: 3 field6?: pb<6, uint_32>; // observed value: 1 } + +// ── Group Album: TRPC envelopes ──────────────────────────────────── +// Raw TRPC packets (not OIDB-wrapped) for the qzone group-album +// service. Service commands look like +// `QunAlbum.trpc.qzone.webapp_qun_*`. Field naming follows the legacy +// schema's positional convention (`field1`/`field2`/...) where the +// reverse-engineered packet has no semantic name yet — keep it stable +// for the parity audit. + +// Common: `extMap` trace tag carried by every request envelope. +export interface ExtMapEntry { + key?: pb<1, string>; + value?: pb<2, string>; +} + +// ── GetMediaList: list media in a group album with pagination ────── + +export interface ReqInfo { + groupId?: pb<1, string>; + albumId?: pb<2, string>; + field3?: pb<3, int_32>; + attachInfo?: pb<4, string>; // 翻页 cursor — empty for the first page + field5?: pb<5, string>; +} + +export interface GetMediaListRequest { + field1?: pb<1, int_32>; + field2?: pb<2, bytes>; + field3?: pb<3, bytes>; + reqInfo?: pb<4, ReqInfo>; + traceId?: pb<5, string>; + extMap?: pb_repeated<10, ExtMapEntry>; +} + +export interface UrlInfo { + url?: pb<1, string>; + width?: pb<2, uint_32>; + height?: pb<3, uint_32>; +} + +export interface PhotoUrl { + spec?: pb<1, uint_32>; + url?: pb<2, UrlInfo>; +} + +export interface ImageInfo { + name?: pb<1, string>; + sloc?: pb<2, string>; + lloc?: pb<3, string>; + photoUrls?: pb_repeated<4, PhotoUrl>; + defaultUrl?: pb<5, UrlInfo>; + isGif?: pb<6, bool>; + hasRaw?: pb<7, bool>; +} + +export interface MediaInfo { + type?: pb<1, uint_32>; + image?: pb<2, ImageInfo>; + uploader?: pb<6, string>; + batchId?: pb<7, uint_64>; + uploadTime?: pb<8, uint_64>; +} + +// Inline-in-legacy: `GetMediaListRspDataSchema.albumInfo.schema`. +export interface GetMediaListAlbumInfo { + albumId?: pb<1, string>; + owner?: pb<2, string>; + name?: pb<3, string>; +} + +export interface GetMediaListRspData { + albumInfo?: pb<1, GetMediaListAlbumInfo>; + mediaList?: pb_repeated<3, MediaInfo>; + prevAttachInfo?: pb<4, string>; + nextAttachInfo?: pb<5, string>; +} + +export interface GetMediaListResponse { + field1?: pb<1, int_32>; + field2?: pb<2, bytes>; + field3?: pb<3, bytes>; + data?: pb<4, GetMediaListRspData>; +} + +// ── DoQunComment: post a comment on a media item ─────────────────── + +export interface CommentContentItem { + type?: pb<1, uint_32>; + content?: pb<2, string>; +} + +export interface CommentUser { + uin?: pb<13, string>; +} + +// Inline-in-legacy: `CommentReqContentSchema.field3.schema`. +export interface CommentReqContentMeta { + field1?: pb<1, uint_32>; + field2?: pb<2, string>; + field3?: pb<3, string>; + field4?: pb<4, string>; + field5?: pb<5, uint_32>; + field6?: pb<6, string>; +} + +export interface CommentReqContent { + field2?: pb<2, CommentUser>; + field3?: pb<3, CommentReqContentMeta>; + clientKey?: pb<7, string>; +} + +// Inline-in-legacy: `CommentReqPhotoInfoSchema.field1.schema.field2.schema`. +export interface CommentReqPhotoMeta { + field1?: pb<1, uint_32>; + field2?: pb<2, string>; + lloc?: pb<3, string>; + field4?: pb<4, string>; + field6?: pb<6, string>; + field7?: pb<7, uint_32>; + field8?: pb<8, uint_32>; + field9?: pb<9, uint_32>; + field14?: pb<14, uint_32>; + field15?: pb<15, uint_32>; + field17?: pb<17, uint_32>; +} + +// Inline-in-legacy: `CommentReqPhotoInfoSchema.field1.schema`. +export interface CommentReqPhotoWrap { + field2?: pb<2, CommentReqPhotoMeta>; +} + +export interface CommentReqPhotoInfo { + field1?: pb<1, CommentReqPhotoWrap>; + albumId?: pb<3, string>; + field5?: pb<5, uint_32>; +} + +// Inline-in-legacy: `CommentReqBodySchema.field1.schema`. +export interface CommentReqBodyHeader { + field3?: pb<3, uint_32>; + field4?: pb<4, string>; +} + +// Inline-in-legacy: `CommentReqBodySchema.field2.schema`. +export interface CommentReqBodyUserWrap { + field1?: pb<1, CommentUser>; +} + +export interface CommentReqBody { + field1?: pb<1, CommentReqBodyHeader>; + field2?: pb<2, CommentReqBodyUserWrap>; + field5?: pb<5, CommentReqPhotoInfo>; // 抓包证实评论文本在 field 5 +} + +// Inline-in-legacy: `DoQunCommentRequestSchema.body.schema`. +export interface DoQunCommentRequestBody { + groupId?: pb<2, string>; + field3?: pb<3, uint_32>; + reqBody?: pb<4, CommentReqBody>; + field5?: pb<5, CommentReqContent>; // 评论文本在外层 field 5 +} + +export interface DoQunCommentRequest { + field1?: pb<1, int_32>; + field2?: pb<2, bytes>; + field3?: pb<3, bytes>; + body?: pb<4, DoQunCommentRequestBody>; + traceId?: pb<5, string>; + extMap?: pb_repeated<10, ExtMapEntry>; +} + +export interface CommentRespUser { + uin?: pb<13, string>; +} + +export interface CommentRespContent { + type?: pb<1, uint_32>; + content?: pb<2, string>; +} + +export interface CommentRespData { + id?: pb<1, string>; + user?: pb<2, CommentRespUser>; + content?: pb_repeated<3, CommentRespContent>; + time?: pb<4, uint_64>; + clientKey?: pb<7, string>; +} + +// Inline-in-legacy: `DoQunCommentResponseSchema.comment.schema`. +export interface DoQunCommentResponseComment { + data?: pb<2, CommentRespData>; +} + +export interface DoQunCommentResponse { + field1?: pb<1, int_32>; + comment?: pb<4, DoQunCommentResponseComment>; +} + +// ── DoQunLike: like / unlike a media item ────────────────────────── + +export interface DoQunLikeReqLikeInfo { + id?: pb<1, string>; + status?: pb<3, uint_32>; +} + +export interface DoQunLikeReqCellCommon { + time?: pb<3, uint_64>; + feedId?: pb<4, string>; +} + +export interface DoQunLikeReqCellUser { + uin?: pb<13, string>; // 抓包证实 uin 是 field 13 +} + +export interface DoQunLikeReqCellUserInfo { + user?: pb<1, DoQunLikeReqCellUser>; +} + +export interface DoQunLikeReqCellQunInfo { + qunId?: pb<1, string>; +} + +export interface DoQunLikeReqCellMedia { + albumId?: pb<3, string>; + batchId?: pb<5, uint_64>; +} + +export interface DoQunLikeReqFeedPublish { + cellCommon?: pb<1, DoQunLikeReqCellCommon>; + cellUserInfo?: pb<2, DoQunLikeReqCellUserInfo>; + cellMedia?: pb<5, DoQunLikeReqCellMedia>; + cellQunInfo?: pb<12, DoQunLikeReqCellQunInfo>; +} + +export interface DoQunLikeReqBody { + type?: pb<2, uint_32>; + like?: pb<3, DoQunLikeReqLikeInfo>; + publish?: pb<4, DoQunLikeReqFeedPublish>; + clientKey?: pb<5, string>; +} + +export interface DoQunLikeRequest { + field1?: pb<1, int_32>; + field2?: pb<2, string>; + field3?: pb<3, string>; + body?: pb<4, DoQunLikeReqBody>; + extMap?: pb_repeated<10, ExtMapEntry>; +} + +export interface DoQunLikeRespBody { + like?: pb<2, DoQunLikeReqLikeInfo>; +} + +export interface DoQunLikeResponse { + field1?: pb<1, int_32>; + body?: pb<4, DoQunLikeRespBody>; +} + +// ── DeleteMedias: delete a media item from a group album ─────────── + +export interface DeleteMediasReqBody { + groupId?: pb<1, string>; + albumId?: pb<2, string>; + lloc?: pb<3, string>; +} + +export interface DeleteMediasRequest { + field1?: pb<1, int_32>; + field2?: pb<2, string>; + field3?: pb<3, string>; + body?: pb<4, DeleteMediasReqBody>; + traceId?: pb<5, string>; + extMap?: pb_repeated<10, ExtMapEntry>; +} + +export interface DeleteMediasResponse { + field1?: pb<1, int_32>; // expected 8694 for success + field2?: pb<2, int_32>; // error code (e.g. 10023) + field3?: pb<3, string>; // error message +} diff --git a/packages/core/src/bridge/web/group-album.ts b/packages/core/src/bridge/web/group-album.ts index 3ea71e19..321e9790 100644 --- a/packages/core/src/bridge/web/group-album.ts +++ b/packages/core/src/bridge/web/group-album.ts @@ -3,7 +3,6 @@ import { createHash } from 'crypto'; import { readFileSync, statSync, createReadStream, writeFileSync, unlinkSync } from 'fs'; import { basename, join } from 'path'; import { tmpdir } from 'os'; -import * as console from "node:console"; // 群相册信息 export interface GroupAlbumInfo { diff --git a/packages/core/tests/proton-parity.test.ts b/packages/core/tests/proton-parity.test.ts index a613d739..a6531434 100644 --- a/packages/core/tests/proton-parity.test.ts +++ b/packages/core/tests/proton-parity.test.ts @@ -52,6 +52,13 @@ import { } 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, @@ -100,6 +107,13 @@ 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'); @@ -688,4 +702,114 @@ describe('proton ↔ legacy parity (longmsg subset)', () => { const decoded = protobuf_decode(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(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(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(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(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(respBytes); + expect(decoded.field1).toBe(8694); + expect(decoded.field2).toBe(10023); + expect(decoded.field3).toBe('no right delete'); + }); });