aps-agent/scripts/check-capability-descriptio...

46 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** 能力描述检查的用例(任务 A1.6)。 */
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { validateCapability } from './check-capability-description.mjs';
const valid = {
id: 'aps.schedule.preview',
providerId: 'aps',
title: '试排一版',
purpose: '按当前项目数据试排一版方案,只出结果不发布',
whenNotToUse: '要落库生效请用 aps.schedule.publish',
effect: 'read',
inputSchema: { type: 'object' },
synonyms: ['试排', '跑一版'],
example: { utterance: '跑一版看看', expects: 'aps.schedule.preview' },
};
test('正例:七要素齐备通过', () => {
assert.deepEqual(validateCapability(valid), []);
});
test('负例:缺「何时不用」被拦下', () => {
const problems = validateCapability({ ...valid, whenNotToUse: '' });
assert.ok(problems.some((p) => p.includes('whenNotToUse')), problems.join(';'));
});
test('负例:id 命名不合规被拦下', () => {
const problems = validateCapability({ ...valid, id: 'doSchedule' });
assert.ok(problems.some((p) => p.includes('id')), problems.join(';'));
});
test('负例:purpose 超长被拦下', () => {
const problems = validateCapability({ ...valid, purpose: '一'.repeat(41) });
assert.ok(problems.some((p) => p.includes('40')), problems.join(';'));
});
test('负例:effect 取值非法被拦下', () => {
const problems = validateCapability({ ...valid, effect: 'execute' });
assert.ok(problems.some((p) => p.includes('effect')), problems.join(';'));
});
test('负例:缺同义词与示例被拦下', () => {
const problems = validateCapability({ ...valid, synonyms: [], example: {} });
assert.equal(problems.length, 2, problems.join(';'));
});