# Phase 5.5: UA Testing — Technical Debt & Test Gaps Reset

## What Was Built

4 technical debt fixes (source code changes) and 8 test improvements (3 smell fixes + 5 coverage gap fills) across 10 files. No new features — this phase purely raises code quality and test coverage before Phase 6.

---

## Running Automated Tests

### Full suite

```bash
python3 -m pytest tests/ -v --tb=short
```

### Only modified test files

```bash
python3 -m pytest tests/test_config.py tests/test_db_connection.py tests/test_scoring.py tests/test_adapters.py tests/test_repositories.py -v --tb=short
```

### Linting

```bash
ruff check src/unfamiliar/analysis/testing.py src/unfamiliar/db/repositories/file_snapshot.py src/unfamiliar/analysis/adapters/javascript_adapter.py src/unfamiliar/analysis/adapters/typescript_adapter.py src/unfamiliar/config.py
ruff check tests/test_config.py tests/test_db_connection.py tests/test_scoring.py tests/test_adapters.py tests/test_repositories.py
```

---

## Verification Checklist

### Tech Debt Fixes

- [ ] `testing.py`: `tier` variable is `Literal["basic", "enhanced"]`, no `# type: ignore` on line ~121
- [ ] `file_snapshot.py`: No `contextlib` import; `ValueError` logged via `logger.warning`, not suppressed
- [ ] `javascript_adapter.py`: `JavaScriptAdapter.__init__` creates `self._parser`; `parse_file` uses `self._parser`
- [ ] `typescript_adapter.py`: `TypeScriptAdapter.__init__` creates `self._ts_parser` and `self._tsx_parser`; `parse_file` selects correct parser by extension
- [ ] `config.py`: No `_BASE_DIR` module-level constant; `load_config()` accepts `base_dir` param; `get_campaign_dir()` accepts `base_dir` param

### Test Smell Fixes

- [ ] `test_db_connection.py`: `test_idempotent_double_init` verifies tables exist and no duplicate meta rows after double init
- [ ] `test_scoring.py`: `test_all_4_signals_combined_higher_than_any_single` asserts `score > 100` and `len(reasons) == 4` (not `== 200`)
- [ ] `test_config.py`: `test_different_repos_produce_different_dirs` replaces hash mirror test; uses `base_dir` param not monkeypatch

### Test Gap Coverage

- [ ] `test_adapters.py`: `TestPythonAdapterDetectAppType` class with 6 tests (Flask, FastAPI, Typer, attribute access, Django non-match, plain code)
- [ ] `test_repositories.py`: `TestMissionRepositoryGetMissionsForModule` — 2 tests (linked, empty)
- [ ] `test_repositories.py`: `TestFileSnapshotGetByPath` — 3 tests (found, not found, cross-campaign)
- [ ] `test_repositories.py`: `TestCampaignRepositoryGenericUpdate` — 3 tests (field changes, preservation, timestamps)
- [ ] `test_repositories.py`: `TestModuleRepositoryUpdate` — 2 tests (category_relevance round-trip, preservation)
- [ ] `test_repositories.py`: `TestChainRepositoryCrudGaps` — 6 tests (create_many, create_many fields, get by id, get nonexistent, get_by_campaign ordered, empty)

---

## Known Issues

- Pre-existing ruff TC003 warnings in `test_config.py` and `test_repositories.py` (stdlib imports not in TYPE_CHECKING block). Not introduced by this phase.
- Cannot run tests in current environment (venv created on different machine). Tests should be verified locally.
