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.
46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
|
import type {
|
|
OidbGroupFileCountViewReq, OidbGroupFileCountViewResp,
|
|
} from '@snowluma/proto-defs/oidb-actions/group-file';
|
|
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
|
|
|
import { GetGroupFileCount } from '../../../src/oidb-services/group-file/get-group-file-count';
|
|
|
|
function makeDeps(body?: OidbGroupFileCountViewResp) {
|
|
const responseData = body !== undefined
|
|
? Buffer.from(protobuf_encode<OidbBase<OidbGroupFileCountViewResp>>({ body }))
|
|
: Buffer.alloc(0);
|
|
const r: SendPacketResult = { success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData };
|
|
return { sendRawPacket: vi.fn(async () => r) };
|
|
}
|
|
|
|
describe('GetGroupFileCount namespace', () => {
|
|
it('declares 0x6D8_3', () => {
|
|
expect(GetGroupFileCount.command).toBe(0x6D8);
|
|
expect(GetGroupFileCount.subCommand).toBe(3);
|
|
});
|
|
|
|
it('routes to 0x6d8_3 with groupUin + appId=7 + busId=0', async () => {
|
|
const deps = makeDeps({ count: { fileCount: 1, maxCount: 100 } });
|
|
await GetGroupFileCount.invoke(deps, { groupId: 12345 });
|
|
const [wire, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
|
expect(wire).toBe('OidbSvcTrpcTcp.0x6d8_3');
|
|
const env = protobuf_decode<OidbBase<OidbGroupFileCountViewReq>>(bytes);
|
|
expect(env.body?.count).toMatchObject({ groupUin: 12345, appId: 7 });
|
|
});
|
|
|
|
it('decodes both counters as plain numbers', async () => {
|
|
const deps = makeDeps({ count: { fileCount: 42, maxCount: 1000 } });
|
|
const out = await GetGroupFileCount.invoke(deps, { groupId: 1 });
|
|
expect(out).toEqual({ fileCount: 42, maxCount: 1000 });
|
|
});
|
|
|
|
it('falls back to maxCount=10000 when the server elides it', async () => {
|
|
const deps = makeDeps({ count: {} });
|
|
const out = await GetGroupFileCount.invoke(deps, { groupId: 1 });
|
|
expect(out).toEqual({ fileCount: 0, maxCount: 10000 });
|
|
});
|
|
});
|