fix(onebot): allow clearing the self signature
Accept explicit empty strings from both longNick and long_nick when callers need to clear the bot signature. Missing and non-string values remain rejected before reaching the bridge. Preserve the QQ-compatible clear representation by omitting the empty profile value, and add action-level and wire-level regression coverage. Live verification confirmed successful clearing and readback on the test bot. Fixes #247
This commit is contained in:
3 files changed
+47
-1
No files matched your search
@@ -2050,7 +2050,7 @@ export const actions = [
|
||||
summary: '设置个性签名(longNick/long_nick,严格 string)',
|
||||
params: { longNick: f.raw(), long_nick: f.raw() },
|
||||
run: async (p, ctx) => {
|
||||
const longNick = p.longNick || p.long_nick;
|
||||
const longNick = p.longNick !== undefined ? p.longNick : p.long_nick;
|
||||
if (typeof longNick !== 'string') return failedResponse(RETCODE.BAD_REQUEST, 'invalid longNick');
|
||||
await ctx.bridge.apis.profile.setSelfLongNick(longNick);
|
||||
return okResponse({});
|
||||
|
||||
@@ -121,6 +121,45 @@ function makeHandler(ctx: ApiActionContext): ApiHandler {
|
||||
return new ApiHandler(ctx);
|
||||
}
|
||||
|
||||
describe('extended-actions / set_self_longnick', () => {
|
||||
it('accepts an empty longNick to clear the signature', async () => {
|
||||
const setSelfLongNick = vi.fn(async () => undefined);
|
||||
const bridge = fakeBridge({ setSelfLongNick });
|
||||
|
||||
const response = await makeHandler(fakeCtx(bridge)).handle('set_self_longnick', {
|
||||
longNick: '',
|
||||
});
|
||||
|
||||
expect(response).toMatchObject({ status: 'ok', retcode: 0 });
|
||||
expect(setSelfLongNick).toHaveBeenCalledWith('');
|
||||
});
|
||||
|
||||
it('accepts an empty long_nick compatibility alias', async () => {
|
||||
const setSelfLongNick = vi.fn(async () => undefined);
|
||||
const bridge = fakeBridge({ setSelfLongNick });
|
||||
|
||||
const response = await makeHandler(fakeCtx(bridge)).handle('set_self_longnick', {
|
||||
long_nick: '',
|
||||
});
|
||||
|
||||
expect(response).toMatchObject({ status: 'ok', retcode: 0 });
|
||||
expect(setSelfLongNick).toHaveBeenCalledWith('');
|
||||
});
|
||||
|
||||
it.each([
|
||||
['missing value', {}],
|
||||
['non-string value', { longNick: 0 }],
|
||||
])('rejects %s without calling the bridge', async (_case, params) => {
|
||||
const setSelfLongNick = vi.fn(async () => undefined);
|
||||
const bridge = fakeBridge({ setSelfLongNick });
|
||||
|
||||
const response = await makeHandler(fakeCtx(bridge)).handle('set_self_longnick', params);
|
||||
|
||||
expect(response).toMatchObject({ status: 'failed', retcode: 1400 });
|
||||
expect(setSelfLongNick).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('extended-actions / group notice options', () => {
|
||||
it('coerces and forwards every supported announcement option', async () => {
|
||||
const sendNotice = vi.fn(async () => ({ ec: 0 }));
|
||||
|
||||
@@ -36,6 +36,13 @@ describe('SetSelfLongNick namespace', () => {
|
||||
expect(env.body?.profile).toEqual({ tag: 102, value: 'hello world' });
|
||||
});
|
||||
|
||||
it('omits the value field when clearing the signature', async () => {
|
||||
const deps = makeDeps();
|
||||
await SetSelfLongNick.invoke(deps, { longNick: '' });
|
||||
const [, bytes] = deps.sendRawPacket.mock.calls[0]!;
|
||||
expect(Buffer.from(bytes).toString('hex')).toBe('08aa221002220708914e12020866');
|
||||
});
|
||||
|
||||
it('coerces non-string longNick into a string (defensive)', async () => {
|
||||
const deps = makeDeps();
|
||||
// simulate a misbehaving caller passing a number
|
||||
|
||||
Reference in new issue
Block a user