Validation, Error Handling & Full Integration
- Remove fallback behavior for malformed SKILL.md files in skill_scanner.cpp - Now harness crashes immediately on invalid YAML frontmatter - Updated tests to use proper YAML frontmatter - Added new test_skill_validation.sh to verify crash behavior - Removed test that expected fallback for invalid frontmatter
This commit is contained in:
@@ -31,13 +31,8 @@ void SkillScanner::scan() {
|
||||
if (entry.is_regular_file() && entry.path().filename() == "SKILL.md") {
|
||||
std::string filepath = entry.path().string();
|
||||
discovered_paths_.push_back(filepath);
|
||||
try {
|
||||
auto metadata = parse_skill_frontmatter(filepath);
|
||||
skill_metadata_.push_back(metadata);
|
||||
} catch (const std::runtime_error& e) {
|
||||
// If parsing fails, add a default entry with the filename
|
||||
skill_metadata_.push_back({entry.path().stem().string(), std::nullopt});
|
||||
}
|
||||
auto metadata = parse_skill_frontmatter(filepath);
|
||||
skill_metadata_.push_back(metadata);
|
||||
}
|
||||
}
|
||||
} catch (const fs::filesystem_error& e) {
|
||||
|
||||
@@ -28,6 +28,7 @@ add_dr_test(process_reasoning)
|
||||
add_dr_test(test_skill_scanner)
|
||||
add_dr_test(test_nested_skills)
|
||||
add_dr_test(test_skill_parsing)
|
||||
add_dr_test(test_skill_validation)
|
||||
add_dr_test(test_skill_listing)
|
||||
|
||||
# Add editor tests
|
||||
|
||||
@@ -3,8 +3,18 @@
|
||||
# Create test skill directories
|
||||
mkdir -p skills/a/b/c
|
||||
mkdir -p skills/a/b/d
|
||||
echo "# Local Skill 1" > skills/a/b/c/SKILL.md
|
||||
echo "# Local Skill 2" > skills/a/b/d/SKILL.md
|
||||
cat > skills/a/b/c/SKILL.md << 'SKILL'
|
||||
---
|
||||
name: nested-skill-1
|
||||
---
|
||||
# Local Skill 1
|
||||
SKILL
|
||||
cat > skills/a/b/d/SKILL.md << 'SKILL'
|
||||
---
|
||||
name: nested-skill-2
|
||||
---
|
||||
# Local Skill 2
|
||||
SKILL
|
||||
|
||||
# Run drharness with -D flag
|
||||
OUTPUT=$("${DRHARNESS}" -D -F dummy.chat)
|
||||
|
||||
@@ -38,19 +38,4 @@ if ! echo "$OUTPUT" | grep -q "name-only-skill"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Test 3: Verify that invalid frontmatter falls back to filename stem
|
||||
cat > skills/SKILL.md << 'SKILL'
|
||||
# Invalid Frontmatter
|
||||
|
||||
This skill has no proper frontmatter.
|
||||
SKILL
|
||||
|
||||
OUTPUT=$("${DRHARNESS}" -S -F dummy.chat)
|
||||
|
||||
# Should fall back to "SKILL" (the stem of the filename)
|
||||
if ! echo "$OUTPUT" | grep -q "SKILL"; then
|
||||
echo "FAIL: Expected 'SKILL' (fallback name) in output"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "All tests passed!"
|
||||
|
||||
@@ -4,8 +4,18 @@
|
||||
# Create test skill directories
|
||||
mkdir -p skills
|
||||
mkdir -p .skills
|
||||
echo "# Local Skill 1" > skills/SKILL.md
|
||||
echo "# Local Skill 2" > .skills/SKILL.md
|
||||
cat > skills/SKILL.md << 'SKILL'
|
||||
---
|
||||
name: local-skill-1
|
||||
---
|
||||
# Local Skill 1
|
||||
SKILL
|
||||
cat > .skills/SKILL.md << 'SKILL'
|
||||
---
|
||||
name: local-skill-2
|
||||
---
|
||||
# Local Skill 2
|
||||
SKILL
|
||||
|
||||
# Run drharness with -D flag
|
||||
OUTPUT=$("${DRHARNESS}" -D -F dummy.chat)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# test_skill_validation.sh - Verifies that invalid SKILL.md files cause a fatal error
|
||||
|
||||
# Test 1: Invalid frontmatter (no closing ---) should crash
|
||||
mkdir -p skills
|
||||
cat > skills/SKILL.md << 'SKILL'
|
||||
---
|
||||
name: invalid-skill
|
||||
description: No closing
|
||||
|
||||
# Invalid Skill
|
||||
SKILL
|
||||
|
||||
set +e
|
||||
"${DRHARNESS}" -D -F dummy.chat >/dev/null 2>&1
|
||||
EXIT_CODE=$?
|
||||
set -e
|
||||
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
echo "FAIL: Expected harness to crash on invalid YAML"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
rm -rf skills
|
||||
|
||||
# Test 2: File without frontmatter should crash
|
||||
mkdir -p skills
|
||||
cat > skills/SKILL.md << 'SKILL'
|
||||
# No Frontmatter
|
||||
|
||||
This skill has no frontmatter.
|
||||
SKILL
|
||||
|
||||
set +e
|
||||
"${DRHARNESS}" -D -F dummy.chat >/dev/null 2>&1
|
||||
EXIT_CODE=$?
|
||||
set -e
|
||||
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
echo "FAIL: Expected harness to crash on file without frontmatter"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "All validation tests passed!"
|
||||
Reference in New Issue
Block a user