fix(protocol): accept Unicode system face identifiers (#324)
This commit is contained in:
6 files changed
+122
-26
No files matched your search
@@ -2,7 +2,10 @@ import { describe, it, expect } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import type { QFaceExtra, QSmallFaceExtra } from '@snowluma/proto-defs/element';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { OidbFetchSysFacesResp } from '@snowluma/proto-defs/oidb-actions/sys-faces';
|
||||
import type {
|
||||
OidbFetchSysFacesReq,
|
||||
OidbFetchSysFacesResp,
|
||||
} from '@snowluma/proto-defs/oidb-actions/sys-faces';
|
||||
import {
|
||||
FetchSysFaces,
|
||||
findFaceEntity,
|
||||
@@ -100,6 +103,27 @@ describe('faceWireFor — classification', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('FetchSysFaces protocol contract', () => {
|
||||
it('encodes the native 0x9154_1 request layout', () => {
|
||||
const body = FetchSysFaces.serialize({} as never, {});
|
||||
expect(body).toEqual({
|
||||
field1: 0,
|
||||
field2: 7,
|
||||
field3: 0,
|
||||
});
|
||||
|
||||
const decoded = protobuf_decode<OidbBase<OidbFetchSysFacesReq>>(
|
||||
FetchSysFaces.encode({ body }),
|
||||
);
|
||||
expect(decoded.body).toEqual({
|
||||
field1: null,
|
||||
field2: 7,
|
||||
field3: null,
|
||||
field4: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('FetchSysFaces.deserialize', () => {
|
||||
it('flattens common + big + magic packs', () => {
|
||||
const packs = FetchSysFaces.deserialize({} as never, {
|
||||
@@ -111,6 +135,27 @@ describe('FetchSysFaces.deserialize', () => {
|
||||
expect(packs[1].emojis[0].aniStickerType).toBe(3);
|
||||
});
|
||||
|
||||
it('preserves Unicode catalog identifiers returned by QQ', () => {
|
||||
const packs = FetchSysFaces.deserialize({} as never, {
|
||||
commonFace: {
|
||||
emojiList: [{
|
||||
emojiPackName: 'emoji',
|
||||
emojiDetail: [{ qSid: '😊', qDes: '/嘿嘿', qCid: 128522, emCode: '400832' }],
|
||||
}],
|
||||
},
|
||||
} as never);
|
||||
|
||||
expect(packs).toEqual([{
|
||||
packName: 'emoji',
|
||||
emojis: [expect.objectContaining({
|
||||
qSid: '😊',
|
||||
qDes: '/嘿嘿',
|
||||
qCid: 128522,
|
||||
emCode: '400832',
|
||||
})],
|
||||
}]);
|
||||
});
|
||||
|
||||
it('fails closed when an id field uses an unsupported wire encoding', () => {
|
||||
const driftedFace = { qDes: '/未知表情' };
|
||||
Object.defineProperty(driftedFace, Symbol.for('snowluma.proton.unknownFields'), {
|
||||
@@ -167,6 +212,37 @@ describe('SysFaceStore — persistent catalog and query seam', () => {
|
||||
expect(store.search('经典').map((face) => face.qSid)).toEqual(['14']);
|
||||
});
|
||||
|
||||
it('persists and searches Unicode catalog ids without exposing them as numeric face ids', async () => {
|
||||
const unicodeFace = entry('😊', null, null, null, '/嘿嘿');
|
||||
unicodeFace.qCid = 128522;
|
||||
unicodeFace.emCode = '400832';
|
||||
const catalog: SysFacePackEntry[] = [{ packName: 'emoji', emojis: [unicodeFace] }];
|
||||
const storage = new MemoryCatalogStorage();
|
||||
const store = new SysFaceStore({
|
||||
storage,
|
||||
now: () => 456,
|
||||
fetchCatalog: async () => catalog,
|
||||
});
|
||||
|
||||
await expect(store.refresh(sender)).resolves.toEqual(catalog);
|
||||
|
||||
expect(storage.saved[0]?.packs).toEqual(catalog);
|
||||
expect(store.search('😊').map((face) => face.qSid)).toEqual(['😊']);
|
||||
expect(store.search('嘿嘿').map((face) => face.qSid)).toEqual(['😊']);
|
||||
expect(store.lookup(128522)).toBeNull();
|
||||
});
|
||||
|
||||
it('still rejects empty and duplicate catalog identifiers', () => {
|
||||
const store = new SysFaceStore();
|
||||
|
||||
expect(() => store.load([{ packName: 'emoji', emojis: [entry('', null, null, null)] }]))
|
||||
.toThrow(/invalid system face id/);
|
||||
expect(() => store.load([{
|
||||
packName: 'emoji',
|
||||
emojis: [entry('😊', null, null, null), entry('😊', null, null, null)],
|
||||
}])).toThrow(/duplicate system face id/);
|
||||
});
|
||||
|
||||
it('coalesces concurrent refreshes and persists the authoritative result once', async () => {
|
||||
const storage = new MemoryCatalogStorage();
|
||||
let fetches = 0;
|
||||
|
||||
Reference in new issue
Block a user