# Pre-Release Hardening: Integration Testing Plan

**Goal**: Verify the Clew Ecosystem (Engine + Platform) is stable, correct, and ready for Alpha.
**Blocker Status**: Priority 1 (Alpha Blocker)

## 1. Clew Engine Testing (`clew-engine`)

### Strategy
- **Framework**: `pytest`
- **Scope**: Unit tests for core logic, Integration tests for adapters (Qdrant/Neo4j), CLI tests.

### Test Cases
1.  **Core Logic**:
    -   `graph.py`: Verify `clean_id` handles special chars.
    -   `graph.py`: Verify `explore_module` returns correct partial graph.
2.  **Adapters** (Mocked & Real):
    -   `adapters.py`: Verify `QdrantAdapter` performs vector search.
    -   `adapters.py`: Verify `Neo4jAdapter` performs graph traversal.
3.  **CLI**:
    -   `cli.py`: Verify `clew --help` runs.
    -   `cli.py`: Verify `clew review` handles empty diffs gracefully.

### Implementation Checklist
- [ ] Create `tests/` directory in `clew-engine`
- [ ] Add `pytest`, `pytest-asyncio`, `pytest-mock` to `dev` dependencies
- [ ] Implement `tests/test_core.py` (Unit)
- [ ] Implement `tests/test_cli.py` (Typer runner)

## 2. Clew Platform Testing (`clew-platform`)

### Strategy
- **Framework**: `pytest` + `TestClient` (FastAPI)
- **Scope**: API endpoints, Worker task execution, Auth flow.

### Test Cases
1.  **API Endpoints**:
    -   `POST /auth/login`: Verify mocked token generation.
    -   `GET /jobs`: Verify job listing.
    -   `POST /jobs`: Verify job submission to Arq.
2.  **Worker**:
    -   `worker.py`: Verify `process_repo` task can run (mocking the Engine ingest).
3.  **Auth**:
    -   Verify `get_current_user` rejects invalid tokens.

### Implementation Checklist
**Note**: These items are for the separate `clew-platform` repository.
- [ ] Create `tests/` directory in clew-platform
- [ ] Add `pytest`, `httpx` to platform requirements
- [ ] Implement `tests/test_api.py`

## 3. End-to-End (E2E) Smoke Test

### Strategy
- **Tool**: Bash script + `curl` + `docker-compose`
- **Scope**: Full stack spin-up and happy path execution.

### Flow
1.  `docker-compose up -d` (Platform + DBs)
2.  Wait for healthchecks (`/health`).
3.  **Ingest**: Submit a job to ingest a small repo (e.g., `clew-resources`).
4.  **Poll**: Wait for job completion.
5.  **Search**: Query the API for a known concept.
6.  **Verify**: Assert results contain expected file.

### Implementation Checklist
- [ ] Create `scripts/test_e2e.sh` in `clew-platform`
- [ ] Create `clew-resources` (tiny dummy repo) for testing or use self.

## 4. Execution Order
1.  **Engine**: Build Unit/CLI tests first (fastest feedback).
2.  **Platform**: Build API tests (ensure contract).
3.  **E2E**: Tie it all together.
