SnowLuma v2.4.2 source snapshot
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run

This commit is contained in:
TanTan committed 2026-11-13 09:02:00 +08:00
commit fa9c73363d
1367 files changed
+355735

No files matched your search

@@ -0,0 +1,150 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x9084Req, Oidb0x9084Resp } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { FetchReactionSummary } from '../../../src/oidb-services/reaction/fetch-reaction-summary';
function makeSender(resp?: Buffer) {
const defaultResp: SendPacketResult = {
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData: resp ?? Buffer.alloc(0),
};
return { sendRawPacket: vi.fn(async () => defaultResp) };
}
describe('FetchReactionSummary namespace', () => {
it('declares command = 0x9084 and subCommand = 1', () => {
expect(FetchReactionSummary.command).toBe(0x9084);
expect(FetchReactionSummary.subCommand).toBe(1);
});
describe('serialize', () => {
it('encodes groupId/sequence as BigInt for uint_64 fields', () => {
const out = FetchReactionSummary.serialize({} as any, {
groupId: 1022489779,
sequence: 1730183,
});
expect(out.groupId).toBe(1022489779n);
expect(out.sequence).toBe(1730183n);
});
it('passes empty / default values for the unused filter fields', () => {
const out = FetchReactionSummary.serialize({} as any, { groupId: 1, sequence: 1 });
expect(out.emojiId).toBe('');
expect(out.emojiType).toBe(0);
expect(out.count).toBe(0);
expect(out.field12).toBe(1);
});
it('emits a 0-length cookie buffer (no continuation)', () => {
const out = FetchReactionSummary.serialize({} as any, { groupId: 1, sequence: 1 });
expect(out.cookie).toBeInstanceOf(Uint8Array);
expect(out.cookie!.length).toBe(0);
});
});
describe('deserialize', () => {
it('keeps entries with count > 0 (used emojis)', () => {
const body: Oidb0x9084Resp = {
entries: [
{ lastReactionTime: 1779456439n, count: 3, emojiType: 1, emojiId: '76' },
{ lastReactionTime: 1779456962n, count: 1, emojiType: 1, emojiId: '124' },
],
};
expect(FetchReactionSummary.deserialize({} as any, body)).toEqual([
{ emojiId: '76', emojiType: 1, count: 3, lastReactionTime: 1779456439 },
{ emojiId: '124', emojiType: 1, count: 1, lastReactionTime: 1779456962 },
]);
});
it('filters out catalog-tail entries (count omitted ≡ 0)', () => {
const body: Oidb0x9084Resp = {
entries: [
{ lastReactionTime: 1n, count: 1, emojiType: 1, emojiId: '76' },
{ emojiType: 1, emojiId: '124' }, // catalog entry
{ emojiType: 1, emojiId: '66' }, // catalog entry
],
};
const out = FetchReactionSummary.deserialize({} as any, body);
expect(out).toHaveLength(1);
expect(out[0]!.emojiId).toBe('76');
});
it('returns an empty array when the response has no entries', () => {
expect(FetchReactionSummary.deserialize({} as any, {})).toEqual([]);
});
it('defaults emojiId / emojiType to safe values when omitted', () => {
const body: Oidb0x9084Resp = {
entries: [{ count: 5, lastReactionTime: 1700000000n }],
};
const [entry] = FetchReactionSummary.deserialize({} as any, body);
expect(entry).toEqual({
emojiId: '',
emojiType: 1,
count: 5,
lastReactionTime: 1700000000,
});
});
it('reports lastReactionTime=0 when omitted on a used entry (degenerate but defensive)', () => {
const body: Oidb0x9084Resp = { entries: [{ count: 2, emojiId: 'x', emojiType: 1 }] };
expect(FetchReactionSummary.deserialize({} as any, body)[0]!.lastReactionTime).toBe(0);
});
});
describe('invoke (e2e via mock sender)', () => {
it('sends to OidbSvcTrpcTcp.0x9084_1', async () => {
const sender = makeSender();
await FetchReactionSummary.invoke(sender, { groupId: 1, sequence: 1 });
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x9084_1');
});
it('end-to-end: encode → decode pipeline yields the parsed summary entries', async () => {
const respEnvelope = Buffer.from(
protobuf_encode<OidbBase<Oidb0x9084Resp>>({
command: 0x9084,
subCommand: 1,
body: {
entries: [
{
lastReactionTime: 1700000000n,
count: 5,
emojiType: 1,
emojiId: '76',
},
{ emojiType: 1, emojiId: '124' }, // catalog noise
],
},
}),
);
const sender = makeSender(respEnvelope);
const result = await FetchReactionSummary.invoke(sender, { groupId: 1, sequence: 1 });
expect(result).toEqual([
{ emojiId: '76', emojiType: 1, count: 5, lastReactionTime: 1700000000 },
]);
});
it('encodes the request envelope with groupId/sequence as uint_64', async () => {
const sender = makeSender();
await FetchReactionSummary.invoke(sender, { groupId: 1022489779, sequence: 1730183 });
const [, reqBytes] = sender.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<Oidb0x9084Req>>(reqBytes);
expect(env.command).toBe(0x9084);
expect(env.subCommand).toBe(1);
expect(env.body?.groupId).toBe(1022489779n);
expect(env.body?.sequence).toBe(1730183n);
});
it('returns an empty array when server responds with empty envelope', async () => {
const sender = makeSender();
const result = await FetchReactionSummary.invoke(sender, { groupId: 1, sequence: 1 });
expect(result).toEqual([]);
});
});
});
@@ -0,0 +1,218 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x9083Req, Oidb0x9083Resp } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { GetEmojiLikes } from '../../../src/oidb-services/reaction/get-emoji-likes';
import { env, s, v } from '../_pb-oracle';
function makeSender(resp?: Buffer) {
const defaultResp: SendPacketResult = {
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData: resp ?? Buffer.alloc(0),
};
return { sendRawPacket: vi.fn(async () => defaultResp) };
}
describe('GetEmojiLikes namespace', () => {
it('declares command = 0x9083 and subCommand = 1', () => {
expect(GetEmojiLikes.command).toBe(0x9083);
expect(GetEmojiLikes.subCommand).toBe(1);
});
describe('serialize', () => {
it('encodes groupId/sequence as BigInt for uint_64 fields', () => {
const out = GetEmojiLikes.serialize({} as any, {
groupId: 12345,
sequence: 99,
emojiId: '76',
});
expect(out.groupId).toBe(12345n);
expect(out.sequence).toBe(99n);
});
it('passes emojiId through unchanged', () => {
const out = GetEmojiLikes.serialize({} as any, {
groupId: 1,
sequence: 1,
emojiId: '128516',
});
expect(out.emojiId).toBe('128516');
});
it('defaults emojiType to 1 when omitted', () => {
const out = GetEmojiLikes.serialize({} as any, {
groupId: 1,
sequence: 1,
emojiId: 'x',
});
expect(out.emojiType).toBe(1);
});
it('uses caller-supplied emojiType when present', () => {
const out = GetEmojiLikes.serialize({} as any, {
groupId: 1,
sequence: 1,
emojiId: 'x',
emojiType: 2,
});
expect(out.emojiType).toBe(2);
});
it('defaults count to 10 when omitted', () => {
const out = GetEmojiLikes.serialize({} as any, {
groupId: 1,
sequence: 1,
emojiId: 'x',
});
expect(out.count).toBe(10);
});
it('uses caller-supplied count when present', () => {
const out = GetEmojiLikes.serialize({} as any, {
groupId: 1,
sequence: 1,
emojiId: 'x',
count: 50,
});
expect(out.count).toBe(50);
});
it('passes the continuation cookie through as a string', () => {
const out = GetEmojiLikes.serialize({} as any, {
groupId: 1,
sequence: 1,
emojiId: 'x',
cookie: 'next',
});
expect(out.cookie).toBe('next');
});
it('emits an empty cookie for the first page', () => {
const out = GetEmojiLikes.serialize({} as any, {
groupId: 1,
sequence: 1,
emojiId: 'x',
});
expect(out.cookie).toBe('');
});
});
describe('deserialize', () => {
it('extracts users from the repeated list and returns the cookie', () => {
const result = GetEmojiLikes.deserialize({} as any, {
users: [{ uin: 10001n }, { uin: 20002n }],
cookie: 'next',
isLast: false,
});
expect(result.users).toEqual([{ uin: 10001 }, { uin: 20002 }]);
expect(result.cookie).toBe('next');
expect(result.isLast).toBe(false);
});
it('filters out users with uin=0 (placeholder / zero-value)', () => {
const result = GetEmojiLikes.deserialize({} as any, {
users: [{ uin: 10001n }, { uin: 0n }, { uin: 20002n }],
});
expect(result.users).toEqual([{ uin: 10001 }, { uin: 20002 }]);
});
it('returns empty users + empty cookie + isLast=true when body has nothing', () => {
const result = GetEmojiLikes.deserialize({} as any, {});
expect(result.users).toEqual([]);
expect(result.cookie).toBe('');
expect(result.isLast).toBe(true);
});
it('returns isLast=true when cookie is absent (final page)', () => {
const result = GetEmojiLikes.deserialize({} as any, {
users: [{ uin: 10001n }],
});
expect(result.isLast).toBe(true);
});
it('handles a missing users field', () => {
const result = GetEmojiLikes.deserialize({} as any, {});
expect(result.users).toEqual([]);
});
});
describe('invoke (e2e via mock sender)', () => {
it('sends to OidbSvcTrpcTcp.0x9083_1', async () => {
const sender = makeSender();
await GetEmojiLikes.invoke(sender, { groupId: 1, sequence: 1, emojiId: '76' });
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x9083_1');
});
it('end-to-end: encode → decode yields parsed user list + cookie', async () => {
const respEnvelope = Buffer.from(
protobuf_encode<OidbBase<Oidb0x9083Resp>>({
command: 0x9083,
subCommand: 1,
body: {
users: [{ uin: 10001n }],
cookie: 'next',
isLast: false,
},
}),
);
const sender = makeSender(respEnvelope);
const result = await GetEmojiLikes.invoke(sender, {
groupId: 1,
sequence: 1,
emojiId: '76',
});
expect(result.users).toEqual([{ uin: 10001 }]);
expect(result.cookie).toBe('next');
expect(result.isLast).toBe(false);
});
it('returns the legacy-stub empty result when server returns ack-only', async () => {
const sender = makeSender();
const result = await GetEmojiLikes.invoke(sender, {
groupId: 1,
sequence: 1,
emojiId: '76',
});
expect(result).toEqual({ users: [], cookie: '', isLast: true });
});
it('encodes the request envelope with proper field types', async () => {
const sender = makeSender();
await GetEmojiLikes.invoke(sender, {
groupId: 12345,
sequence: 99,
emojiId: '128516',
emojiType: 2,
count: 20,
});
const [, reqBytes] = sender.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<Oidb0x9083Req>>(reqBytes);
expect(env.command).toBe(0x9083);
expect(env.subCommand).toBe(1);
expect(env.body?.groupId).toBe(12345n);
expect(env.body?.sequence).toBe(99n);
expect(env.body?.emojiId).toBe('128516');
expect(env.body?.emojiType).toBe(2);
expect(env.body?.count).toBe(20);
});
it('byte-oracle: request body uses type then emoji id, not the set-reaction order', async () => {
const sender = makeSender();
await GetEmojiLikes.invoke(sender, {
groupId: 12345,
sequence: 99,
emojiId: '76',
emojiType: 1,
count: 20,
});
const [, reqBytes] = sender.sendRawPacket.mock.calls[0]!;
const body = [...v(2, 12345), ...v(3, 99), ...v(4, 1), ...s(5, '76'), ...v(8, 20)];
expect(Buffer.from(reqBytes).toString('hex')).toBe(env(0x9083, 1, body, false));
});
});
});
@@ -0,0 +1,171 @@
import { describe, expect, it, vi } from 'vitest';
import { protobuf_decode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbGroupReaction } from '@snowluma/proto-defs/oidb-actions/base';
import type { SendPacketResult } from '@snowluma/common/packet-sender';
import { SetReaction } from '../../../src/oidb-services/reaction/set-reaction';
function makeSender() {
const defaultResp: SendPacketResult = {
success: true,
gotResponse: true,
errorCode: 0,
errorMessage: '',
responseData: Buffer.alloc(0),
};
return { sendRawPacket: vi.fn(async () => defaultResp) };
}
describe('SetReaction namespace', () => {
it('declares command = 0x9082', () => {
expect(SetReaction.command).toBe(0x9082);
});
it('resolveSubCommand: isSet=true → 1, isSet=false → 2', () => {
expect(
SetReaction.resolveSubCommand({ groupId: 1, sequence: 1, code: 'x', isSet: true }),
).toBe(1);
expect(
SetReaction.resolveSubCommand({ groupId: 1, sequence: 1, code: 'x', isSet: false }),
).toBe(2);
});
describe('serialize', () => {
it('produces type=1 for short QQ-face codes (≤3 chars)', () => {
const out = SetReaction.serialize({} as any, {
groupId: 12345,
sequence: 99,
code: '76',
isSet: true,
});
expect(out).toEqual({
groupUin: 12345,
sequence: 99,
code: '76',
type: 1,
field6: false,
field7: false,
});
});
it('produces type=1 for exactly 3-character codes (boundary)', () => {
const out = SetReaction.serialize({} as any, {
groupId: 1,
sequence: 1,
code: '999',
isSet: true,
});
expect(out.type).toBe(1);
});
it('produces type=2 for codes longer than 3 chars (unicode codepoint)', () => {
const out = SetReaction.serialize({} as any, {
groupId: 1,
sequence: 1,
code: '128516',
isSet: false,
});
expect(out.type).toBe(2);
});
it('passes through groupId/sequence/code verbatim', () => {
const out = SetReaction.serialize({} as any, {
groupId: 999,
sequence: 42,
code: 'abc',
isSet: true,
});
expect(out.groupUin).toBe(999);
expect(out.sequence).toBe(42);
expect(out.code).toBe('abc');
});
it('always sets field6/field7 to false (deferred behaviour)', () => {
const out = SetReaction.serialize({} as any, {
groupId: 1,
sequence: 1,
code: 'x',
isSet: true,
});
expect(out.field6).toBe(false);
expect(out.field7).toBe(false);
});
});
describe('deserialize', () => {
it('always returns void regardless of body content', () => {
expect(SetReaction.deserialize({} as any, {})).toBeUndefined();
});
});
describe('encode / decode round trip', () => {
it('encode preserves groupUin/sequence/code/type in the envelope body', () => {
const env: OidbBase<OidbGroupReaction> = {
command: 0x9082,
subCommand: 1,
body: { groupUin: 12345, sequence: 99, code: '76', type: 1 } as OidbGroupReaction,
};
const bytes = SetReaction.encode(env);
const decoded = SetReaction.decode(bytes);
expect(decoded.command).toBe(0x9082);
expect(decoded.subCommand).toBe(1);
});
});
describe('invoke (e2e via mock sender)', () => {
it('routes to OidbSvcTrpcTcp.0x9082_1 when isSet=true', async () => {
const sender = makeSender();
await SetReaction.invoke(sender, {
groupId: 12345,
sequence: 99,
code: '76',
isSet: true,
});
expect(sender.sendRawPacket).toHaveBeenCalledOnce();
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x9082_1');
});
it('routes to OidbSvcTrpcTcp.0x9082_2 when isSet=false', async () => {
const sender = makeSender();
await SetReaction.invoke(sender, {
groupId: 12345,
sequence: 99,
code: '76',
isSet: false,
});
expect(sender.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x9082_2');
});
it('packages the serialized body into the OIDB envelope wire', async () => {
const sender = makeSender();
await SetReaction.invoke(sender, {
groupId: 12345,
sequence: 99,
code: '128516',
isSet: true,
});
const [, bytes] = sender.sendRawPacket.mock.calls[0]!;
const env = protobuf_decode<OidbBase<OidbGroupReaction>>(bytes);
expect(env.command).toBe(0x9082);
expect(env.subCommand).toBe(1);
expect(env.body).toMatchObject({
groupUin: 12345,
sequence: 99,
code: '128516',
type: 2,
});
});
it('resolves to undefined (void)', async () => {
const sender = makeSender();
const result = await SetReaction.invoke(sender, {
groupId: 1,
sequence: 1,
code: 'x',
isSet: true,
});
expect(result).toBeUndefined();
});
});
});