#!/usr/bin/env python3 import os, re, json, hashlib, sys WORK=os.path.dirname(os.path.abspath(__file__)); ROOT=os.path.dirname(os.path.dirname(WORK)) DRAFT=os.path.join(WORK,'청구취지작성규칙_공유물분할청구_beta_0.8.draft.md') SRC=os.path.join(ROOT,'사건종류_공유물분할청구','청구취지작성규칙_공유물분할청구_v2.md') doc=open(DRAFT,encoding='utf-8').read(); src=open(SRC,encoding='utf-8').read() fails=[] def chk(cond,msg): print(('PASS ' if cond else 'FAIL ')+msg) if not cond: fails.append(msg) # 0. input hashes unchanged snap=json.load(open(os.path.join(WORK,'identity_ledger.json'),encoding='utf-8'))['snapshot'] for k,v in snap.items(): h=hashlib.sha256(open(v['path'],'rb').read()).hexdigest() chk(h==v['sha256'], f'input unchanged: {k}') # 1. title & identity chk(doc.split('\n')[0]=='# 공유물분할 청구 — 청구취지 작성 규칙','title exact') chk('| 사건종류 | 공유물분할 청구 |' in doc and '| 사건키 | 공유물분할청구 |' in doc,'metadata identity') meta=re.search(r'### 0\.1 메타데이터\n\n((?:\|.*\n)+)',doc).group(1).strip().split('\n') fields=[r.split('|')[1].strip() for r in meta[2:]] chk(fields==['사건종류','사건키','적용범위','적용제외'], f'metadata fields exactly four: {fields}') # 2. template residue chk(not re.search(r'(? ')>=2, f'FORM-SHP-0{n} has 주문 block') # 8. five states, statuses, URL prohibition for s in ['작성 진행','재검토를 붙여 진행','해당 부분 보완 대기','다른 구성·절차로 전환','해당 구성 중단']: chk(f'| {s} |' in doc, f'state defined: {s}') chk('작성됨 / 부분 작성 / 보완 대기 / 전환 / 해당 구성 중단' in doc,'writing statuses') chk('문구 검사 미완료 / 문구 검사 완료 / 법률·사실 쟁점 재검토 필요 / 변호사 제출 전 검토 완료' in doc,'review statuses') chk('### A.3 URL 직접 접근·조회·우회 수집 금지' in doc,'URL prohibition section') # 9. forbidden phrase ph='이하 '+'동일' chk(ph not in doc,'no abbreviation phrase') # 10. 주문 문장 verbatim from source src_orders=[l for l in src.split('\n') if l.startswith('> ')] mo=[l for l in src_orders if l not in doc] chk(not mo, f'all {len(src_orders)} 주문 lines verbatim: missing {mo}') # 11. STOP state names consistent across §1.2/§2.3/§7.2 (spot: each STOP code in §7.2 table has state) sec72=re.search(r'### 7\.2.*?### 7\.3',doc,re.S).group(0) for code in re.findall(r'STOP-SHP-[A-Z]+-\d\d',src): chk(code in sec72, f'{code} in §7.2') print('\nTOTAL FAILS:',len(fails)) sys.exit(1 if fails else 0)