Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test-plugin-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- name: Validate all skills
run: node scripts/validate-skills.js

- name: Test skill lint rules
run: node --test scripts/lib/skill-lint-test.js

- name: Test skill eval runner
run: node --test scripts/run-evals-test.js

Expand Down
104 changes: 104 additions & 0 deletions scripts/lib/skill-lint-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env node

'use strict';

/**
* Unit tests for the fence-stripping helper behind the required-section rule.
*
* The rule is observed indirectly: a heading inside a fenced block must NOT
* satisfy `## Overview`, so "Missing required section: ## Overview" is the
* signal that the block was stripped — and its absence is the signal that
* prose outside the block survived.
*/

const assert = require('node:assert/strict');
const test = require('node:test');
const { lintSkillContent } = require('./skill-lint');

const KNOWN = new Set(['portable-skill']);

/**
* A structurally valid SKILL.md whose `## Overview` heading is supplied by the
* caller — either as real prose or buried inside a fenced block.
*/
function skillWithOverview(overviewBlock) {
return `---
name: portable-skill
description: Guides agents through portable work. Use when testing skill portability.
---

# Portable Skill

${overviewBlock}

## When to Use
Use for fence-parsing tests.

## Common Rationalizations
None.

## Red Flags
None.

## Verification
Verify the result.
`;
}

const overviewMissing = result => result.errors.includes('Missing required section: ## Overview');

const OVERVIEW = '## Overview\nPortable workflow.';

test('a real Overview heading satisfies the required-section check', () => {
const result = lintSkillContent('portable-skill', skillWithOverview(OVERVIEW), KNOWN);
assert.deepEqual(result.errors, []);
});

// A heading buried in a fenced block must not satisfy the check.
for (const [description, block] of [
['a plain backtick fence', '```markdown\n## Overview\n```'],
['an unlabeled fence', '```\n## Overview\n```'],
['a tilde fence', '~~~markdown\n## Overview\n~~~'],
['an indented fence', ' ```markdown\n## Overview\n ```'],
['a fence with a longer closer', '```markdown\n## Overview\n````'],
]) {
test(`a heading inside ${description} does not satisfy the check`, () => {
const result = lintSkillContent('portable-skill', skillWithOverview(block), KNOWN);
assert.equal(overviewMissing(result), true);
});
}

// Closing-fence handling: prose after the block must survive, so a closing
// fence that goes unrecognized shows up as a missing section.
for (const [description, block] of [
['a same-length closing fence', `\`\`\`markdown\nfenced example\n\`\`\`\n\n${OVERVIEW}`],
['a longer closing fence', `\`\`\`markdown\nfenced example\n\`\`\`\`\`\n\n${OVERVIEW}`],
['an indented closing fence', `\`\`\`markdown\nfenced example\n \`\`\`\n\n${OVERVIEW}`],
]) {
test(`prose after ${description} is still linted`, () => {
const result = lintSkillContent('portable-skill', skillWithOverview(block), KNOWN);
assert.equal(overviewMissing(result), false);
});
}

test('a shorter run of backticks does not close a longer fence', () => {
// The inner ``` and the heading it wraps belong to the ````-fenced block.
const block = '````markdown\n```\n## Overview\n````';
const result = lintSkillContent('portable-skill', skillWithOverview(block), KNOWN);
assert.equal(overviewMissing(result), true);
});

test('a backtick fence does not close a tilde fence', () => {
const block = '~~~markdown\n```\n## Overview\n~~~';
const result = lintSkillContent('portable-skill', skillWithOverview(block), KNOWN);
assert.equal(overviewMissing(result), true);
});

test('an unterminated fence fails loud rather than passing silently', () => {
// Everything after an unclosed fence is treated as fenced, so the sections
// below it are reported missing instead of being silently accepted.
const block = '```markdown\n## Overview';
const result = lintSkillContent('portable-skill', skillWithOverview(block), KNOWN);
assert.equal(overviewMissing(result), true);
assert.equal(result.errors.includes('Missing required section: ## Verification'), true);
});
33 changes: 32 additions & 1 deletion scripts/lib/skill-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,40 @@ const SKILL_REF_PATTERNS = [
/**
* Strip fenced code blocks from markdown content so that headings, references,
* and trigger phrases inside examples or templates are not matched by lint rules.
*
* Scans line by line rather than matching a single regex, so the three fence
* forms CommonMark allows — tilde fences, fences indented up to three spaces,
* and closing fences longer than their opener — are stripped like plain
* ```-fences. A regex over the whole document misses all three, which lets a
* heading inside such a block satisfy the required-section check.
*/
function stripFencedCodeBlocks(content) {
return content.replace(/^(`{3,})[^\n]*\n[\s\S]*?^\1\s*$/gm, '');
const kept = [];
let fence = null;

for (const line of content.split(/\r?\n/)) {
if (fence) {
const closingFence = line.match(/^ {0,3}(`+|~+)[ \t]*$/);
if (
closingFence
&& closingFence[1][0] === fence.marker
&& closingFence[1].length >= fence.length
) {
fence = null;
}
continue;
}

const openingFence = line.match(/^ {0,3}(`{3,}|~{3,})/);
if (openingFence) {
fence = { marker: openingFence[1][0], length: openingFence[1].length };
continue;
}

kept.push(line);
}

return kept.join('\n');
}

/**
Expand Down