diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0c9c77e0..2285e3f7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -343,14 +343,16 @@ jobs: - name: Initialize database run: | - mkdir -p .codeframe + # E2E tests expect database at tests/e2e/.codeframe/state.db + mkdir -p tests/e2e/.codeframe source .venv/bin/activate - python -c "from codeframe.persistence.database import Database; db = Database('.codeframe/state.db'); db.initialize(); db.close()" - echo "✅ Database initialized" + python -c "from codeframe.persistence.database import Database; db = Database('tests/e2e/.codeframe/state.db'); db.initialize(); db.close()" + echo "✅ Database initialized at tests/e2e/.codeframe/state.db" - name: Start backend server env: - DATABASE_PATH: ${{ github.workspace }}/.codeframe/state.db + # Must match TEST_DB_PATH in tests/e2e/e2e-config.ts + DATABASE_PATH: ${{ github.workspace }}/tests/e2e/.codeframe/state.db WORKSPACE_ROOT: ${{ github.workspace }} CODEFRAME_DEPLOYMENT_MODE: self_hosted run: | diff --git a/.gitignore b/.gitignore index 9cf30f91..2089c8ed 100644 --- a/.gitignore +++ b/.gitignore @@ -83,3 +83,5 @@ testsprite_tests/tmp/config.json tests/e2e/playwright-report/ tests/e2e/test-results/ tests/e2e/.auth/ +tests/e2e/.codeframe/ +test_audit_report.md diff --git a/docs/TESTING_STRATEGY.md b/docs/TESTING_STRATEGY.md new file mode 100644 index 00000000..5022d7dd --- /dev/null +++ b/docs/TESTING_STRATEGY.md @@ -0,0 +1,267 @@ +# Testing Strategy for CodeFRAME + +This document outlines the testing philosophy, guidelines, and best practices for the CodeFRAME project. + +## Testing Philosophy + +### Core Principles + +1. **Real Implementations Over Mocks**: Prefer testing with real components when possible. Mocking should only be used for external services that are impractical to use in tests. + +2. **Mock Boundaries, Not Internals**: Only mock at system boundaries (external APIs, network calls). Never mock internal methods or classes to make tests pass. + +3. **Tests Should Fail When Code Breaks**: If removing a function or breaking logic doesn't cause a test to fail, the test is not valuable. + +4. **Integration Tests for Workflows**: Test complete workflows with real database and file operations. Unit tests should focus on pure logic. + +## Test Categories + +### Unit Tests +- **Purpose**: Test individual functions and classes in isolation +- **Mock Policy**: Mock only external I/O (network, external APIs) +- **Location**: `tests/` directory (excluding `tests/integration/`) +- **Run Command**: `pytest -m "not integration"` + +**Good Unit Test Example**: +```python +def test_sanitize_prompt_removes_special_chars(): + """Test pure logic - no mocking needed.""" + result = sanitize_prompt_input("Hello ") + assert "