refactor(bridge): extract protocol layer into @snowluma/bridge package
Phase 2 of the 4-package split (RoadMap #3). Moves ~35 files — events / event-bus / identity-service / packet-pipeline / element- builder / bridge-oidb / qq-info / msg-push/* / highway/* / web/* + the bridge-side formatters — out of `packages/core/src/bridge/` into the new `@snowluma/bridge` workspace package. Everything that translates QQ wire bytes ↔ typed events/elements now lives there. Why --- - `packages/core/src/bridge/` was actually two layers: a low-level "protocol decoder + I/O" set (msg-push, highway, packet-pipeline, identity, element-builder) AND the Api-class host (bridge.ts + apis/*). The Api layer can't move without the protocol layer moving first, but the two had grown into one directory. - Bridge-internal consumers (highway uploaders, OIDB envelope helper, element-builder, msg-push parsers) only ever needed `bridge.identity` + `bridge.sendRawPacket` + the upload-metadata cache. Splitting them out lets that minimal surface live in the bridge package as `BridgeContext` while the api-layer's extended context (with `apis: ApiHub`) stays in @snowluma/core. What stays in @snowluma/core (apis layer): - bridge.ts ── the god-class that composes the protocol building blocks + mounts apis - bridge-interface.ts ── public façade for OneBot consumers - manager.ts ── per-uin BridgeManager hub - apis/* ── the 13 typed Api classes - bridge-context.ts (NEW) ── extends @snowluma/bridge's slim BridgeContext with `apis: ApiHub` so the 13 Api classes keep their typed `this.ctx.apis.X.method()` access. Layout ------ Moved via `git mv` (history preserved): events / event-bus / identity-service / packet-pipeline / element-builder / bridge-oidb / qq-info / msg-push/* / highway/* / web/* → @snowluma/bridge/<sub> utils/event-format.ts → @snowluma/bridge/format.ts (the last one renamed because the destination directory only has bridge-related files; `format.ts` reads cleaner than `event-format`. Listed as a rename in git's `RM` output — content unchanged.) Layering fixes (functionality preserved, just type signatures) -------------------------------------------------------------- - `element-builder.SendContext.bridge` → typed as `BridgeContext` instead of `Bridge`. Reads only `bridge.identity` and the upload-cache (both on BridgeContext); the concrete `Bridge` instance still passes via free upcast. - `bridge-oidb.runOidb` signature widened from `Bridge` to `BridgeContext` — same reason. - `highway/{highway-client,pipeline,image-upload,ptt-upload, video-upload}.ts` — same. - `format.ts::formatReply` parameter typed as a new local `ReplyEventLookup` structural type (`{ findEvent(id): JsonObject | null }`) instead of `MessageStore` from @snowluma/onebot. The OneBot `MessageStore` is a structural superset; consumers pass it through unchanged. - JSON value types moved to a new `@snowluma/common/json` subpath (consumed by format.ts) — `onebot/types.ts` re-exports them so external `import { JsonValue } from '<…>/onebot/types'` paths keep working. - `UploadedFileMeta` interface moved from `core/src/bridge/bridge.ts` into `@snowluma/bridge/bridge-context.ts` — element-builder + the forward-builder both read the upload cache through BridgeContext, so the type has to live in @snowluma/bridge. `bridge.ts` keeps its re-export for back-compat. Changes ------- - New package `packages/bridge/` (package.json with per-file subpath exports mirroring legacy `core/src/bridge/<x>` layout 1:1, tsconfig.json, typecheck script). - 35 `.ts` files moved via `git mv` (3 files counted by git as RM — rename + modify because Bridge → BridgeContext type swap). - 150+ import sites rewritten across `packages/core/src` and `packages/core/tests`: `'../bridge/<x>'`, `'../../bridge/<x>'`, `'../src/bridge/<x>'`, `'@/bridge/web/<x>'`, and vitest `vi.mock(...)` literals all collapse to `@snowluma/bridge/<x>`. - `@snowluma/core` depends on `@snowluma/bridge` (workspace:*). - `@snowluma/bridge` depends on `@snowluma/common`, `@snowluma/proto-defs`, `@snowluma/proton`. - `packages/core/src/utils/` directory removed (empty). Verification ------------ - Full workspace `pnpm -r typecheck`: all 10 projects clean. - core test suite: 552 passed / 552 total (pre-existing websocket-darwin-arm64.node addon failure unchanged — same baseline as the previous refactor commits). - Vite build (with stubbed native binary): clean — 143 modules, 2.84 MB bundle / 224 KB gzip, identical envelope to the pre-split build. Phase 3 (next): OneBot + WebUI move into @snowluma/onebot. The runnable `index.ts` stays in @snowluma/core as the application entry, importing `OneBotManager` from `@snowluma/onebot`.
This commit is contained in:
107 files changed
+467
-229
No files matched your search
@@ -14,9 +14,9 @@ import type {
|
||||
// the module object is a no-op — proton has already inlined the call.
|
||||
// We mock `runOidb` (non-generic) to return real proton-encoded bytes
|
||||
// that the production-side codec actually decodes.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -25,7 +25,7 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { ExtrasApi, AiVoiceChatType } from '../../src/bridge/apis/extras';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', () => ({
|
||||
runOidb: vi.fn(async () => new Uint8Array()),
|
||||
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
||||
encodeOidbEnv: vi.fn(() => new Uint8Array()),
|
||||
@@ -40,7 +40,7 @@ vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
const { buildSendElemsMock } = vi.hoisted(() => ({
|
||||
buildSendElemsMock: vi.fn(async (_elements: unknown[], _ctx?: Record<string, unknown>) => []),
|
||||
}));
|
||||
vi.mock('../../src/bridge/element-builder', () => ({
|
||||
vi.mock('@snowluma/bridge/element-builder', () => ({
|
||||
buildSendElems: buildSendElemsMock,
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', () => ({
|
||||
runOidb: vi.fn(async () => new Uint8Array()),
|
||||
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
||||
encodeOidbEnv: vi.fn(() => new Uint8Array()),
|
||||
@@ -10,7 +10,7 @@ vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
// element-builder reaches into protoEncode with element-specific schemas
|
||||
// that we don't want to construct manually in tests; stub it to return
|
||||
// a benign placeholder.
|
||||
vi.mock('../../src/bridge/element-builder', () => ({
|
||||
vi.mock('@snowluma/bridge/element-builder', () => ({
|
||||
buildSendElems: vi.fn(async () => []),
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', () => ({
|
||||
runOidb: vi.fn(async () => new Uint8Array()),
|
||||
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
||||
encodeOidbEnv: vi.fn(() => new Uint8Array()),
|
||||
decodeOidbEnv: vi.fn(() => ({ body: {} })),
|
||||
}));
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { FriendApi } from '../../src/bridge/apis/friend';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import type { Oidb0x8a7Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
// is `runOidb` (non-generic, untouched by proton) returning real bytes
|
||||
// that the production-side codec then decodes. `makeOidbEnvelope` is a
|
||||
// pure TS helper, so its mock works for introspection.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -20,7 +20,7 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { GroupAdminApi } from '../../src/bridge/apis/group-admin';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ import type {
|
||||
// the module object is a no-op — proton has already inlined the call.
|
||||
// We mock `runOidb` (non-generic, proton leaves it alone) to return real
|
||||
// proton-encoded bytes, which the production-side codec then decodes.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -28,12 +28,12 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../../src/bridge/highway/highway-client', () => ({
|
||||
vi.mock('@snowluma/bridge/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({})),
|
||||
uploadHighwayHttp: vi.fn(async () => undefined),
|
||||
}));
|
||||
|
||||
vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/utils', () => ({
|
||||
loadBinarySource: vi.fn(async (_src: string, fallback: string) => ({
|
||||
bytes: new Uint8Array([1, 2, 3]),
|
||||
fileName: `${fallback}.bin`,
|
||||
@@ -43,8 +43,8 @@ vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
FILE_UPLOAD_MAX_BYTES: 4 * 1024 * 1024 * 1024,
|
||||
}));
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as highwayClient from '../../src/bridge/highway/highway-client';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import * as highwayClient from '@snowluma/bridge/highway';
|
||||
import { GroupFileApi } from '../../src/bridge/apis/group-file';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/bridge-oidb', () => ({
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', () => ({
|
||||
runOidb: vi.fn(async () => new Uint8Array()),
|
||||
makeOidbEnvelope: vi.fn((_oidbCmd, _subCmd, body) => ({ body })),
|
||||
encodeOidbEnv: vi.fn(() => new Uint8Array()),
|
||||
|
||||
@@ -10,9 +10,9 @@ import type { Oidb0x9083Resp } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
// is `runOidb` (non-generic, untouched by proton) returning real bytes
|
||||
// that the production-side codec actually decodes. `makeOidbEnvelope` is
|
||||
// a pure TS helper, so its mock works for introspection.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -21,7 +21,7 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { InteractionApi } from '../../src/bridge/apis/interaction';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ import type {
|
||||
// so mocking them on the module object is a no-op. We mock `runOidb`
|
||||
// (non-generic, untouched by proton) to return real proton-encoded bytes
|
||||
// that the production-side codec then actually decodes.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -22,7 +22,7 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import { MiscApi } from '../../src/bridge/apis/misc';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ import type {
|
||||
// the module object is a no-op — proton has already inlined the call.
|
||||
// We mock `runOidb` (non-generic) to return real proton-encoded bytes
|
||||
// that the production-side codec actually decodes.
|
||||
vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('../../src/bridge/bridge-oidb')>(
|
||||
'../../src/bridge/bridge-oidb',
|
||||
vi.mock('@snowluma/bridge/bridge-oidb', async () => {
|
||||
const actual = await vi.importActual<typeof import('@snowluma/bridge/bridge-oidb')>(
|
||||
'@snowluma/bridge/bridge-oidb',
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
@@ -25,19 +25,19 @@ vi.mock('../../src/bridge/bridge-oidb', async () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('../../src/bridge/highway/highway-client', () => ({
|
||||
vi.mock('@snowluma/bridge/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({})),
|
||||
uploadHighwayHttp: vi.fn(async () => undefined),
|
||||
}));
|
||||
|
||||
vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/utils', () => ({
|
||||
loadBinarySource: vi.fn(async () => ({ bytes: new Uint8Array([1, 2, 3]), fileName: 'avatar.bin' })),
|
||||
computeHashes: vi.fn(() => ({ md5: new Uint8Array(16), sha1: new Uint8Array(20) })),
|
||||
computeMd5: vi.fn(() => new Uint8Array(16)),
|
||||
}));
|
||||
|
||||
import * as oidb from '../../src/bridge/bridge-oidb';
|
||||
import * as highwayClient from '../../src/bridge/highway/highway-client';
|
||||
import * as oidb from '@snowluma/bridge/bridge-oidb';
|
||||
import * as highwayClient from '@snowluma/bridge/highway';
|
||||
import { ProfileApi } from '../../src/bridge/apis/profile';
|
||||
import { mockBridge } from './_helpers';
|
||||
|
||||
@@ -161,7 +161,7 @@ describe('apis/profile', () => {
|
||||
|
||||
it('setGroupAvatar rejects an empty file before hitting highway', async () => {
|
||||
const bridge = mockBridge();
|
||||
const { loadBinarySource } = await import('../../src/bridge/highway/utils');
|
||||
const { loadBinarySource } = await import('@snowluma/bridge/highway/utils');
|
||||
vi.mocked(loadBinarySource).mockResolvedValueOnce({
|
||||
bytes: new Uint8Array(0), fileName: 'empty.png',
|
||||
} as any);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { BridgeEventBus } from '../src/bridge/event-bus';
|
||||
import type { FriendMessage, GroupMessage } from '../src/bridge/events';
|
||||
import { BridgeEventBus } from '@snowluma/bridge/event-bus';
|
||||
import type { FriendMessage, GroupMessage } from '@snowluma/bridge/events';
|
||||
|
||||
function makeFriendMessage(): FriendMessage {
|
||||
return {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { Bridge } from '../src/bridge/bridge';
|
||||
import { IdentityService } from '../src/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo } from '../src/bridge/qq-info';
|
||||
import type { GroupMemberJoin, QQEventVariant } from '../src/bridge/events';
|
||||
import { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo } from '@snowluma/bridge/qq-info';
|
||||
import type { GroupMemberJoin, QQEventVariant } from '@snowluma/bridge/events';
|
||||
import type { PacketInfo } from '@snowluma/common/protocol-types';
|
||||
|
||||
const SELF_UIN = '10001';
|
||||
|
||||
@@ -4,14 +4,14 @@ import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import type { SendMessageRequest, SendMessageResponse } from '@snowluma/proto-defs/action';
|
||||
import type { FileExtra } from '@snowluma/proto-defs/message';
|
||||
|
||||
vi.mock('../src/bridge/element-builder', () => ({
|
||||
vi.mock('@snowluma/bridge/element-builder', () => ({
|
||||
buildSendElems: vi.fn(async () => [{ text: { str: 'stub media elem' } }]),
|
||||
}));
|
||||
|
||||
describe('Bridge private media routing', () => {
|
||||
it('includes resolved uid in the final c2c send request for media messages', async () => {
|
||||
const { Bridge } = await import('../src/bridge/bridge');
|
||||
const { IdentityService } = await import('../src/bridge/identity-service');
|
||||
const { IdentityService } = await import('@snowluma/bridge/identity-service');
|
||||
|
||||
class TestBridge extends Bridge {
|
||||
capturedBody: Uint8Array | null = null;
|
||||
@@ -60,7 +60,7 @@ describe('Bridge private media routing', () => {
|
||||
// implementation wrote c2c routing + richText.notOnlineFile +
|
||||
// c2cCmd=11 — the QQ-NT server rejected every c2c file send.
|
||||
const { Bridge } = await import('../src/bridge/bridge');
|
||||
const { IdentityService } = await import('../src/bridge/identity-service');
|
||||
const { IdentityService } = await import('@snowluma/bridge/identity-service');
|
||||
|
||||
class TestBridge extends Bridge {
|
||||
capturedBody: Uint8Array | null = null;
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
vi.mock('../src/bridge/highway/image-upload', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/image-upload', () => ({
|
||||
uploadImageMsgInfo: vi.fn(async () => new Uint8Array([7, 8, 9])),
|
||||
}));
|
||||
vi.mock('../src/bridge/highway/ptt-upload', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/ptt-upload', () => ({
|
||||
uploadPttMsgInfo: vi.fn(async () => new Uint8Array([4, 5, 6])),
|
||||
}));
|
||||
vi.mock('../src/bridge/highway/video-upload', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/video-upload', () => ({
|
||||
uploadVideoMsgInfo: vi.fn(async () => new Uint8Array([1, 2, 3])),
|
||||
}));
|
||||
|
||||
import { buildSendElems } from '../src/bridge/element-builder';
|
||||
import { buildSendElems } from '@snowluma/bridge/element-builder';
|
||||
|
||||
const fakeBridge = {} as any;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import type {
|
||||
MessageElement,
|
||||
QQEventVariant,
|
||||
TempMessage,
|
||||
} from '../src/bridge/events';
|
||||
} from '@snowluma/bridge/events';
|
||||
|
||||
const SELF_ID = 10001;
|
||||
const PEER_UIN = 22222;
|
||||
|
||||
@@ -12,8 +12,8 @@ import {
|
||||
formatMessageSegments,
|
||||
formatReply,
|
||||
formatUser,
|
||||
} from '../src/utils/event-format';
|
||||
import type { QQEventVariant } from '../src/bridge/events';
|
||||
} from '@snowluma/bridge/format';
|
||||
import type { QQEventVariant } from '@snowluma/bridge/events';
|
||||
|
||||
// ─── Test fakes (just the find* surface event-format uses) ───
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { BridgeEventBus } from '../src/bridge/event-bus';
|
||||
import { BridgeEventBus } from '@snowluma/bridge/event-bus';
|
||||
|
||||
// Wrap convertEvent in a vi.fn that delegates to the real impl by
|
||||
// default, so one test can override it to return null without making
|
||||
@@ -18,7 +18,7 @@ import type {
|
||||
GroupMemberJoin,
|
||||
TempMessage,
|
||||
QQEventVariant,
|
||||
} from '../src/bridge/events';
|
||||
} from '@snowluma/bridge/events';
|
||||
import type { JsonObject, MessageMeta } from '../src/onebot/types';
|
||||
|
||||
const SELF_UIN = '10001';
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import type { GroupReactNotify } from '@snowluma/proto-defs/notify';
|
||||
import { decodeEvent0x2DC } from '../src/bridge/msg-push/decoders/event-0x2dc';
|
||||
import type { MsgPushContext } from '../src/bridge/msg-push/context';
|
||||
import { IdentityService } from '../src/bridge/identity-service';
|
||||
import type { GroupMsgEmojiLikeEvent, QQEventVariant } from '../src/bridge/events';
|
||||
import { decodeEvent0x2DC } from '@snowluma/bridge/msg-push/decoders/event-0x2dc';
|
||||
import type { MsgPushContext } from '@snowluma/bridge/msg-push/context';
|
||||
import { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
import type { GroupMsgEmojiLikeEvent, QQEventVariant } from '@snowluma/bridge/events';
|
||||
import { convertGroupMsgEmojiLike } from '../src/onebot/event-converter/to-notice';
|
||||
import { GROUP_MESSAGE_EVENT, hashMessageIdInt32 } from '../src/onebot/message-id';
|
||||
import { formatEvent } from '../src/utils/event-format';
|
||||
import { formatEvent } from '@snowluma/bridge/format';
|
||||
import { subscribeLogs, type LogEntry } from '@snowluma/common/logger';
|
||||
|
||||
const SELF_UIN = '10001';
|
||||
|
||||
@@ -3,7 +3,7 @@ import os from 'os';
|
||||
import path from 'path';
|
||||
import { pathToFileURL } from 'url';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { loadBinarySource, resolveLocalFilePath } from '../src/bridge/highway/utils';
|
||||
import { loadBinarySource, resolveLocalFilePath } from '@snowluma/bridge/highway/utils';
|
||||
|
||||
describe('highway source paths', () => {
|
||||
it('normalizes file URLs with an extra leading slash on POSIX', () => {
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/highway/pipeline', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/pipeline', () => ({
|
||||
runNtv2Upload: vi.fn(async () => ({ msgInfo: { msgInfoBody: [], extBizInfo: {} } })),
|
||||
finalizeMediaMsgInfo: vi.fn(() => new Uint8Array([0xCA, 0xFE])),
|
||||
hexToBytes: vi.fn((hex: string) => new Uint8Array(hex.length / 2)),
|
||||
}));
|
||||
|
||||
vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/utils', () => ({
|
||||
loadBinarySource: vi.fn(async () => ({ bytes: new Uint8Array([1, 2, 3]), fileName: 'src.jpg' })),
|
||||
computeHashes: vi.fn(() => ({
|
||||
md5: new Uint8Array(16),
|
||||
@@ -22,9 +22,9 @@ vi.mock('../../src/bridge/highway/utils', () => ({
|
||||
detectImageFormat: vi.fn(() => ({ format: 1000, width: 800, height: 600 })),
|
||||
}));
|
||||
|
||||
import * as pipeline from '../../src/bridge/highway/pipeline';
|
||||
import { uploadImageMsgInfo } from '../../src/bridge/highway/image-upload';
|
||||
import { GROUP_IMAGE_CMD_ID, PRIVATE_IMAGE_CMD_ID } from '../../src/bridge/highway/highway-client';
|
||||
import * as pipeline from '@snowluma/bridge/highway/pipeline';
|
||||
import { uploadImageMsgInfo } from '@snowluma/bridge/highway/image-upload';
|
||||
import { GROUP_IMAGE_CMD_ID, PRIVATE_IMAGE_CMD_ID } from '@snowluma/bridge/highway';
|
||||
|
||||
describe('image-upload', () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
|
||||
vi.mock('../../src/bridge/highway/highway-client', () => ({
|
||||
vi.mock('@snowluma/bridge/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({ sessionId: 'fake-session' })),
|
||||
uploadHighwayHttp: vi.fn(async () => undefined),
|
||||
buildHighwayExtend: vi.fn(() => new Uint8Array([0xAA, 0xBB])),
|
||||
@@ -16,14 +16,14 @@ vi.mock('../../src/bridge/highway/highway-client', () => ({
|
||||
GROUP_IMAGE_CMD_ID: 1004,
|
||||
}));
|
||||
|
||||
import * as highway from '../../src/bridge/highway/highway-client';
|
||||
import * as highway from '@snowluma/bridge/highway';
|
||||
import {
|
||||
finalizeMediaMsgInfo,
|
||||
hexToBytes,
|
||||
makeClientRandomId,
|
||||
runNtv2Upload,
|
||||
type MediaSubFileUpload,
|
||||
} from '../../src/bridge/highway/pipeline';
|
||||
} from '@snowluma/bridge/highway/pipeline';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { EncodableMediaMsgInfo, NTV2UploadRichMediaReq, NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/highway/pipeline', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/pipeline', () => ({
|
||||
runNtv2Upload: vi.fn(async () => ({ msgInfo: { msgInfoBody: [], extBizInfo: {} } })),
|
||||
finalizeMediaMsgInfo: vi.fn(() => new Uint8Array([0xAA, 0xBB])),
|
||||
hexToBytes: vi.fn((hex: string) => new Uint8Array(hex.length / 2)),
|
||||
}));
|
||||
|
||||
import * as pipeline from '../../src/bridge/highway/pipeline';
|
||||
import { uploadPttMsgInfo, GROUP_PTT_CMD_ID, PRIVATE_PTT_CMD_ID } from '../../src/bridge/highway/ptt-upload';
|
||||
import * as pipeline from '@snowluma/bridge/highway/pipeline';
|
||||
import { uploadPttMsgInfo, GROUP_PTT_CMD_ID, PRIVATE_PTT_CMD_ID } from '@snowluma/bridge/highway/ptt-upload';
|
||||
|
||||
const FINGERPRINT = {
|
||||
noByteFallback: true,
|
||||
|
||||
@@ -11,20 +11,20 @@
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
|
||||
vi.mock('../../src/bridge/highway/pipeline', () => ({
|
||||
vi.mock('@snowluma/bridge/highway/pipeline', () => ({
|
||||
runNtv2Upload: vi.fn(async () => ({ msgInfo: { msgInfoBody: [], extBizInfo: {} } })),
|
||||
finalizeMediaMsgInfo: vi.fn(() => new Uint8Array([0x12, 0x34])),
|
||||
hexToBytes: vi.fn((hex: string) => new Uint8Array(hex.length / 2)),
|
||||
}));
|
||||
|
||||
import * as pipeline from '../../src/bridge/highway/pipeline';
|
||||
import * as pipeline from '@snowluma/bridge/highway/pipeline';
|
||||
import {
|
||||
uploadVideoMsgInfo,
|
||||
GROUP_VIDEO_CMD_ID,
|
||||
GROUP_VIDEO_THUMB_CMD_ID,
|
||||
PRIVATE_VIDEO_CMD_ID,
|
||||
PRIVATE_VIDEO_THUMB_CMD_ID,
|
||||
} from '../../src/bridge/highway/video-upload';
|
||||
} from '@snowluma/bridge/highway/video-upload';
|
||||
|
||||
const FINGERPRINT = {
|
||||
noByteFallback: true,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { IdentityService } from '../src/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo, UserProfileInfo } from '../src/bridge/qq-info';
|
||||
import { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo, UserProfileInfo } from '@snowluma/bridge/qq-info';
|
||||
|
||||
const SELF_UIN = '10001';
|
||||
const GROUP_ID = 123456789;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { MediaIndexer } from '../src/onebot/media-indexer';
|
||||
import type { MessageElement } from '../src/bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
|
||||
function makeMediaStore() {
|
||||
return {
|
||||
|
||||
@@ -3,7 +3,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { MediaStore } from '../src/onebot/media-store';
|
||||
import { convertEvent, type ConverterContext } from '../src/onebot/event-converter';
|
||||
import type { GroupMessage, FriendMessage, MessageElement } from '../src/bridge/events';
|
||||
import type { GroupMessage, FriendMessage, MessageElement } from '@snowluma/bridge/events';
|
||||
|
||||
const SELF_ID = 10001;
|
||||
const PEER_UIN = 22222;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { MediaUrlResolver } from '../src/onebot/media-url-resolver';
|
||||
import type { MessageElement } from '../src/bridge/events';
|
||||
import type { MessageElement } from '@snowluma/bridge/events';
|
||||
|
||||
// Minimal stand-ins for the two collaborators. Each test wires whatever
|
||||
// subset of Bridge methods the element type exercises.
|
||||
|
||||
@@ -4,7 +4,7 @@ import path from 'path';
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||
import { parseMessage } from '../src/onebot/message-parser';
|
||||
import { buildSendElems } from '../src/bridge/element-builder';
|
||||
import { buildSendElems } from '@snowluma/bridge/element-builder';
|
||||
import type { MentionExtraSend } from '@snowluma/proto-defs/action';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import { parseMsgPush, MSG_PUSH_CMD } from '../src/bridge/msg-push';
|
||||
import { IdentityService } from '../src/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo } from '../src/bridge/qq-info';
|
||||
import { parseMsgPush, MSG_PUSH_CMD } from '@snowluma/bridge/msg-push';
|
||||
import { IdentityService } from '@snowluma/bridge/identity-service';
|
||||
import type { GroupMemberInfo, QQGroupInfo } from '@snowluma/bridge/qq-info';
|
||||
// Proton's call-site analyzer keys off the literal type identifier
|
||||
// printed in `protobuf_encode<X>` — it walks imports by *original*
|
||||
// name (not alias). If both `import { X } from 'proto/notify'` and
|
||||
@@ -18,7 +18,7 @@ import type {
|
||||
import type { PushMsg } from '@snowluma/proto-defs/message';
|
||||
import type {
|
||||
GroupMemberJoin, FriendAddEvent, QQEventVariant,
|
||||
} from '../src/bridge/events';
|
||||
} from '@snowluma/bridge/events';
|
||||
|
||||
// Local alias for the event-side recall type — derived via Extract so
|
||||
// we avoid an `import { FriendRecall as X }` that collides with the
|
||||
|
||||
@@ -13,7 +13,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_encode } from '@snowluma/proton';
|
||||
import { subscribeLogs, type LogEntry } from '@snowluma/common/logger';
|
||||
|
||||
vi.mock('../src/bridge/highway/highway-client', () => ({
|
||||
vi.mock('@snowluma/bridge/highway', () => ({
|
||||
fetchHighwaySession: vi.fn(async () => ({ sessionId: 'fake-session' })),
|
||||
uploadHighwayHttp: vi.fn(async () => undefined),
|
||||
buildHighwayExtend: vi.fn(() => new Uint8Array([0xAA, 0xBB])),
|
||||
@@ -24,12 +24,12 @@ vi.mock('../src/bridge/highway/highway-client', () => ({
|
||||
import {
|
||||
runNtv2Upload,
|
||||
type MediaSubFileUpload,
|
||||
} from '../src/bridge/highway/pipeline';
|
||||
} from '@snowluma/bridge/highway/pipeline';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
|
||||
import { MsgPushRegistry } from '../src/bridge/msg-push/registry';
|
||||
import type { MsgPushContext } from '../src/bridge/msg-push/context';
|
||||
import { decodeEvent0x2DC } from '../src/bridge/msg-push/decoders/event-0x2dc';
|
||||
import { MsgPushRegistry } from '@snowluma/bridge/msg-push/registry';
|
||||
import type { MsgPushContext } from '@snowluma/bridge/msg-push/context';
|
||||
import { decodeEvent0x2DC } from '@snowluma/bridge/msg-push/decoders/event-0x2dc';
|
||||
|
||||
function encodeOidbResponse(body: unknown): Buffer {
|
||||
return Buffer.from(protobuf_encode<OidbBase<NTV2UploadRichMediaResp>>({
|
||||
|
||||
@@ -7,7 +7,7 @@ import { describe, expect, it, vi } from 'vitest';
|
||||
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
|
||||
import type {
|
||||
FriendInfo, GroupMemberInfo, QQGroupInfo, UserProfileInfo,
|
||||
} from '../../src/bridge/qq-info';
|
||||
} from '@snowluma/bridge/qq-info';
|
||||
import {
|
||||
getFriendList,
|
||||
getGroupInfo,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import { ApiHandler, type ApiActionContext } from '../../src/onebot/api-handler';
|
||||
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
|
||||
import type { GroupRequestInfo } from '../../src/bridge/qq-info';
|
||||
import type { GroupRequestInfo } from '@snowluma/bridge/qq-info';
|
||||
import type { MessageMeta } from '../../src/onebot/types';
|
||||
|
||||
function fakeMeta(overrides: Partial<MessageMeta> = {}): MessageMeta {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { handleGroupAddRequest } from '../../src/onebot/modules/request-actions';
|
||||
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
|
||||
import type { GroupRequestInfo } from '../../src/bridge/qq-info';
|
||||
import type { GroupRequestInfo } from '@snowluma/bridge/qq-info';
|
||||
|
||||
// See `contact-actions.test.ts` for the auto-promotion rationale.
|
||||
const APIS_ROUTING: Record<string, string> = {
|
||||
|
||||
Reference in new issue
Block a user