feat(onebot): implement set_group_portrait via highway cmdId 3000
Port the Lagrange.Core protocol path for group avatar upload —
napcat's NTQQ GroupService.setHeader has no oidb wrapper, but
Lagrange.Core/Internal/Context/Logic/Implementation/OperationLogic.cs
spells out the wire shape: same highway HTTP endpoint as personal
avatar, but with cmdId=3000 and a GroupAvatarExtra proto carried as
the `extend` blob (type=101, groupUin, field3={field1=1}, field5=3,
field6=1 — all four are protocol-prescribed constants).
Adds:
- GroupAvatarExtraSchema in proto/oidb-action.ts
- bridge.setGroupAvatar(groupId, source) wrapping the highway upload
- BridgeInterface.setGroupAvatar
- OneBot set_group_portrait action (was a stub returning
'not yet implemented'; accepts the same file-source variants as
set_qq_avatar)
5 new tests: 3 bridge-action (cmdId, extra-blob round-trip, empty-file
guard) + 2 OneBot (forwarding, param validation) — also tightens the
existing setAvatar test to assert the extend blob stays empty.
This commit is contained in:
7 files changed
+134
-3
No files matched your search
@@ -117,8 +117,40 @@ describe('actions/profile', () => {
|
||||
await profile.setAvatar(bridge as any, '/some/avatar.png');
|
||||
expect(highwayClient.fetchHighwaySession).toHaveBeenCalledOnce();
|
||||
expect(highwayClient.uploadHighwayHttp).toHaveBeenCalledOnce();
|
||||
const [, , cmdId] = vi.mocked(highwayClient.uploadHighwayHttp).mock.calls[0]!;
|
||||
const [, , cmdId, , , extend] = vi.mocked(highwayClient.uploadHighwayHttp).mock.calls[0]!;
|
||||
expect(cmdId).toBe(90);
|
||||
expect((extend as Uint8Array).length).toBe(0); // personal avatar has no extra payload
|
||||
});
|
||||
|
||||
it('setGroupAvatar uses cmdId 3000 and packs the Lagrange GroupAvatarExtra constants', async () => {
|
||||
const bridge = mockBridge();
|
||||
await profile.setGroupAvatar(bridge as any, 12345, '/some/group-avatar.png');
|
||||
expect(highwayClient.fetchHighwaySession).toHaveBeenCalledOnce();
|
||||
expect(highwayClient.uploadHighwayHttp).toHaveBeenCalledOnce();
|
||||
const [, , cmdId, , , extend] = vi.mocked(highwayClient.uploadHighwayHttp).mock.calls[0]!;
|
||||
expect(cmdId).toBe(3000);
|
||||
// Decode the extra blob back through the schema and assert every
|
||||
// protocol-prescribed constant lands where it should.
|
||||
const { protoDecode } = await import('../../src/protobuf/decode');
|
||||
const { GroupAvatarExtraSchema } = await import('../../src/bridge/proto/oidb-action');
|
||||
const decoded = protoDecode(extend as Uint8Array, GroupAvatarExtraSchema);
|
||||
expect(decoded).toEqual({
|
||||
type: 101,
|
||||
groupUin: 12345,
|
||||
field3: { field1: 1 },
|
||||
field5: 3,
|
||||
field6: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('setGroupAvatar rejects an empty file before hitting highway', async () => {
|
||||
const bridge = mockBridge();
|
||||
const { loadBinarySource } = await import('../../src/bridge/highway/utils');
|
||||
vi.mocked(loadBinarySource).mockResolvedValueOnce({
|
||||
bytes: new Uint8Array(0), fileName: 'empty.png',
|
||||
} as any);
|
||||
await expect(profile.setGroupAvatar(bridge as any, 1, 'empty.png')).rejects.toThrow(/empty/);
|
||||
expect(highwayClient.fetchHighwaySession).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('getProfileLike (self): resolves self UID, returns formatted favorite + vote info', async () => {
|
||||
|
||||
@@ -497,3 +497,37 @@ describe('extended-actions / set_diy_online_status', () => {
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 100, wording: 'denied' });
|
||||
});
|
||||
});
|
||||
|
||||
// ─── set_group_portrait (Lagrange-protocol highway upload, cmdId 3000) ───
|
||||
|
||||
describe('extended-actions / set_group_portrait', () => {
|
||||
it('forwards group_id + file to bridge.setGroupAvatar', async () => {
|
||||
const setGroupAvatar = vi.fn(async () => {});
|
||||
const bridge = fakeBridge({ setGroupAvatar: setGroupAvatar as any });
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('set_group_portrait', {
|
||||
group_id: 12345, file: '/tmp/avatar.png',
|
||||
});
|
||||
expect(res.status).toBe('ok');
|
||||
expect(setGroupAvatar).toHaveBeenCalledWith(12345, '/tmp/avatar.png');
|
||||
});
|
||||
|
||||
it('rejects missing group_id or file', async () => {
|
||||
const setGroupAvatar = vi.fn();
|
||||
const bridge = fakeBridge({ setGroupAvatar: setGroupAvatar as any });
|
||||
const r1 = await makeHandler(fakeCtx(bridge)).handle('set_group_portrait', { file: 'x' });
|
||||
const r2 = await makeHandler(fakeCtx(bridge)).handle('set_group_portrait', { group_id: 1 });
|
||||
expect(r1).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||
expect(r2).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||
expect(setGroupAvatar).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('surfaces highway / decode errors as action_failed', async () => {
|
||||
const bridge = fakeBridge({
|
||||
setGroupAvatar: (async () => { throw new Error('highway 500'); }) as any,
|
||||
});
|
||||
const res = await makeHandler(fakeCtx(bridge)).handle('set_group_portrait', {
|
||||
group_id: 1, file: 'x.png',
|
||||
});
|
||||
expect(res).toMatchObject({ status: 'failed', retcode: 100, wording: 'highway 500' });
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user