feat: add async SQLite on Node 24 and improve messaging diagnostics (#520)
Move database work off the main thread on Node.js 24 and improve message handling and runtime diagnostics. Preserve migration, restart, and concurrency coverage with the async SQLite driver.
This commit is contained in:
1 parent
20f48d11ec
commit
c7428363cb
170 files changed
+7748
-3913
No files matched your search
@@ -420,16 +420,16 @@ describe('formatReply', () => {
|
||||
members: { '778899:20001': { card: '冬至' } },
|
||||
});
|
||||
|
||||
it('renders [回复:0] when the reply id is missing', () => {
|
||||
expect(formatReply(stubStore({}), identity, 0)).toBe('[回复:0]');
|
||||
expect(formatReply(stubStore({}), identity, Number.NaN)).toBe('[回复:0]');
|
||||
it('renders [回复:0] when the reply id is missing', async () => {
|
||||
expect(await formatReply(stubStore({}), identity, 0)).toBe('[回复:0]');
|
||||
expect(await formatReply(stubStore({}), identity, Number.NaN)).toBe('[回复:0]');
|
||||
});
|
||||
|
||||
it('renders [回复:<id>] when the store has no matching event', () => {
|
||||
expect(formatReply(stubStore({}), identity, 4100)).toBe('[回复:4100]');
|
||||
it('renders [回复:<id>] when the store has no matching event', async () => {
|
||||
expect(await formatReply(stubStore({}), identity, 4100)).toBe('[回复:4100]');
|
||||
});
|
||||
|
||||
it('resolves a group reply from the identity roster', () => {
|
||||
it('resolves a group reply from the identity roster', async () => {
|
||||
const store = stubStore({
|
||||
4100: {
|
||||
message_type: 'group',
|
||||
@@ -438,10 +438,10 @@ describe('formatReply', () => {
|
||||
message: [{ type: 'text', data: { text: '霜降好' } }],
|
||||
},
|
||||
});
|
||||
expect(formatReply(store, identity, 4100)).toBe('[回复 [冬至(20001)]: 霜降好]');
|
||||
expect(await formatReply(store, identity, 4100)).toBe('[回复 [冬至(20001)]: 霜降好]');
|
||||
});
|
||||
|
||||
it('coerces string user_id / group_id and uses the stored sender card on cache miss', () => {
|
||||
it('coerces string user_id / group_id and uses the stored sender card on cache miss', async () => {
|
||||
const store = stubStore({
|
||||
4101: {
|
||||
message_type: 'group',
|
||||
@@ -451,10 +451,10 @@ describe('formatReply', () => {
|
||||
message: '晚风',
|
||||
},
|
||||
});
|
||||
expect(formatReply(store, stubIdentity(), 4101)).toBe('[回复 [处暑(20003)]: 晚风]');
|
||||
expect(await formatReply(store, stubIdentity(), 4101)).toBe('[回复 [处暑(20003)]: 晚风]');
|
||||
});
|
||||
|
||||
it('does not treat private messages as group and ignores a whitespace-only card', () => {
|
||||
it('does not treat private messages as group and ignores a whitespace-only card', async () => {
|
||||
const store = stubStore({
|
||||
4102: {
|
||||
message_type: 'private',
|
||||
@@ -466,10 +466,10 @@ describe('formatReply', () => {
|
||||
});
|
||||
// Fallback is `(card || nickname).trim()`: a whitespace card is truthy
|
||||
// before trim, so the nickname is not used.
|
||||
expect(formatReply(store, stubIdentity(), 4102)).toBe('[回复 20001: 私聊一句]');
|
||||
expect(await formatReply(store, stubIdentity(), 4102)).toBe('[回复 20001: 私聊一句]');
|
||||
});
|
||||
|
||||
it('uses sender.nickname when card is absent', () => {
|
||||
it('uses sender.nickname when card is absent', async () => {
|
||||
const store = stubStore({
|
||||
4102: {
|
||||
message_type: 'private',
|
||||
@@ -478,10 +478,12 @@ describe('formatReply', () => {
|
||||
message: [{ type: 'text', data: { text: '私聊一句' } }],
|
||||
},
|
||||
});
|
||||
expect(formatReply(store, stubIdentity(), 4102)).toBe('[回复 [寒露(20001)]: 私聊一句]');
|
||||
expect(await formatReply(store, stubIdentity(), 4102)).toBe(
|
||||
'[回复 [寒露(20001)]: 私聊一句]',
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps the bare uin when sender is not a usable object', () => {
|
||||
it('keeps the bare uin when sender is not a usable object', async () => {
|
||||
const noSender = stubStore({
|
||||
4103: {
|
||||
message_type: 'private',
|
||||
@@ -490,7 +492,7 @@ describe('formatReply', () => {
|
||||
message: 'x',
|
||||
},
|
||||
});
|
||||
expect(formatReply(noSender, stubIdentity(), 4103)).toBe('[回复 20004: x]');
|
||||
expect(await formatReply(noSender, stubIdentity(), 4103)).toBe('[回复 20004: x]');
|
||||
|
||||
const arraySender = stubStore({
|
||||
4104: {
|
||||
@@ -500,10 +502,10 @@ describe('formatReply', () => {
|
||||
message: 'y',
|
||||
},
|
||||
});
|
||||
expect(formatReply(arraySender, stubIdentity(), 4104)).toBe('[回复 20004: y]');
|
||||
expect(await formatReply(arraySender, stubIdentity(), 4104)).toBe('[回复 20004: y]');
|
||||
});
|
||||
|
||||
it('maps non-numeric user_id to 0 and skips the sender-name fallback', () => {
|
||||
it('maps non-numeric user_id to 0 and skips the sender-name fallback', async () => {
|
||||
const store = stubStore({
|
||||
4105: {
|
||||
message_type: 'private',
|
||||
@@ -512,10 +514,10 @@ describe('formatReply', () => {
|
||||
message: 'z',
|
||||
},
|
||||
});
|
||||
expect(formatReply(store, stubIdentity(), 4105)).toBe('[回复 0: z]');
|
||||
expect(await formatReply(store, stubIdentity(), 4105)).toBe('[回复 0: z]');
|
||||
});
|
||||
|
||||
it('truncates the body preview to 30 characters after segment rendering', () => {
|
||||
it('truncates the body preview to 30 characters after segment rendering', async () => {
|
||||
const store = stubStore({
|
||||
4106: {
|
||||
message_type: 'private',
|
||||
@@ -523,12 +525,12 @@ describe('formatReply', () => {
|
||||
message: [{ type: 'text', data: { text: '正'.repeat(80) } }],
|
||||
},
|
||||
});
|
||||
expect(formatReply(store, stubIdentity(), 4106)).toBe(
|
||||
expect(await formatReply(store, stubIdentity(), 4106)).toBe(
|
||||
`[回复 20004: ${'正'.repeat(30)}...]`,
|
||||
);
|
||||
});
|
||||
|
||||
it('renders referenced reply segments as tokens instead of recursing', () => {
|
||||
it('renders referenced reply segments as tokens instead of recursing', async () => {
|
||||
const store = stubStore({
|
||||
4107: {
|
||||
message_type: 'private',
|
||||
@@ -539,16 +541,16 @@ describe('formatReply', () => {
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(formatReply(store, stubIdentity(), 4107)).toBe('[回复 20004: [回复:1] 外层]');
|
||||
expect(await formatReply(store, stubIdentity(), 4107)).toBe('[回复 20004: [回复:1] 外层]');
|
||||
});
|
||||
|
||||
it('returns [回复:<id>] when findEvent throws', () => {
|
||||
it('returns [回复:<id>] when findEvent throws', async () => {
|
||||
const store: ReplyEventLookup = {
|
||||
findEvent: () => {
|
||||
throw new Error('store unavailable');
|
||||
},
|
||||
};
|
||||
expect(formatReply(store, identity, 4100)).toBe('[回复:4100]');
|
||||
expect(await formatReply(store, identity, 4100)).toBe('[回复:4100]');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { randomUUID } from 'crypto';
|
||||
import fs, { promises as fsp } from 'fs';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { pathToFileURL } from 'url';
|
||||
import { STAGE_DIR, stageSourceToDisk, sweepStagedUploads } from '@snowluma/protocol/highway/stage';
|
||||
|
||||
const stageRoot = await fsp.mkdtemp(path.join(os.tmpdir(), 'sl-proto-stage-root-'));
|
||||
const tmpdir = vi.spyOn(os, 'tmpdir').mockReturnValue(stageRoot);
|
||||
const { STAGE_DIR, stageSourceToDisk, sweepStagedUploads } =
|
||||
await import('@snowluma/protocol/highway/stage');
|
||||
tmpdir.mockRestore();
|
||||
|
||||
const DOWNLOAD_UA =
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36';
|
||||
@@ -56,9 +61,13 @@ afterEach(async () => {
|
||||
await fsp.rm(scratch, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await fsp.rm(stageRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('STAGE_DIR', () => {
|
||||
it('is os.tmpdir()/media-stage', () => {
|
||||
expect(STAGE_DIR).toBe(path.join(os.tmpdir(), 'media-stage'));
|
||||
expect(STAGE_DIR).toBe(path.join(stageRoot, 'media-stage'));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { OidbSpecialTitle } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { SetSpecialTitle } from '../../../src/oidb-services/group-admin/set-special-title';
|
||||
import { env, v, s, m } from '../_pb-oracle';
|
||||
|
||||
function makeDeps() {
|
||||
const r: SendPacketResult = {
|
||||
@@ -41,4 +42,23 @@ describe('SetSpecialTitle namespace', () => {
|
||||
// int_32 preserves the signed -1 sentinel after the wire round-trip.
|
||||
expect(env.body?.body?.expireTime).toBe(-1);
|
||||
});
|
||||
|
||||
it.each(['', ' ', '龙王👑'])('preserves title %j in both wire fields', async (title) => {
|
||||
const deps = makeDeps();
|
||||
await SetSpecialTitle.invoke(deps, { groupId: 12345, userId: 67890, title });
|
||||
expect(deps.resolveUserUid).toHaveBeenCalledWith(67890, 12345);
|
||||
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
expect(wire).toBe('OidbSvcTrpcTcp.0x8fc_2');
|
||||
|
||||
// Empty titles must emit tag 5 + length 0 and tag 7 + length 0:
|
||||
// omitting either field turns clearing the title into a silent no-op (#517).
|
||||
const member = [
|
||||
...s(1, 'resolved-uid'),
|
||||
...s(5, title),
|
||||
...v(6, 0xffffffff),
|
||||
...s(7, title),
|
||||
];
|
||||
const body = [...v(1, 12345), ...m(3, member)];
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe(env(0x8fc, 2, body, false));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user