feat(mcp): complete action results and invocation examples
Document result shapes and practical calls for all built-in actions, including prerequisites, streaming workflows and compatibility limits. Preserve existing interfaces and execution behavior, and verify the catalog against action validation and representative responses.
This commit is contained in:
27 files changed
+14140
-33
No files matched your search
@@ -2,6 +2,9 @@
|
||||
// declarative action and renders coherent metadata/markdown.
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { collectActionDocs, renderActionDocsMarkdown } from '../src/action-docs';
|
||||
import { ACTION_REGISTRY } from '../src/actions';
|
||||
import { defineAction, defineStreamAction } from '../src/action-kit';
|
||||
import { okResponse } from '../src/types';
|
||||
|
||||
describe('action-docs', () => {
|
||||
const docs = collectActionDocs();
|
||||
@@ -75,6 +78,54 @@ describe('action-docs', () => {
|
||||
expect(md).toContain('# OneBot Actions');
|
||||
expect(md).toContain('`set_group_ban`');
|
||||
expect(md).toContain('| 参数 | 类型 | 必填 | 默认 | 说明 |');
|
||||
expect(md).toContain('"action": "set_group_ban"');
|
||||
expect(md).toContain('"duration": 600');
|
||||
});
|
||||
|
||||
it.each(ACTION_REGISTRY.actions)(
|
||||
'$canonical examples pass the real parameter parser',
|
||||
({ spec, doc }) => {
|
||||
expect(doc.returnsSchema).toBeTypeOf('object');
|
||||
expect(doc.examples?.length).toBeGreaterThan(0);
|
||||
|
||||
// Both built-in spec kinds expose a pure parser; do not call handlers
|
||||
// here, since examples include writes and process-lifecycle actions.
|
||||
if (!('parse' in spec) || typeof spec.parse !== 'function') {
|
||||
throw new Error(`${doc.name} has no pure parameter parser`);
|
||||
}
|
||||
|
||||
for (const example of doc.examples ?? []) {
|
||||
expect(example.summary).not.toBe('');
|
||||
const keys = new Set(doc.params.map((param) => param.name));
|
||||
|
||||
for (const key of Object.keys(example.params)) {
|
||||
expect(keys.has(key), `${doc.name} unknown example param ${key}`).toBe(true);
|
||||
}
|
||||
|
||||
expect(spec.parse(example.params), `${doc.name}: ${example.summary}`).toMatchObject(
|
||||
{ ok: true },
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it('keeps documentation metadata optional for existing custom specs', () => {
|
||||
for (const define of [defineAction, defineStreamAction]) {
|
||||
const spec = define({ name: 'custom', params: {}, run: () => okResponse() });
|
||||
expect(spec.describe().examples).toBeUndefined();
|
||||
expect(spec.describe().returnsSchema).toBeUndefined();
|
||||
expect(spec.parse({})).toMatchObject({ ok: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('isolates collected examples and schemas from caller mutations', () => {
|
||||
const copy = collectActionDocs();
|
||||
const action = copy.find((doc) => doc.name === 'send_group_msg')!;
|
||||
action.examples![0].params.group_id = 99999;
|
||||
action.returnsSchema!.type = 'null';
|
||||
const fresh = collectActionDocs().find((doc) => doc.name === action.name)!;
|
||||
expect(fresh.examples![0].params.group_id).toBe(20001);
|
||||
expect(fresh.returnsSchema!.type).toBe('object');
|
||||
});
|
||||
|
||||
it('documents custom reply content on every forward entry point', () => {
|
||||
|
||||
@@ -403,7 +403,7 @@ describe('set_group_ban describe', () => {
|
||||
expect(doc.summary).toBe('禁言群成员(duration=0 解除)');
|
||||
expect(doc.readOnly).toBe(false);
|
||||
expect(doc.returns).toBeUndefined();
|
||||
expect(doc.returnsSchema).toBeUndefined();
|
||||
expect(doc.returnsSchema).toMatchObject({ type: 'null' });
|
||||
expect(doc.stream).toBeUndefined();
|
||||
expect(doc.invariants).toEqual([]);
|
||||
expect(doc.params).toEqual([
|
||||
|
||||
@@ -228,7 +228,7 @@ describe('set_friend_add_request describe', () => {
|
||||
expect(doc.summary).toBe('处理好友添加请求');
|
||||
expect(doc.readOnly).toBe(false);
|
||||
expect(doc.returns).toBeUndefined();
|
||||
expect(doc.returnsSchema).toBeUndefined();
|
||||
expect(doc.returnsSchema).toMatchObject({ type: 'null' });
|
||||
expect(doc.stream).toBeUndefined();
|
||||
expect(doc.invariants).toEqual([]);
|
||||
expect(doc.params).toEqual([
|
||||
@@ -526,7 +526,7 @@ describe('set_group_add_request describe', () => {
|
||||
expect(doc.summary).toBe('处理加群请求');
|
||||
expect(doc.readOnly).toBe(false);
|
||||
expect(doc.returns).toBeUndefined();
|
||||
expect(doc.returnsSchema).toBeUndefined();
|
||||
expect(doc.returnsSchema).toMatchObject({ type: 'null' });
|
||||
expect(doc.stream).toBeUndefined();
|
||||
expect(doc.invariants).toEqual([]);
|
||||
expect(doc.params).toEqual([
|
||||
|
||||
Reference in new issue
Block a user