@chrono-meta/fh-gate 3.28.0 → 3.29.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.
Files changed (40) hide show
  1. package/.claude-plugin/marketplace.json +4 -4
  2. package/CHEATSHEET.md +2 -2
  3. package/CLAUDE.md +5 -2
  4. package/docs/REFERENCE.md +4 -1
  5. package/knowledge/shared/harness-core/claude_md_full_reference.md +2 -0
  6. package/knowledge/shared/harness-core/claude_md_gate_details.md +7 -0
  7. package/knowledge/shared/harness-core/dispatch_conditional_prohibition.md +12 -0
  8. package/knowledge/shared/harness-core/fh_three_layer_canon.md +12 -0
  9. package/knowledge/shared/harness-core/measurement-integrity-checklist.md +16 -0
  10. package/knowledge/shared/learnings/subagent_invocations_log.yaml +56 -0
  11. package/package.json +3 -1
  12. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  13. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  14. package/plugins/fh-meta/CHANGELOG.md +22 -0
  15. package/plugins/fh-meta/skills/auto-decorrelation/SKILL.md +17 -0
  16. package/plugins/fh-meta/skills/sim-conductor/SKILL.md +2 -2
  17. package/plugins/fh-meta/skills/sim-conductor/SKILL_detail.md +3 -3
  18. package/plugins/fh-meta/skills/steel-quench/SKILL.md +25 -1
  19. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  20. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  21. package/scripts/degrade_direction_scan.sh +43 -0
  22. package/scripts/dispatch_receipt.py +185 -0
  23. package/scripts/doc_claim_triad_scan.py +43 -4
  24. package/scripts/fh-gate.sh +71 -11
  25. package/scripts/finding_fleet.sh +15 -3
  26. package/scripts/package_coverage_check.sh +5 -0
  27. package/scripts/selfcheck.sh +41 -20
  28. package/scripts/session_checklist.py +155 -12
  29. package/scripts/test_degrade_scan_shell_probes.sh +81 -0
  30. package/scripts/test_dispatch_receipt_lanes.sh +95 -0
  31. package/scripts/test_doc_claim_triad_lanes.sh +30 -0
  32. package/scripts/test_fh_audit_check_lanes.sh +10 -5
  33. package/scripts/test_fh_gate_regressions.sh +71 -1
  34. package/scripts/test_finding_pipeline_lanes.sh +83 -0
  35. package/scripts/test_locale_invariance_lanes.sh +19 -0
  36. package/scripts/test_mutation_probe_lanes.sh +22 -6
  37. package/scripts/test_selfcheck_state_lanes.sh +32 -0
  38. package/scripts/test_session_checklist_lanes.sh +138 -0
  39. package/templates/PRE-PUBLISH-CHECKLIST.md +10 -0
  40. package/templates/degrade_direction_scan.sh +43 -0
@@ -3,13 +3,22 @@
3
3
 
4
4
  Two subcommands:
5
5
 
6
- extract --transcript <jsonl> [--out <md>]
6
+ extract --transcript <jsonl> [--out <md>] [--utterances <jsonl>]
7
7
  Reads a Claude Code transcript JSONL and emits a checklist SKELETON in
8
8
  Markdown: one row per operator utterance, 상태 column EMPTY. Opens TWO
9
9
  channels — raw entries and compaction-summary "All user messages"
10
10
  sections — and prints how many of each it found (0 found still counts
11
11
  as OPENED, never as "not opened"). See fh_signal_2026-09-18 for the
12
- doctrine this mechanizes.
12
+ doctrine this mechanizes. A THIRD channel, the UserPromptSubmit hook record
13
+ (tracks/_meta/utterances/<session_id>.jsonl, written by utterance_checklist_hook.py),
14
+ is merged in: it also holds messages sent while a tool was running, which the
15
+ transcript misses. Merge rule: a hook row is the same utterance as a transcript row
16
+ when the normalized text is equal (a hook row flagged `truncated` matches by prefix)
17
+ AND the timestamps are within HOOK_MATCH_WINDOW_S; each transcript row pairs with at
18
+ most one hook row (nearest in time). Unpaired hook rows are added as `H<n>` rows;
19
+ transcript rows keep `<n>`, summary rows `S<n>`. The header always states the hook
20
+ channel's state: not read (file absent) is NOT zero rows; a malformed line or an
21
+ unreadable file is a channel error (rc=2) and the transcript rows still print.
13
22
 
14
23
  check --file <md>
15
24
  Validates a FILLED checklist. FORM ONLY — this command never judges
@@ -57,6 +66,7 @@ closing/companion mark) apply only to entries that carry no metadata at all;
57
66
  there a byte-identical pasted envelope is indistinguishable by design.
58
67
  """
59
68
  import argparse
69
+ import datetime
60
70
  import json
61
71
  import os
62
72
  import re
@@ -343,7 +353,112 @@ def md_escape(text):
343
353
  return (text or "").replace("|", "\\|")
344
354
 
345
355
 
346
- def do_extract(transcript_path, out_path):
356
+ HOOK_MATCH_WINDOW_S = 1800 # a queued message can reach the transcript long after the hook saw it; further apart = a repeat, not the same message
357
+
358
+
359
+ def parse_ts(ts):
360
+ """transcript timestamps are UTC («…Z»); hook timestamps are local naive («YYYY-MM-DDTHH:MM:SS»). -> aware UTC datetime or None."""
361
+ c = parse_ts_candidates(ts)
362
+ return c[0] if c else None
363
+
364
+
365
+ TS_SHAPE_RE = re.compile(r"^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?Z?$")
366
+
367
+
368
+ def parse_ts_candidates(ts):
369
+ """-> [aware UTC datetimes]. A local naive time inside a DST fall-back hour names TWO instants (fold 0 and 1);
370
+ both are returned so the matcher can use the nearer one (codex 2026-10-19: picking one created a duplicate row)."""
371
+ if not isinstance(ts, str) or not TS_SHAPE_RE.match(ts):
372
+ return [] # exact shape only — `ts[:19]` alone accepted trailing garbage as a valid time (codex R2)
373
+ try:
374
+ dt = datetime.datetime.strptime(ts[:19], "%Y-%m-%dT%H:%M:%S")
375
+ except ValueError:
376
+ return []
377
+ if ts.endswith("Z"):
378
+ return [dt.replace(tzinfo=datetime.timezone.utc)]
379
+ out = []
380
+ for fold in (0, 1):
381
+ u = dt.replace(fold=fold).astimezone(datetime.timezone.utc)
382
+ if u not in out:
383
+ out.append(u)
384
+ return out
385
+
386
+
387
+ def default_hook_path(transcript_path):
388
+ sid = os.path.splitext(os.path.basename(transcript_path))[0]
389
+ hub = os.environ.get("FH_HUB") or os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
390
+ return os.path.join(hub, "tracks", "_meta", "utterances", sid + ".jsonl")
391
+
392
+
393
+ def read_hook_channel(path):
394
+ """-> (state, rows, bad_lines, detail). state: «read» · «absent» · «error». rows: [{ts, text, truncated}]."""
395
+ if not os.path.lexists(path):
396
+ return "absent", [], 0, ""
397
+ if not os.path.isfile(path):
398
+ return "error", [], 0, "not a regular file"
399
+ rows, bad = [], 0
400
+ try:
401
+ with open(path, "rb") as f:
402
+ for raw in f:
403
+ try:
404
+ line = raw.decode("utf-8").strip() # strict: a replaced byte would make a different text and a spurious H row
405
+ if not line:
406
+ continue
407
+ d = json.loads(line)
408
+ except Exception:
409
+ bad += 1
410
+ continue
411
+ if not isinstance(d, dict) or not isinstance(d.get("text"), str) or not d["text"].strip():
412
+ bad += 1
413
+ continue
414
+ if not parse_ts_candidates(d.get("ts")):
415
+ bad += 1 # the hook always writes ts; without it the time window cannot apply, so the row is not trusted
416
+ continue
417
+ rows.append({"ts": d.get("ts"), "text": d["text"], "truncated": d.get("truncated") is True})
418
+ except OSError as e:
419
+ return "error", [], 0, e.strerror or "unreadable"
420
+ return "read", rows, bad, ""
421
+
422
+
423
+ def merge_hook_rows(raw_rows, hook_rows):
424
+ """-> (hook_only, matched_count). Both channels record the same conversation in the same order, so pairing is
425
+ ORDER-PRESERVING, not nearest-first: hook rows in time order each take the EARLIEST unpaired transcript row of equal
426
+ normalized text inside HOOK_MATCH_WINDOW_S. Exact-text pairs (any row) are made first and truncated-prefix pairs
427
+ second, so a truncated hook row cannot take the row another hook row matches exactly. Still greedy, not an optimal
428
+ assignment — a named residual. (codex 2026-10-19: nearest-first greedy turned two
429
+ repeated «yes» pairs into three rows.) A transcript row with no usable time pairs on text alone."""
430
+ raw_norms = [normalize_utterance(r["text"]) for r in raw_rows]
431
+ raw_dts = [parse_ts(r["ts"]) for r in raw_rows]
432
+ order = sorted(range(len(hook_rows)), key=lambda k: (min(parse_ts_candidates(hook_rows[k]["ts"]) or [datetime.datetime.max.replace(tzinfo=datetime.timezone.utc)]), k))
433
+ used, paired = set(), set()
434
+
435
+ def within(hdts, i):
436
+ if raw_dts[i] is None or not hdts:
437
+ return True
438
+ return min(abs((h - raw_dts[i]).total_seconds()) for h in hdts) <= HOOK_MATCH_WINDOW_S
439
+
440
+ for prefix_pass in (False, True):
441
+ for k in order:
442
+ h = hook_rows[k]
443
+ if k in paired or (prefix_pass and not h["truncated"]):
444
+ continue # pass 1 = exact text for every row (a truncated row whose text is exact counts); pass 2 = prefixes
445
+ hn = normalize_utterance(h["text"])
446
+ hdts = parse_ts_candidates(h["ts"])
447
+ cands = [i for i, rn in enumerate(raw_norms)
448
+ if i not in used and (rn == hn or (prefix_pass and hn and rn.startswith(hn))) and within(hdts, i)]
449
+ if cands:
450
+ best = min(cands, key=lambda i: (raw_dts[i] is None, raw_dts[i] or 0, i))
451
+ used.add(best); paired.add(k)
452
+ hook_only = []
453
+ for k in order:
454
+ if k in paired:
455
+ continue
456
+ hdts = parse_ts_candidates(hook_rows[k]["ts"])
457
+ hook_only.append({"ts": hdts[0].strftime("%Y-%m-%dT%H:%M:%SZ") if hdts else None, "text": hook_rows[k]["text"]})
458
+ return hook_only, len(paired)
459
+
460
+
461
+ def do_extract(transcript_path, out_path, utterances_path=None):
347
462
  if not os.path.isfile(transcript_path):
348
463
  sys.stderr.write("error: transcript not found: %s\n" % transcript_path)
349
464
  return 10
@@ -389,6 +504,13 @@ def do_extract(transcript_path, out_path):
389
504
  continue
390
505
  raw_rows.append({"ts": entry.get("timestamp"), "text": text})
391
506
 
507
+ hook_path = utterances_path or default_hook_path(transcript_path)
508
+ hook_state, hook_rows, hook_bad, hook_detail = read_hook_channel(hook_path)
509
+ hook_only, hook_matched = merge_hook_rows(raw_rows, hook_rows)
510
+
511
+ # summary quotes are compared against the transcript rows only, as before: matching them against hook-only rows
512
+ # too dropped a distinct request that happened to repeat a short quote (codex 2026-10-19). A duplicate row is the
513
+ # safe direction; a missing one is not.
392
514
  raw_norms = [normalize_utterance(r["text"]) for r in raw_rows]
393
515
 
394
516
  summary_found_total = 0
@@ -406,7 +528,7 @@ def do_extract(transcript_path, out_path):
406
528
  n_raw = len(raw_rows)
407
529
  n_summary_found = summary_found_total
408
530
  n_summary_added = len(summary_rows)
409
- rc = 2 if parse_errors else 0 # v5: an unparsable line may have been an utterance — loud, never rc=0
531
+ rc = 2 if (parse_errors or hook_bad or hook_state == "error") else 0 # v5: an unparsable line may have been an utterance — loud, never rc=0
410
532
 
411
533
  lines_out = []
412
534
  title = "# 세션 요청 체크리스트 (스켈레톤) — %s" % os.path.basename(transcript_path)
@@ -419,6 +541,15 @@ def do_extract(transcript_path, out_path):
419
541
  lines_out.append(chr(0x1F4CE) + " " + "원장 = %s (%d lines)" % (transcript_path, line_count))
420
542
  if parse_errors:
421
543
  lines_out.append("🟥 JSONL 파싱 실패 %d줄 — 그 줄의 발화는 이 표에 없다 (rc=2)" % parse_errors)
544
+ if hook_state == "read":
545
+ lines_out.append("🪝 훅 기록 채널 읽음 — %d건 · 전사와 일치 %d건 · 훅 전용 %d건 (행 번호 H = 훅 전용, S = 요약, 숫자 = 전사)"
546
+ % (len(hook_rows), hook_matched, len(hook_only)))
547
+ elif hook_state == "absent":
548
+ lines_out.append("🟨 훅 기록 채널 안 읽음 — 파일 없음: %s (0건이 아니라 미열람; 훅이 안 걸렸거나 다른 허브일 수 있다)" % hook_path)
549
+ else:
550
+ lines_out.append("🟥 훅 기록 채널 오류 — %s: %s (rc=2; 전사 행은 그대로 아래에 있다)" % (hook_path, hook_detail))
551
+ if hook_bad:
552
+ lines_out.append("🟥 훅 기록 %d줄 해석 실패 — 그 줄의 발화는 이 표에 없을 수 있다 (rc=2)" % hook_bad)
422
553
  lines_out.append("")
423
554
  lines_out.append(
424
555
  "| # | \uc2dc\uac01 | \ubc1c\ud654(\uc694\uc9c0) | \uc0c1\ud0dc | \uc99d\uac70 | \uc0ac\uc720 / \ub0a8\uc740 \uac83 | \uc81c\uc548(\uc774\ubc88 \uc138\uc158 vs \uc774\uc6d4) |"
@@ -435,6 +566,16 @@ def do_extract(transcript_path, out_path):
435
566
  "| %d | %s | %s | | | | |" % (n, format_ts(r["ts"]), md_escape(blurb))
436
567
  )
437
568
 
569
+ h = 0
570
+ for r in hook_only:
571
+ h += 1
572
+ blurb = collapse(r["text"])
573
+ if len(blurb) > 160:
574
+ blurb = blurb[:160] + "\u2026"
575
+ lines_out.append(
576
+ "| H%d | %s | %s | | | | |" % (h, format_ts(r["ts"]), md_escape(blurb))
577
+ )
578
+
438
579
  s = 0
439
580
  for r in summary_rows:
440
581
  s += 1
@@ -502,19 +643,19 @@ def carry_forward(lines_out, out_path):
502
643
  continue # an empty row has nothing to carry
503
644
  if in_orphans:
504
645
  orphans_prev.append(l); continue # earlier orphans stay orphans unless they match below
505
- prev.setdefault((c[1], c[2]), c[3:])
506
- used, out = set(), []
646
+ prev.setdefault((c[1], c[2]), []).append(c[3:]) # a LIST per key: repeated rows (same minute, same words) keep each judgment, in order
647
+ used, out = 0, []
507
648
  for l in lines_out:
508
649
  c = _cells(l)
509
650
  key = (c[1], c[2]) if c else None
510
- if c and key in prev and not any(c[3:]):
511
- out.append("| %s | %s | %s | %s | %s | %s | %s |" % tuple(c[:3] + prev[key]))
512
- used.add(key); continue
651
+ if c and prev.get(key) and not any(c[3:]):
652
+ out.append("| %s | %s | %s | %s | %s | %s | %s |" % tuple(c[:3] + prev[key].pop(0)))
653
+ used += 1; continue
513
654
  out.append(l)
514
- orphans = ["| %s | %s | %s | %s | %s | %s | %s |" % ((("-",) + k + tuple(v))) for k, v in prev.items() if k not in used]
655
+ orphans = ["| %s | %s | %s | %s | %s | %s | %s |" % ((("-",) + k + tuple(v))) for k, vs in prev.items() for v in vs]
515
656
  orphans += orphans_prev
516
657
  if used or orphans:
517
- out.insert(4, "↩️ 이전 결과서에서 판정 %d줄 이어받음 · 못 맞춘 판정 %d줄은 맨 아래 «이전 결과서에서 이어받지 못한 판정»에 보존" % (len(used), len(orphans)))
658
+ out.insert(4, "↩️ 이전 결과서에서 판정 %d줄 이어받음 · 못 맞춘 판정 %d줄은 맨 아래 «이전 결과서에서 이어받지 못한 판정»에 보존" % (used, len(orphans)))
518
659
  if orphans:
519
660
  out += ["", CARRY_HEADING, "", "| # | 시각 | 발화(요지) | 상태 | 증거 | 사유 / 남은 것 | 제안(이번 세션 vs 이월) |",
520
661
  "|---|---|---|---|---|---|---|"] + orphans
@@ -751,6 +892,8 @@ def build_parser():
751
892
  p_extract = sub.add_parser("extract", help="extract a checklist skeleton from a transcript JSONL")
752
893
  p_extract.add_argument("--transcript", required=True)
753
894
  p_extract.add_argument("--out", default=None)
895
+ p_extract.add_argument("--utterances", default=None,
896
+ help="hook record jsonl (default: <hub>/tracks/_meta/utterances/<session id>.jsonl)")
754
897
 
755
898
  p_unblocked = sub.add_parser(
756
899
  "unblocked",
@@ -865,7 +1008,7 @@ def main(argv=None):
865
1008
  args = parser.parse_args(argv)
866
1009
 
867
1010
  if args.cmd == "extract":
868
- return do_extract(args.transcript, args.out)
1011
+ return do_extract(args.transcript, args.out, args.utterances)
869
1012
  if args.cmd == "check":
870
1013
  return do_check(args.file)
871
1014
  if args.cmd == "unblocked":
@@ -835,5 +835,86 @@ else
835
835
  fi
836
836
  rm -rf "$_s1bc"
837
837
 
838
+ # ── S7: `set -e` under an exit contract with its own error code, no ERR trap (fh-gate.sh, 2026-10-20) ──
839
+ # POS = the pre-#927 shape. CTL1 = same file with the ERR trap. CTL2 = a contract with no separate error
840
+ # code ("0 pass / 1 fail" — an unexpected 1 already points the safe way). POS must fire for the two
841
+ # zeros to be readable.
842
+ _s7=$(mktemp -d "${TMPDIR:-/tmp}/s7_XXXXXX")
843
+ cat > "$_s7/pos.sh" <<'P1'
844
+ #!/usr/bin/env bash
845
+ # Exit codes:
846
+ # 0 — PASS
847
+ # 1 — PENDING (proceed with awareness)
848
+ # 10 — Harness error
849
+ set -euo pipefail
850
+ F=$(mktemp "$TMPDIR/x_XXXXXX")
851
+ echo "FH_GATE_VERDICT: PASS"; exit 0
852
+ P1
853
+ cat > "$_s7/ctl1.sh" <<'P2'
854
+ #!/usr/bin/env bash
855
+ # Exit codes:
856
+ # 0 — PASS
857
+ # 1 — PENDING (proceed with awareness)
858
+ # 10 — Harness error
859
+ set -euo pipefail
860
+ trap 'exit 10' ERR
861
+ F=$(mktemp "$TMPDIR/x_XXXXXX")
862
+ echo "FH_GATE_VERDICT: PASS"; exit 0
863
+ P2
864
+ cat > "$_s7/ctl2.sh" <<'P3'
865
+ #!/usr/bin/env bash
866
+ # Exit: 0 = all assertions pass; 1 = a regression.
867
+ set -euo pipefail
868
+ run_assertions
869
+ P3
870
+ # Round-1 cross-family additions: a trap that does not exit is no guard (POS2); `set -o errexit` with an
871
+ # EXIT_*ERROR constant and no comment header is the same contract (POS3); a named handler that exits is a
872
+ # guard (CTL3).
873
+ cat > "$_s7/pos2.sh" <<'P4'
874
+ #!/usr/bin/env bash
875
+ # Exit codes: 0 PASS · 1 PENDING · 10 harness error
876
+ set -euo pipefail
877
+ cleanup() { rm -f "$F"; }
878
+ trap cleanup ERR
879
+ F=$(mktemp "$TMPDIR/x_XXXXXX")
880
+ P4
881
+ cat > "$_s7/pos3.sh" <<'P5'
882
+ #!/usr/bin/env bash
883
+ set -o errexit
884
+ EXIT_PASS=0
885
+ EXIT_HARNESS_ERROR=10
886
+ F=$(mktemp "$TMPDIR/x_XXXXXX")
887
+ P5
888
+ cat > "$_s7/ctl3.sh" <<'P6'
889
+ #!/usr/bin/env bash
890
+ # Exit codes: 0 PASS · 1 PENDING · 10 harness error
891
+ set -euo pipefail
892
+ on_err() {
893
+ echo "failed" >&2
894
+ exit 10
895
+ }
896
+ trap on_err ERR
897
+ F=$(mktemp "$TMPDIR/x_XXXXXX")
898
+ P6
899
+ _s7n(){ bash "$SCAN" "$1" 2>/dev/null | grep -c 'S7:' || true; }
900
+ _p=$(_s7n "$_s7/pos.sh"); _c1=$(_s7n "$_s7/ctl1.sh"); _c2=$(_s7n "$_s7/ctl2.sh")
901
+ _p2=$(_s7n "$_s7/pos2.sh"); _p3=$(_s7n "$_s7/pos3.sh"); _c3=$(_s7n "$_s7/ctl3.sh")
902
+ if [ "$_p2" -eq 1 ]; then ok "S7 POS2: a trap that does not exit (trap cleanup ERR) is not a guard"
903
+ else bad "S7 POS2: trap cleanup ERR suppressed the finding ($_p2)"; fi
904
+ if [ "$_p3" -eq 1 ]; then ok "S7 POS3: set -o errexit + EXIT_HARNESS_ERROR constant (no comment header) is flagged"
905
+ else bad "S7 POS3: errexit/constant spelling missed ($_p3)"; fi
906
+ if [ "$_c3" -eq 0 ]; then ok "S7 CTL3: a named ERR handler that exits is a guard"
907
+ else bad "S7 CTL3: flagged a file whose ERR handler exits ($_c3)"; fi
908
+ if [ "$_p" -eq 1 ]; then
909
+ ok "S7 POS: set -e + own error code + no ERR trap is flagged once ($_p)"
910
+ if [ "$_c1" -eq 0 ]; then ok "S7 CTL1: the same file with an ERR trap is silent"
911
+ else bad "S7 CTL1: flagged a file that has the ERR trap ($_c1)"; fi
912
+ if [ "$_c2" -eq 0 ]; then ok "S7 CTL2: a pass/fail-only contract is silent"
913
+ else bad "S7 CTL2: flagged a contract without a separate error code ($_c2)"; fi
914
+ else
915
+ bad "S7 POS: expected exactly 1 hit, got $_p — CTL results UNINTERPRETABLE"
916
+ fi
917
+ rm -rf "$_s7"
918
+
838
919
  echo "degrade-scan shell probes: $pass passed, $fail failed"
839
920
 
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env bash
2
+ # test_dispatch_receipt_lanes.sh — lanes for scripts/dispatch_receipt.py (governor's receipt for dispatched edit work).
3
+ # Each lane builds a throwaway git repo under mktemp. Exit: 0 all lanes pass · 1 a lane failed · 10 harness error.
4
+ # codex 2026-10-20 R1 shaped the second half: quoted paths, renames, submodules, swallowed tool errors, rewritten claims, and a
5
+ # revert probe that runs the mismatch lanes themselves against a mutant (they must go red there).
6
+ set -uo pipefail
7
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ R="$HERE/dispatch_receipt.py"
9
+ [ -r "$R" ] || { echo "HARNESS-ERROR: $R missing"; exit 10; }
10
+ command -v python3 >/dev/null || { echo "HARNESS-ERROR: python3 missing"; exit 10; }
11
+ T=$(mktemp -d) || exit 10; trap 'rm -rf "$T"' EXIT
12
+ FAIL=0
13
+ TOOL=$R
14
+ check(){ local want=$1 pat=$2; shift 2; local out rc
15
+ out=$(python3 "$TOOL" "$@" 2>&1); rc=$?
16
+ [ "$rc" = "$want" ] && { [ -z "$pat" ] || grep -qE -- "$pat" <<<"$out"; }; } # here-string, not a pipe: grep -q + pipefail = SIGPIPE flip
17
+ lane(){ local name=$1; shift
18
+ if check "$@"; then echo " ✅ $name"; else echo " ❌ $name — want rc=$1 /$2/"; local o; o=$(python3 "$TOOL" "${@:3}" 2>&1); sed -n '1,8s/^/ /p' <<<"$o"; FAIL=1; fi; }
19
+
20
+ mk(){ local d="$T/$1"; mkdir -p "$d"; git -C "$d" init -q; git -C "$d" config user.email t@t; git -C "$d" config user.name t
21
+ git -C "$d" config commit.gpgsign false; echo base > "$d/base.txt"; echo old > "$d/old.txt"; git -C "$d" add base.txt old.txt
22
+ git -C "$d" commit -qm base; echo "$d"; }
23
+
24
+ echo "── dispatch_receipt lanes ──"
25
+ A=$(mk a); echo x > "$A/a.txt"; echo y > "$A/sp ace.txt"; git -C "$A" add a.txt "sp ace.txt"; git -C "$A" commit -qm work
26
+ lane "L1 claimed = changed → match" 0 'CLAIMED-MATCHES: 2' "$A" HEAD~1 --claimed "a.txt,sp ace.txt"
27
+ lane "L2 claimed a path that did not change" 1 '^ b\.txt$' "$A" HEAD~1 --claimed "a.txt,sp ace.txt,b.txt"
28
+ lane "L3 changed a path the claim left out" 1 '^ sp ace\.txt$' "$A" HEAD~1 --claimed "a.txt"
29
+ lane "L4 no claim: receipt only" 0 'commits=1 paths=2' "$A" HEAD~1
30
+ lane "L4b per-path hash line" 0 '^ path [0-9a-f]{16} +a\.txt$' "$A" HEAD~1
31
+ B=$(mk b)
32
+ lane "L5 nothing changed but paths claimed → rc 1" 1 'CLAIMED-NOT-CHANGED:' "$B" HEAD --claimed "a.txt"
33
+ lane "L5b nothing changed, nothing claimed" 0 'paths=0' "$B" HEAD
34
+ echo dirty >> "$B/base.txt"
35
+ lane "L6 uncommitted tracked change" 1 'NOT-COMMITTED: 1' "$B" HEAD
36
+ lane "L7 unresolvable base → harness error" 10 'HARNESS-ERROR' "$A" no-such-ref
37
+ lane "L8 not a directory → harness error" 10 'not a directory' "$T/nope" HEAD
38
+ lane "L9 usage" 2 'usage:' "$A"
39
+ lane "L9b unknown option" 2 'usage:' "$A" HEAD --bogus
40
+ # ── codex R1 cases ──
41
+ C=$(mk c); git -C "$C" mv old.txt new.txt; git -C "$C" commit -qm mv
42
+ lane "R1 a rename lists BOTH paths (claiming only the new one is rc 1)" 1 '^ old\.txt$' "$C" HEAD~1 --claimed "new.txt"
43
+ lane "R1b claiming both sides of the move matches" 0 'CLAIMED-MATCHES: 2' "$C" HEAD~1 --claimed "new.txt,old.txt"
44
+ D=$(mk d); printf 'z\n' > "$D/$(printf 'nl\nname')"; git -C "$D" add -A; git -C "$D" commit -qm nl
45
+ git -C "$D" -c core.quotePath=true diff --name-only HEAD~1 HEAD > "$T/claim_quoted" # git's own quoted spelling, taken from git
46
+ grep -qx '"nl\\nname"' "$T/claim_quoted" || { echo "HARNESS-ERROR: fixture is not git's quoted spelling: $(cat "$T/claim_quoted")"; exit 10; }
47
+ lane "R2 git's quoted spelling of a newline path is not that path" 1 'CLAIMED-NOT-CHANGED' "$D" HEAD~1 --claimed-file "$T/claim_quoted"
48
+ printf 'nl\nname\0' > "$T/claim_nul"
49
+ lane "R2b the real newline path (NUL-separated claim) matches" 0 'CLAIMED-MATCHES: 1' "$D" HEAD~1 --claimed-file "$T/claim_nul"
50
+ lane "R3 a claim with a stray space is refused, not rewritten" 2 'leading/trailing space' "$A" HEAD~1 --claimed " a.txt,sp ace.txt"
51
+ lane "R3b an empty entry (trailing comma) is refused" 2 'empty entry' "$A" HEAD~1 --claimed "a.txt,sp ace.txt,"
52
+ lane "R3c a duplicate entry is refused" 2 'duplicate' "$A" HEAD~1 --claimed "a.txt,a.txt"
53
+ E=$(mk e); S=$(mk sub); git -C "$E" -c protocol.file.allow=always submodule add -q "$S" sm 2>/dev/null; git -C "$E" commit -qm sm
54
+ lane "R4 a submodule is shown as a submodule, not hashed as a blob" 0 '^ path submodule [0-9a-f]{12} +sm$' "$E" HEAD~1
55
+ SIDE=$(git -C "$A" commit-tree "HEAD~1^{tree}" -p HEAD~1 -m side) # same repo, diverged: not an ancestor of HEAD
56
+ lane "R5 base not an ancestor of head → harness error" 10 'not an ancestor' "$A" "$SIDE"
57
+ lane "R5b (a foreign sha is unresolvable here)" 10 'HARNESS-ERROR' "$A" 0000000000000000000000000000000000000001
58
+
59
+ # ── codex R2 cases ──
60
+ F=$(mk f); S2=$(mk sub2); git -C "$F" -c protocol.file.allow=always submodule add -q "$S2" sm 2>/dev/null; git -C "$F" commit -qm sm
61
+ echo more > "$S2/m.txt"; git -C "$S2" add m.txt; git -C "$S2" commit -qm m; git -C "$F/sm" pull -q 2>/dev/null; git -C "$F" add sm; git -C "$F" commit -qm bump
62
+ git -C "$F" config diff.ignoreSubmodules all
63
+ lane "R6 repo config diff.ignoreSubmodules=all cannot hide a gitlink bump" 1 '^ sm$' "$F" HEAD~1 --claimed "x.txt"
64
+ G=$(mk g); git -C "$G" update-index --assume-unchanged base.txt; echo edited >> "$G/base.txt"
65
+ lane "R7 an assume-unchanged edit makes «committed» unprovable" 1 'UNPROVABLE-CLEAN: 1' "$G" HEAD
66
+ printf 'a.txt\n\n' > "$T/claim_dbl"
67
+ lane "R8 a doubled trailing terminator is an empty entry" 2 'empty entry' "$A" HEAD~1 --claimed-file "$T/claim_dbl"
68
+ printf 'a.txt\n' > "$T/claim_one"
69
+ lane "R9 a duplicate across --claimed and --claimed-file is refused" 2 'across claim options' "$A" HEAD~1 --claimed "a.txt,sp ace.txt" --claimed-file "$T/claim_one"
70
+ lane "R9b … and across two --claimed options" 2 'across claim options' "$A" HEAD~1 --claimed "a.txt" --claimed "a.txt"
71
+
72
+ # ── codex R3 cases ──
73
+ H=$(mk h); mkdir -p "$H/sub"; echo s > "$H/sub/in.txt"; git -C "$H" add sub/in.txt; git -C "$H" commit -qm sub; echo o >> "$H/old.txt"; git -C "$H" commit -qam outside
74
+ git -C "$H" config diff.relative true
75
+ lane "R10 run from a subdirectory with diff.relative=true still sees the outside change" 1 '^ old\.txt$' "$H/sub" HEAD~1 --claimed "x.txt"
76
+ I=$(mk i); echo y > "$I/z.txt"; git -C "$I" add z.txt; git -C "$I" commit -qm z
77
+ if out=$(GIT_DIR="$B/.git" GIT_WORK_TREE="$B" python3 "$R" "$I" HEAD~1 --claimed "z.txt" 2>&1) && grep -q 'CLAIMED-MATCHES: 1' <<<"$out"; then
78
+ echo " ✅ R11 inherited GIT_DIR/GIT_WORK_TREE do not redirect the measurement"
79
+ else echo " ❌ R11 inherited GIT_DIR redirected the receipt"; sed -n '1,5s/^/ /p' <<<"$out"; FAIL=1; fi
80
+
81
+ # ── revert probe: neuter the claimed-vs-actual comparison; the mismatch lanes (L2, L3, L5, R1) must go RED on the mutant ──
82
+ M="$T/mut.py"; sed 's/missing, extra = sorted(claim - actual), sorted(actual - claim)/missing, extra = [], []/' "$R" > "$M"
83
+ if grep -q 'missing, extra = \[\], \[\]' "$M"; then
84
+ TOOL=$M; red=0
85
+ check 1 '^ b\.txt$' "$A" HEAD~1 --claimed "a.txt,sp ace.txt,b.txt" || red=$((red+1))
86
+ check 1 '^ sp ace\.txt$' "$A" HEAD~1 --claimed "a.txt" || red=$((red+1))
87
+ check 1 'CLAIMED-NOT-CHANGED:' "$B" HEAD --claimed "a.txt" || red=$((red+1))
88
+ check 1 '^ old\.txt$' "$C" HEAD~1 --claimed "new.txt" || red=$((red+1))
89
+ TOOL=$R
90
+ if [ "$red" = 4 ]; then echo " ✅ RV comparison off → 4/4 mismatch lanes red on the mutant"
91
+ else echo " ❌ RV only $red/4 mismatch lanes went red on the mutant — they do not measure the comparison"; FAIL=1; fi
92
+ else echo " ❌ RV mutation did not apply (HARNESS-ERROR in the probe)"; FAIL=1; fi
93
+
94
+ [ "$FAIL" = 0 ] && echo "── all lanes ok ──"
95
+ exit "$FAIL"
@@ -119,6 +119,36 @@ else
119
119
  no "L7 되돌림 전이" "주입rc=$INJ 복원rc=$RST 잔존=$LEFT"
120
120
  fi
121
121
 
122
+ # L9 — 2026-10-20: 이름 대체 찾기는 git 이면 «추적된» 파일만 본다. 미추적 사본(실험 복제본)이 이름을 겹치게 해 보정이 거짓 실패하던 것.
123
+ G8="$TMP/l8repo"; mkdir -p "$G8/templates" "$G8/junk/a" "$G8/junk/b" "$TMP/l8plain"
124
+ git -C "$G8" init -q && echo t > "$G8/templates/known.sh" && git -C "$G8" add templates/known.sh \
125
+ && git -C "$G8" -c user.email=t@t -c user.name=t -c commit.gpgsign=false commit -qm k
126
+ cp "$G8/templates/known.sh" "$G8/junk/a/known.sh"; cp "$G8/templates/known.sh" "$G8/junk/b/known.sh"; echo u > "$G8/junk/a/only_untracked.sh"
127
+ echo p > "$TMP/l8plain/plain.sh"
128
+ L8=$(python3 - "$SCAN" "$G8" "$TMP/l8plain" <<'PY8'
129
+ import importlib.util, sys
130
+ spec = importlib.util.spec_from_file_location("s", sys.argv[1]); m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
131
+ g, plain = sys.argv[2], sys.argv[3]
132
+ a = m.resolve(g, "scripts/known.sh")
133
+ b = m.resolve(g, "scripts/only_untracked.sh")
134
+ c = m.resolve(plain, "x/plain.sh")
135
+ print("A=%s B=%s C=%s" % (bool(a and a.endswith("templates/known.sh")), b is None, bool(c and c.endswith("plain.sh"))))
136
+ PY8
137
+ )
138
+ if [ "$L8" = "A=True B=True C=True" ]; then ok "L9 이름 찾기: 미추적 사본 둘이 있어도 추적된 하나 · 미추적에만 있으면 없음 · git 밖은 종전대로"
139
+ else no "L9 이름 찾기 (추적 파일 기준)" "$L8"; fi
140
+
141
+ # L9b — codex R1: git 이 «git 밖» 이 아닌 이유로 실패하면 옛 전체 훑기로 돌아가지 않고 못 찾은 것으로 닫힌다
142
+ mkdir -p "$TMP/fakegit"; printf '#!/bin/sh\necho "fatal: index file corrupt" >&2\nexit 128\n' > "$TMP/fakegit/git"; chmod +x "$TMP/fakegit/git"
143
+ L9B=$(PATH="$TMP/fakegit:/usr/bin:/bin" python3 - "$SCAN" "$G8" <<'PY9'
144
+ import importlib.util, sys
145
+ spec = importlib.util.spec_from_file_location("s", sys.argv[1]); m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
146
+ print("FAILED=%s R=%s" % (m._tracked(sys.argv[2]) == m._INVENTORY_FAILED, m.resolve(sys.argv[2], "templates/known.sh")))
147
+ PY9
148
+ )
149
+ if [ "$L9B" = "FAILED=True R=None" ]; then ok "L9b git 목록 실패 → 못 찾음(닫힌 쪽) · 옛 전체 훑기로 안 떨어진다"
150
+ else no "L9b git 목록 실패의 방향" "$L9B"; fi
151
+
122
152
  echo "── PASS=$PASS FAIL=$FAIL ──"
123
153
  [ "$FAIL" -eq 0 ] || { echo "FAILED=1"; exit 1; }
124
154
  echo "FAILED=0"
@@ -89,10 +89,11 @@ run_new() {
89
89
  echo "── ② frontier digest"
90
90
  hasnt "$S" "$F8" "$T/f8.sent" "frontier" "L8 old diagnosis file, fresh digest → silent"
91
91
  has "$S" "$F9" "$T/f9.sent" "frontier_digest 10d" "L9 KP: digest 10d → warns"
92
- echo "── ③ sim Area B"
93
- has "$S" "$F4" "$T/f4.sent" "FH internal sim 40d" "L4 area_D run does not reset Area B clock"
94
- has "$S" "$F5" "$T/f5.sent" "FH internal sim 116d" "L5 KP: Area B 116d → warns (true alarm kept)"
92
+ echo "── ③ sim Area B — event-bound since 2026-10-19: no terminal line at any age"
93
+ hasnt "$S" "$F4" "$T/f4.sent" "FH internal sim" "L4 Area B 40d → silent (event-bound, no clock)"
94
+ hasnt "$S" "$F5" "$T/f5.sent" "FH internal sim" "L5 Area B 116d → silent (the old true alarm is retired by decision)"
95
95
  hasnt "$S" "$F1" "$T/f1.sent" "FH internal sim" "L5b Area B 3d → silent"
96
+ has "$S" "$F2" "$T/f2.sent" "weekly_audit 10d" "L5c control: the banner still prints (removal did not silence ①)"
96
97
  echo "── ④ sentinels"
97
98
  for m in projA_mapping_skipped projB_wizard_done projC_wizard_declined projD_wizard_reminder_muted; do
98
99
  hasnt "$S" "$F6" "$S6" "$m sentinel" "L6 state marker $m not aged"
@@ -127,11 +128,15 @@ probe() { # name sed-expr lane-fn
127
128
  }
128
129
  lane1() { hasnt "$1" "$F1" "$T/f1.sent" "weekly audit history" "L1-probe"; }
129
130
  lane2() { hasnt "$1" "$F8" "$T/f8.sent" "frontier" "L8-probe"; has "$1" "$F9" "$T/f9.sent" "frontier_digest 10d" "L9-probe"; }
130
- lane3() { has "$1" "$F4" "$T/f4.sent" "FH internal sim 40d" "L4-probe"; }
131
+ # lane3: the retired ③ — a warning-presence mutant: insert an Area B line (no threshold, no dir guard)
132
+ # in a copy; the 116d fixture must make it speak, so the lane proves «no Area B line» is really asserted
133
+ lane3() { hasnt "$1" "$F5" "$T/f5.sent" "FH internal sim" "L5-probe"; }
131
134
  lane4() { hasnt "$1" "$F6" "$S6" "projA_mapping_skipped sentinel" "L6-probe"; }
132
135
  probe weekly 's#tracks/_audit"/weekly_audit_\*\.md#tracks/_audit"/harvest_*.md#' lane1
133
136
  probe frontier 's#tracks/_meta"/frontier_digest_\*\.md#knowledge/shared/harness-core"/harness_frontier_diagnosis_*.md#' lane2
134
- probe sim 's#sim_\*_area_B\*\.md#sim_*.md#' lane3
137
+ probe sim '/# ④ Custom sentinels/i\
138
+ local -a _fh_sims; _fh_sims=( "${FH_DIR}/tracks/_meta"/sim_*_area_B*.md(N.om) ); local sim="${_fh_sims[1]:-}"; [[ -n "$sim" ]] \&\& warns+=("FH internal sim (re-inserted mutant)")
139
+ ' lane3
135
140
  probe sentinel '/\*_wizard_done|\*_mapping_skipped/d' lane4
136
141
  lane5() { hasntk "$1" "$F10" "$T/f10.sent" "weekly_audit" "L10-probe"; }
137
142
  probe emulate '/^ emulate -L zsh$/d' lane5
@@ -250,13 +250,83 @@ check_out "cross: both legs' findings survive the union" 2 'FH_GATE_LEGS: claude
250
250
  run_cross "$CROSS_BLOCK" "$CROSS_BLOCK"
251
251
  # A machine with only one family is the COMMON case, not an edge case. It must not be silent.
252
252
  ONELEG="$TMPROOT/oneleg"; mkdir -p "$ONELEG"; cp "$FAKEBIN/claude" "$ONELEG/claude"
253
- check_out "cross: codex absent → single leg, DECORRELATED: no" 0 'FH_GATE_DECORRELATED: no' \
253
+ # the gate needs jq; with PATH cut to $ONELEG:/usr/bin:/bin a Homebrew-only jq vanishes and every single-leg lane
254
+ # would end at 10 before reaching the code under test (codex R1, 2026-10-22) — carry jq, never the other backend
255
+ _jq=$(command -v jq 2>/dev/null) && [ ! -e "$ONELEG/jq" ] && ln -s "$_jq" "$ONELEG/jq"
256
+ check_out "cross: codex absent → single leg, DECORRELATED: no" 3 'FH_GATE_DECORRELATED: no' \
254
257
  env PATH="$ONELEG:/usr/bin:/bin" FH_BACKEND=cross FH_MODEL=fake \
255
258
  FAKE_PAYLOAD_CLAUDE="$CROSS_PASS" FAKE_PAYLOAD="$CROSS_PASS" \
256
259
  bash "$GATE" "$SUBJECT" quick test
260
+ # 🟥 2026-10-22: a single-leg PASS used to exit 0 — the same code as a two-family PASS, so a caller that reads
261
+ # only the exit code (a pre-commit hook, `fh-gate && merge`) could not tell them apart; only text lines differed
262
+ # (LLM call-site inventory, arXiv:2610.24545). Cross was REQUESTED, so a run that could not provide it is not
263
+ # a pass: it goes to a person (ESCALATE, 3) with the reason in a machine-readable line.
264
+ check_out "cross: single leg PASS → ESCALATE (3), not a pass" 3 'FH_GATE_VERDICT: ESCALATE' \
265
+ env PATH="$ONELEG:/usr/bin:/bin" FH_BACKEND=cross FH_MODEL=fake \
266
+ FAKE_PAYLOAD_CLAUDE="$CROSS_PASS" FAKE_PAYLOAD="$CROSS_PASS" \
267
+ bash "$GATE" "$SUBJECT" quick test
268
+ check_out "cross: single leg PASS → the reason is machine-readable" 3 '^FH_GATE_ESCALATE_REASON: cross-degraded' \
269
+ env PATH="$ONELEG:/usr/bin:/bin" FH_BACKEND=cross FH_MODEL=fake \
270
+ FAKE_PAYLOAD_CLAUDE="$CROSS_PASS" FAKE_PAYLOAD="$CROSS_PASS" \
271
+ bash "$GATE" "$SUBJECT" quick test
272
+ CROSS_PEND='{"status":"SUCCESS","verdict":"PENDING","findings_count":1,"findings_a":0,"findings_b":1,"findings":[{"grade":"B","location":"x:1","title":"t","evidence":"e","fix":"f"}]}'
273
+ check_out "cross: single leg PENDING → ESCALATE (1 is «proceed»)" 3 'FH_GATE_VERDICT: ESCALATE' \
274
+ env PATH="$ONELEG:/usr/bin:/bin" FH_BACKEND=cross FH_MODEL=fake \
275
+ FAKE_PAYLOAD_CLAUDE="$CROSS_PEND" FAKE_PAYLOAD="$CROSS_PEND" \
276
+ bash "$GATE" "$SUBJECT" quick test
277
+ # control: a single-leg BLOCKED keeps its own, stricter code
278
+ check_out "cross: single leg BLOCKED stays BLOCKED (2)" 2 'FH_GATE_VERDICT: BLOCKED' \
279
+ env PATH="$ONELEG:/usr/bin:/bin" FH_BACKEND=cross FH_MODEL=fake \
280
+ FAKE_PAYLOAD_CLAUDE="$CROSS_BLOCK" FAKE_PAYLOAD="$CROSS_BLOCK" \
281
+ bash "$GATE" "$SUBJECT" quick test
282
+ # the explicit, logged override keeps the leg's verdict — and says so in the output
283
+ check_out "cross: single leg + FH_GATE_CROSS_ALLOW_SINGLE=1 → PASS, override logged" 0 '^FH_GATE_CROSS_OVERRIDE: FH_GATE_CROSS_ALLOW_SINGLE=1' \
284
+ env PATH="$ONELEG:/usr/bin:/bin" FH_BACKEND=cross FH_MODEL=fake FH_GATE_CROSS_ALLOW_SINGLE=1 \
285
+ FAKE_PAYLOAD_CLAUDE="$CROSS_PASS" FAKE_PAYLOAD="$CROSS_PASS" \
286
+ bash "$GATE" "$SUBJECT" quick test
287
+ # control: the override is exact — any other value does not unlock it
288
+ check_out "cross: FH_GATE_CROSS_ALLOW_SINGLE=yes is not the override" 3 'FH_GATE_VERDICT: ESCALATE' \
289
+ env PATH="$ONELEG:/usr/bin:/bin" FH_BACKEND=cross FH_MODEL=fake FH_GATE_CROSS_ALLOW_SINGLE=yes \
290
+ FAKE_PAYLOAD_CLAUDE="$CROSS_PASS" FAKE_PAYLOAD="$CROSS_PASS" \
291
+ bash "$GATE" "$SUBJECT" quick test
257
292
  check "cross: no family available → fails closed" 10 \
258
293
  env PATH="/usr/bin:/bin" FH_BACKEND=cross bash "$GATE" "$SUBJECT" quick test
259
294
 
295
+ # An unexpected failure must not leave as status 1 (= PENDING, "proceed"). Reported from outside
296
+ # (2026-10-20); measured: `mktemp` failing under `set -e` ended the gate with 1, also through the npm bin.
297
+ check "unexpected failure (mktemp) → HARNESS_ERROR, not PENDING" 10 \
298
+ env TMPDIR="$TMPROOT/does-not-exist" FH_DRY_RUN=1 bash "$GATE" "$SUBJECT" quick test
299
+ check "unexpected failure via npm bin → HARNESS_ERROR, not PENDING" 10 \
300
+ env TMPDIR="$TMPROOT/does-not-exist" FH_DRY_RUN=1 node bin/fh-gate.js "$SUBJECT" quick test
301
+ # `set -u` ends the script with 1 WITHOUT firing ERR — only the exit-time check sees it (cross-family review).
302
+ # Outside an FH checkout the record base falls back to $HOME, so an unset HOME is an unbound variable there.
303
+ # cross mode must pass a leg's 11/12 through — every leg gets the same arguments (local-model self-audit
304
+ # candidate, reproduced 2026-10-20: both came out as 10). Control: the non-cross bad level is 11.
305
+ check "cross + bad gate level → 11 (argument error), not 10" 11 \
306
+ env PATH="$FAKEBIN:/usr/bin:/bin" FH_BACKEND=cross FH_MODEL=fake bash "$GATE" "$SUBJECT" medium test
307
+ check "cross + FH_DRY_RUN=1 → 12 (dry-run), not 10" 12 \
308
+ env PATH="$FAKEBIN:/usr/bin:/bin" FH_BACKEND=cross FH_DRY_RUN=1 FH_MODEL=fake bash "$GATE" "$SUBJECT" quick test
309
+ check_out "cross + FH_DRY_RUN=1 → the prompt is printed" 12 'FH GOVERNANCE GATE' \
310
+ env PATH="$FAKEBIN:/usr/bin:/bin" FH_BACKEND=cross FH_DRY_RUN=1 FH_MODEL=fake bash "$GATE" "$SUBJECT" quick test
311
+ check "control: non-cross bad gate level → 11" 11 \
312
+ env PATH="$FAKEBIN:/usr/bin:/bin" FH_BACKEND=claude FH_MODEL=fake bash "$GATE" "$SUBJECT" medium test
313
+ # With stderr closed every message fails; the handlers' own messages must not stop their `exit`, and a real
314
+ # verdict must keep its code (cross-family review round 2: `--invalid 2>&-` returned 1).
315
+ check "stderr closed + unexpected failure → still HARNESS_ERROR" 10 \
316
+ env TMPDIR="$TMPROOT/does-not-exist" FH_DRY_RUN=1 bash -c 'exec 2>&-; exec bash "$@"' _ "$GATE" "$SUBJECT" quick test
317
+ # With stderr closed a PASS run either keeps 0 or fails closed with 10 — which one depends on whether some
318
+ # ordinary `>&2` line on the way fails first (macOS bash 3.2 here: 0; the Linux CI runner: 10). What it must
319
+ # never do is leave as 1/2/3, i.e. a verdict it did not reach. (First draft pinned 0 and CI showed 10.)
320
+ env PATH="$FAKEBIN:/usr/bin:/bin" FH_BACKEND=claude FH_MODEL=fake FAKE_PAYLOAD="$CROSS_PASS" \
321
+ bash -c 'exec 2>&-; exec bash "$@"' _ "$GATE" "$SUBJECT" quick test >/dev/null 2>&1
322
+ _sc=$?
323
+ case "$_sc" in
324
+ 0|10) printf 'PASS %-58s (exit %s)\n' "stderr closed + PASS run → 0 or 10, never a lower verdict" "$_sc"; pass=$((pass + 1)) ;;
325
+ *) printf 'FAIL %-58s expected 0 or 10, got %s\n' "stderr closed + PASS run → 0 or 10, never a lower verdict" "$_sc"; fail=$((fail + 1)) ;;
326
+ esac
327
+ check "unbound variable (HOME unset, outside a checkout) → HARNESS_ERROR" 10 \
328
+ env -u HOME FH_DRY_RUN=1 bash -c 'cd "$1" && exec bash "$2" "$3" quick test' _ "$TMPROOT" "$PWD/$GATE" "$SUBJECT"
329
+
260
330
  echo
261
331
  echo "────────────────────────────────────────────────────────────────────"
262
332
  printf 'fh-gate regressions: %d passed, %d failed\n' "$pass" "$fail"