ec8d0464a3
短句如"苏州攻略页面"此前会被规则/LLM 误判为 product-campaign-page(先追问 促销信息),导致用户体验成"卡住不动"。规则层扩大页面生成意图识别,并新增 coercePageGenerationSkill 在 LLM 判为 product-campaign-page 但明显是内容页 时强制纠正为 static-page-publish,避免不必要的追问。同步更新两个技能文档 的适用边界说明。 Co-authored-by: Cursor <cursoragent@cursor.com>
95 lines
4.4 KiB
JavaScript
95 lines
4.4 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
buildAutoChatSkillPrefix,
|
|
buildChatSkillPrompt,
|
|
CHAT_SKILL_DEFINITIONS,
|
|
filterChatSkills,
|
|
isPageGenerationIntent,
|
|
} from './chat-skills.mjs';
|
|
|
|
test('filterChatSkills shows summarize and analyze without granted skills', () => {
|
|
const visible = filterChatSkills(CHAT_SKILL_DEFINITIONS, { canPublish: false });
|
|
assert.ok(visible.some((item) => item.id === 'summarize'));
|
|
assert.ok(visible.some((item) => item.id === 'analyze'));
|
|
assert.equal(visible.some((item) => item.id === 'generate-page'), false);
|
|
});
|
|
|
|
test('filterChatSkills gates platform skills by grantedSkills', () => {
|
|
const visible = filterChatSkills(CHAT_SKILL_DEFINITIONS, {
|
|
canPublish: false,
|
|
grantedSkills: ['web', 'search'],
|
|
});
|
|
assert.ok(visible.some((item) => item.id === 'web-search'));
|
|
assert.ok(visible.some((item) => item.id === 'code-search'));
|
|
assert.equal(visible.some((item) => item.id === 'form-collect'), false);
|
|
assert.equal(visible.some((item) => item.id === 'service-integration-smoke'), false);
|
|
assert.equal(visible.some((item) => item.id === 'product-campaign-page'), false);
|
|
});
|
|
|
|
test('filterChatSkills shows product campaign page when granted', () => {
|
|
const visible = filterChatSkills(CHAT_SKILL_DEFINITIONS, {
|
|
canPublish: false,
|
|
grantedSkills: ['product-campaign-page'],
|
|
});
|
|
assert.ok(visible.some((item) => item.id === 'product-campaign-page'));
|
|
});
|
|
|
|
test('filterChatSkills shows service integration smoke when granted', () => {
|
|
const visible = filterChatSkills(CHAT_SKILL_DEFINITIONS, {
|
|
canPublish: false,
|
|
grantedSkills: ['service-integration-smoke'],
|
|
});
|
|
assert.ok(visible.some((item) => item.id === 'service-integration-smoke'));
|
|
});
|
|
|
|
test('filterChatSkills shows generate-page when publish is allowed', () => {
|
|
const visible = filterChatSkills(CHAT_SKILL_DEFINITIONS, { canPublish: true });
|
|
assert.ok(visible.some((item) => item.id === 'generate-page'));
|
|
});
|
|
|
|
test('buildChatSkillPrompt includes skill name for platform skills', () => {
|
|
assert.match(buildChatSkillPrompt('web', 'web'), /请使用 web 技能/);
|
|
assert.match(buildChatSkillPrompt('service-integration-smoke'), /标准联调流程/);
|
|
assert.match(buildChatSkillPrompt('product-campaign-page'), /商品宣传 \/ 活动页/);
|
|
assert.match(buildChatSkillPrompt('generate-page'), /static-page-publish/);
|
|
assert.match(buildChatSkillPrompt('generate-page'), /docx-generate/);
|
|
assert.match(buildChatSkillPrompt('generate-page'), /public\/\*\.docx/);
|
|
assert.match(buildChatSkillPrompt('generate-page'), /long-image-download/);
|
|
assert.match(buildChatSkillPrompt('generate-page'), /generate_long_image/);
|
|
});
|
|
|
|
test('prefillOnly is set for open-ended chat skills', () => {
|
|
assert.equal(CHAT_SKILL_DEFINITIONS.find((item) => item.id === 'web-search')?.prefillOnly, true);
|
|
assert.equal(CHAT_SKILL_DEFINITIONS.find((item) => item.id === 'generate-page')?.prefillOnly, undefined);
|
|
});
|
|
|
|
test('buildAutoChatSkillPrefix enables web for news-like queries', () => {
|
|
assert.match(
|
|
buildAutoChatSkillPrefix('帮我搜索今天热点新闻', ['web', 'search']),
|
|
/先搜索今天\/最新相关的新闻与热点/,
|
|
);
|
|
assert.equal(buildAutoChatSkillPrefix('帮我总结一下这段话', ['web', 'search']), '');
|
|
assert.equal(buildAutoChatSkillPrefix('帮我搜索今天热点新闻', ['search']), '');
|
|
});
|
|
|
|
test('buildAutoChatSkillPrefix enables publish for page generation requests', () => {
|
|
const prefix = buildAutoChatSkillPrefix('帮我做一个 Hello 糖的 H5 页面', ['static-page-publish']);
|
|
assert.match(prefix, /static-page-publish/);
|
|
assert.match(prefix, /write_file\/edit_file/);
|
|
assert.match(prefix, /禁止只给本地路径/);
|
|
assert.equal(buildAutoChatSkillPrefix('帮我做一个 Hello 糖的 H5 页面', []), '');
|
|
});
|
|
|
|
test('isPageGenerationIntent matches implicit travel guide page requests', () => {
|
|
assert.equal(isPageGenerationIntent('苏州攻略页面'), true);
|
|
assert.equal(isPageGenerationIntent('帮我看看苏州攻略,1日攻略,做一个页面'), true);
|
|
assert.equal(isPageGenerationIntent('你好'), false);
|
|
});
|
|
|
|
test('buildAutoChatSkillPrefix enables publish for implicit page requests', () => {
|
|
const prefix = buildAutoChatSkillPrefix('苏州攻略页面', ['static-page-publish']);
|
|
assert.match(prefix, /static-page-publish/);
|
|
assert.match(prefix, /禁止询问是否还要发布/);
|
|
});
|