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