# task-76.1 완료 보고서: InsuWiki Phase 2 운영 안정성 패치

## 팀: dev1-team (헤르메스 팀장)
## 작업일: 2026-03-02

---

## 작업 요약

InsuWiki 프로젝트의 운영 안정성을 위한 5개 패치 작업 완료.

## 서브태스크 상세

### H-1. Firestore 복합 인덱스 추가 (불칸 담당)
- 파일: `/home/jay/projects/insuwiki/firestore.indexes.json`
- 기존 3개 인덱스 유지, 6개 복합 인덱스 + 1개 필드 오버라이드 추가
- 추가된 인덱스:
  - documents: editingBy + editingAt (cleanupLocks 쿼리)
  - documents: isDeleted + authorId (휴지통 사용자 뷰)
  - documents: isDeleted + deletedAt DESC (휴지통 관리자 뷰)
  - insurance_metadata: companyId + productId (RAG 쿼리)
  - gemini_file_cache: driveFileId + expireAt (캐시 조회)
  - insurance_chunks: sourceType + companyId + productId (YouTube 크롤링)
  - query_logs.createdAt DESC 필드 오버라이드 (모니터링 페이지)

### H-2. 누락 컬렉션 Firestore 규칙 추가 (불칸 담당)
- 파일: `/home/jay/projects/insuwiki/firestore.rules`
- 기존 11개 컬렉션 규칙 100% 보존 (task-71.1 isAdmin 규칙 포함)
- 12개 신규 규칙 추가:
  - users/{userId}/savedLinks: 소유자 접근
  - documents/{docId}/embeddings: 클라이언트 차단 (Admin SDK 전용)
  - insurance_chunks/insurance_terms/insurance_tables: 클라이언트 차단
  - query_logs: 관리자 읽기, 쓰기 차단
  - youtube_channels/youtube_knowledge: 클라이언트 차단 (Cloud Functions 전용)
  - whitelist: 인증 사용자 읽기, 관리자 쓰기
  - apiKeys: 관리자 전용
  - conversation_sessions: 소유자 접근
  - drafts: 소유자 접근

### H-3. CI/CD 파이프라인 구축 (헤르메스 직접)
- 파일: `/home/jay/projects/insuwiki/.github/workflows/pr-check.yml` (신규)
- PR 검증 워크플로우: tsc --noEmit → ESLint → next build
- 기존 firestore-backup.yml 유지

### H-4. 프로덕션 console.log 제거 (이리스 담당)
- 대상: nextapp/src/ 하위 6개 파일에서 24건 제거
- 제거 후 잔여 console.log: 0건 확인
- console.error, console.warn 모두 유지
- 수정 파일:
  - DocumentClient.tsx: 15건 제거
  - firebase.ts: 2건 제거
  - ReflectEditor.tsx: 2건 제거
  - useWikiMap.ts: 1건 제거
  - ServiceWorkerRegistrar.tsx: 1건 제거
  - admin/purge/route.ts: 1건 제거

### H-5. node_modules 및 불필요 파일 git 추적 제거 (헤르메스 직접)
- .gitignore에 추가: functions/node_modules/, chrome_profile_notebooklm/, firestore-debug.log
- git rm --cached 실행:
  - functions/node_modules/: 12,234개 파일 추적 해제
  - chrome_profile_notebooklm/: 128개 파일 추적 해제
  - firestore-debug.log: 1개 파일 추적 해제
- 중복 항목(.vercel, .env*.local) 정리

## 생성/수정 파일 목록

| 파일 | 변경 | 비고 |
|------|------|------|
| firestore.indexes.json | 수정 | 6개 인덱스 + 1 오버라이드 추가 |
| firestore.rules | 수정 | 12개 컬렉션 규칙 추가 |
| .github/workflows/pr-check.yml | 신규 | CI/CD PR 검증 |
| .gitignore | 수정 | 3개 항목 추가 |
| nextapp/src/app/docs/[id]/DocumentClient.tsx | 수정 | 15건 console.log 제거 |
| nextapp/src/lib/firebase.ts | 수정 | 2건 console.log 제거 |
| nextapp/src/components/ReflectEditor.tsx | 수정 | 2건 console.log 제거 |
| nextapp/src/hooks/useWikiMap.ts | 수정 | 1건 console.log 제거 |
| nextapp/src/components/ServiceWorkerRegistrar.tsx | 수정 | 1건 console.log 제거 |
| nextapp/src/app/api/admin/purge/route.ts | 수정 | 1건 console.log 제거 |

## 테스트 결과

- npm run build: 성공 (모든 페이지 빌드 통과)
- console.log 잔여 검사: 0건 (nextapp/src/ 전체)
- JSON 유효성: firestore.indexes.json 파싱 성공

## 버그 유무

없음

## 비고

- git commit은 수행하지 않음 (아누 검토 후 통합 커밋 예정)
- Phase 1(task-70.1, task-71.1) 변경사항 모두 보존됨
- firestore deploy 시 자동으로 새 인덱스 생성됨 (시간 소요 가능)
