@chrono-meta/fh-gate 3.13.0 → 3.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -627,12 +627,277 @@ else
627
627
  fi
628
628
 
629
629
  echo "[psa single-file lanes] pass=$pass fail=$fail"
630
+ # ── B 레인 : 비텍스트 입력은 «깨끗함»이 아니라 UNSCANNABLE(3) (2026-09-19) ─────────────
631
+ # 🟥 이 레인들이 막는 것: 줄 단위 스캔이 PDF/docx/이미지의 텍스트를 **원리적으로 못 읽는데**
632
+ # rc=0 CLEAN 을 내던 결함. 실측(추가 당일, 이 게이트가 지키는 바로 그 표면에서):
633
+ # paper/forge_harness_v1.0.2.pdf PyMuPDF <operator-token>=1 <org-token>=1 · psa_scan rc=0 CLEAN
634
+ # 포장이 판정을 뒤집었다. 내용이 아니라.
635
+ _bdir=$(mktemp -d); trap 'rm -rf "$_bdir"' EXIT
636
+
637
+ # 🟥 PDF 추출은 «선택 의존»(pymupdf)이고 **CI 에는 없다**(`validate.yml` 은 pyyaml 만 깐다).
638
+ # 그때 추출기는 exit 3 으로 떨어지고 스캐너는 UNSCANNABLE 을 낸다 — **그게 옳은 동작**이다.
639
+ # 게이트는 선택 의존 없이도 서야 하고, 없을 때의 답은 «깨끗함»이 아니라 «못 읽겠다»다.
640
+ # ⇒ PDF 축 레인은 능력에 따라 **기대값이 갈린다**. 🟥 스킵이 아니다 — 없으면 «fail-closed 로
641
+ # 떨어지는가»를 대신 단언한다. 그 방향이 이 변경의 본체라 오히려 더 중요한 팔이다.
642
+ # (이 조건부는 CI 가 B1·B1b·B6·X1 을 `want=1 got=3` 으로 떨어뜨려서 생겼다 — 코드가 아니라
643
+ # 레인이 로컬 환경을 과도하게 고정하고 있었다.)
644
+ if python3 -c 'import pymupdf' 2>/dev/null || python3 -c 'import fitz' 2>/dev/null; then
645
+ _PDFCAP=1; printf ' PDF 추출 가능(pymupdf) — PDF 축은 «추출해서 잡는가»로 잰다\n'
646
+ else
647
+ _PDFCAP=0; printf ' PDF 추출 불가(pymupdf 없음) — PDF 축은 «fail-closed 로 떨어지는가»로 잰다\n'
648
+ fi
649
+
650
+ # 🟥 픽스처는 «머릿속 PDF» 가 아니라 **실제 PDF 바이트**여야 한다. python3+zlib 로 최소 PDF 를
651
+ # 짓되, 토큰은 **비압축 평문 스트림**에 둔다 — 그래야 「스캐너가 읽을 수 있었는데도 안 읽었다」
652
+ # 가 아니라 「읽을 수 없는 포장」이라는 이 레인의 논지가 선다(압축이면 자명해서 시험이 약해진다).
653
+ python3 - "$_bdir" <<'_PYB'
654
+ import sys, os
655
+ d = sys.argv[1]
656
+ body = b"BT /F1 12 Tf 72 720 Td (contact PSABINCANARY here) Tj ET"
657
+ # 🟥 b"%PDF" 에 `%` 포맷을 쓰지 마라 — 파이썬이 `%P` 를 지시자로 읽고 죽는다. 첫 시도가 그렇게
658
+ # 죽었고, 파일이 안 생겨 스캐너가 MISSING(3)을 냈는데 rc 만 보면 «통과»로 읽혔다.
659
+ # (레인이 초록인 두 번째 이유 = 입력이 코드에 안 닿음. 문자열 단언이 그걸 잡았다.)
660
+ pdf = (b"%PDF-1.4\n"
661
+ b"1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj\n"
662
+ b"2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj\n"
663
+ b"3 0 obj<</Type/Page/Parent 2 0 R/MediaBox[0 0 612 792]/Contents 4 0 R>>endobj\n"
664
+ b"4 0 obj<</Length " + str(len(body)).encode() + b">>stream\n"
665
+ + body +
666
+ b"\nendstream endobj\n"
667
+ b"\x00\x00trailer<</Root 1 0 R>>\n%%EOF\n") # NUL: 실물 PDF 가 압축 스트림에서 늘 갖는 것
668
+ open(os.path.join(d, "tok.pdf"), "wb").write(pdf)
669
+ open(os.path.join(d, "tok.txt"), "w").write("contact PSABINCANARY here\n")
670
+ open(os.path.join(d, "clean.bin"), "wb").write(b"\x00\x01\x02 nothing interesting here\n")
671
+ # 🟥 픽스처가 실제로 생겼고 실제로 NUL 을 갖는지 «여기서» 확인한다 — 안 하면 파일 부재가
672
+ # UNSCANNABLE 과 같은 rc=3 으로 읽힌다(둘은 다른 사건이다).
673
+ for n, want_nul in (("tok.pdf", True), ("tok.txt", False), ("clean.bin", True)):
674
+ p = os.path.join(d, n)
675
+ assert os.path.exists(p), "FIXTURE MISSING: " + n
676
+ has = b"\x00" in open(p, "rb").read()
677
+ assert has == want_nul, "FIXTURE SHAPE WRONG: %s nul=%s" % (n, has)
678
+ _PYB
679
+
680
+ # 🟥 패턴은 psa_load 대신 **직접 주입**한다 — 이 레인은 «비텍스트를 어떻게 판정하나» 를 재지
681
+ # «운영자 오버라이드 파일이 거기 있나» 를 재는 게 아니다. 후자에 의존하면 레인이 환경을 잰다.
682
+ _run_b() { ( . "$LIB"; export PSA_STREAM=$(printf 'HIGH\tPSABINCANARY') PSA_ALLOWLIST=/dev/null \
683
+ PSA_DEFAULTS_OK=1 PSA_BAD_ROWS=0 PSA_OVERRIDE_PRESENT=1; psa_scan_file "$1" 2>&1 ); }
684
+
685
+ _o=$(_run_b "$_bdir/tok.pdf"); _r=$?
686
+ # 🟥 추출기가 붙은 뒤로 이 픽스처의 기대값은 3 이 아니라 **1** 이다 — «못 읽겠다» 에서 «읽어서
687
+ # 잡았다» 로 올라간 것이고, 그게 이 변경의 요점이다. 3 은 이제 «추출도 실패» 일 때만 나온다.
688
+ if [ "$_PDFCAP" = "1" ]; then
689
+ check "B1 🟥 토큰을 품은 PDF → 추출해서 HIT(1). CLEAN(0) 은 절대 아님" 1 "$_r" "PSABINCANARY" "$_o"
690
+ else
691
+ check "B1 🟥 추출기 없음 → UNSCANNABLE(3). 🟥 CLEAN(0) 만은 절대 아님" 3 "$_r" "UNSCANNABLE" "$_o"
692
+ fi
693
+ # 🟥 B1b 는 fail-before 가 만들어낸 레인이다. 첫 판은 스캔 «전에» return 3 을 했는데, 그러면
694
+ # 옛 스캐너가 실제로 잡던 히트(비압축 스트림 PDF)가 사라졌다 — 미탐을 고치다 다른 미탐을
695
+ # 만든 것이다. 이 파일의 `_incomplete` 주석이 이미 그 교리를 적고 있었다:
696
+ # "'I could not certify this' and 'I saw nothing' are different."
697
+ if [ "$_PDFCAP" = "1" ]; then
698
+ check "B1b 🟥 «추출했다»를 말하고 스캔한다 (원바이트가 아니라 추출 텍스트)" 1 "$_r" "EXTRACTED" "$_o"
699
+ else
700
+ printf ' ⏭ B1b — pymupdf 없음, 추출 경로 자체가 없다 (skip != pass; B1 이 fail-closed 를 잰다)\\n'
701
+ fi
702
+
703
+ _o=$(_run_b "$_bdir/tok.txt"); _r=$?
704
+ check "B2 같은 토큰의 .txt → HIT(1) (기존 동작 무변경)" 1 "$_r" "PSABINCANARY" "$_o"
705
+
706
+ _o=$(_run_b "$_bdir/clean.bin"); _r=$?
707
+ check "B3 추출 불가 바이너리 → UNSCANNABLE(3) — «못 읽음»을 «깨끗함»으로 안 바꾼다" 3 "$_r" "UNSCANNABLE" "$_o"
708
+
709
+ # 🟥 컨트롤 — 이게 없으면 B1·B3 의 3 이 «모든 것이 3» 인지 구별이 안 된다
710
+ printf 'ordinary text, no tokens\n' > "$_bdir/plain.txt"
711
+ _o=$(_run_b "$_bdir/plain.txt"); _r=$?
712
+ check "B4 CONTROL — 평범한 텍스트는 여전히 CLEAN(0) (3이 아무 데나 안 뜬다)" 0 "$_r" "" "$_o"
713
+
714
+ # 🟥 B6/B7 은 cross-family(codex) 가 «NUL 만으로는 안 된다» 를 실행으로 보여서 생긴 레인이다.
715
+ # B6 = 그 반례 그대로: NUL 이 «하나도 없는» 유효 PDF 인데 텍스트가 hex string 안에 있다.
716
+ # B7 = 그 수리(mime 축)가 과차단하지 않는가 — 이게 없으면 «전부 3» 이 통과로 보인다.
717
+ python3 - "$_bdir" <<'_PYC'
718
+ import sys, os
719
+ d = sys.argv[1]
720
+
721
+ # 🟥 «깨지면 안 되는 것부터» 만든다. 초판은 assert 를 앞에 뒀고, 그게 걸리자 뒤의 픽스처 둘이
722
+ # 통째로 안 생겨서 B7/B9 가 «코드 결함처럼 보이는 MISSING(3)» 을 냈다. 한 픽스처의 실패가
723
+ # 다른 레인을 죽이면 그 레인들은 더는 자기가 재려던 것을 안 잰다.
724
+ open(os.path.join(d, "ok.json"), "w").write('{"note":"line-scannable, must stay CLEAN"}\n')
725
+ _broken_body = b"BT (contact PSABINCANARY here) Tj ET"
726
+ open(os.path.join(d, "broken.pdf"), "wb").write(
727
+ b"%PDF-1.4\n4 0 obj<</Length " + str(len(_broken_body)).encode() + b">>stream\n"
728
+ + _broken_body + b"\nendstream endobj\ntrailer\n%%EOF\n")
729
+
730
+ # 🟥 NUL 이 «없는» PDF 를 손으로 조립한다. PyMuPDF 로 저장하면 같은 입력에도 NUL 유무가
731
+ # 갈린다(실측: 822B NUL 없음 / 844B NUL 있음). 그 비결정성을 타면 이 레인이 어떤 축을
732
+ # 시험하는지가 실행마다 바뀐다 — mime 축을 재려 했는데 NUL 축이 먼저 걸리는 식으로.
733
+ # 아래는 xref 까지 갖춘 유효 PDF 이고 전부 ASCII 이며 본문 스트림도 비압축이다.
734
+ def _mini_pdf(tok):
735
+ objs = [
736
+ b"<</Type/Catalog/Pages 2 0 R>>",
737
+ b"<</Type/Pages/Kids[3 0 R]/Count 1>>",
738
+ b"<</Type/Page/Parent 2 0 R/MediaBox[0 0 612 792]"
739
+ b"/Resources<</Font<</F1 5 0 R>>>>/Contents 4 0 R>>",
740
+ ]
741
+ body = b"BT /F1 12 Tf 72 720 Td (" + tok + b") Tj ET"
742
+ objs.append(b"<</Length " + str(len(body)).encode() + b">>stream\n" + body + b"\nendstream")
743
+ objs.append(b"<</Type/Font/Subtype/Type1/BaseFont/Helvetica>>")
744
+ out = bytearray(b"%PDF-1.4\n"); offs = []
745
+ for i, o in enumerate(objs, 1):
746
+ offs.append(len(out)); out += str(i).encode() + b" 0 obj" + o + b"endobj\n"
747
+ x = len(out)
748
+ out += b"xref\n0 " + str(len(objs) + 1).encode() + b"\n0000000000 65535 f \n"
749
+ for o in offs:
750
+ out += ("%010d 00000 n \n" % o).encode()
751
+ out += (b"trailer<</Size " + str(len(objs) + 1).encode() + b"/Root 1 0 R>>\nstartxref\n"
752
+ + str(x).encode() + b"\n%%EOF\n")
753
+ return bytes(out)
754
+
755
+ _ascii = _mini_pdf(b"contact PSABINCANARY here")
756
+ assert b"\x00" not in _ascii, "FIXTURE WRONG: NUL 이 있으면 mime 축이 아니라 NUL 축을 재게 된다"
757
+ open(os.path.join(d, "ascii.pdf"), "wb").write(_ascii)
758
+ _PYC
759
+
760
+ _o=$(_run_b "$_bdir/broken.pdf"); _r=$?
761
+ check "B9 🟥 컨테이너를 열었는데 0자 → UNSCANNABLE(3). «빈 추출»은 CLEAN 이 아니다" 3 "$_r" "UNSCANNABLE" "$_o"
762
+
763
+ _o=$(_run_b "$_bdir/ascii.pdf"); _r=$?
764
+ # codex 반례: NUL 이 없어 1축은 못 잡고, mime 축이 잡아 추출로 넘긴다. hex string 은 PyMuPDF 가
765
+ # 디코드하므로 최종 판정은 HIT — 「포장으로 숨긴다」가 닫혔다는 뜻이다.
766
+ if [ "$_PDFCAP" = "1" ]; then
767
+ check "B6 🟥 NUL 없는 ASCII-only PDF(토큰이 hex) → 추출해서 HIT(1) — codex 반례 닫힘" 1 "$_r" "PSABINCANARY" "$_o"
768
+ else
769
+ check "B6 🟥 추출기 없어도 codex 반례는 CLEAN 으로 안 샌다 → UNSCANNABLE(3)" 3 "$_r" "UNSCANNABLE" "$_o"
770
+ fi
771
+
772
+ _o=$(_run_b "$_bdir/ok.json"); _r=$?
773
+ check "B7 CONTROL — application/json 은 여전히 CLEAN(0) (mime 축이 과차단 안 한다)" 0 "$_r" "" "$_o"
774
+
775
+ # 🟥 B8 — 과차단 컨트롤. 출하 집합(482파일)에 `.pptx` 2건이 실린다. 단순 «컨테이너는 거절» 이면
776
+ # **매 릴리스가 막히고**, 그게 override 를 훈련시켜 게이트를 무장해제한다. 추출이 그걸 막는다.
777
+ _pptx="$REPO_ROOT/plugins/fh-preprep/skills/preprep/fixtures/fixture_R3_positive.pptx"
778
+ if [ -f "$_pptx" ]; then
779
+ _o=$(_run_b "$_pptx"); _r=$?
780
+ check "B8 CONTROL — 출하 .pptx 는 추출해서 CLEAN(0) (컨테이너를 통째로 막지 않는다)" 0 "$_r" "" "$_o"
781
+ _cond_lanes=$((_cond_lanes+1))
782
+ else
783
+ printf ' ⏭ B8 skipped — 출하 pptx 픽스처 부재 (skip != pass)\n'
784
+ fi
785
+
786
+ # 실물 — 이 레포가 실제로 예치하는 파일
787
+ if [ -f "$REPO_ROOT/paper/forge_harness_v1.0.2.pdf" ]; then
788
+ _o=$(_run_b "$REPO_ROOT/paper/forge_harness_v1.0.2.pdf"); _r=$?
789
+ # 🟥 이 레인은 «특정 사설 토큰이 잡히나» 가 아니라 «**기전이 걸리나**» 를 잰다. 토큰을 단언하면
790
+ # 그 토큰을 이 파일에 적어야 하고, 이 파일은 npm 출하 집합이다 — 레인이 자기가 막으려는
791
+ # 유출을 만들게 된다. (실제로 초판이 그랬고, 발행 게이트가 그걸 잡았다.)
792
+ # 기전 = 「원바이트가 아니라 추출 텍스트를 스캔했다」이고, 그것이 EXTRACTED 줄이다.
793
+ if [ "$_PDFCAP" = "1" ]; then
794
+ check "B5 🟥 실물 예치 PDF → 추출 경로를 탄다 (원바이트 스캔이 아니다)" 0 "$_r" "EXTRACTED" "$_o"
795
+ else
796
+ check "B5 🟥 실물 예치 PDF → 추출기 없으면 UNSCANNABLE(3), 종전의 거짓 CLEAN 아님" 3 "$_r" "UNSCANNABLE" "$_o"
797
+ fi
798
+ _cond_lanes=$((_cond_lanes+1))
799
+ else
800
+ printf ' ⏭ B5 skipped — paper/forge_harness_v1.0.2.pdf 부재 (skip != pass)\n'
801
+ fi
802
+
803
+
804
+ # ── X 레인 : psa_extract_text.py 를 «직접» 실행한다 (2026-09-19) ───────────────────────
805
+ # 🟥 왜 별도인가: B 레인은 이 추출기를 `psa_scan_file` 을 통해 **간접**으로만 태웠고,
806
+ # new-code-anchor 게이트가 그것을 잡았다 — *"a lane NAMES the file without running it …
807
+ # adding another mention does not clear it."* 추출기는 자기 계약(0 텍스트 · 2 사용법/부재 ·
808
+ # 3 추출불가)을 가지므로 그 계약을 **직접** 재는 레인이 있어야 한다.
809
+ _X="$REPO_ROOT/scripts/psa_extract_text.py"
810
+ if [ -f "$_X" ] && command -v python3 >/dev/null 2>&1; then
811
+ _xd=$(mktemp -d)
812
+ python3 - "$_xd" <<'_PYX'
813
+ import sys, os
814
+ d = sys.argv[1]
815
+ # 🟥 결정적 픽스처 — PyMuPDF 저장은 같은 입력에도 NUL 유무가 갈린다(실측 822B/844B).
816
+ # xref 까지 갖춘 유효 PDF 를 손으로 조립하면 그 비결정성을 안 탄다.
817
+ def _mini_pdf(tok):
818
+ objs = [b"<</Type/Catalog/Pages 2 0 R>>",
819
+ b"<</Type/Pages/Kids[3 0 R]/Count 1>>",
820
+ b"<</Type/Page/Parent 2 0 R/MediaBox[0 0 612 792]"
821
+ b"/Resources<</Font<</F1 5 0 R>>>>/Contents 4 0 R>>"]
822
+ body = b"BT /F1 12 Tf 72 720 Td (" + tok + b") Tj ET"
823
+ objs.append(b"<</Length " + str(len(body)).encode() + b">>stream\n" + body + b"\nendstream")
824
+ objs.append(b"<</Type/Font/Subtype/Type1/BaseFont/Helvetica>>")
825
+ out = bytearray(b"%PDF-1.4\n"); offs = []
826
+ for i, o in enumerate(objs, 1):
827
+ offs.append(len(out)); out += str(i).encode() + b" 0 obj" + o + b"endobj\n"
828
+ x = len(out)
829
+ out += b"xref\n0 " + str(len(objs) + 1).encode() + b"\n0000000000 65535 f \n"
830
+ for o in offs:
831
+ out += ("%010d 00000 n \n" % o).encode()
832
+ out += (b"trailer<</Size " + str(len(objs) + 1).encode() + b"/Root 1 0 R>>\nstartxref\n"
833
+ + str(x).encode() + b"\n%%EOF\n")
834
+ return bytes(out)
835
+ open(os.path.join(d, "good.pdf"), "wb").write(_mini_pdf(b"contact PSABINCANARY here"))
836
+ _b = b"BT (contact PSABINCANARY here) Tj ET"
837
+ open(os.path.join(d, "broken.pdf"), "wb").write(
838
+ b"%PDF-1.4\n4 0 obj<</Length " + str(len(_b)).encode() + b">>stream\n" + _b
839
+ + b"\nendstream endobj\ntrailer\n%%EOF\n")
840
+ open(os.path.join(d, "plain.md"), "w").write("contact PSABINCANARY here\n")
841
+ open(os.path.join(d, "junk.bin"), "wb").write(bytes(range(256)) * 2)
842
+ _PYX
843
+
844
+ _xrun() { _xout=$(python3 "$_X" "$1" 2>/dev/null); _xrc=$?; }
845
+
846
+ _xrun "$_xd/good.pdf"
847
+ if [ "$_PDFCAP" = "1" ]; then
848
+ { [ "$_xrc" = "0" ] && printf '%s' "$_xout" | grep -q PSABINCANARY; } \
849
+ && ok "X1 유효 PDF → exit 0 + 본문 텍스트(글리프를 풀어 읽는다)" \
850
+ || bad "X1 rc=$_xrc / 토큰 미검출 — 추출기가 PDF 텍스트를 못 읽는다"
851
+ else
852
+ # 🟥 «의존이 없다»를 «빈 텍스트 + exit 0»으로 내면 호출부가 그걸 CLEAN 으로 스캔한다.
853
+ [ "$_xrc" = "3" ] && ok "X1 pymupdf 없음 → exit 3 (의존 부재를 «빈 성공»으로 안 낸다)" \
854
+ || bad "X1 rc=$_xrc (want 3) — 의존 부재가 통과 방향으로 샌다"
855
+ fi
856
+
857
+ _xrun "$_xd/broken.pdf"
858
+ [ "$_xrc" = "3" ] \
859
+ && ok "X2 🟥 컨테이너가 0자를 내면 exit 3 — «열었는데 아무것도 없음»은 CLEAN 이 아니다" \
860
+ || bad "X2 rc=$_xrc (want 3) — 빈 추출이 통과하면 거짓 초록이 한 층 아래로 옮겨간다"
861
+
862
+ _xrun "$_xd/junk.bin"
863
+ [ "$_xrc" = "3" ] && ok "X3 알 수 없는 비텍스트 → exit 3 (목록 밖은 거절 방향)" \
864
+ || bad "X3 rc=$_xrc (want 3)"
865
+
866
+ _xrun "$_xd/plain.md"
867
+ { [ "$_xrc" = "0" ] && printf '%s' "$_xout" | grep -q PSABINCANARY; } \
868
+ && ok "X4 CONTROL — 텍스트는 그대로 통과(0). 3 이 아무 데나 안 뜬다" \
869
+ || bad "X4 rc=$_xrc — 텍스트 경로가 깨졌다"
870
+
871
+ _xrun "$_xd/nope.pdf"
872
+ [ "$_xrc" = "2" ] && ok "X5 없는 파일 → exit 2 (사용법 오류와 추출 실패를 가른다)" \
873
+ || bad "X5 rc=$_xrc (want 2)"
874
+
875
+ _xout=$(python3 "$_X" 2>/dev/null); _xrc=$?
876
+ [ "$_xrc" = "2" ] && ok "X6 인자 없음 → exit 2" || bad "X6 rc=$_xrc (want 2)"
877
+
878
+ # 실물 — 이 레포가 실제로 출하하는 컨테이너
879
+ _xp="$REPO_ROOT/plugins/fh-preprep/skills/preprep/fixtures/fixture_R3_positive.pptx"
880
+ if [ -f "$_xp" ]; then
881
+ _xrun "$_xp"
882
+ { [ "$_xrc" = "0" ] && [ "${#_xout}" -gt 1000 ]; } \
883
+ && ok "X7 출하 .pptx → exit 0 + XML 전 파트(${#_xout}자). 발행 게이트가 안을 본다" \
884
+ || bad "X7 rc=$_xrc / ${#_xout}자 — 출하 컨테이너를 못 읽으면 매 릴리스가 막힌다"
885
+ _cond_lanes=$((_cond_lanes+1))
886
+ else
887
+ printf ' ⏭ X7 skipped — 출하 pptx 픽스처 부재 (skip != pass)\n'
888
+ fi
889
+ rm -rf "$_xd"
890
+ else
891
+ echo " ❌ INSTRUMENT ERROR — psa_extract_text.py 또는 python3 부재; X 레인 미실행(스킵 아님)"
892
+ fail=$((fail+1))
893
+ fi
894
+
630
895
  [ "$fail" -eq 0 ] || exit 1
631
896
  # 🟥 플로어는 **조건부 레인을 반영한 값**이다. 33 = zsh 없는 러너의 기저(Z1~Z4 · E2~E5/zsh 스킵).
632
897
  # zsh 가 있으면 +8. 상수 하나로 박으면 «스킵 = 계기 오류» 가 되어 러너를 거짓 적색으로 만든다.
633
898
  # ⚠️ 그리고 이 수식이 말하는 진짜 사실을 잊지 마라: **zsh 축은 zsh 가 있는 곳에서만 검증된다.**
634
899
  # CI 에 zsh 를 설치한 이유가 그것이고(.github/workflows/validate.yml), 그게 없으면 이 PR 이
635
900
  # 고친 결함의 축이 CI 에서 **한 번도** 안 돌아간다.
636
- _floor=$((52 + _cond_lanes))
901
+ _floor=$((62 + _cond_lanes))
637
902
  [ "$pass" -ge "$_floor" ] || { echo " ❌ INSTRUMENT ERROR — only $pass lanes ran; expected >=$_floor (zsh 조건부 +$_cond_lanes)"; exit 3; }
638
903
  exit 0
@@ -59,6 +59,25 @@ case "${FH_STUB_MODE:-say}" in
59
59
  # L26 (2026-09-05) — a command that runs long past any sane --timeout, default SIGTERM
60
60
  # disposition (no trap): dies as soon as the watchdog signals it, so a lane can tell "the
61
61
  # deadline was enforced" from "we just waited for it to finish on its own".
62
+ # L28 — multi-turn. Emits the shape `--output-format json` produces and echoes back whichever
63
+ # session id it was resumed with, so a lane can tell "the runner plumbed --resume" apart from
64
+ # "it did not". A fresh call mints a NEW id from a counter file, which is what makes the
65
+ # ARM/CTRL pair discriminate: same id across turns = carried, different ids = cold sessions.
66
+ turns) _sid=""; _prev=""; _res=0
67
+ for _a in "$@"; do [ "$_prev" = "--resume" ] && _sid="$_a"; _prev="$_a"; done
68
+ if [ -n "$_sid" ]; then _res=1; else
69
+ _c=$(cat "${FH_STUB_SID_COUNTER:-/dev/null}" 2>/dev/null); [ -n "$_c" ] || _c=0
70
+ _n=$((_c+1)); echo "$_n" > "${FH_STUB_SID_COUNTER:-/dev/null}" 2>/dev/null || true
71
+ _sid="SID-$_n"
72
+ fi
73
+ printf '{"session_id":"%s","result":"resumed=%s sid=%s"}\n' "$_sid" "$_res" "$_sid" ;;
74
+ # L28k/l/m — the three ways a multi-turn run can fail while looking clean.
75
+ turns_badjson) echo "not json at all {" ;;
76
+ turns_nosid) printf '{"result":"answer with no session id"}\n' ;;
77
+ turns_die2) _c=$(cat "${FH_STUB_SID_COUNTER:-/dev/null}" 2>/dev/null); [ -n "$_c" ] || _c=0
78
+ _n=$((_c+1)); echo "$_n" > "${FH_STUB_SID_COUNTER:-/dev/null}" 2>/dev/null || true
79
+ if [ "$_n" -eq 2 ]; then exit 7; fi
80
+ printf '{"session_id":"SID-fixed","result":"turn %s ok"}\n' "$_n" ;;
62
81
  hang) sleep 30 ;;
63
82
  esac
64
83
  exit 0
@@ -397,5 +416,112 @@ grep -q -- "--mcp-config $WORKROOT/mcp27.json" "$LOG2" && grep -q -- "--strict-m
397
416
  && ok "L27c --mcp-config <file> reaches the CLI together with --strict-mcp-config (explicit allow, still strict)" \
398
417
  || no "L27c --mcp-config not plumbed (or strict dropped when a file is given)"
399
418
 
419
+ echo "── L28 multi-turn — --turns plumbing + --no-resume CONTROL ─────────"
420
+ # 🟥 These lanes measure the RUNNER'S WIRING (is --resume passed, is session_id parsed, are
421
+ # turns counted), not whether a real session carries context. The live known-pair for THAT
422
+ # is recorded in the marker: ARM answered the turn-1 fact at turn 2 with one session id;
423
+ # --no-resume answered "you never told me" with two. A stub cannot establish that, and
424
+ # pretending it does would be the muscle-not-skeleton defect.
425
+
426
+ printf 'turn one\n# a comment turn that must be skipped\n\nturn two\nturn three\n' > "$WORKROOT/t3.txt"
427
+
428
+ # ── usage guards (known-negative: a bad invocation must NOT proceed) ──
429
+ # 🟥 rc=2 ALONE IS NOT THE ASSERTION. Before --turns existed, an unknown flag ALSO exits 2 —
430
+ # so a bare rc check is green for the wrong reason (lane-green reason ②: the input never
431
+ # reached the code under test). Each guard therefore asserts the REASON in the message.
432
+ run_sut --arm a --reps 1 --turns "$WORKROOT/does_not_exist.txt" --out "$WORKROOT/o28a"
433
+ { [ "$RC" -eq 2 ] && printf '%s' "$OUT" | grep -q -- "--turns file not found"; } \
434
+ && ok "L28a missing --turns file → rc=2 AND the message names the file (not 'unknown flag')" \
435
+ || no "L28a rc=$RC / message did not name a missing --turns file"
436
+
437
+ printf '# only a comment\n\n\n' > "$WORKROOT/t_empty.txt"
438
+ run_sut --arm a --reps 1 --turns "$WORKROOT/t_empty.txt" --out "$WORKROOT/o28b"
439
+ { [ "$RC" -eq 2 ] && printf '%s' "$OUT" | grep -q "no turns"; } \
440
+ && ok "L28b comment/blank-only turns file → rc=2 naming 'no turns' (a zero-turn run must not read as clean)" \
441
+ || no "L28b rc=$RC / message did not name a zero-turn file — an empty conversation would score as a run"
442
+
443
+ run_sut --arm a --reps 1 --prompt p --turns "$WORKROOT/t3.txt" --out "$WORKROOT/o28c"
444
+ { [ "$RC" -eq 2 ] && printf '%s' "$OUT" | grep -q "mutually exclusive"; } \
445
+ && ok "L28c --prompt + --turns → rc=2 naming the conflict (which one ran must never be ambiguous)" \
446
+ || no "L28c rc=$RC / message did not name the conflict"
447
+
448
+ # ── ARM: resume ON ──
449
+ OUTDIR="$WORKROOT/o28arm"; LOGA="$WORKROOT/argv28arm.log"; : > "$LOGA"; : > "$WORKROOT/sid_arm"
450
+ ( cd "$SRC" && PATH="$STUBBIN:$PATH" HOME="$FAKEHOME" FH_STUB_MODE=turns \
451
+ FH_STUB_ARGV_LOG="$LOGA" FH_STUB_SID_COUNTER="$WORKROOT/sid_arm" \
452
+ bash "$SUT" --arm mt --reps 1 --turns "$WORKROOT/t3.txt" --out "$OUTDIR" ) >/dev/null 2>&1
453
+ TSV="$OUTDIR/mt_r1.turns.tsv"
454
+ NROW=$( [ -f "$TSV" ] && awk 'NR>1' "$TSV" | grep -c . || echo 0 )
455
+ [ "$NROW" -eq 3 ] && ok "L28d 5-line file → 3 turns (blank + # skipped)" \
456
+ || no "L28d turn count is $NROW, expected 3 — comment/blank skipping is off"
457
+ NSID=$( [ -f "$TSV" ] && awk 'NR>1{print $3}' "$TSV" | sort -u | grep -c . || echo 0 )
458
+ [ "$NSID" -eq 1 ] && ok "L28e ARM — all 3 turns share ONE session id (the conversation was carried)" \
459
+ || no "L28e ARM produced $NSID distinct session ids, expected 1"
460
+ NRES=$(grep -c -- "--resume" "$LOGA" || true)
461
+ [ "$NRES" -eq 2 ] && ok "L28f ARM — --resume reached the CLI on turns 2..N exactly (2 of 3)" \
462
+ || no "L28f ARM passed --resume $NRES times, expected 2"
463
+ NMARK=$(grep -c '^===== turn ' "$OUTDIR/mt_r1.txt" 2>/dev/null || true)
464
+ [ "$NMARK" -eq 3 ] && ok "L28g concatenated transcript carries all 3 turns (existing scorers read this file)" \
465
+ || no "L28g transcript has $NMARK turn markers, expected 3"
466
+
467
+ # ── CTRL: --no-resume. 🟥 Without this arm L28e/L28f measure nothing ──
468
+ OUTDIR="$WORKROOT/o28ctrl"; LOGC="$WORKROOT/argv28ctrl.log"; : > "$LOGC"; : > "$WORKROOT/sid_ctrl"
469
+ ( cd "$SRC" && PATH="$STUBBIN:$PATH" HOME="$FAKEHOME" FH_STUB_MODE=turns \
470
+ FH_STUB_ARGV_LOG="$LOGC" FH_STUB_SID_COUNTER="$WORKROOT/sid_ctrl" \
471
+ bash "$SUT" --arm mt --reps 1 --no-resume --turns "$WORKROOT/t3.txt" --out "$OUTDIR" ) >/dev/null 2>&1
472
+ TSVC="$OUTDIR/mt_r1.turns.tsv"
473
+ NSIDC=$( [ -f "$TSVC" ] && awk 'NR>1{print $3}' "$TSVC" | sort -u | grep -c . || echo 0 )
474
+ [ "$NSIDC" -eq 3 ] && ok "L28h CTRL — 3 turns, 3 DISTINCT session ids (cold sessions, as designed)" \
475
+ || no "L28h CTRL produced $NSIDC distinct session ids, expected 3 — the control is dead"
476
+ NRESC=$(grep -c -- "--resume" "$LOGC" || true)
477
+ [ "$NRESC" -eq 0 ] && ok "L28i CTRL — --resume never reached the CLI" \
478
+ || no "L28i CTRL passed --resume $NRESC times, expected 0"
479
+
480
+ # ── L28j 기존 단발 경로 무변경 (회귀) ──
481
+ OUTDIR="$WORKROOT/o28j"; LOGJ="$WORKROOT/argv28j.log"; : > "$LOGJ"
482
+ ( cd "$SRC" && PATH="$STUBBIN:$PATH" HOME="$FAKEHOME" FH_STUB_MODE=say FH_STUB_ARGV_LOG="$LOGJ" \
483
+ bash "$SUT" --arm a --reps 1 --prompt p --out "$OUTDIR" ) >/dev/null 2>&1
484
+ { ! grep -q -- "--resume" "$LOGJ"; } && { ! grep -q -- "--output-format" "$LOGJ"; } \
485
+ && [ -s "$OUTDIR/a_r1.txt" ] && [ ! -f "$OUTDIR/a_r1.turns.tsv" ] \
486
+ && ok "L28j single-shot path untouched — no --resume, no --output-format, no turns.tsv" \
487
+ || no "L28j single-shot path changed — --turns leaked into the path every existing probe runs on"
488
+
489
+ # ── 🟥 L28k/l/m — known-NEGATIVES. cross-family (codex) named these: without them the suite
490
+ # reported "44 passed, 0 failed" over three S/A-tier folds. A lane set that only walks the
491
+ # happy path measures that the happy path works, which nobody doubted.
492
+ mt_run() { # $1=stub mode $2=outdir tag ; sets RC and OUTDIR
493
+ OUTDIR="$WORKROOT/$2"; : > "$WORKROOT/sid_$2"
494
+ ( cd "$SRC" && PATH="$STUBBIN:$PATH" HOME="$FAKEHOME" FH_STUB_MODE="$1" \
495
+ FH_STUB_SID_COUNTER="$WORKROOT/sid_$2" \
496
+ bash "$SUT" --arm mt --reps 1 --turns "$WORKROOT/t3.txt" --out "$OUTDIR" ) >"$WORKROOT/o_$2.log" 2>&1
497
+ RC=$?
498
+ }
499
+
500
+ mt_run turns_badjson b28k
501
+ # 🟥 The assertion is CONTAMINATED, not rc — this script ends in a deliberate `exit 0`.
502
+ { grep -q "RESULT: CONTAMINATED" "$WORKROOT/o_b28k.log" \
503
+ && grep -q "PARSE_FAILED" "$OUTDIR/mt_r1.turns.tsv" 2>/dev/null; } \
504
+ && ok "L28k unparseable turn output → CONTAMINATED AND note=PARSE_FAILED (not folded into 'said nothing')" \
505
+ || no "L28k not CONTAMINATED / PARSE_FAILED not recorded — a dead parser reads as an empty answer"
506
+
507
+ mt_run turns_die2 b28l
508
+ { grep -q "RESULT: CONTAMINATED" "$WORKROOT/o_b28l.log" \
509
+ && grep -q "MULTI-TURN INCOMPLETE — first failing turn: 2" "$WORKROOT/o_b28l.log"; } \
510
+ && ok "L28l turn 2 dies, turn 3 succeeds → CONTAMINATED and names turn 2 (not last-turn rc only)" \
511
+ || no "L28l a conversation that broke mid-way still scored as clean"
512
+
513
+ mt_run turns_nosid b28m
514
+ { grep -q "RESULT: CONTAMINATED" "$WORKROOT/o_b28m.log" \
515
+ && grep -q "did not demonstrably run" "$WORKROOT/o_b28m.log"; } \
516
+ && ok "L28m no session_id on a resume turn → CONTAMINATED (the evidence IS the claim)" \
517
+ || no "L28m a turn that cannot be shown to share the session passed silently"
518
+
519
+ # 🟥 CONTROL for the three above: the SAME harness on a healthy stub must pass. Without this,
520
+ # an rc!=0 caused by something unrelated would read as three successful known-negatives.
521
+ mt_run turns b28n
522
+ grep -q "RESULT: CLEAN" "$WORKROOT/o_b28n.log" \
523
+ && ok "L28n CONTROL — healthy multi-turn run is CLEAN (k/l/m are not firing on everything)" \
524
+ || no "L28n CONTROL was not CLEAN — L28k/l/m prove nothing"
525
+
400
526
  echo "sim_isolated_run lanes: $pass passed, $fail failed"
401
527
  [ "$fail" -eq 0 ] || exit 1
@@ -0,0 +1,45 @@
1
+ {
2
+ "_README": [
3
+ "SubagentStop hook snippet — TRACKED, so it arrives with a clone. Every .claude/settings*.json path",
4
+ "in this repo is gitignored, so the hook REGISTRATION cannot be tracked. This is the tracked SOURCE",
5
+ "that install-wizard merges into the user's local settings. Shipping the script is not the same",
6
+ "proposition as wiring it — this file is the difference.",
7
+ "",
8
+ "What it does: when a subagent finishes, it checks the newest session checklist for a row whose",
9
+ "declared BLOCKER now reads DONE while the row itself is still open, and surfaces those rows.",
10
+ "",
11
+ "WHY HERE. Measured 2026-09-19 on this repo's own checklist: rows A6/A8 declared «A13 선행», A13",
12
+ "landed DONE, and nothing re-read the file. Three operator requests degraded until the operator",
13
+ "asked again. The existing `check` passed the same file clean (rows=14 ok=14 violations=0 rc=0) —",
14
+ "form was never the problem. A subagent finishing IS «한 차례 끝났다», the one moment a blocker",
15
+ "plausibly just closed.",
16
+ "",
17
+ "DEGRADE: advisory and silent. No checklist, no dependency edges, no python3 → say nothing, exit 0.",
18
+ "It NEVER blocks. A noisy hook on every subagent stop trains people to ignore hooks, which disarms",
19
+ "the ones guarding irreversible surfaces.",
20
+ "",
21
+ "🟥 exit 0 ALWAYS. A hook that exits non-zero has its stdout DISCARDED and its stderr NOT relayed —",
22
+ "the warning would reach nobody. The finding travels as hookSpecificOutput.additionalContext.",
23
+ "",
24
+ "🟥 SCHEMA: the hook block lives under `project_settings_json`, exactly as every other snippet",
25
+ "here does. A first draft put `hooks` at the top level; install-wizard then SKIPS the file",
26
+ "SILENTLY — the lane that caught it (SHIP-1) exists because a skipped snippet looks identical",
27
+ "to an absent one."
28
+ ],
29
+ "project_settings_json": {
30
+ "hooks": {
31
+ "SubagentStop": [
32
+ {
33
+ "matcher": "",
34
+ "hooks": [
35
+ {
36
+ "type": "command",
37
+ "command": "bash \"${CLAUDE_PROJECT_DIR:-$HOME/projects/forge-harness}/scripts/checklist_unblocked_hook.sh\"",
38
+ "timeout": 15
39
+ }
40
+ ]
41
+ }
42
+ ]
43
+ }
44
+ }
45
+ }