diff options
| author | Jesse Vincent <jesse@fsck.com> | 2025-11-23 12:28:58 -0800 |
|---|---|---|
| committer | Jesse Vincent <jesse@fsck.com> | 2025-11-23 12:28:58 -0800 |
| commit | f3d6c331a1950abb19ef1f28a78b01765ad1b873 (patch) | |
| tree | ca3c38443b66345816a8a1557b7cc464f911eec6 /tests/opencode/setup.sh | |
| parent | b0ba2cf15afc786940c2cdd984962d4f7d278b4a (diff) | |
test: add automated test suite for opencode plugin
Create comprehensive tests in tests/opencode/ that verify the plugin
works correctly in an isolated test environment:
- setup.sh: Creates temp HOME and installs plugin with proper symlinks
- test-plugin-loading.sh: Verifies plugin structure and JavaScript syntax
- test-skills-core.sh: Unit tests for skills-core.js library functions
- test-tools.sh: Integration tests for use_skill/find_skills (requires OpenCode)
- test-priority.sh: Tests project > personal > superpowers priority
- run-tests.sh: Main test runner with options for integration tests
Run basic tests: ./tests/opencode/run-tests.sh
Run all tests: ./tests/opencode/run-tests.sh --integration
Diffstat (limited to 'tests/opencode/setup.sh')
| -rwxr-xr-x | tests/opencode/setup.sh | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/opencode/setup.sh b/tests/opencode/setup.sh new file mode 100755 index 0000000..5eb0b31 --- /dev/null +++ b/tests/opencode/setup.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# Setup script for OpenCode plugin tests +# Creates an isolated test environment with proper plugin installation +set -euo pipefail + +# Get the repository root (two levels up from tests/opencode/) +REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" + +# Create temp home directory for isolation +export TEST_HOME=$(mktemp -d) +export HOME="$TEST_HOME" +export XDG_CONFIG_HOME="$TEST_HOME/.config" + +# Install plugin to test location +mkdir -p "$HOME/.config/opencode/superpowers" +cp -r "$REPO_ROOT/lib" "$HOME/.config/opencode/superpowers/" +cp -r "$REPO_ROOT/skills" "$HOME/.config/opencode/superpowers/" + +# Copy plugin directory +mkdir -p "$HOME/.config/opencode/superpowers/.opencode/plugin" +cp "$REPO_ROOT/.opencode/plugin/superpowers.js" "$HOME/.config/opencode/superpowers/.opencode/plugin/" + +# Register plugin via symlink +mkdir -p "$HOME/.config/opencode/plugin" +ln -sf "$HOME/.config/opencode/superpowers/.opencode/plugin/superpowers.js" \ + "$HOME/.config/opencode/plugin/superpowers.js" + +# Create test skills in different locations for testing + +# Personal test skill +mkdir -p "$HOME/.config/opencode/skills/personal-test" +cat > "$HOME/.config/opencode/skills/personal-test/SKILL.md" <<'EOF' +--- +name: personal-test +description: Test personal skill for verification +--- +# Personal Test Skill + +This is a personal skill used for testing. + +PERSONAL_SKILL_MARKER_12345 +EOF + +# Create a project directory for project-level skill tests +mkdir -p "$TEST_HOME/test-project/.opencode/skills/project-test" +cat > "$TEST_HOME/test-project/.opencode/skills/project-test/SKILL.md" <<'EOF' +--- +name: project-test +description: Test project skill for verification +--- +# Project Test Skill + +This is a project skill used for testing. + +PROJECT_SKILL_MARKER_67890 +EOF + +echo "Setup complete: $TEST_HOME" +echo "Plugin installed to: $HOME/.config/opencode/superpowers/.opencode/plugin/superpowers.js" +echo "Plugin registered at: $HOME/.config/opencode/plugin/superpowers.js" +echo "Test project at: $TEST_HOME/test-project" + +# Helper function for cleanup (call from tests or trap) +cleanup_test_env() { + if [ -n "${TEST_HOME:-}" ] && [ -d "$TEST_HOME" ]; then + rm -rf "$TEST_HOME" + fi +} + +# Export for use in tests +export -f cleanup_test_env +export REPO_ROOT |
