feat(onebot): TierB ③ — RE'd OIDB actions (ark share / doubt friends / robot-add)

All recovered from QQNT wrapper.linux.node via IDA — NapCat ships these as
kernel-only with no portable packet wire, so each cmd + protobuf was traced
from the binary (worker ctor cmd/subcmd via BaseOidbWorker::DoSendOidbReq;
field tags from the per-feature EncodeRequest). All uin-form OIDB (envelope
reserved=1, matching the NT worker flag=1). One commit for easy rollback.

New OIDB services + byte-oracle tests (fixed-wire, mutation-resistant):
- 0x9130_0 getBuddyRecommendContactArkJson → share_peer/send_ark_share (user)
- 0x8b7_5  getGroupRecommendContactArkJson → share_peer/send_ark_share (group),
           share_group_ex/send_group_ark_share (NapCat's getArkJsonGroupShare
           was NOT RE'd; routed to this confident equivalent — documented)
- 0xd69_0  getDoubtBuddyReq → get_doubt_friends_add_request
- 0xd69_0  approvalDoubtBuddyReq → set_doubt_friends_add_request (approve only)
- 0xf00_3  modifyGroupExtInfoV2 → set_group_robot_add_option (EXTInfo tags
           30/31; GroupExtFilter is client-side gating, not on the wire)

NOT shipped (kernel-.so-side, no static cmd recoverable from this binary —
honest, no guessed packets): get_robot_uin_range (trpc method-routed),
create_collection/get_collection_list (Weiyun multi-step), trans_group_file.

Doubt-list string field NAMES (nick/source/msg) are medium-confidence
(generic serializer); uid+reqTime are high. READ path, so a mislabel is
cosmetic, never a wire/ban risk. Wired through bridge friend/contacts/
groupAdmin apis; proto-defs + per-file subpath exports registered.
This commit is contained in:
DrSmoothl committed 2026-06-18 21:12:29 +08:00
1 parent b9a015a4aa
commit 43cd4a0b99
21 files changed
+931

No files matched your search

+20
View File
@@ -87,6 +87,26 @@
"types": "./src/oidb-services/friend/handle-friend-request.ts",
"default": "./src/oidb-services/friend/handle-friend-request.ts"
},
"./oidb-services/friend/get-doubt-buddy-req": {
"types": "./src/oidb-services/friend/get-doubt-buddy-req.ts",
"default": "./src/oidb-services/friend/get-doubt-buddy-req.ts"
},
"./oidb-services/friend/approve-doubt-buddy-req": {
"types": "./src/oidb-services/friend/approve-doubt-buddy-req.ts",
"default": "./src/oidb-services/friend/approve-doubt-buddy-req.ts"
},
"./oidb-services/contacts/get-buddy-recommend-ark": {
"types": "./src/oidb-services/contacts/get-buddy-recommend-ark.ts",
"default": "./src/oidb-services/contacts/get-buddy-recommend-ark.ts"
},
"./oidb-services/contacts/get-group-recommend-ark": {
"types": "./src/oidb-services/contacts/get-group-recommend-ark.ts",
"default": "./src/oidb-services/contacts/get-group-recommend-ark.ts"
},
"./oidb-services/group-admin/modify-group-ext-info": {
"types": "./src/oidb-services/group-admin/modify-group-ext-info.ts",
"default": "./src/oidb-services/group-admin/modify-group-ext-info.ts"
},
"./oidb-services/friend/delete-friend": {
"types": "./src/oidb-services/friend/delete-friend.ts",
"default": "./src/oidb-services/friend/delete-friend.ts"
@@ -0,0 +1,40 @@
// 0x9130_0 — getBuddyRecommendContactArkJson: ask the server to build a
// "recommend contact" ARK share card for a friend (by uin). Returns the
// ark JSON string the card is rendered from. RE'd from QQNT
// buddy_recommend_contact_ark_json.cc (EncodeRequest writes uin/phone/jump_url;
// DecodeResponse reads field 1 = ark json). uin-form OIDB (envelope reserved=1).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbBuddyRecommendArkReq, OidbBuddyRecommendArkResp,
} from '@snowluma/proto-defs/oidb-actions/contact-ark';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace GetBuddyRecommendArk {
export const command = 0x9130;
export const subCommand = 0;
export const uinForm = true;
export interface Params { userId: number; phoneNumber?: string }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbBuddyRecommendArkReq => ({
uin: p.userId,
phoneNum: p.phoneNumber ?? '',
// Client-side jump_url the kernel hard-codes alongside the uin; the
// server echoes it into the card. Mirrors the NT template exactly.
jumpUrl: `mqqapi://card/show_pslcard?src_type=internal&source=sharecard&version=1&uin=${p.userId}`,
});
export const deserialize = (_ctx: Deps, body: OidbBuddyRecommendArkResp): string => body.arkJson ?? '';
export const encode = (env: OidbBase<OidbBuddyRecommendArkReq>): Uint8Array =>
protobuf_encode<OidbBase<OidbBuddyRecommendArkReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbBuddyRecommendArkResp> =>
protobuf_decode<OidbBase<OidbBuddyRecommendArkResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<string> =>
invokeOidb(deps, GetBuddyRecommendArk, params);
}
@@ -0,0 +1,40 @@
// 0x8b7_5 — getGroupRecommendContactArkJson: ask the server to build a
// "recommend contact" ARK share card for a group (by group code). Returns the
// ark JSON string. RE'd from QQNT group_get_ark_json_worker.cc (EncodeRequest
// writes {1:reqType=1, 2:groupCode, 5:flag=1}); response read in
// group_info_mgr.cc `[gp_get_ark_json]` as {1:bussness_error_code, 5:ark_json}.
// uin-form OIDB (envelope reserved=1).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbGroupRecommendArkReq, OidbGroupRecommendArkResp,
} from '@snowluma/proto-defs/oidb-actions/contact-ark';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace GetGroupRecommendArk {
export const command = 0x8B7;
export const subCommand = 5;
export const uinForm = true;
export interface Params { groupId: number }
export type Deps = OidbSender;
// reqType and flag are constants the NT encoder always sends (1 and 1).
export const serialize = (_ctx: Deps, p: Params): OidbGroupRecommendArkReq => ({
reqType: 1,
groupCode: p.groupId,
flag: 1,
});
export const deserialize = (_ctx: Deps, body: OidbGroupRecommendArkResp): string => body.arkJson ?? '';
export const encode = (env: OidbBase<OidbGroupRecommendArkReq>): Uint8Array =>
protobuf_encode<OidbBase<OidbGroupRecommendArkReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbGroupRecommendArkResp> =>
protobuf_decode<OidbBase<OidbGroupRecommendArkResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<string> =>
invokeOidb(deps, GetGroupRecommendArk, params);
}
@@ -0,0 +1,37 @@
// 0xd69_0 — approvalDoubtBuddyReq: approve a doubtful friend-add request
// (可能认识的人). RE'd from QQNT doubt_codec.cc EncodeRequest sub_3F3EC90:
// {1:uid, 2:uid, [3:u32], [4:str]} — tags 3/4 emitted only when present, and
// NapCat passes empty str1/str2, so the approve flow is just {1:uid, 2:uid}.
// Same OIDB cmd as the getter; the server discriminates by body shape.
// uin-form OIDB (envelope reserved=1). NapCat only supports approve (no
// reject — rejection would be a separate delDoubtBuddyReq cmd, not RE'd here).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { OidbDoubtApprovalReq } from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace ApproveDoubtBuddyReq {
export const command = 0xD69;
export const subCommand = 0;
export const uinForm = true;
export interface Params { uid: string }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbDoubtApprovalReq => ({
uid: p.uid,
targetUid: p.uid,
});
export const deserialize = (_ctx: Deps, _: OidbEmpty): void => {};
export const encode = (env: OidbBase<OidbDoubtApprovalReq>): Uint8Array =>
protobuf_encode<OidbBase<OidbDoubtApprovalReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbEmpty> =>
protobuf_decode<OidbBase<OidbEmpty>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, ApproveDoubtBuddyReq, params);
}
@@ -0,0 +1,56 @@
// 0xd69_0 — getDoubtBuddyReq: list the "doubtful" friend-add requests
// (可能认识的人 / 被过滤的好友申请). RE'd from QQNT doubt_codec.cc.
// Request {1:1, 2:{1:num, 2:uk}} (reqId is NOT on the wire). Response body
// holds a repeated item list; we surface the fields NapCat exposes.
// READ-only: the string field names (nick/source/msg) are MEDIUM confidence
// (generic serializer), so a mislabel is cosmetic, never a wire/ban risk.
// uid (tag1) and reqTime (tag9) are HIGH confidence.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbDoubtGetReq, OidbDoubtGetResp,
} from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export interface DoubtBuddyRequest {
[key: string]: import('@snowluma/common/json').JsonValue;
/** Opaque uid — pass back as `flag` to set_doubt_friends_add_request. */
uid: string;
nick: string;
source: string;
msg: string;
reqTime: number;
}
export namespace GetDoubtBuddyReq {
export const command = 0xD69;
export const subCommand = 0;
export const uinForm = true;
export interface Params { count: number; cookie?: string }
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbDoubtGetReq => ({
field1: 1,
inner: { num: p.count, uk: p.cookie ?? '' },
});
export const deserialize = (_ctx: Deps, body: OidbDoubtGetResp): DoubtBuddyRequest[] =>
(body.body?.list ?? []).map((it) => ({
uid: it.uid ?? '',
nick: it.nick ?? '',
source: it.source ?? '',
msg: it.msg ?? '',
reqTime: Number(it.reqTime ?? 0),
}));
export const encode = (env: OidbBase<OidbDoubtGetReq>): Uint8Array =>
protobuf_encode<OidbBase<OidbDoubtGetReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbDoubtGetResp> =>
protobuf_decode<OidbBase<OidbDoubtGetResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<DoubtBuddyRequest[]> =>
invokeOidb(deps, GetDoubtBuddyReq, params);
}
@@ -0,0 +1,55 @@
// 0xf00_3 — modifyGroupExtInfoV2, used for set_group_robot_add_option.
// RE'd from QQNT group_ext_list_modify_codec.cc:
// ModifyGroupExtInfoReq{ 1:groupCode, 2:GroupExtInfo{ 1:groupCode,
// 2:EXTInfo{ 30:inviteRobotMemberSwitch, 31:inviteRobotMemberExamine } } }
// The NT GroupExtFilter (2nd kernel arg) is client-side only — it just gates
// which EXTInfo fields the encoder emits — so we mirror that by only setting
// the fields the caller provides. uin-form OIDB (envelope reserved=1).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type {
OidbModifyGroupExtReq, OidbModifyGroupExtResp, OidbGroupExtBody,
} from '@snowluma/proto-defs/oidb-actions/group-ext';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace ModifyGroupExtInfo {
export const command = 0xF00;
export const subCommand = 3;
export const uinForm = true;
export interface Params {
groupId: number;
/** undefined → leave unchanged (field not emitted). */
robotMemberSwitch?: number;
robotMemberExamine?: number;
}
export type Deps = OidbSender;
export const serialize = (_ctx: Deps, p: Params): OidbModifyGroupExtReq => {
const ext: OidbGroupExtBody = {};
if (p.robotMemberSwitch !== undefined) ext.inviteRobotMemberSwitch = p.robotMemberSwitch;
if (p.robotMemberExamine !== undefined) ext.inviteRobotMemberExamine = p.robotMemberExamine;
return {
groupCode: p.groupId,
info: { groupCode: p.groupId, ext },
};
};
export const deserialize = (_ctx: Deps, body: OidbModifyGroupExtResp): void => {
// Envelope-level OIDB errors are already thrown by invokeOidb; this is the
// body-level ack. 0 (or absent) = success.
if (body.result && body.result !== 0) {
throw new Error(`modifyGroupExtInfo failed: result=${body.result}`);
}
};
export const encode = (env: OidbBase<OidbModifyGroupExtReq>): Uint8Array =>
protobuf_encode<OidbBase<OidbModifyGroupExtReq>>(env);
export const decode = (bytes: Uint8Array): OidbBase<OidbModifyGroupExtResp> =>
protobuf_decode<OidbBase<OidbModifyGroupExtResp>>(bytes);
export const invoke = (deps: Deps, params: Params): Promise<void> =>
invokeOidb(deps, ModifyGroupExtInfo, params);
}
@@ -0,0 +1,54 @@
// Independent protobuf byte-oracle helpers for OIDB service tests.
//
// These build expected wire bytes from FIRST PRINCIPLES (the RE'd tag
// numbers), NOT via proton — so asserting `proton.encode(...) === pb.env(...)`
// goes red if a proto-defs field tag is wrong or silently changes. A
// symmetric encode→decode round-trip can't catch a tag swap; this can.
//
// Emission rules mirror proton's observed behaviour: fields in ASCENDING
// tag order, and proto3 defaults (0 / '' / false) OMITTED.
function uvarint(n: number): number[] {
const out: number[] = [];
let x = n;
do {
let b = x % 128;
x = Math.floor(x / 128);
if (x > 0) b |= 0x80;
out.push(b);
} while (x > 0);
return out;
}
function tag(field: number, wire: number): number[] {
return uvarint(field * 8 + wire);
}
/** varint field (wire type 0). */
export function v(field: number, value: number): number[] {
return [...tag(field, 0), ...uvarint(value)];
}
/** length-delimited string field (wire type 2). */
export function s(field: number, str: string): number[] {
const b = [...Buffer.from(str, 'utf8')];
return [...tag(field, 2), ...uvarint(b.length), ...b];
}
/** length-delimited sub-message field (wire type 2). */
export function m(field: number, msg: number[]): number[] {
return [...tag(field, 2), ...uvarint(msg.length), ...msg];
}
/**
* Wrap a body in the OidbBase envelope exactly as proton emits it:
* command(1), subCommand(2) [omitted when 0], body(4), reserved(12)=1
* [only when uinForm]. errorCode(3)/errorMsg(5) are defaults → omitted.
*/
export function env(command: number, subCommand: number, body: number[], uinForm: boolean): string {
const out = [...v(1, command)];
if (subCommand !== 0) out.push(...v(2, subCommand));
out.push(...m(4, body));
if (uinForm) out.push(...v(12, 1));
return Buffer.from(out).toString('hex');
}
@@ -0,0 +1,53 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbBuddyRecommendArkResp } from '@snowluma/proto-defs/oidb-actions/contact-ark';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { GetBuddyRecommendArk } from '../../../src/oidb-services/contacts/get-buddy-recommend-ark';
import { env, v, s } from '../_pb-oracle';
function makeSender(arkJson = '{"app":"com.tencent.contact.lua"}') {
const respEnv: OidbBase<OidbBuddyRecommendArkResp> = { command: 0x9130, subCommand: 0, body: { arkJson } };
const r: SendPacketResult = {
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<OidbBuddyRecommendArkResp>>(respEnv)),
};
return { sendRawPacket: vi.fn(async () => r) };
}
describe('GetBuddyRecommendArk namespace', () => {
it('declares command 0x9130 sub 0, uin form', () => {
expect(GetBuddyRecommendArk.command).toBe(0x9130);
expect(GetBuddyRecommendArk.subCommand).toBe(0);
expect(GetBuddyRecommendArk.uinForm).toBe(true);
});
it('serializes uin + the hard-coded jump_url template (phone defaults to empty)', () => {
const out = GetBuddyRecommendArk.serialize({} as any, { userId: 5 });
expect(out).toMatchObject({ uin: 5, phoneNum: '' });
expect(out.jumpUrl).toBe('mqqapi://card/show_pslcard?src_type=internal&source=sharecard&version=1&uin=5');
});
it('byte-oracle: routes to 0x9130_0 and locks req tags {1:uin, 2:phone, 3:jumpUrl}', async () => {
const sender = makeSender();
const ark = await GetBuddyRecommendArk.invoke(sender, { userId: 10000 });
expect(ark).toBe('{"app":"com.tencent.contact.lua"}');
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0x9130_0');
const jumpUrl = 'mqqapi://card/show_pslcard?src_type=internal&source=sharecard&version=1&uin=10000';
// phoneNum '' is a proto3 default → omitted; only tags 1 + 3 present.
const body = [...v(1, 10000), ...s(3, jumpUrl)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0x9130, 0, body, true));
});
it('includes phone tag 2 when a phone number is provided', () => {
const out = GetBuddyRecommendArk.serialize({} as any, { userId: 7, phoneNumber: '123' });
expect(out.phoneNum).toBe('123');
});
it('deserialize returns the ark json string ("" when absent)', () => {
expect(GetBuddyRecommendArk.deserialize({} as any, { arkJson: 'x' })).toBe('x');
expect(GetBuddyRecommendArk.deserialize({} as any, {})).toBe('');
});
});
@@ -0,0 +1,44 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbGroupRecommendArkResp } from '@snowluma/proto-defs/oidb-actions/contact-ark';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { GetGroupRecommendArk } from '../../../src/oidb-services/contacts/get-group-recommend-ark';
import { env, v } from '../_pb-oracle';
function makeSender(arkJson = '{"app":"com.tencent.structmsg"}') {
const respEnv: OidbBase<OidbGroupRecommendArkResp> = { command: 0x8B7, subCommand: 5, body: { errCode: 0, arkJson } };
const r: SendPacketResult = {
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<OidbGroupRecommendArkResp>>(respEnv)),
};
return { sendRawPacket: vi.fn(async () => r) };
}
describe('GetGroupRecommendArk namespace', () => {
it('declares command 0x8B7 sub 5, uin form', () => {
expect(GetGroupRecommendArk.command).toBe(0x8B7);
expect(GetGroupRecommendArk.subCommand).toBe(5);
expect(GetGroupRecommendArk.uinForm).toBe(true);
});
it('serializes the constant reqType=1 / flag=1 + group code', () => {
expect(GetGroupRecommendArk.serialize({} as any, { groupId: 999 })).toEqual({ reqType: 1, groupCode: 999, flag: 1 });
});
it('byte-oracle: routes to 0x8b7_5 and locks req tags {1:reqType, 2:groupCode, 5:flag}', async () => {
const sender = makeSender();
const ark = await GetGroupRecommendArk.invoke(sender, { groupId: 12345 });
expect(ark).toBe('{"app":"com.tencent.structmsg"}');
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0x8b7_5');
const body = [...v(1, 1), ...v(2, 12345), ...v(5, 1)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0x8B7, 5, body, true));
});
it('deserialize returns the ark json from response field 5', () => {
expect(GetGroupRecommendArk.deserialize({} as any, { errCode: 0, arkJson: 'g' })).toBe('g');
expect(GetGroupRecommendArk.deserialize({} as any, {})).toBe('');
});
});
@@ -0,0 +1,37 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbEmpty } from '@snowluma/proto-defs/oidb';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { ApproveDoubtBuddyReq } from '../../../src/oidb-services/friend/approve-doubt-buddy-req';
import { env, s } from '../_pb-oracle';
function makeSender() {
const respEnv: OidbBase<OidbEmpty> = { command: 0xD69, subCommand: 0, body: {} };
const r: SendPacketResult = {
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<OidbEmpty>>(respEnv)),
};
return { sendRawPacket: vi.fn(async () => r) };
}
describe('ApproveDoubtBuddyReq namespace', () => {
it('declares command 0xD69 sub 0, uin form', () => {
expect(ApproveDoubtBuddyReq.command).toBe(0xD69);
expect(ApproveDoubtBuddyReq.subCommand).toBe(0);
expect(ApproveDoubtBuddyReq.uinForm).toBe(true);
});
it('serializes the uid into both tag 1 and tag 2 (str1/str2 omitted, matching NapCat approve flow)', () => {
expect(ApproveDoubtBuddyReq.serialize({} as any, { uid: 'u_x' })).toEqual({ uid: 'u_x', targetUid: 'u_x' });
});
it('byte-oracle: routes to 0xd69_0 and locks req tags {1:uid, 2:uid}', async () => {
const sender = makeSender();
await ApproveDoubtBuddyReq.invoke(sender, { uid: 'u_abc' });
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0xd69_0');
const body = [...s(1, 'u_abc'), ...s(2, 'u_abc')];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xD69, 0, body, true));
});
});
@@ -0,0 +1,56 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbDoubtGetResp } from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { GetDoubtBuddyReq } from '../../../src/oidb-services/friend/get-doubt-buddy-req';
import { env, v, m } from '../_pb-oracle';
function makeSender(): { sendRawPacket: ReturnType<typeof vi.fn> } {
const respEnv: OidbBase<OidbDoubtGetResp> = {
command: 0xD69, subCommand: 0,
body: { status: 1, body: { list: [
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000n },
], reason: '' } },
};
const r: SendPacketResult = {
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<OidbDoubtGetResp>>(respEnv)),
};
return { sendRawPacket: vi.fn(async () => r) };
}
describe('GetDoubtBuddyReq namespace', () => {
it('declares command 0xD69 sub 0, uin form', () => {
expect(GetDoubtBuddyReq.command).toBe(0xD69);
expect(GetDoubtBuddyReq.subCommand).toBe(0);
expect(GetDoubtBuddyReq.uinForm).toBe(true);
});
it('serializes {1:1, 2:{1:count, 2:uk}} (reqId is not on the wire)', () => {
expect(GetDoubtBuddyReq.serialize({} as any, { count: 50 })).toEqual({ field1: 1, inner: { num: 50, uk: '' } });
});
it('byte-oracle: routes to 0xd69_0 and locks nested req tags {1:const1, 2:{1:num, 2:uk}}', async () => {
const sender = makeSender();
await GetDoubtBuddyReq.invoke(sender, { count: 50 });
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0xd69_0');
// uk '' omitted (proto3 default); inner carries only num.
const inner = [...v(1, 50)];
const body = [...v(1, 1), ...m(2, inner)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xD69, 0, body, true));
});
it('deserializes the item list to the OneBot shape (uid + reqTime high-confidence)', async () => {
const list = await GetDoubtBuddyReq.invoke(makeSender(), { count: 10 });
expect(list).toEqual([
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000 },
]);
});
it('deserialize returns [] when the body has no list', () => {
expect(GetDoubtBuddyReq.deserialize({} as any, { status: 1 })).toEqual([]);
});
});
@@ -0,0 +1,56 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbModifyGroupExtResp } from '@snowluma/proto-defs/oidb-actions/group-ext';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { ModifyGroupExtInfo } from '../../../src/oidb-services/group-admin/modify-group-ext-info';
import { env, v, m } from '../_pb-oracle';
function makeSender(result = 0) {
const respEnv: OidbBase<OidbModifyGroupExtResp> = { command: 0xF00, subCommand: 3, body: { groupCode: 12345, result } };
const r: SendPacketResult = {
success: true, gotResponse: true, errorCode: 0, errorMessage: '',
responseData: Buffer.from(protobuf_encode<OidbBase<OidbModifyGroupExtResp>>(respEnv)),
};
return { sendRawPacket: vi.fn(async () => r) };
}
describe('ModifyGroupExtInfo namespace', () => {
it('declares command 0xF00 sub 3, uin form', () => {
expect(ModifyGroupExtInfo.command).toBe(0xF00);
expect(ModifyGroupExtInfo.subCommand).toBe(3);
expect(ModifyGroupExtInfo.uinForm).toBe(true);
});
it('only includes the fields the caller provides', () => {
expect(ModifyGroupExtInfo.serialize({} as any, { groupId: 1, robotMemberSwitch: 1 }))
.toEqual({ groupCode: 1, info: { groupCode: 1, ext: { inviteRobotMemberSwitch: 1 } } });
expect(ModifyGroupExtInfo.serialize({} as any, { groupId: 1 }))
.toEqual({ groupCode: 1, info: { groupCode: 1, ext: {} } });
});
it('byte-oracle: routes to 0xf00_3 and locks nested tags {1:gc,2:{1:gc,2:{30:switch,31:examine}}}', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 1, robotMemberExamine: 2 });
const [cmd, bytes] = sender.sendRawPacket.mock.calls[0]!;
expect(cmd).toBe('OidbSvcTrpcTcp.0xf00_3');
const ext = [...v(30, 1), ...v(31, 2)];
const info = [...v(1, 12345), ...m(2, ext)];
const body = [...v(1, 12345), ...m(2, info)];
expect(Buffer.from(bytes).toString('hex')).toBe(env(0xF00, 3, body, true));
});
it('CAVEAT: a value of 0 is omitted on the wire (proto3 default) — documents the disable edge', async () => {
const sender = makeSender();
await ModifyGroupExtInfo.invoke(sender, { groupId: 12345, robotMemberSwitch: 0 });
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
// tag 30 varint = 0xF0 0x01; with value 0 it must NOT appear on the wire.
expect(Buffer.from(bytes).toString('hex')).not.toContain('f001');
});
it('deserialize throws on a non-zero body result', () => {
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 5 })).toThrow(/result=5/);
expect(() => ModifyGroupExtInfo.deserialize({} as any, { result: 0 })).not.toThrow();
});
});