# -*- coding: utf-8 -*-
import json, io, os
import _remerge
ROOT=r"D:\01.프로젝트\DB수집"
d=json.load(io.open(os.path.join(ROOT,"작업파일","_targets.json"),encoding="utf-8"))
gg2=[x for x in d["work"] if "공공기관2" in x]
today=[x for x in d["sub"] if "_제출패키지_2026-06-21" in x]
out=io.open(os.path.join(ROOT,"작업파일","_verify_scope_out.txt"),"w",encoding="utf-8")
def run(title, files, apply):
    out.write("\n===== %s (%d개) =====\n"%(title,len(files)))
    pend=0; applied=0
    for rel in files:
        p=os.path.join(ROOT,rel)
        base=os.path.basename(p)
        r=_remerge.process(p, apply=False, height=False)  # dry first
        nc=r.get("n_change",0)
        if nc>0:
            pend+=1
            out.write("  [미병합잔여] %s  추가=%d add=%s\n"%(base,nc,r.get("add")))
            if apply:
                r2=_remerge.process(p, apply=True, height=False)
                out.write("     -> 적용 ok=%s 변경=%s 검증fail=%s\n"%(r2.get("ok"),r2.get("n_change"),r2.get("fails")))
                if r2.get("ok"): applied+=1
        else:
            out.write("  [정상] %s (병합완료, 추가0)\n"%base)
    out.write("  >> %s: 미병합잔여 %d개, 적용 %d개\n"%(title,pend,applied))
    return pend,applied
p1,a1=run("공공기관2 작업본", gg2, apply=True)
p2,a2=run("오늘(2026-06-21) 제출폴더", today, apply=True)
out.close()
print("공공기관2: 잔여%d 적용%d | 오늘제출: 잔여%d 적용%d"%(p1,a1,p2,a2))
