"""Confirmation scope test (2026-10-13): run settings (scope / builders / checkers / negative) need confirmation, reference-only sections are shown as "확정 불필요(참고)". No Rhino. Uses its own data root 검증/confirm_test_data (recreated) with piers made from the two protected templates.""" import os import shutil import sys from pathlib import Path APP = Path(__file__).resolve().parents[1] TD = APP / "검증" / "confirm_test_data" if TD.exists(): shutil.rmtree(TD) shutil.copytree(APP / "data" / "_템플릿", TD / "_템플릿", ignore=shutil.ignore_patterns("_이전")) os.environ["PIERAPP_DATA"] = str(TD) sys.path.insert(0, str(APP / "web")) import app as webapp # noqa: E402 sys.path.insert(0, str(Path(__file__).resolve().parent)) from testlib import confirm_required # noqa: E402 import store # noqa: E402 ok = True RUN = {("params", "scope"), ("params", "builders"), ("expected", "checkers"), ("expected", "negative")} def check(name, cond, detail=""): global ok ok &= bool(cond) print("PASS" if cond else "FAIL", name, str(detail)[:200], flush=True) c = webapp.app.test_client() for nm, tpl in (("울산", "산외교울산P1형"), ("운곡", "운곡교P1형")): c.post("/pier/new", data={"name": nm, "type": "T형", "template": "tpl:" + tpl}) u, w = store.Pier("울산"), store.Pier("운곡") need_u = set(webapp.unconfirmed(u)) check("Ulsan: run settings required", RUN <= need_u, sorted(RUN - need_u)) check("Ulsan: run settings required by every gate in scope", all(RUN <= {(r["file"], r["key"]) for r in u.gate_requirements(g)} for g in u.scope())) need_w = set(webapp.unconfirmed(w)) check("Ungok: absent run settings not required", not (RUN & need_w), sorted(RUN & need_w)) info = {(s["file"], s["key"]) for s in u.sections() if store.is_info(s["key"])} check("reference sections not required", info and not (info & need_u), sorted(info & need_u)) check("reference keys", {k for _, k in info} == {"_schema", "_meta", "_note", "rebar_marks_src"}, sorted(info)) b = webapp.gate_blockers(u, "G1") check("G1 blocked while run settings unconfirmed", "params.builders 미확정" in b and "expected.checkers 미확정" in b, b) confirm_required(c, webapp, store, "울산", "시험") check("confirming every required bundle clears all required", webapp.unconfirmed(u) == [], webapp.unconfirmed(u)) check("G1 not blocked after confirming every required bundle", webapp.gate_blockers(u, "G1") == [], webapp.gate_blockers(u, "G1")) left = [s["key"] for s in u.sections() if not u.section_state(s["file"], s["key"])["confirmed"]] check("only reference sections left unconfirmed", set(left) == {k for _, k in info}, left) h = c.get("/pier/울산").get_data(as_text=True) check("pier page shows reference label", h.count("확정 불필요(참고)") == len(info), h.count("확정 불필요(참고)")) check("pier page shows no plain 미확정 row", '미확정' not in h) h = c.get("/pier/울산/section/params/_meta").get_data(as_text=True) check("section page shows reference label", "확정 불필요(참고)" in h) X = u.load("expected") X["negative"]["G1"][0]["d"] = [4, 0, 0] u.save("expected", X) check("edited run setting needs re-confirm", ("expected", "negative") in webapp.unconfirmed(u) and u.section_state("expected", "negative")["stale"]) shutil.rmtree(TD) print("RESULT", "PASS" if ok else "FAIL") sys.exit(0 if ok else 1)