solorpower/docs/development_and_testing.md
haneulai a716dbef96
Some checks are pending
CI / Crawler (Python ${{ matrix.python-version }}) (3.10) (push) Waiting to run
CI / Crawler (Python ${{ matrix.python-version }}) (3.11) (push) Waiting to run
CI / API (Python 3.11) (push) Waiting to run
CI / Database migration (push) Waiting to run
CI / App web build (Node 20) (push) Waiting to run
feat: harden solar monitoring through stage 7
2026-08-07 14:07:22 +09:00

77 lines
3.1 KiB
Markdown

# 개발 환경 및 테스트 가이드
이 문서는 새 개발 환경과 CI에서 SolarPower 프로젝트를 같은 방법으로 설치하고 검증하기 위한 기준이다. 실제 Supabase 자격 증명이나 운영 서버 연결 없이도 기본 회귀 테스트를 실행할 수 있다.
## 지원 환경
- Crawler: Python 3.10 또는 3.11
- API: Python 3.11
- App: Node.js 20, npm
- DB migration test: PostgreSQL 15 (`psql` 또는 Docker 사용)
프로젝트의 `.env` 파일은 설치 및 단위 테스트에 필요하지 않다. 운영 작업을 수행할 때만 별도로 주입한다.
## Crawler
`crawler/requirements.in`에는 crawler, 과거 데이터 복구, 일일 통계 작업의 직접 의존성과 Python 3.10 호환 제약이 기록되어 있다. `crawler/requirements.txt`는 새 환경에서 해석하고 검증한 전체 고정 버전 목록이며 설치와 CI는 이 파일을 사용한다.
```powershell
cd crawler
python -m venv .venv
.\.venv\Scripts\python -m pip install -r requirements.txt
.\.venv\Scripts\python -m unittest discover -s tests -p "test_*.py" -v
```
Linux/macOS에서는 마지막 두 명령의 Python 경로를 `.venv/bin/python`으로 바꾼다. 외부 사이트 응답 파서 테스트는 `crawler/tests/fixtures/`의 고정 응답을 사용하므로 네트워크나 실제 계정에 의존하지 않는다.
## API server
`api_server/requirements.in`은 직접 의존성의 기준이고, `api_server/requirements.txt`는 배포 및 CI가 사용하는 고정 버전 목록이다.
```powershell
cd api_server
python -m venv .venv
.\.venv\Scripts\python -m pip install -r requirements.txt
$env:SUPABASE_URL = "http://localhost:54321"
$env:SUPABASE_KEY = "test-key"
$env:DEBUG = "false"
.\.venv\Scripts\python -m unittest discover -s tests -p "test_*.py" -v
```
위 값은 설정 로딩을 위한 테스트용 값이며 실제 DB 연결에는 사용되지 않는다.
## App
`package-lock.json`을 저장소에 포함하고 CI와 새 환경에서는 `npm ci`를 사용한다.
```powershell
cd app
npm ci
npm run test:ci
```
현재 `test:ci`는 Expo 웹 export를 수행하여 의존성, 번들링, 정적 산출물 생성을 함께 검사한다. 출력 디렉터리는 `app/dist/`이며 Git에서 제외된다.
## DB migration
통계 쓰기 일관성 migration은 독립 PostgreSQL 15 DB에서 다음 계약 테스트로 확인한다.
```powershell
$env:PGPASSWORD = "postgres"
cd supabase/tests
psql -h localhost -U postgres -d postgres -f stats_write_consistency_test.sql
```
테스트 SQL이 필요한 최소 스키마를 만들고 migration을 적용한 뒤 RPC, 일별·월별 집계 trigger와 기존 데이터 보존 조건을 검증한다.
## CI 기준
`.github/workflows/ci.yml`은 push와 pull request마다 다음 작업을 독립 실행한다.
1. Crawler: Python 3.10/3.11 전체 단위·fixture 테스트
2. API: Python 3.11 전체 단위 테스트
3. Database: PostgreSQL 15 migration 계약 테스트
4. App: Node 20에서 `npm ci` 후 Expo 웹 build
CI에는 운영 비밀값을 등록하지 않는다. 실제 외부 사이트, 운영 Supabase, Telegram 전송은 배포 후 별도의 운영 확인 절차로 검증한다.