Files
drharness/tests/test_skill_parsing.sh
darthrubik c9461f2e88 YAML Frontmatter Parsing & Debug Parsing
- Add skill_parsing.hpp and skill_parsing.cpp for YAML frontmatter parsing
- Extract name (required) and description (optional) from SKILL.md files
- Add -y flag to print parsed metadata and exit
- Add test_skill_parsing.sh to verify the -y flag functionality
- Update CMakeLists.txt to include the new source and test
2026-05-20 16:21:58 -05:00

108 lines
2.4 KiB
Bash

#!/bin/bash
# test_skill_parsing.sh - Verifies the -y flag correctly parses YAML frontmatter
# Create test skill files
echo '# Test Skill' > "$TEST_TEMP_DIR/test_skill.md"
# Test 1: Skill with name and description
cat > "$TEST_TEMP_DIR/full_skill.md" << 'SKILL'
---
name: full-skill
description: A full skill with description
---
# Full Skill Content
This is the full skill.
SKILL
OUTPUT=$("${DRHARNESS}" -y "$TEST_TEMP_DIR/full_skill.md" -F dummy.chat)
if ! echo "$OUTPUT" | grep -q "name: full-skill"; then
echo "FAIL: Expected 'name: full-skill' in output"
exit 1
fi
if ! echo "$OUTPUT" | grep -q "description: A full skill with description"; then
echo "FAIL: Expected description in output"
exit 1
fi
# Test 2: Skill with only name (no description)
cat > "$TEST_TEMP_DIR/name_only_skill.md" << 'SKILL'
---
name: name-only-skill
---
# Name Only Skill Content
SKILL
OUTPUT=$("${DRHARNESS}" -y "$TEST_TEMP_DIR/name_only_skill.md" -F dummy.chat)
if ! echo "$OUTPUT" | grep -q "name: name-only-skill"; then
echo "FAIL: Expected 'name: name-only-skill' in output"
exit 1
fi
if echo "$OUTPUT" | grep -q "description:"; then
echo "FAIL: Unexpected description in output"
exit 1
fi
# Test 3: Missing name should fail
cat > "$TEST_TEMP_DIR/missing_name_skill.md" << 'SKILL'
---
description: No name here
---
# Missing Name Skill
SKILL
set +e
"${DRHARNESS}" -y "$TEST_TEMP_DIR/missing_name_skill.md" -F dummy.chat 2>/dev/null
MISSING_NAME_EXIT=$?
set -e
if [ $MISSING_NAME_EXIT -eq 0 ]; then
echo "FAIL: Expected failure when name is missing"
exit 1
fi
# Test 4: Invalid frontmatter (no closing ---) should fail
cat > "$TEST_TEMP_DIR/invalid_skill.md" << 'SKILL'
---
name: invalid-skill
description: No closing
# Invalid Skill
SKILL
set +e
"${DRHARNESS}" -y "$TEST_TEMP_DIR/invalid_skill.md" -F dummy.chat 2>/dev/null
INVALID_EXIT=$?
set -e
if [ $INVALID_EXIT -eq 0 ]; then
echo "FAIL: Expected failure for invalid frontmatter"
exit 1
fi
# Test 5: File without frontmatter should fail
cat > "$TEST_TEMP_DIR/no_frontmatter_skill.md" << 'SKILL'
# No Frontmatter Skill
This skill has no frontmatter.
SKILL
set +e
"${DRHARNESS}" -y "$TEST_TEMP_DIR/no_frontmatter_skill.md" -F dummy.chat 2>/dev/null
NO_FRONTMATTER_EXIT=$?
set -e
if [ $NO_FRONTMATTER_EXIT -eq 0 ]; then
echo "FAIL: Expected failure for file without frontmatter"
exit 1
fi
echo "All tests passed!"