# task-361.1 완료 보고서: 자동포스팅 테마 선택 개선 (연속 중복 방지)

## 작업 요약
`get_random_theme()` 함수에 히스토리 기반 연속 중복 방지 로직을 추가하고, `run_full_pipeline.py`의 NavyGold 고정을 제거하여 랜덤 테마를 사용하도록 변경.

## 변경 파일

- **수정**: `renderer/themes.py` — `get_random_theme()` 히스토리 기반 중복 방지 구현
- **신규**: `tests/test_themes.py` — 테마 중복 방지 테스트 8건
- **수정**: `run_full_pipeline.py` — NavyGold 고정 → `get_random_theme()` 사용

## 구현 상세

### 1. themes.py — `get_random_theme()` 개선
- `HISTORY_FILE` 상수 추가: `data/theme_history.json`
- 히스토리 파일에서 `last_theme` 로드 → 해당 테마를 후보에서 제외
- 제외된 테마의 가중치를 나머지에 비례 배분 (정규화 불필요 — `random.choices`가 자동 처리)
- 선택 후 히스토리 업데이트: `last_theme`, `recent`(최대 5개), `updated`(ISO8601)
- `data/` 디렉토리 자동 생성 (`os.makedirs`)
- I/O 실패 시 fallback: 기존 랜덤 로직으로 동작 (서비스 중단 방지)

### 2. run_full_pipeline.py — NavyGold 고정 제거
- Step 3: `get_theme("NavyGold")` → `get_random_theme()`
- Step 4: `theme_name="NavyGold"` → `theme_name=theme.name`
- import: `get_theme` → `get_random_theme`

### 3. daily_runner.py — 확인 완료
- 이미 `get_random_theme()` 사용 중 (336줄, 361줄) → 자동 적용됨

## 테스트 결과

test_themes.py: **8/8 PASSED** (0.10s)

- test_no_consecutive_duplicates: 10회 연속 호출 중복 없음 확인
- test_history_file_created: 히스토리 파일 생성 확인
- test_history_file_updated: last_theme, recent 업데이트 확인
- test_recent_list_max_5: recent 리스트 최대 5개 유지 확인
- test_fallback_no_history_file: 파일 없을 때 정상 동작 확인
- test_fallback_corrupted_history: 깨진 JSON fallback 확인
- test_weight_redistribution: 제외 후 가중치 재분배 확인
- test_function_signature_unchanged: 함수 시그니처 유지 확인

## QC 자동 검증 결과

- api_health: SKIP (서버 작업 아님)
- file_check: PASS (보고서/.done 생성 후)
- data_integrity: PASS
- test_runner: FAIL — `test_evergreen_topics.py` 기존 테스트 실패 (본 작업 무관)
- tdd_check: PASS
- schema_contract: SKIP
- pyright_check: WARN — `sys.path.insert` 런타임 경로 구조의 기존 import 해석 이슈
- style_check: PASS (black + isort)
- scope_check: SKIP

## Git 커밋

- `8361f92` — [task-361.1] 테마 연속 중복 방지 테스트 추가 (RED)
- `39cf6f8` — [task-361.1] get_random_theme() 히스토리 기반 연속 중복 방지 구현 (GREEN)
- `5cd4930` — [task-361.1] run_full_pipeline.py NavyGold 고정 제거 → get_random_theme() 사용

## Worktree

- 브랜치: `task/task-361.1-dev1`
- 경로: `/home/jay/projects/ThreadAuto/.worktrees/task-361.1-dev1`

## 버그/이슈
- 없음 (기존 test_evergreen_topics.py 실패는 본 작업과 무관)
