chore(core): flatten single-file dirs + drop dead writeFailed surface

Two small cleanups that came out of the round-2 architecture review
and are sub-five-minutes each — bundled because each one is too
small to justify its own commit.

#5 — flatten single-file directories
  packages/core/src/bridge/builders/element-builder.ts
    -> packages/core/src/bridge/element-builder.ts
  packages/core/src/bridge/handlers/msg-push-handler.ts
    -> packages/core/src/bridge/msg-push-handler.ts

  Both dirs had exactly one file in them — a smell that says
  "planned a sibling that never landed". Moving up one level
  removes the wrapper directory.

  Touch list:
    - bridge.ts:                  2 import paths
    - bridge/actions/forward.ts:  2 import paths
    - msg-push-handler.ts:        internal ../X -> ./X for events,
                                  proto/element, proto/message (the
                                  dynamic-import-typeof references too)
    - element-builder.ts:         internal ../X -> ./X for bridge,
                                  events, highway/*
    - 4 test files:               import paths (2 regular, 2 vi.mock)

#6 — drop IdentityService.hasWriteFailure
  identity-service.ts had a `private writeFailed = false` field set
  by the runWrite catch block and exposed via `get hasWriteFailure()`,
  but a full-repo grep showed zero callers of the getter. It was a
  public API stub for a feature that hadn't been wired (a webui
  health indicator, presumably).

  Removed:
    - the field
    - the getter
    - the assignment in runWrite's catch block (the error log on
      the next line is the actual observable behavior; nothing else
      reads the flag)

  If we want a "did any write fail this session" surface later,
  it's trivial to add back with an explicit consumer in mind.

Behavior preserved end-to-end. No public API change outside the
moved files. 369 tests pass (unchanged). 3 stability runs.
This commit is contained in:
DrSmoothl committed 2026-05-12 20:59:25 +08:00
1 parent 069548918b
commit dd02535a73
9 files changed
+29 -35

No files matched your search

+2 -2
View File
@@ -6,8 +6,8 @@
import type { Bridge } from '../bridge';
import { gunzipSync, gzipSync } from 'zlib';
import { protoDecode, protoEncode } from '../../protobuf/decode';
import { buildSendElems } from '../builders/element-builder';
import { parseMsgPush } from '../handlers/msg-push-handler';
import { buildSendElems } from '../element-builder';
import { parseMsgPush } from '../msg-push-handler';
import type { ForwardNodePayload } from '../events';
import type { PacketInfo } from '../../protocol/types';
import {
+2 -2
View File
@@ -6,10 +6,10 @@ import type { PacketInfo } from '../protocol/types';
import type { ForwardNodePayload, QQEventVariant, MessageElement } from './events';
import type { FriendInfo, QQGroupInfo, GroupMemberInfo, UserProfileInfo, GroupRequestInfo } from './qq-info';
import { QQInfo } from './qq-info';
import { MSG_PUSH_CMD, parseMsgPush } from './handlers/msg-push-handler';
import { MSG_PUSH_CMD, parseMsgPush } from './msg-push-handler';
import type { PacketSender, SendPacketResult } from '../protocol/packet-sender';
import { protoEncode, protoDecode } from '../protobuf/decode';
import { buildSendElems } from './builders/element-builder';
import { buildSendElems } from './element-builder';
import { IdentityService } from './identity-service';
import { createLogger } from '../utils/logger';
import {
@@ -2,20 +2,20 @@
// for encoding with protoEncode(SendMessageRequestSchema).
// Port of src/bridge/src/bridge_messages.cpp build_send_elems()
import type { Bridge } from '../bridge';
import type { MessageElement } from '../events';
import type { ProtoDecoded } from '../../protobuf/decode';
import { protoEncode } from '../../protobuf/decode';
import type { Bridge } from './bridge';
import type { MessageElement } from './events';
import type { ProtoDecoded } from '../protobuf/decode';
import { protoEncode } from '../protobuf/decode';
import {
ElemSchema,
} from '../proto/element';
} from './proto/element';
import {
MentionExtraSendSchema,
MarkdownDataSchema,
} from '../proto/action';
import { uploadImageMsgInfo } from '../highway/image-upload';
import { uploadPttMsgInfo } from '../highway/ptt-upload';
import { uploadVideoMsgInfo } from '../highway/video-upload';
} from './proto/action';
import { uploadImageMsgInfo } from './highway/image-upload';
import { uploadPttMsgInfo } from './highway/ptt-upload';
import { uploadVideoMsgInfo } from './highway/video-upload';
type ProtoElem = Partial<ProtoDecoded<typeof ElemSchema>>;
@@ -71,7 +71,6 @@ export class IdentityService {
private readonly uinByUid = new Map<string, number>();
private readonly uidByUin = new Map<number, string>();
private inTransaction = false;
private writeFailed = false;
constructor(
private readonly qqInfo: QQInfo,
@@ -106,10 +105,6 @@ export class IdentityService {
return this.db !== null;
}
get hasWriteFailure(): boolean {
return this.writeFailed;
}
rememberFriends(friends: FriendInfo[]): void {
this.qqInfo.setFriends(friends);
for (const friend of friends) this.rememberUidUin(friend.uid, friend.uin);
@@ -693,7 +688,6 @@ export class IdentityService {
try {
fn();
} catch (err) {
this.writeFailed = true;
log.error('identity db write failed [%s]: %s', label, err instanceof Error ? (err.stack ?? err.message) : String(err));
}
}
@@ -2,31 +2,31 @@
// into bridge events. Port of src/bridge/src/handlers/msg_push_handler.h/.cpp
import { inflateSync } from 'zlib';
import { protoDecode } from '../../protobuf/decode';
import { WireMessage } from '../../protobuf/wire';
import { PushMsgSchema } from '../proto/message';
import { protoDecode } from '../protobuf/decode';
import { WireMessage } from '../protobuf/wire';
import { PushMsgSchema } from './proto/message';
import {
MentionExtraSchema, QFaceExtraSchema, QSmallFaceExtraSchema,
MsgInfoSchema, GroupFileExtraSchema, NotOnlineImageSchema,
} from '../proto/element';
import { FileExtraSchema } from '../proto/message';
} from './proto/element';
import { FileExtraSchema } from './proto/message';
import {
GroupChangeSchema, GroupAdminSchema, GroupJoinSchema,
GroupInvitationSchema, GroupInviteSchema,
FriendRequestSchema, FriendRecallSchema,
GroupMuteSchema, NotifyMessageBodySchema,
GeneralGrayTipInfoSchema, OperatorInfoSchema,
} from '../proto/notify';
import type { QQInfo } from '../qq-info';
import type { PacketInfo } from '../../protocol/types';
} from './proto/notify';
import type { QQInfo } from './qq-info';
import type { PacketInfo } from '../protocol/types';
import type {
QQEventVariant, MessageElement,
FriendMessage, GroupMessage, TempMessage,
GroupMemberJoin, GroupMemberLeave, GroupMuteEvent, GroupAdminEvent,
FriendRecall, GroupRecallEvent, FriendRequestEvent, GroupInviteEvent,
FriendPokeEvent, GroupPokeEvent, GroupEssenceEvent,
} from '../events';
import type { ProtoDecoded, ProtoSchema } from '../../protobuf/decode';
} from './events';
import type { ProtoDecoded, ProtoSchema } from '../protobuf/decode';
// --- PkgType enum ---
const enum PkgType {
@@ -147,7 +147,7 @@ function unwrapGroupNotifyPayload(content: Uint8Array): Uint8Array | null {
// --- Element conversion ---
type ElemDecoded = ProtoDecoded<typeof import('../proto/element').ElemSchema>;
type ElemDecoded = ProtoDecoded<typeof import('./proto/element').ElemSchema>;
function convertElements(elems: ElemDecoded[]): MessageElement[] {
const result: MessageElement[] = [];
@@ -497,7 +497,7 @@ function convertElements(elems: ElemDecoded[]): MessageElement[] {
}
function extractRichtextExtras(
rt: ProtoDecoded<typeof import('../proto/message').RichTextSchema>,
rt: ProtoDecoded<typeof import('./proto/message').RichTextSchema>,
elements: MessageElement[],
isGroup = false
): void {
+1 -1
View File
@@ -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/builders/element-builder', () => ({
vi.mock('../../src/bridge/element-builder', () => ({
buildSendElems: vi.fn(async () => []),
}));
@@ -3,7 +3,7 @@ import type { SendPacketResult } from '../src/protocol/packet-sender';
import { protoDecode, protoEncode } from '../src/protobuf/decode';
import { SendMessageRequestSchema, SendMessageResponseSchema } from '../src/bridge/proto/action';
vi.mock('../src/bridge/builders/element-builder', () => ({
vi.mock('../src/bridge/element-builder', () => ({
buildSendElems: vi.fn(async () => [{ text: { str: 'stub media elem' } }]),
}));
+1 -1
View File
@@ -3,7 +3,7 @@ import os from 'os';
import path from 'path';
import { describe, it, expect, vi } from 'vitest';
import { parseMessage } from '../src/onebot/message-parser';
import { buildSendElems } from '../src/bridge/builders/element-builder';
import { buildSendElems } from '../src/bridge/element-builder';
import { MentionExtraSendSchema } from '../src/bridge/proto/action';
import { makeOidbBaseSchema } from '../src/bridge/proto/oidb';
import { NTV2UploadRichMediaRespSchema } from '../src/bridge/proto/highway';
+1 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { parseMsgPush, MSG_PUSH_CMD } from '../src/bridge/handlers/msg-push-handler';
import { parseMsgPush, MSG_PUSH_CMD } from '../src/bridge/msg-push-handler';
import { QQInfo, type GroupMemberInfo, type QQGroupInfo } from '../src/bridge/qq-info';
import { PushMsgSchema } from '../src/bridge/proto/message';
import { GroupChangeSchema, OperatorInfoSchema } from '../src/bridge/proto/notify';