Files
SnowLuma/packages/protocol/tests/oidb-services/group-file/get-group-file-count.test.ts
T
DrSmoothl c027161a64 fix(protocol): get_group_file_system_info returns real counts + space (#196)
file_count 恒为 0(且 used_space/limit_count/total_space 是占位/写死值)。根因:
0x6D8 view 命令分三个 subcommand(1=List, 2=Count, 3=Space),但 getCount 错发到
**subCommand 3(Space)** 且 busId=0,并从 pb<1>/pb<2> 读计数——服务端根本没返回
Count 块,于是恒 0。

真机 RE(bot 在测试群传/删文件核对):
- Count 走 **0x6D8_2 + busId=6**,响应 Count 块里 fileCount=**field 4**、maxCount(文件
  数上限,如 1500)=**field 6**(旧 pb<1>/pb<2> 全落空)。
- Space 走 **0x6D8_3**,响应 Space 块 totalSpace=**field 4**、usedSpace=**field 5**(64 位)。
- 实测:fileCount=4、limitCount=1500、usedSpace=20103729、totalSpace=10737418240。

修复:改 GetGroupFileCount 到 subCommand 2 + busId 6 + 正确 tag;新增 GetGroupFileSpace
(0x6D8_3);action 并发查两者,四个字段全返回**服务端实际值**(优于 NapCat 的写死占位)。
含 count/space 编解码回归测试。catalog regen。

typecheck 12 包;protocol 591 / onebot 521 / core 472 全绿。
2026-07-04 01:59:52 +08:00

46 lines
2.1 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_2 (Count subcommand)', () => {
expect(GetGroupFileCount.command).toBe(0x6D8);
expect(GetGroupFileCount.subCommand).toBe(2);
});
it('routes to 0x6d8_2 with groupUin + appId=7 + busId=6 (#196)', 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_2');
const env = protobuf_decode<OidbBase<OidbGroupFileCountViewReq>>(bytes);
expect(env.body?.count).toMatchObject({ groupUin: 12345, appId: 7, busId: 6 });
});
it('decodes fileCount (field 4) + maxCount (field 6) 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 });
});
});