import sqlite3, time

db_path = '/home/jooyoung/.openclaw/workspace-260312/orchestration/data/battle.db'
conn = sqlite3.connect(db_path)
cursor = conn.cursor()

seed_data = [
    {
        "source": "subagent", "error_type": "comm_protocol", 
        "error_message": "postMessage 기반 결과 수집 실패", 
        "error_context": "iframe context 의존으로 Playwright에서 불가", 
        "resolution": "BE 매개 통신(REST API)으로 해결", 
        "resolution_type": "approach_change"
    },
    {
        "source": "subagent", "error_type": "stat_injection_missing", 
        "error_message": "스탯 주입 코드를 파싱만 하고 게임 객체에 미주입", 
        "error_context": "2회 반복됨", 
        "resolution": "명시적으로 게임 객체 주입 지시 (코드 픽스)", 
        "resolution_type": "code_fix"
    },
    {
        "source": "subagent", "error_type": "model_limitation", 
        "error_message": "대용량 코드 복사 시 간소화 재구현 경향", 
        "error_context": "Sonnet 사용 시 발생 (토큰 제약)", 
        "resolution": "Opus 모델로 전환하여 정밀 추출 성공", 
        "resolution_type": "model_switch"
    },
    {
        "source": "subagent", "error_type": "architecture_violation", 
        "error_message": "전투 코드를 adapters/에 복사 방식 3회 실패", 
        "error_context": "원본과 분기 발생", 
        "resolution": "복사 금지, SSOT 참조(iframe canonical 경로) 방식으로 전환", 
        "resolution_type": "approach_change"
    },
    {
        "source": "e2e", "error_type": "env_constraint", 
        "error_message": "networkidle 타임아웃 위험", 
        "error_context": "RAM 3.8GB 환경에서 발생", 
        "resolution": "domcontentloaded + waitForTimeout 조합으로 변경", 
        "resolution_type": "code_fix"
    },
    {
        "source": "subagent", "error_type": "env_constraint", 
        "error_message": "playwright-core 바이너리 못 찾음", 
        "error_context": "playwright-core import 시도", 
        "resolution": "playwright 패키지로 import 변경", 
        "resolution_type": "code_fix"
    },
    {
        "source": "server", "error_type": "case_mapping", 
        "error_message": "chaptersCompleted 등 업데이트 미반영", 
        "error_context": "API는 camelCase, DB 함수는 snake_case 기대", 
        "resolution": "db.py에 camelCase -> snake_case 매핑 dict 추가", 
        "resolution_type": "code_fix"
    },
    {
        "source": "server", "error_type": "field_parsing", 
        "error_message": "EXP 계산 시 enemyLevel 1로 들어감", 
        "error_context": "body.enemyLevel 최상위 필드를 읽지 않고 enemyStats.level만 참조", 
        "resolution": "battle_data.get('enemyLevel', 1) fallback 추가", 
        "resolution_type": "code_fix"
    },
    {
        "source": "subagent", "error_type": "test_integrity", 
        "error_message": "E2E 패배 시 난이도 하향 / autoWin 삽입 우회 시도", 
        "error_context": "LLM의 가장 위험한 경향", 
        "resolution": "발주 프롬프트에 게임 룰/난이도/HP 조작 절대 금지 명시", 
        "resolution_type": "prompt_constraint"
    }
]

now = time.time()
for d in seed_data:
    cursor.execute('''
        INSERT INTO error_cases (
            source, error_type, error_message, error_context,
            resolution, resolution_type, resolved, created_at, resolved_at
        ) VALUES (?, ?, ?, ?, ?, ?, 1, ?, ?)
    ''', (
        d["source"], d["error_type"], d["error_message"], d["error_context"],
        d["resolution"], d["resolution_type"], now, now
    ))

conn.commit()
print(f"Seeded {len(seed_data)} errors.")
conn.close()
