# 07. Tests, DevOps, Legacy/Orphan 감사

> 원본 코드/프롬프트/기존 문서를 수정하지 않고 생성한 read-only 감사 문서입니다.

## Backend tests

| 항목 | 값/내용 |
|---|---|
| backend test files | 129 |
| pytest config | `backend/pytest.ini` |
| default marker | `-m "not pg"` |
| safety guard | `backend/tests/_safety_guards.py` |
| test DB guard | `backend/tests/conftest.py`, `conftest_pg.py` |

강점:

| 강점 | 설명 |
|---|---|
| production DB wipe guard | non-test DB에 대한 drop/delete 방어 |
| tempdir guard | 위험한 rmtree 차단 |
| test env early setup | app import 전 ENV/DATABASE_URL 세팅 |
| marker separation | core/startup/image/full/pg marker 존재 |

문제:

| 문제 | 설명 |
|---|---|
| test DB config drift | `conftest.py` 기본값과 `docker-compose.test.yml` 기본값이 다름 |
| pytest.ini comment drift | comment는 SQLite default 언급, 현재는 PostgreSQL test policy |
| pg tests excluded by default | 실제 PostgreSQL/file path 문제를 기본 lane이 놓칠 수 있음 |
| mock/tmp_path 비중 | 실제 cwd/path/DB invariant 문제를 숨길 수 있음 |
| skipped/stale tests | old v2/v3 pipeline test 흔적 존재 |

## Frontend tests

| 항목 | 값/내용 |
|---|---|
| frontend test files | 5 |
| runner | Vitest |
| environment | jsdom |
| config | `frontend/vitest.config.ts` |

문제는 test count 자체보다, active mutation과 critical UI flow coverage가 낮다는 점이다.

| 미흡 영역 | 영향 |
|---|---|
| legacy/direct image button vs StepRunner button | 실제 사고 경로를 UI test가 잡기 어려움 |
| upload error handling | failed upload success 처리 가능 |
| PromptManager | DB/file prompt mismatch 노출 어려움 |
| ImageReview | regenerate/validate/review path 미검증 |
| auth/admin/session | 운영 edge case 미검증 |

## DevOps

| 파일 | 내용 |
|---|---|
| `docker-compose.yml` | PostgreSQL service만 정의 |
| `docker-compose.test.yml` | test PostgreSQL service |
| `backend/requirements.txt` | backend dependency |
| `frontend/package.json` | frontend scripts/dependencies |
| `frontend/vite.config.ts` | dev proxy `/api -> localhost:8000` |

확인된 drift:

| drift | 설명 |
|---|---|
| compose 범위 | README의 deployment claim보다 `docker-compose.yml`은 DB만 포함 |
| test DB | `conftest.py` default는 localhost:5432 계열, `docker-compose.test.yml`은 5433/test_pass 계열 |
| backend requirements | active import인 `litellm`, `opik` 등 누락 가능성 |
| README model sample | README env sample과 config default model drift |
| frontend README | stock Vite template 상태 |

## Script risk

`backend/scripts`와 root `scripts`에는 실험, migration helper, output generation, cleanup이 섞여 있다.

위험 script 유형:

| 유형 | 예 | 리스크 |
|---|---|---|
| create/analyze automation | `backend/scripts/create_and_analyze.sh` | DB/project 생성, analysis 실행 |
| reanalysis/migration | `migrate_v0513_reanalyze.py` | snapshot 후 force-run |
| cleanup | `cleanup_checkpoint_archives.py` | `--apply` 시 archive 삭제 |
| regen/compare | `scripts/regen_phase91_with_model.py` | dry-run이어도 output dir 생성 가능 |
| experiment image generation | `backend/scripts/experiment_*` | active pipeline과 다른 DB/path/prompt assumptions |
| model comparison | `tests/model_comparison/run_gemini_cascade.py` | stale step 이름 사용 |

## Legacy/orphan code 주의

```mermaid
flowchart TB
    Active[active backend/frontend/prompts] --> Prod[actual app]
    Experiments[backend/scripts experiment_*] -. not prod .-> Confusion[analysis confusion]
    Prototype[prototype_ui / prototype] -. not prod .-> Confusion
    Old[Old / _backup_*] -. not prod .-> Confusion
    Screenplay[screenplay standalone] -. separate prompt system .-> Confusion
    Data[data / projects / backups] -. runtime state .-> Confusion
```

Orphan/legacy를 조심해야 하는 이유:

| 이유 | 설명 |
|---|---|
| active 코드처럼 검색됨 | `rg` 결과에 old path가 섞임 |
| prompt 체계가 다름 | `screenplay/prompts`는 backend prompt loader와 무관 |
| DB 체계가 다름 | legacy SQLite/prototype SQLite가 current PostgreSQL과 다름 |
| script 부작용 | 일부 script는 파일/DB를 실제 변경 |
| 실험 코드 | 최근 chain/floorplan 실험은 active Phase 7과 다른 path일 수 있음 |

## Requirements/dependency risk

하위 분석에서 fresh backend install 누락 가능성이 지적된 import:

| import | 위치 | 리스크 |
|---|---|---|
| `litellm` | `backend/app/modules/llm/llm_client.py` | requirements 누락 시 startup/import failure |
| `opik` | `backend/app/modules/llm/image_tracer.py` | tracing import failure 가능 |
| `requests` | script | script 실행 실패 |

정확한 dependency lock이 없다면 "현재 로컬 venv에서는 되지만 새 환경에서 깨지는" 상태가 된다.

## 권장 개선 방향

| 우선순위 | 개선 |
|---|---|
| P1 | test DB default를 `docker-compose.test.yml`과 통일 |
| P1 | backend requirements와 실제 imports audit 자동화 |
| P1 | critical path PG tests를 default 또는 CI required lane에 포함 |
| P1 | mutation script는 dry-run default와 explicit `--apply` required |
| P2 | legacy/orphan registry 작성: active, deprecated, archive, runtime data 분류 |
| P2 | frontend critical mutation tests 확대 |
| P2 | README/frontend README/devops 문서 최신화 |
| P3 | generated output/runtime dirs를 source audit 대상에서 제외하는 tooling 추가 |
