refactor(packages): rename @snowluma/bridge → @snowluma/protocol
The package previously named "bridge" houses the protocol-byte layer (OIDB cmds, msg-push decoders, highway uploaders, element-builder, event bus). The name "bridge" suggested transport/lifecycle, which it isn't — that role lives in core/hook and core/bridge/manager. Rename to match what's actually inside. This is a pure rename: zero logic changes, all 73 import sites updated mechanically and TS-verified. core/onebot dependencies key updated. ESLint override path adjusted for the moved oidb-services directory. Rename detection threshold: git log --find-renames=20% recommended when following history across this commit — content-replacement (@snowluma/bridge → @snowluma/protocol) dropped per-file similarity below git's default 50% on import-heavy files.
This commit is contained in:
238 files changed
+247
-284
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { protobuf_decode } from '@snowluma/proton';
|
||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import type { Oidb0x112aReq } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
|
||||
import { SetSelfLongNick } from '../../../src/oidb-services/profile/set-self-long-nick';
|
||||
|
||||
function makeDeps() {
|
||||
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData: Buffer.alloc(0) };
|
||||
return {
|
||||
sendRawPacket: vi.fn(async () => r),
|
||||
identity: { uin: '10001' } as any,
|
||||
};
|
||||
}
|
||||
|
||||
describe('SetSelfLongNick namespace', () => {
|
||||
it('declares 0x112A_2', () => {
|
||||
expect(SetSelfLongNick.command).toBe(0x112A);
|
||||
expect(SetSelfLongNick.subCommand).toBe(2);
|
||||
});
|
||||
|
||||
describe('invoke', () => {
|
||||
it('routes to OidbSvcTrpcTcp.0x112a_2', async () => {
|
||||
const deps = makeDeps();
|
||||
await SetSelfLongNick.invoke(deps, { longNick: 'hello world' });
|
||||
expect(deps.sendRawPacket.mock.calls[0]![0]).toBe('OidbSvcTrpcTcp.0x112a_2');
|
||||
});
|
||||
|
||||
it('wraps the long nick in profile { tag: 102, value }', async () => {
|
||||
const deps = makeDeps();
|
||||
await SetSelfLongNick.invoke(deps, { longNick: 'hello world' });
|
||||
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<Oidb0x112aReq>>(bytes);
|
||||
expect(env.body?.uin).toBe(10001n);
|
||||
expect(env.body?.profile).toEqual({ tag: 102, value: 'hello world' });
|
||||
});
|
||||
|
||||
it('coerces non-string longNick into a string (defensive)', async () => {
|
||||
const deps = makeDeps();
|
||||
// simulate a misbehaving caller passing a number
|
||||
await SetSelfLongNick.invoke(deps, { longNick: 12345 as any });
|
||||
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
const env = protobuf_decode<OidbBase<Oidb0x112aReq>>(bytes);
|
||||
expect(env.body?.profile?.value).toBe('12345');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user