Return the NapCat-compatible long_nick field from get_stranger_info for both freshly fetched and cached user profiles. Keep the field present as an empty string when profile data is unavailable so callers receive a stable response shape. Document the response contract in the Action schema and generated MCP catalog, and cover fetched, cached, and empty fallback paths with regression tests. This change reuses the existing profile signature value and does not add QQ requests or alter protocol packets. Closes #246
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import type { ApiActionContext } from '../src/api-handler';
|
|
import { actions } from '../src/actions/friend';
|
|
|
|
const getStrangerInfo = actions.find((action) => action.names[0] === 'get_stranger_info');
|
|
if (!getStrangerInfo) throw new Error('get_stranger_info action missing');
|
|
|
|
describe('get_stranger_info action', () => {
|
|
it('returns an empty long_nick when no profile provider is available', async () => {
|
|
const response = await getStrangerInfo.toHandler({} as ApiActionContext)({ user_id: 123456 });
|
|
|
|
expect(response).toMatchObject({
|
|
status: 'ok',
|
|
retcode: 0,
|
|
data: {
|
|
user_id: 123456,
|
|
nickname: '',
|
|
sex: 'unknown',
|
|
age: 0,
|
|
long_nick: '',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('documents long_nick as a required string response field', () => {
|
|
const schema = getStrangerInfo.describe().returnsSchema;
|
|
|
|
expect(schema).toMatchObject({
|
|
type: 'object',
|
|
properties: {
|
|
long_nick: { type: 'string', description: '个性签名' },
|
|
},
|
|
});
|
|
expect(schema?.required).toContain('long_nick');
|
|
});
|
|
});
|