refactor(onebot): extract OneBot protocol translation into @snowluma/onebot

Phase 3 of the 4-package split (RoadMap #3). Moves the entire
`packages/core/src/onebot/` subtree (43 source files + 20 test files
spanning network adapters, action handlers, event converters, message
parser, message store, media store, instance + manager) into the new
`@snowluma/onebot` workspace package. The remaining `@snowluma/core`
now hosts only the api-layer (Bridge class + 13 Api classes), the
hook tooling, the WebUI server, and the runnable `index.ts`.

Why
---
- The OneBot adapter is the public-facing OneBot11 protocol surface;
  it has its own version cadence and its own consumers (third-party
  bots talking OneBot WS / HTTP). Splitting it lets that cadence move
  independently of the Api-on-ctx layer.
- The two were sharing the `packages/core/` build pipeline only
  because they happened to live in the same directory. Nothing in
  the api-layer reaches into OneBot internals.
- Mirrors NapCat / Lagrange.OneBot's repo split (their OneBot adapter
  is a separate assembly from the Core protocol library).

Layout
------
Moved via `git mv` (history preserved):
  packages/core/src/onebot/*  → @snowluma/onebot/src/<x>
  packages/core/tests/onebot/* (6 files)   → @snowluma/onebot/tests/
  packages/core/tests/{message-parser,message-store,event-pipeline,
    media-store,media-url-resolver,event-converter,
    http-server-hot-reload,http-server-content-type,
    api-handler-logging,message-id,group-msg-emoji-like,
    config,media-indexer,network-manager}.test.ts (14 files)
                                              → @snowluma/onebot/tests/

What stays in @snowluma/core
----------------------------
- `bridge/{bridge,bridge-interface,bridge-context,manager}.ts`
- `bridge/apis/*` (the 13 typed Api classes)
- `hook/*` (debugger/injector — tooling for the core protocol layer)
- `webui/*` (admin UI server — application wiring, not the OneBot
  adapter itself)
- `index.ts` (application entry that wires BridgeManager +
  OneBotManager + HookManager + WebUI together)

Changes
-------
- New package `packages/onebot/` (package.json with subpath exports
  mirroring legacy `core/src/onebot/<x>` 1:1, tsconfig.json,
  vitest.config.ts with `SNOWLUMA_LOG_LEVEL=debug` env so the action-
  dispatch logging tests see debug-level subscribers — copied verbatim
  from core's vitest.config.ts).
- @snowluma/core grows new subpath exports for the api-layer files
  OneBot's type-only imports need: `./bridge`, `./bridge-interface`,
  `./bridge-context`, `./manager`, `./apis`.
- `@snowluma/onebot` depends on `@snowluma/bridge`, `@snowluma/common`,
  `@snowluma/core`, `@snowluma/proto-defs`, `@snowluma/proton`,
  `@snowluma/websocket`.
- `@snowluma/core` depends on `@snowluma/onebot` (for index.ts +
  webui/server.ts wiring).
- 100+ import sites rewritten via sed:
  * OneBot → core: `'../bridge/bridge'` → `'@snowluma/core/bridge'`,
    `'../bridge/manager'` → `'@snowluma/core/manager'`,
    `'../bridge/bridge-interface'` → `'@snowluma/core/bridge-interface'`,
    `'@/bridge/bridge'` (vite path alias) → `'@snowluma/core/bridge'`.
  * Core → OneBot: `'./onebot/manager'` → `'@snowluma/onebot/manager'`,
    `'../onebot/config'` → `'@snowluma/onebot/config'`, etc.
  * Test relative paths: `'../../src/onebot/<x>'` → `'../src/<x>'`
    after the test file move (one level shallower).
- New `packages/onebot/src/env.d.ts` declaring `__APP_VERSION__` and
  `__BUILD_WEBUI__` (the vite-injected globals `info.ts` reads).

Workspace cycle
---------------
core ↔ onebot is allowed by pnpm workspaces. The runtime direction
is one-way: core → onebot (index.ts constructs OneBotManager,
webui/server reads OneBot config). OneBot only reaches into core for
TYPES (Bridge, BridgeInterface, BridgeManager, ClientKeyInfo,
DownloadRKeyInfo); those imports use `import type` so they compile
out at runtime and don't introduce a real cycle.

Verification
------------
- Full workspace `pnpm -r typecheck`: all 11 projects clean.
- `@snowluma/core` test suite: 302/302 pass (33 test files).
- `@snowluma/onebot` test suite: 250/250 pass (20 test files;
  pre-existing `network-manager.test.ts` native-addon failure
  unchanged — same baseline as before the split).
- Combined: 552/552 — identical pass count to the pre-Phase-3
  baseline.
- Vite build with stubbed native binary: clean, 2.84 MB bundle /
  224 KB gzip (identical envelope).
This commit is contained in:
DrSmoothl committed 2026-05-21 08:52:00 +08:00
1 parent f7a03ca05a
commit 9a30df9907
71 files changed
+286 -59

No files matched your search

+27
View File
@@ -5,6 +5,32 @@
"private": true,
"type": "module",
"main": "../../dist/index.mjs",
"exports": {
".": {
"types": "./src/index.ts",
"default": "../../dist/index.mjs"
},
"./bridge": {
"types": "./src/bridge/bridge.ts",
"default": "./src/bridge/bridge.ts"
},
"./bridge-interface": {
"types": "./src/bridge/bridge-interface.ts",
"default": "./src/bridge/bridge-interface.ts"
},
"./bridge-context": {
"types": "./src/bridge/bridge-context.ts",
"default": "./src/bridge/bridge-context.ts"
},
"./manager": {
"types": "./src/bridge/manager.ts",
"default": "./src/bridge/manager.ts"
},
"./apis": {
"types": "./src/bridge/apis/index.ts",
"default": "./src/bridge/apis/index.ts"
}
},
"scripts": {
"build": "vite build",
"build:all": "cross-env BUILD_WEBUI=true vite build",
@@ -16,6 +42,7 @@
"dependencies": {
"@snowluma/bridge": "workspace:*",
"@snowluma/common": "workspace:*",
"@snowluma/onebot": "workspace:*",
"@snowluma/proto-defs": "workspace:*",
"@snowluma/proton": "workspace:*",
"@snowluma/websocket": "workspace:*"
+1 -1
View File
@@ -1,5 +1,5 @@
import { BridgeManager } from './bridge/manager';
import { OneBotManager } from './onebot/manager';
import { OneBotManager } from '@snowluma/onebot/manager';
import { loadRuntimeConfig } from '@snowluma/common/runtime';
import { closeLogger, createLogger } from '@snowluma/common/logger';
import { HookManager } from './hook/hook-manager';
+3 -3
View File
@@ -4,9 +4,9 @@ import { Hono, type Context } from 'hono';
import { describeTrustProxy, makeClientIpResolver, parseTrustProxy } from './client-ip';
import { createLogger, getLogLevel, getRecentLogs, LOG_LEVELS, setLogLevel, subscribeLogs } from '@snowluma/common/logger';
import { randomBytes } from 'crypto';
import type { OneBotManager } from '../onebot/manager';
import { loadOneBotConfig, saveOneBotConfig } from '../onebot/config';
import type { OneBotConfig } from '../onebot/types';
import type { OneBotManager } from '@snowluma/onebot/manager';
import { loadOneBotConfig, saveOneBotConfig } from '@snowluma/onebot/config';
import type { OneBotConfig } from '@snowluma/onebot/types';
import type { HookManager, HookProcessInfo } from '../hook/hook-manager';
import path from 'path';
import { existsSync, readFileSync } from 'fs';
+103
View File
@@ -0,0 +1,103 @@
{
"name": "@snowluma/onebot",
"version": "1.9.0",
"private": true,
"type": "module",
"description": "SnowLuma OneBot v11 adapter — the protocol translation layer that maps the public OneBot vocabulary (HTTP / WebSocket actions, message segments, post events) onto @snowluma/core's typed Api hub (`bridge.apis.<area>.method()`). Owns network adapters (HTTP server / HTTP client / WS server / WS client), the registered action handlers, the receive-side event→OneBot converter, message-id hashing, message store (SQLite-backed event history), media store, and the OneBot instance + manager that ties one OneBotConfig to one Bridge. Per-file subpath exports mirror the legacy `core/src/onebot/*` layout 1:1 so the previous `import { … } from '../onebot/<x>'` collapses to `import { … } from '@snowluma/onebot/<x>'`.",
"main": "./src/index.ts",
"types": "./src/index.ts",
"exports": {
".": {
"types": "./src/index.ts",
"default": "./src/index.ts"
},
"./manager": {
"types": "./src/manager.ts",
"default": "./src/manager.ts"
},
"./instance": {
"types": "./src/instance.ts",
"default": "./src/instance.ts"
},
"./instance-context": {
"types": "./src/instance-context.ts",
"default": "./src/instance-context.ts"
},
"./api-handler": {
"types": "./src/api-handler.ts",
"default": "./src/api-handler.ts"
},
"./config": {
"types": "./src/config.ts",
"default": "./src/config.ts"
},
"./types": {
"types": "./src/types.ts",
"default": "./src/types.ts"
},
"./message-id": {
"types": "./src/message-id.ts",
"default": "./src/message-id.ts"
},
"./message-parser": {
"types": "./src/message-parser.ts",
"default": "./src/message-parser.ts"
},
"./message-store": {
"types": "./src/message-store.ts",
"default": "./src/message-store.ts"
},
"./media-store": {
"types": "./src/media-store.ts",
"default": "./src/media-store.ts"
},
"./media-indexer": {
"types": "./src/media-indexer.ts",
"default": "./src/media-indexer.ts"
},
"./media-url-resolver": {
"types": "./src/media-url-resolver.ts",
"default": "./src/media-url-resolver.ts"
},
"./event-filter": {
"types": "./src/event-filter.ts",
"default": "./src/event-filter.ts"
},
"./event-pipeline": {
"types": "./src/event-pipeline.ts",
"default": "./src/event-pipeline.ts"
},
"./event-converter": {
"types": "./src/event-converter/index.ts",
"default": "./src/event-converter/index.ts"
},
"./event-converter/utils": {
"types": "./src/event-converter/utils.ts",
"default": "./src/event-converter/utils.ts"
},
"./instance-rkey": {
"types": "./src/instance-rkey.ts",
"default": "./src/instance-rkey.ts"
}
},
"scripts": {
"test": "vitest run",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@snowluma/bridge": "workspace:*",
"@snowluma/common": "workspace:*",
"@snowluma/core": "workspace:*",
"@snowluma/proto-defs": "workspace:*",
"@snowluma/proton": "workspace:*",
"@snowluma/websocket": "workspace:*"
},
"devDependencies": {
"@hono/node-server": "^1.19.14",
"@types/node": "^24.12.2",
"hono": "^4.12.14",
"typescript": "catalog:",
"vite": "catalog:",
"vitest": "^4.1.4"
}
}
File renamed without changes.
@@ -1,6 +1,6 @@
import type { JsonObject, JsonValue, MessageMeta } from './types';
import type { ForwardPreviewMeta } from './modules/message-actions';
import type { BridgeInterface } from '../bridge/bridge-interface';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import { RETCODE, failedResponse } from './types';
import { createLogger, type Logger } from '@snowluma/common/logger';
import { summarizeParams } from '@snowluma/common/log-summary';
@@ -18,7 +18,7 @@ import { register as registerExtended } from './actions/extended';
import { register as registerGroupAlbum } from './actions/group-album';
import { WebHonorType } from '@snowluma/bridge/web/group-honor';
import { ClientKeyInfo } from '@/bridge/bridge';
import type { ClientKeyInfo } from '@snowluma/core/bridge';
export interface MessageSendResult {
messageId: number;
File renamed without changes.
+8
View File
@@ -0,0 +1,8 @@
// Globals injected by Vite at build time (see `packages/core/vite.config.ts`).
// `__APP_VERSION__` reads from the monorepo root `package.json::version`;
// `__BUILD_WEBUI__` flips on when `BUILD_WEBUI=true` is set so the runner
// stitches the SPA assets in. Both are typed as `unknown` outside vite
// (e.g. when running tests via vitest where the plugin isn't applied) —
// callers guard with `typeof __APP_VERSION__ !== 'undefined'`.
declare const __BUILD_WEBUI__: boolean;
declare const __APP_VERSION__: string;
File renamed without changes.
@@ -1,5 +1,5 @@
import type { WebHonorType } from '@snowluma/bridge/web/group-honor';
import type { Bridge } from '../bridge/bridge';
import type { Bridge } from '@snowluma/core/bridge';
import type { ApiActionContext } from './api-handler';
import type { ConverterContext } from './event-converter';
import type { MediaStore } from './media-store';
@@ -35,7 +35,7 @@ import {
getRecordInfo as getCachedRecordInfo,
} from './modules/media-actions';
import { handleGroupAddRequest } from './modules/request-actions';
import type { BridgeInterface } from '../bridge/bridge-interface';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
/**
* Single shared context bag that flows through every OneBot instance-internal
@@ -1,6 +1,6 @@
import type { MessageElement } from '@snowluma/bridge/events';
import type { DownloadRKeyInfo } from '../bridge/bridge';
import type { BridgeInterface } from '../bridge/bridge-interface';
import type { DownloadRKeyInfo } from '@snowluma/core/bridge';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import { createLogger } from '@snowluma/common/logger';
const log = createLogger('OneBot');
@@ -1,5 +1,5 @@
import path from 'path';
import type { BridgeInterface } from '../bridge/bridge-interface';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import { ApiHandler } from './api-handler';
import type { ConverterContext } from './event-converter';
import { MediaIndexer } from './media-indexer';
@@ -1,5 +1,5 @@
import type { BridgeInterface } from '../bridge/bridge-interface';
import type { BridgeManager } from '../bridge/manager';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import type { BridgeManager } from '@snowluma/core/manager';
import { createLogger } from '@snowluma/common/logger';
import { loadOneBotConfig } from './config';
import { OneBotInstance } from './instance';
File renamed without changes.
@@ -1,4 +1,4 @@
import type { BridgeInterface } from '../bridge/bridge-interface';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import type { MessageElement } from '@snowluma/bridge/events';
import type { RKeyCache } from './instance-rkey';
File renamed without changes.
@@ -1,4 +1,4 @@
import type { BridgeInterface } from '../../bridge/bridge-interface';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import type { IdentityService } from '@snowluma/bridge/identity-service';
import type { OneBotInstanceContext } from '../instance-context';
import type { JsonObject } from '../types';
@@ -1,4 +1,4 @@
import type { BridgeInterface } from '../../bridge/bridge-interface';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import { createLogger } from '@snowluma/common/logger';
import type { MediaStore } from '../media-store';
import type { JsonObject } from '../types';
@@ -1,4 +1,4 @@
import type { BridgeInterface } from '../../bridge/bridge-interface';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
import type { ForwardNodePayload, MessageElement } from '@snowluma/bridge/events';
import { createLogger } from '@snowluma/common/logger';
import type { MessageSendResult } from '../api-handler';
@@ -1,4 +1,4 @@
import type { BridgeInterface } from '../../bridge/bridge-interface';
import type { BridgeInterface } from '@snowluma/core/bridge-interface';
export async function handleGroupAddRequest(
bridge: BridgeInterface,
File renamed without changes.
@@ -5,7 +5,7 @@
// from blowing the line width.
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { ApiHandler } from '../src/onebot/api-handler';
import { ApiHandler } from '../src/api-handler';
import { subscribeLogs, type LogEntry } from '@snowluma/common/logger';
import { summarizeParams } from '@snowluma/common/log-summary';
@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import fs from 'fs';
import os from 'os';
import path from 'path';
import { loadOneBotConfig, makeDefaultOneBotConfig, saveOneBotConfig } from '../src/onebot/config';
import { loadOneBotConfig, makeDefaultOneBotConfig, saveOneBotConfig } from '../src/config';
const TOKEN_PATTERN = /^[A-Za-z0-9_-]{43}$/;
@@ -16,8 +16,8 @@ import {
getGroupMemberList,
getLoginInfo,
getStrangerInfo,
} from '../../src/onebot/modules/contact-actions';
import type { OneBotInstanceContext } from '../../src/onebot/instance-context';
} from '../src/modules/contact-actions';
import type { OneBotInstanceContext } from '../src/instance-context';
/**
* A typed BridgeInterface where every property is undefined by default;
@@ -3,13 +3,13 @@ import {
convertEvent,
elementsToOneBotSegments,
type ConverterContext,
} from '../src/onebot/event-converter';
} from '../src/event-converter';
import {
buildDispatchPayload,
pickDispatchJson,
resolveReportOptions,
shapeEventForAdapter,
} from '../src/onebot/event-filter';
} from '../src/event-filter';
import type {
FriendMessage,
GroupMessage,
@@ -4,14 +4,14 @@ 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
// the others lose the real conversion behavior.
vi.mock('../src/onebot/event-converter', async () => {
const actual = await vi.importActual<typeof import('../src/onebot/event-converter')>('../src/onebot/event-converter');
vi.mock('../src/event-converter', async () => {
const actual = await vi.importActual<typeof import('../src/event-converter')>('../src/event-converter');
return { ...actual, convertEvent: vi.fn(actual.convertEvent) };
});
import { convertEvent, type ConverterContext } from '../src/onebot/event-converter';
import { registerEventPipeline } from '../src/onebot/event-pipeline';
import type { OneBotInstanceContext } from '../src/onebot/instance-context';
import { convertEvent, type ConverterContext } from '../src/event-converter';
import { registerEventPipeline } from '../src/event-pipeline';
import type { OneBotInstanceContext } from '../src/instance-context';
import type {
FriendMessage,
GroupMessage,
@@ -19,7 +19,7 @@ import type {
TempMessage,
QQEventVariant,
} from '@snowluma/bridge/events';
import type { JsonObject, MessageMeta } from '../src/onebot/types';
import type { JsonObject, MessageMeta } from '../src/types';
const SELF_UIN = '10001';
const SELF_ID = 10001;
@@ -5,10 +5,10 @@
// param coercion, retcode shape) is part of what's under test.
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { ApiHandler, type ApiActionContext } from '../../src/onebot/api-handler';
import { ApiHandler, type ApiActionContext } from '../src/api-handler';
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
import type { GroupRequestInfo } from '@snowluma/bridge/qq-info';
import type { MessageMeta } from '../../src/onebot/types';
import type { MessageMeta } from '../src/types';
function fakeMeta(overrides: Partial<MessageMeta> = {}): MessageMeta {
return {
@@ -15,11 +15,11 @@
import { describe, expect, it, vi } from 'vitest';
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
import type { OneBotInstanceContext } from '../../src/onebot/instance-context';
import type { OneBotInstanceContext } from '../src/instance-context';
import {
sendGroupForwardMessage,
sendPrivateForwardMessage,
} from '../../src/onebot/modules/message-actions';
} from '../src/modules/message-actions';
function fakeBridge(overrides: Partial<BridgeInterface> = {}): BridgeInterface {
return new Proxy(overrides as BridgeInterface, {
@@ -12,8 +12,8 @@ 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 { convertGroupMsgEmojiLike } from '../src/event-converter/to-notice';
import { GROUP_MESSAGE_EVENT, hashMessageIdInt32 } from '../src/message-id';
import { formatEvent } from '@snowluma/bridge/format';
import { subscribeLogs, type LogEntry } from '@snowluma/common/logger';
@@ -4,9 +4,9 @@
import { describe, expect, it, vi, beforeAll, afterAll } from 'vitest';
import http from 'http';
import { HttpServerAdapter } from '../src/onebot/network/http-server-adapter';
import type { NetworkAdapterContext } from '../src/onebot/network/adapter';
import type { HttpServerNetwork } from '../src/onebot/types';
import { HttpServerAdapter } from '../src/network/http-server-adapter';
import type { NetworkAdapterContext } from '../src/network/adapter';
import type { HttpServerNetwork } from '../src/types';
// ─── Helpers ───
@@ -9,9 +9,9 @@
import { describe, expect, it, vi, afterEach } from 'vitest';
import http from 'http';
import type { AddressInfo } from 'net';
import { HttpServerAdapter } from '../src/onebot/network/http-server-adapter';
import { NetworkReloadType, type NetworkAdapterContext } from '../src/onebot/network/adapter';
import type { HttpServerNetwork } from '../src/onebot/types';
import { HttpServerAdapter } from '../src/network/http-server-adapter';
import { NetworkReloadType, type NetworkAdapterContext } from '../src/network/adapter';
import type { HttpServerNetwork } from '../src/types';
function fakeCtx(): NetworkAdapterContext {
return {
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest';
import { MediaIndexer } from '../src/onebot/media-indexer';
import { MediaIndexer } from '../src/media-indexer';
import type { MessageElement } from '@snowluma/bridge/events';
function makeMediaStore() {
@@ -1,8 +1,8 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
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 { MediaStore } from '../src/media-store';
import { convertEvent, type ConverterContext } from '../src/event-converter';
import type { GroupMessage, FriendMessage, MessageElement } from '@snowluma/bridge/events';
const SELF_ID = 10001;
@@ -1,5 +1,5 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { MediaUrlResolver } from '../src/onebot/media-url-resolver';
import { MediaUrlResolver } from '../src/media-url-resolver';
import type { MessageElement } from '@snowluma/bridge/events';
// Minimal stand-ins for the two collaborators. Each test wires whatever
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { hashMessageIdInt32, GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../src/onebot/message-id';
import { hashMessageIdInt32, GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../src/message-id';
describe('hashMessageIdInt32', () => {
it('returns consistent hash for same inputs', () => {
@@ -3,7 +3,7 @@ import os from 'os';
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 { parseMessage } from '../src/message-parser';
import { buildSendElems } from '@snowluma/bridge/element-builder';
import type { MentionExtraSend } from '@snowluma/proto-defs/action';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { MessageStore } from '../src/onebot/message-store';
import { hashMessageIdInt32, GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../src/onebot/message-id';
import { MessageStore } from '../src/message-store';
import { hashMessageIdInt32, GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT } from '../src/message-id';
import fs from 'fs';
import path from 'path';
@@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';
import { IOneBotNetworkAdapter, NetworkReloadType, OneBotNetworkManager } from '../src/onebot/network';
import type { NetworkAdapterContext } from '../src/onebot/network';
import type { JsonObject, NetworkBase } from '../src/onebot/types';
import type { DispatchPayload } from '../src/onebot/event-filter';
import { IOneBotNetworkAdapter, NetworkReloadType, OneBotNetworkManager } from '../src/network';
import type { NetworkAdapterContext } from '../src/network';
import type { JsonObject, NetworkBase } from '../src/types';
import type { DispatchPayload } from '../src/event-filter';
interface FakeNetworkConfig extends NetworkBase {
// Allows tests to influence behavior via config:
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from 'vitest';
import { handleGroupAddRequest } from '../../src/onebot/modules/request-actions';
import { handleGroupAddRequest } from '../src/modules/request-actions';
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
import type { GroupRequestInfo } from '@snowluma/bridge/qq-info';
@@ -17,8 +17,8 @@
import { describe, expect, it, vi } from 'vitest';
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
import type { OneBotInstanceContext } from '../../src/onebot/instance-context';
import { sendGroupMessage } from '../../src/onebot/modules/message-actions';
import type { OneBotInstanceContext } from '../src/instance-context';
import { sendGroupMessage } from '../src/modules/message-actions';
function fakeBridge(overrides: Partial<BridgeInterface> = {}): BridgeInterface {
return new Proxy(overrides as BridgeInterface, {
@@ -16,8 +16,8 @@
import { describe, expect, it, vi } from 'vitest';
import type { BridgeInterface } from '../../src/bridge/bridge-interface';
import type { OneBotInstanceContext } from '../../src/onebot/instance-context';
import { sendPrivateMessage } from '../../src/onebot/modules/message-actions';
import type { OneBotInstanceContext } from '../src/instance-context';
import { sendPrivateMessage } from '../src/modules/message-actions';
function fakeBridge(overrides: Partial<BridgeInterface> = {}): BridgeInterface {
return new Proxy(overrides as BridgeInterface, {
+13
View File
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node"],
"noEmit": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}
+33
View File
@@ -0,0 +1,33 @@
// Vitest config — runs the OneBot tests against the workspace TS
// source directly (no build step). The 20 tests here were previously
// inside `packages/core/tests/` and ran via `@snowluma/core`'s vitest
// invocation; they moved over wholesale in the Phase 3 split.
import protobufVitePlugin from '@snowluma/proton/vite';
import { defineConfig } from 'vitest/config';
export default defineConfig({
// `@snowluma/proton` provides the bare-specifier resolver that turns
// `import type { OidbBase } from '@snowluma/proto-defs/oidb'` into
// a zero-runtime encoder/decoder at the call site. The same plugin
// is loaded by `@snowluma/core`'s vite config — keep it here so the
// OneBot tests resolve identically.
plugins: [protobufVitePlugin()],
test: {
include: ['tests/**/*.test.ts'],
environment: 'node',
// Suppress the logger's file transport during tests so the suite
// doesn't litter cwd with logs/snowluma-*.log files. Tests that
// explicitly cover file output set their own SNOWLUMA_LOG_FILE='1'
// + SNOWLUMA_LOG_DIR=<tmp>.
//
// Run at debug level so tests asserting on debug-level log entries
// (e.g. action dispatch entry lines) actually see them via the
// ring buffer / subscribers, which sit behind the console-level
// gate. Mirrors the equivalent env setup in @snowluma/core's
// vitest.config.ts.
env: {
SNOWLUMA_LOG_FILE: '0',
SNOWLUMA_LOG_LEVEL: 'debug'
}
},
});
+43
View File
@@ -84,6 +84,9 @@ importers:
'@snowluma/common':
specifier: workspace:*
version: link:../common
'@snowluma/onebot':
specifier: workspace:*
version: link:../onebot
'@snowluma/proto-defs':
specifier: workspace:*
version: link:../proto-defs
@@ -125,6 +128,46 @@ importers:
specifier: ^4.1.4
version: 4.1.4(@types/[email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))
packages/onebot:
dependencies:
'@snowluma/bridge':
specifier: workspace:*
version: link:../bridge
'@snowluma/common':
specifier: workspace:*
version: link:../common
'@snowluma/core':
specifier: workspace:*
version: link:../core
'@snowluma/proto-defs':
specifier: workspace:*
version: link:../proto-defs
'@snowluma/proton':
specifier: workspace:*
version: link:../proton
'@snowluma/websocket':
specifier: workspace:*
version: link:../websocket
devDependencies:
'@hono/node-server':
specifier: ^1.19.14
version: 1.19.14([email protected])
'@types/node':
specifier: ^24.12.2
version: 24.12.2
hono:
specifier: ^4.12.14
version: 4.12.14
typescript:
specifier: 'catalog:'
version: 6.0.2
vite:
specifier: 'catalog:'
version: 8.0.8(@types/[email protected])([email protected])([email protected])([email protected])([email protected])
vitest:
specifier: ^4.1.4
version: 4.1.4(@types/[email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))
packages/proto-defs:
dependencies:
'@snowluma/proton':