# task-2038: InsuRo PL-1~7 재구현 (유실 코드 복구)

## 배경
task-2026에서 PL-1~7(콘텐츠 팩토리 파이프라인 고도화) 코드가 worktree에서 구현되었으나,
커밋/푸시 없이 worktree가 삭제되어 코드가 유실됨 (task-2034에서 확인).
task-2026 보고서를 참조하여 동일 범위를 재구현해야 함.

## ★ 반드시 먼저 읽을 파일
- `/home/jay/workspace/memory/reports/task-2026.md` — 원래 구현 내역 상세
- `/home/jay/workspace/memory/plans/insuro-system/checklist.md` L494~525 — PL-1~7 항목 정의

## ★ 프로젝트: `/home/jay/projects/InsuRo/` (main 브랜치에서 worktree 생성)

## PL-1~7 구현 범위

### PL-1: Pydantic 스키마 계약 정의
- `server/schemas/pipeline.py` 생성
- PipelineRun, PipelineStage, PipelineResult 모델
- schema_version 필드 포함
- 상태 전이: PENDING → RUNNING → SUCCESS/FAILED

### PL-2: pipeline_runs 테이블 + 상태 머신
- `server/models/pipeline.py` 또는 Supabase migration
- _transition_status() 메서드로 상태 전이 검증
- 유효하지 않은 전이 시 예외 발생

### PL-3: Celery/ARQ 비동기 작업 큐
- 현재 InsuRo는 Celery 미사용이므로 **asyncio 기반 큐 구현** (경량)
- retry_pipeline(), requeue_failed_stage() 함수
- 최대 3회 재시도, 지수 백오프

### PL-4: 부분 롤백 전략
- 특정 stage 실패 시 해당 stage만 재실행 가능
- 전체 파이프라인 롤백은 마지막 성공 checkpoint로

### PL-5: AutomationStepper 4단계 확장
- `src/components/AutomationStepper.tsx` 수정
- 기존 3단계 → 4단계 (D→B→A→Publish)
- MAX_POLL_INTERVAL 도입 (지수 백오프)

### PL-6: 로그 마스킹
- `_mask_pii()` 함수: 파이프라인 로그에서 PII 마스킹
- 이메일, 전화번호, 이름 패턴 → "***" 치환

### PL-7: E2E 4축 실패 시나리오 테스트
- `server/tests/test_pipeline_failures.py` 생성
- 4축: 네트워크 타임아웃, 인증 만료, 스키마 불일치, 외부 API 에러
- 각 축별 최소 2개 테스트 케이스 = 8건+

## 완료 시그니처
- [grep] `schema_version\|PipelineRun` @ `server/`
- [grep] `_transition_status\|retry_pipeline\|requeue_failed_stage` @ `server/`
- [grep] `MAX_POLL_INTERVAL\|_mask_pii` @ `server/ src/`
- [grep] `TestPipelineFailure\|test_pipeline_failure` @ `server/tests/`

## 검증 시나리오
1. `npm run build` → 빌드 성공
2. `cd server && python -m pytest tests/test_pipeline*.py -v` → 전 테스트 PASS
3. `grep -rn "schema_version" server/` → 1건+
4. `grep -rn "MAX_POLL_INTERVAL" src/` → 1건+
5. `python -m pytest tests/ -x --tb=short` → 전체 테스트 suite 회귀 없음

## 레벨
- normal

## 프로젝트
- insuro