feat(protocol): complete system face catalog lifecycle

Persist and validate the shared system face catalog, refresh it once when the first account connects, and coalesce concurrent loads. Resolve outgoing face metadata from the catalog so startup races, unknown IDs, and incomplete entries fail before sending.
This commit is contained in:
DrSmoothl committed 2026-08-04 23:13:32 +08:00
1 parent 938975dd45
commit 8e9a4d878e
11 files changed
+776 -65

No files matched your search

@@ -0,0 +1,38 @@
import { describe, expect, it, vi } from 'vitest';
import { SysFaceStore, type SysFaceCatalogStorage } from '@snowluma/protocol/sys-face-store';
import { BridgeManager } from '../src/bridge/manager';
import { bindSystemFaceCatalog } from '../src/sys-face-catalog';
const storage: SysFaceCatalogStorage = {
load: async () => null,
save: async () => {},
};
describe('bindSystemFaceCatalog', () => {
it('starts one shared catalog prewarm from the first logged-in account', async () => {
let fetches = 0;
const store = new SysFaceStore({
fetchCatalog: async () => {
fetches += 1;
return [{
packName: '经典',
emojis: [{
qSid: '14', qDes: '/微笑', emCode: '14', qCid: null,
aniStickerType: null, aniStickerPackId: null, aniStickerId: null,
url: null, emojiNameAlias: [],
aniStickerWidth: null, aniStickerHeight: null,
}],
}];
},
});
const manager = new BridgeManager();
bindSystemFaceCatalog(manager, { store, storage });
const packetSender = { sendPacket: vi.fn() } as never;
manager.onHookLogin(101, '10001', packetSender);
manager.onHookLogin(202, '20002', packetSender);
await vi.waitFor(() => expect(fetches).toBe(1));
expect(store.lookup(14)?.qDes).toBe('/微笑');
});
});