232 lines
5.8 KiB
Bash
Executable File
232 lines
5.8 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Skill Migrator Test Script
|
|
# Tests the non-interactive mode functionality
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
MIGRATE_SCRIPT="$HOME/.config/opencode/skills/skill-migrator/scripts/migrate.sh"
|
|
TEST_DIR="$HOME/.agents-test"
|
|
|
|
echo "========================================"
|
|
echo " SKILL MIGRATOR TEST SUITE"
|
|
echo "========================================"
|
|
echo ""
|
|
|
|
# Setup: Create test skills
|
|
setup_test_env() {
|
|
echo "Setting up test environment..."
|
|
rm -rf "$TEST_DIR"
|
|
mkdir -p "$TEST_DIR"
|
|
|
|
# Create a test skill
|
|
mkdir -p "$TEST_DIR/test-skill-1"
|
|
cat > "$TEST_DIR/test-skill-1/SKILL.md" << 'EOF'
|
|
---
|
|
name: test-skill-1
|
|
description: Test skill 1 for migration testing
|
|
---
|
|
|
|
# Test Skill 1
|
|
|
|
This is a test skill.
|
|
EOF
|
|
|
|
# Create another test skill
|
|
mkdir -p "$TEST_DIR/test-skill-2"
|
|
cat > "$TEST_DIR/test-skill-2/SKILL.md" << 'EOF'
|
|
---
|
|
name: test-skill-2
|
|
description: Test skill 2 for migration testing
|
|
---
|
|
|
|
# Test Skill 2
|
|
|
|
This is another test skill.
|
|
EOF
|
|
|
|
echo "✓ Test environment created"
|
|
echo ""
|
|
}
|
|
|
|
# Test 1: Basic non-interactive migration
|
|
test_basic_migration() {
|
|
echo "Test 1: Basic Non-Interactive Migration"
|
|
echo "----------------------------------------"
|
|
|
|
# Clean target
|
|
rm -rf "$HOME/.config/opencode/skills/test-skill-1"
|
|
rm -rf "$HOME/.config/opencode/skills/test-skill-2"
|
|
|
|
# Run migration with non-interactive flags
|
|
if "$MIGRATE_SCRIPT" "$TEST_DIR" --all --yes; then
|
|
echo "✓ Migration completed successfully"
|
|
else
|
|
echo "✗ Migration failed"
|
|
return 1
|
|
fi
|
|
|
|
# Verify skills were migrated
|
|
if [[ -d "$HOME/.config/opencode/skills/test-skill-1" && -d "$HOME/.config/opencode/skills/test-skill-2" ]]; then
|
|
echo "✓ Skills migrated to correct location"
|
|
else
|
|
echo "✗ Skills not found in target directory"
|
|
return 1
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
# Test 2: Skip conflict strategy
|
|
test_skip_strategy() {
|
|
echo "Test 2: Skip Conflict Strategy"
|
|
echo "-------------------------------"
|
|
|
|
# Modify source skill
|
|
echo "# Modified" >> "$TEST_DIR/test-skill-1/SKILL.md"
|
|
|
|
# Run migration with skip strategy
|
|
if "$MIGRATE_SCRIPT" "$TEST_DIR" --all --yes --conflict-strategy skip; then
|
|
echo "✓ Migration with skip strategy completed"
|
|
else
|
|
echo "✗ Migration failed"
|
|
return 1
|
|
fi
|
|
|
|
# Verify original skill was NOT overwritten
|
|
if ! grep -q "# Modified" "$HOME/.config/opencode/skills/test-skill-1/SKILL.md"; then
|
|
echo "✓ Existing skill was skipped (not overwritten)"
|
|
else
|
|
echo "✗ Existing skill was overwritten (should have been skipped)"
|
|
return 1
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
# Test 3: Overwrite conflict strategy
|
|
test_overwrite_strategy() {
|
|
echo "Test 3: Overwrite Conflict Strategy"
|
|
echo "------------------------------------"
|
|
|
|
# Run migration with overwrite strategy
|
|
if "$MIGRATE_SCRIPT" "$TEST_DIR" --all --yes --conflict-strategy overwrite; then
|
|
echo "✓ Migration with overwrite strategy completed"
|
|
else
|
|
echo "✗ Migration failed"
|
|
return 1
|
|
fi
|
|
|
|
# Verify skill WAS overwritten
|
|
if grep -q "# Modified" "$HOME/.config/opencode/skills/test-skill-1/SKILL.md"; then
|
|
echo "✓ Existing skill was overwritten"
|
|
else
|
|
echo "✗ Existing skill was not overwritten"
|
|
return 1
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
# Test 4: Backup conflict strategy
|
|
test_backup_strategy() {
|
|
echo "Test 4: Backup Conflict Strategy"
|
|
echo "---------------------------------"
|
|
|
|
# Run migration with backup strategy
|
|
if "$MIGRATE_SCRIPT" "$TEST_DIR" --all --yes --conflict-strategy backup; then
|
|
echo "✓ Migration with backup strategy completed"
|
|
else
|
|
echo "✗ Migration failed"
|
|
return 1
|
|
fi
|
|
|
|
# Verify backup was created
|
|
if ls "$HOME/.config/opencode/skills/test-skill-1.backup."* 1> /dev/null 2>&1; then
|
|
echo "✓ Backup was created"
|
|
else
|
|
echo "✗ Backup not found"
|
|
return 1
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
# Test 5: Dry run
|
|
test_dry_run() {
|
|
echo "Test 5: Dry Run Mode"
|
|
echo "---------------------"
|
|
|
|
# Create a new test skill that doesn't exist yet
|
|
mkdir -p "$TEST_DIR/test-skill-3"
|
|
cat > "$TEST_DIR/test-skill-3/SKILL.md" << 'EOF'
|
|
---
|
|
name: test-skill-3
|
|
description: Test skill 3 for dry run testing
|
|
---
|
|
|
|
# Test Skill 3
|
|
|
|
This skill should not be migrated in dry run.
|
|
EOF
|
|
|
|
# Run migration with dry-run
|
|
if "$MIGRATE_SCRIPT" "$TEST_DIR" --all --dry-run; then
|
|
echo "✓ Dry run completed"
|
|
else
|
|
echo "✗ Dry run failed"
|
|
return 1
|
|
fi
|
|
|
|
# Verify skill was NOT actually migrated
|
|
if [[ ! -d "$HOME/.config/opencode/skills/test-skill-3" ]]; then
|
|
echo "✓ Dry run correctly made no changes"
|
|
else
|
|
echo "✗ Skill was migrated (should not happen in dry run)"
|
|
return 1
|
|
fi
|
|
|
|
echo ""
|
|
}
|
|
|
|
# Cleanup
|
|
cleanup() {
|
|
echo "Cleaning up..."
|
|
rm -rf "$TEST_DIR"
|
|
rm -rf "$HOME/.config/opencode/skills/test-skill-1"
|
|
rm -rf "$HOME/.config/opencode/skills/test-skill-2"
|
|
rm -rf "$HOME/.config/opencode/skills/test-skill-3"
|
|
rm -f "$HOME/.config/opencode/skills/test-skill-1.backup."*
|
|
echo "✓ Cleanup complete"
|
|
echo ""
|
|
}
|
|
|
|
# Run all tests
|
|
main() {
|
|
setup_test_env
|
|
|
|
local failed=0
|
|
|
|
test_basic_migration || ((failed++))
|
|
test_skip_strategy || ((failed++))
|
|
test_overwrite_strategy || ((failed++))
|
|
test_backup_strategy || ((failed++))
|
|
test_dry_run || ((failed++))
|
|
|
|
cleanup
|
|
|
|
echo "========================================"
|
|
echo " TEST RESULTS"
|
|
echo "========================================"
|
|
if [[ $failed -eq 0 ]]; then
|
|
echo "✓ All tests passed!"
|
|
exit 0
|
|
else
|
|
echo "✗ $failed test(s) failed"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
main "$@"
|