test: align js validator use-section rules
This commit is contained in:
16
scripts/tests/validate_skills_headings.test.js
Normal file
16
scripts/tests/validate_skills_headings.test.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const assert = require('assert');
|
||||||
|
const { hasUseSection } = require('../validate-skills');
|
||||||
|
|
||||||
|
const samples = [
|
||||||
|
['## When to Use', true],
|
||||||
|
['## Use this skill when', true],
|
||||||
|
['## When to Use This Skill', true],
|
||||||
|
['## Overview', false],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const [heading, expected] of samples) {
|
||||||
|
const content = `\n${heading}\n- item\n`;
|
||||||
|
assert.strictEqual(hasUseSection(content), expected, heading);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('ok');
|
||||||
@@ -32,12 +32,24 @@ const MAX_SKILL_LINES = 500;
|
|||||||
const ALLOWED_FIELDS = new Set([
|
const ALLOWED_FIELDS = new Set([
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
|
'risk',
|
||||||
|
'source',
|
||||||
'license',
|
'license',
|
||||||
'compatibility',
|
'compatibility',
|
||||||
'metadata',
|
'metadata',
|
||||||
'allowed-tools',
|
'allowed-tools',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const USE_SECTION_PATTERNS = [
|
||||||
|
/^##\s+When\s+to\s+Use/im,
|
||||||
|
/^##\s+Use\s+this\s+skill\s+when/im,
|
||||||
|
/^##\s+When\s+to\s+Use\s+This\s+Skill/im,
|
||||||
|
];
|
||||||
|
|
||||||
|
function hasUseSection(content) {
|
||||||
|
return USE_SECTION_PATTERNS.some(pattern => pattern.test(content));
|
||||||
|
}
|
||||||
|
|
||||||
function isPlainObject(value) {
|
function isPlainObject(value) {
|
||||||
return value && typeof value === 'object' && !Array.isArray(value);
|
return value && typeof value === 'object' && !Array.isArray(value);
|
||||||
}
|
}
|
||||||
@@ -99,6 +111,7 @@ function addStrictSectionErrors(label, missing, baselineSet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function run() {
|
||||||
const skillIds = listSkillIds(SKILLS_DIR);
|
const skillIds = listSkillIds(SKILLS_DIR);
|
||||||
const baseline = loadBaseline();
|
const baseline = loadBaseline();
|
||||||
const baselineUse = new Set(baseline.useSection || []);
|
const baselineUse = new Set(baseline.useSection || []);
|
||||||
@@ -202,7 +215,7 @@ for (const skillId of skillIds) {
|
|||||||
longFiles.push(skillId);
|
longFiles.push(skillId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!content.includes('## Use this skill when')) {
|
if (!hasUseSection(content)) {
|
||||||
missingUseSection.push(skillId);
|
missingUseSection.push(skillId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,3 +281,13 @@ if (errors.length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Validation passed for ${skillIds.length} skills.`);
|
console.log(`Validation passed for ${skillIds.length} skills.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
hasUseSection,
|
||||||
|
run,
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user