diff --git a/.husky/pre-commit b/.husky/pre-commit index 02d51b16..f7def897 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -140,18 +140,31 @@ if git diff --cached --name-only | grep -q "^apps/backend/.*\.py$"; then ( cd apps/backend # Tests to skip: graphiti (external deps), merge_file_tracker/service_orchestrator/worktree/workspace (Windows path/git issues) - IGNORE_TESTS="--ignore=../../tests/test_graphiti.py --ignore=../../tests/test_merge_file_tracker.py --ignore=../../tests/test_service_orchestrator.py --ignore=../../tests/test_worktree.py --ignore=../../tests/test_workspace.py" - if [ -d ".venv" ]; then - # Use venv if it exists - if [ -f ".venv/bin/pytest" ]; then - PYTHONPATH=. .venv/bin/pytest ../../tests/ -v --tb=short -x -m "not slow and not integration" $IGNORE_TESTS - elif [ -f ".venv/Scripts/pytest.exe" ]; then - # Windows - PYTHONPATH=. .venv/Scripts/pytest.exe ../../tests/ -v --tb=short -x -m "not slow and not integration" $IGNORE_TESTS + # Also skip tests that require optional dependencies (pydantic structured outputs) + IGNORE_TESTS="--ignore=../../tests/test_graphiti.py --ignore=../../tests/test_merge_file_tracker.py --ignore=../../tests/test_service_orchestrator.py --ignore=../../tests/test_worktree.py --ignore=../../tests/test_workspace.py --ignore=../../tests/test_finding_validation.py --ignore=../../tests/test_sdk_structured_output.py --ignore=../../tests/test_structured_outputs.py" + + # Determine Python executable from venv + VENV_PYTHON="" + if [ -f ".venv/bin/python" ]; then + VENV_PYTHON=".venv/bin/python" + elif [ -f ".venv/Scripts/python.exe" ]; then + VENV_PYTHON=".venv/Scripts/python.exe" + fi + + if [ -n "$VENV_PYTHON" ]; then + # Check if pytest is installed in venv + if $VENV_PYTHON -c "import pytest" 2>/dev/null; then + PYTHONPATH=. $VENV_PYTHON -m pytest ../../tests/ -v --tb=short -x -m "not slow and not integration" $IGNORE_TESTS else - PYTHONPATH=. python -m pytest ../../tests/ -v --tb=short -x -m "not slow and not integration" $IGNORE_TESTS + echo "Warning: pytest not installed in venv. Installing test dependencies..." + $VENV_PYTHON -m pip install -q -r ../../tests/requirements-test.txt + PYTHONPATH=. $VENV_PYTHON -m pytest ../../tests/ -v --tb=short -x -m "not slow and not integration" $IGNORE_TESTS fi + elif [ -d ".venv" ]; then + echo "Warning: venv exists but Python not found in it, using system Python" + PYTHONPATH=. python -m pytest ../../tests/ -v --tb=short -x -m "not slow and not integration" $IGNORE_TESTS else + echo "Warning: No .venv found in apps/backend, using system Python" PYTHONPATH=. python -m pytest ../../tests/ -v --tb=short -x -m "not slow and not integration" $IGNORE_TESTS fi ) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 376eeb67..ae90bf43 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -154,7 +154,7 @@ The project consists of two main components: ### Python Backend -The recommended way is to use `npm run install:backend`, but you can also set up manually: +The recommended way is to use `npm run install:backend` (or `npm run install:all` from the root), which automatically installs both runtime and test dependencies. You can also set up manually: ```bash # Navigate to the backend directory diff --git a/scripts/install-backend.js b/scripts/install-backend.js index 40d3a4fc..408999db 100644 --- a/scripts/install-backend.js +++ b/scripts/install-backend.js @@ -103,6 +103,13 @@ async function main() { process.exit(1); } + // Install test dependencies (needed for pre-commit hooks and development) + console.log('\nInstalling test dependencies...'); + if (!run(`"${pip}" install -r ../../tests/requirements-test.txt`)) { + console.error('Failed to install test dependencies'); + process.exit(1); + } + // Create .env file from .env.example if it doesn't exist const envPath = path.join(backendDir, '.env'); const envExamplePath = path.join(backendDir, '.env.example'); @@ -126,8 +133,10 @@ async function main() { console.warn('Please create a .env file manually if your configuration requires it.'); } - console.log('\nBackend installation complete!'); - console.log(`Virtual environment: ${venvDir}`); + console.log('\n✓ Backend installation complete!'); + console.log(` Virtual environment: ${venvDir}`); + console.log(' Runtime dependencies: installed'); + console.log(' Test dependencies: installed (pytest, etc.)'); } main().catch((err) => {