@chrono-meta/fh-gate 2.7.0 → 2.9.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 (47) hide show
  1. package/.claude/rules/fh_4axis_gate.md +33 -5
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/AGENTS.md +4 -0
  4. package/CLAUDE.md +169 -183
  5. package/README.ja.md +157 -53
  6. package/README.ko.md +147 -50
  7. package/README.md +136 -50
  8. package/README.zh.md +137 -46
  9. package/docs/ETHOS.md +20 -8
  10. package/docs/GATE_DAY.md +235 -0
  11. package/docs/OUTPUT_EVIDENCE.md +13 -2
  12. package/docs/codex-compat.md +10 -2
  13. package/knowledge/shared/dialogue/ai_dialogue_playbook.md +131 -0
  14. package/knowledge/shared/harness-core/agents_md_runtime_details.md +10 -3
  15. package/knowledge/shared/harness-core/claude_md_gate_details.md +90 -0
  16. package/knowledge/shared/harness-core/dispatch_conditional_prohibition.md +75 -0
  17. package/knowledge/shared/harness-core/fh_three_layer_canon.md +97 -5
  18. package/knowledge/shared/harness-core/field_verdict_crossfamily_gate.md +96 -5
  19. package/knowledge/shared/harness-core/harness_incubator_doctrine.md +6 -1
  20. package/knowledge/shared/harness-core/ship_readiness_gate.md +2 -2
  21. package/knowledge/shared/learnings/subagent_invocations_log.yaml +137 -0
  22. package/knowledge/shared/rules/multi_session_close_protocol.md +15 -4
  23. package/package.json +12 -2
  24. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  25. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  26. package/plugins/fh-meta/CHANGELOG.md +116 -0
  27. package/plugins/fh-meta/skills/cross-ecosystem-synergy-detection/SKILL.md +127 -0
  28. package/scripts/branch_claim.sh +3 -1
  29. package/scripts/chamber_candidate_collect.sh +71 -13
  30. package/scripts/listing_watch.sh +187 -0
  31. package/scripts/mapped_tracks.sh +113 -0
  32. package/scripts/package_coverage_check.sh +54 -0
  33. package/scripts/prior_art_prompt.sh +49 -2
  34. package/scripts/selfcheck.sh +44 -1
  35. package/scripts/session_close_check.sh +56 -3
  36. package/scripts/test_chamber_sig_lanes.sh +151 -0
  37. package/scripts/test_leak_scan_control_lanes.sh +163 -0
  38. package/scripts/test_listing_watch_lanes.sh +162 -0
  39. package/scripts/test_mapped_tracks_lanes.sh +162 -0
  40. package/scripts/test_peer_worktree_detect_lanes.sh +138 -0
  41. package/scripts/test_prepush_destructive_lanes.sh +366 -0
  42. package/scripts/test_prior_art_prompt_lanes.sh +48 -0
  43. package/scripts/test_regression_guard_ci_lanes.sh +124 -0
  44. package/scripts/test_wizard_snippet_merge_lanes.sh +40 -0
  45. package/templates/predelete_check.test.sh +56 -0
  46. package/templates/regression_guard.sh +75 -3
  47. package/templates/settings.PriorArt.snippet.json +41 -12
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env bash
2
+ # test_listing_watch_lanes.sh — listing_watch.sh 의 레인.
3
+ # 🟥 네트워크를 안 쓴다: PATH 앞에 `gh` 스텁을 놓아 응답을 고정한다.
4
+ # (실망 사용 검증은 `--selftest` 가 known-pair 로 따로 한다 — 그건 네트워크가 필요하다)
5
+ HUB="${CLAUDE_PROJECT_DIR:-$(cd "$(dirname "$0")/.." && pwd)}"
6
+ SUT="$HUB/scripts/listing_watch.sh"
7
+ PASS=0; FAIL=0
8
+ ok(){ PASS=$((PASS+1)); printf ' ✅ %s\n' "$1"; }
9
+ ng(){ FAIL=$((FAIL+1)); printf ' ❌ %s\n 기대: %s\n 실제: %s\n' "$1" "$2" "$3"; }
10
+
11
+ SB=$(mktemp -d); trap 'rm -rf "$SB"' EXIT
12
+ mkdir -p "$SB/tracks/_meta" "$SB/bin"
13
+
14
+ mkstub(){ # $1 = state|merged|badexit
15
+ cat > "$SB/bin/gh" <<STUB
16
+ #!/usr/bin/env bash
17
+ case "\$*" in
18
+ *"contents/README.md"*) printf '%s' "\$(printf 'chrono-meta/forge-harness' | base64)" ;;
19
+ # 🟥 본체 jq 는 4필드다: state|merged|라벨개수|라벨목록. 스텁이 3필드면 계기가 대상과 어긋난다.
20
+ *"issues/33"*) [ "$1" = "merged" ] && printf 'open|2026-08-19T06:48:10Z|0|' || printf 'open|null|1|validation-passed' ;;
21
+ *"issues/999"*) exit 1 ;;
22
+ *) exit 1 ;;
23
+ esac
24
+ STUB
25
+ chmod +x "$SB/bin/gh"
26
+ }
27
+
28
+ run(){ CLAUDE_PROJECT_DIR="$SB" PATH="$SB/bin:$PATH" bash "$SUT" "$@" 2>&1; }
29
+
30
+ # ── L1: gh 부재 → SKIPPED (pass 아님) ─────────────────────────────
31
+ printf 'walkinglabs/x\t33\tpr\tchrono-meta/forge-harness\n' > "$SB/tracks/_meta/listing_watch_channels.tsv"
32
+ # 🟥 두 번 틀린 자리다. ① 초판: `PATH=/nonexistent` 가 `bash` 까지 지워 «계기» 를 시험했다.
33
+ # ② 2판: `/bin:/usr/bin` 은 **호스트 의존**이다 — 리눅스에선 거기 진짜 gh 가 있을 수 있고
34
+ # 그러면 이 레인이 «대상» 이 아니라 «그 머신» 을 재게 된다(cross-family 지목).
35
+ # ③ 정본: 본체에 주입 seam(`LISTING_WATCH_GH`)을 두고 존재하지 않는 이름을 넣는다.
36
+ o=$(CLAUDE_PROJECT_DIR="$SB" LISTING_WATCH_GH="gh-does-not-exist-$$" bash "$SUT" --force 2>&1); r=$?
37
+ case "$o" in *SKIPPED*) ok "L1 gh 부재 → SKIPPED (not passed)" ;; *) ng "L1" "SKIPPED" "$o" ;; esac
38
+ [ "$r" = "0" ] && ok "L1b gh 부재여도 exit 0 (훅 무음 방지)" || ng "L1b" "0" "$r"
39
+
40
+ # ── L2: 매니페스트 부재 → DISABLED (실패 아님) ────────────────────
41
+ mkstub state
42
+ mv "$SB/tracks/_meta/listing_watch_channels.tsv" "$SB/m.bak"
43
+ o=$(run --force); case "$o" in *DISABLED*) ok "L2 매니페스트 부재 → DISABLED" ;; *) ng "L2" "DISABLED" "$o" ;; esac
44
+ mv "$SB/m.bak" "$SB/tracks/_meta/listing_watch_channels.tsv"
45
+
46
+ # ── L3: 주석만 있는 매니페스트 → DISABLED (0행을 «정상»으로 안 읽는다) ──
47
+ cp "$SB/tracks/_meta/listing_watch_channels.tsv" "$SB/m.bak"
48
+ printf '# only a comment\n' > "$SB/tracks/_meta/listing_watch_channels.tsv"
49
+ o=$(run --force); case "$o" in *DISABLED*) ok "L3 유효행 0 → DISABLED" ;; *) ng "L3" "DISABLED" "$o" ;; esac
50
+ cp "$SB/m.bak" "$SB/tracks/_meta/listing_watch_channels.tsv"
51
+
52
+ # ── L4: 최초 실행 → 스냅샷 생성 + 변화 «없음» ─────────────────────
53
+ rm -f "$SB/tracks/_meta/.listing_watch_state.tsv"
54
+ o=$(run --force)
55
+ case "$o" in *최초*) ok "L4 최초 실행을 «변화» 로 오보하지 않는다" ;; *) ng "L4" "최초 실행 안내" "$o" ;; esac
56
+ [ -s "$SB/tracks/_meta/.listing_watch_state.tsv" ] && ok "L4b 스냅샷 파일 생성" || ng "L4b" "비어있지 않은 스냅샷" "(없음)"
57
+
58
+ # ── L5: 무변화 → 무출력 (오탐 0) ──────────────────────────────────
59
+ o=$(run --force)
60
+ [ -z "$o" ] && ok "L5 무변화 → 무출력" || ng "L5" "(빈 출력)" "$o"
61
+
62
+ # ── L6: 상태 전이 → 검출 ★ 이 레인이 본체다 ──────────────────────
63
+ mkstub merged
64
+ o=$(run --force)
65
+ # 🟥 배너 문구만 보면 «라벨만 바뀐 버그» 도 통과한다 — **관측된 전이 자체**를 단언한다.
66
+ case "$o" in *"바뀌었다"*) ok "L6 변화 배너 발화" ;; *) ng "L6" "변화 보고" "$o" ;; esac
67
+ case "$o" in *MERGED*) ok "L6b 전이 «내용»이 MERGED 로 찍힌다" ;; *) ng "L6b" "지금: … MERGED" "$o" ;; esac
68
+ case "$o" in *"이전:"*) ok "L6c 이전 상태도 같이 보여준다" ;; *) ng "L6c" "이전: …" "$o" ;; esac
69
+
70
+ # ── L7: 스로틀 — 24h 안이면 조용 ──────────────────────────────────
71
+ o=$(run) # --force 없음
72
+ [ -z "$o" ] && ok "L7 스로틀 동작 (24h 내 재실행 조용)" || ng "L7" "(빈 출력)" "$o"
73
+
74
+ # ── L8: API 실패를 «없음» 이 아니라 FAILED 로 ─────────────────────
75
+ printf 'walkinglabs/x\t999\tpr\t-\n' > "$SB/tracks/_meta/listing_watch_channels.tsv"
76
+ rm -f "$SB/tracks/_meta/.listing_watch_state.tsv"
77
+ run --force >/dev/null
78
+ s=$(cat "$SB/tracks/_meta/.listing_watch_state.tsv" 2>/dev/null)
79
+ case "$s" in *FAILED*) ok "L8 API 실패 → FAILED (0 으로 안 접는다)" ;; *) ng "L8" "FAILED" "$s" ;; esac
80
+
81
+ # ── L9: 🟥 FAILED 반복이 «무출력» 이 되면 안 된다 (자기 헤더 배반 방지) ──
82
+ cat > "$SB/bin/gh" <<'STUB'
83
+ #!/usr/bin/env bash
84
+ exit 1
85
+ STUB
86
+ chmod +x "$SB/bin/gh"
87
+ printf 'r/x\t1\tpr\t-\n' > "$SB/tracks/_meta/listing_watch_channels.tsv"
88
+ rm -f "$SB/tracks/_meta/.listing_watch_state.tsv"
89
+ run --force >/dev/null 2>&1 # 1회차: 스냅샷이 FAILED 로 굳는다
90
+ o=$(run --force) # 2회차: 변화는 «없다» — 그래도 말해야 한다
91
+ case "$o" in *FAILED*|*"읽지 못했다"*) ok "L9 FAILED 반복도 매번 보고 (인증만료≠변화없음)" ;; *) ng "L9" "FAILED 보고" "${o:-(무출력)}" ;; esac
92
+
93
+ # ── L10: 연속 탭(빈 필드)에서 needle 이 밀리지 않는다 ──
94
+ mkstub state
95
+ printf 'walkinglabs/x\t33\t\tchrono-meta/forge-harness\n' > "$SB/tracks/_meta/listing_watch_channels.tsv"
96
+ rm -f "$SB/tracks/_meta/.listing_watch_state.tsv"
97
+ run --force >/dev/null 2>&1
98
+ s9=$(cat "$SB/tracks/_meta/.listing_watch_state.tsv" 2>/dev/null)
99
+ case "$s9" in *LISTED*) ok "L10 빈 필드 있어도 needle 이 제자리 (IFS 탭 축약 방지)" ;; *) ng "L10" "LISTED" "$s9" ;; esac
100
+
101
+ # ── L11: 개행 없는 마지막 행도 읽는다 ──
102
+ printf 'walkinglabs/x\t33\tpr\tchrono-meta/forge-harness\nwalkinglabs/y\t33\tpr\tchrono-meta/forge-harness' > "$SB/tracks/_meta/listing_watch_channels.tsv"
103
+ rm -f "$SB/tracks/_meta/.listing_watch_state.tsv"
104
+ run --force >/dev/null 2>&1
105
+ n=$(grep -c . "$SB/tracks/_meta/.listing_watch_state.tsv" 2>/dev/null || echo 0)
106
+ [ "$n" = "2" ] && ok "L11 개행 없는 마지막 행 누락 안 함 (2/2)" || ng "L11" "2행" "${n}행"
107
+
108
+ # ── L12: 라벨 개수를 실어 ["a,b"] 와 ["a","b"] 를 가른다 ──
109
+ case "$s9" in *" "[0-9]*:*) ok "L12 라벨 필드가 «개수:목록» 형태" ;; *) ng "L12" "N:labels" "$s9" ;; esac
110
+
111
+ # ── L13/L14: 🟥 **반대 플랫폼 흉내** — 이 둘이 이 스위트의 하중선이다.
112
+ # 2026-08-21 실측: 로컬(macOS) 16/16 초록인데 **CI(리눅스)에서 L7·L9 가 죽었다.**
113
+ # 원인 둘 다 «한 플랫폼에서만 나는» 형태였다:
114
+ # ⓐ `stat -f %m` 은 GNU 에서 **실패가 아니라 성공하며 파일시스템 정보를 뱉는다**
115
+ # → `||` 폴백이 안 타고 산술식이 깨진다
116
+ # ⓑ grep 패턴의 `\t` 를 GNU grep 은 **리터럴 t** 로 읽는다 → FAILED 보고가 0건
117
+ # 로컬 초록이 증거가 못 된다는 뜻이므로, **여기서 반대 플랫폼을 스텁으로 만든다.**
118
+ mkstub state
119
+ printf 'walkinglabs/x\t33\tpr\tchrono-meta/forge-harness\n' > "$SB/tracks/_meta/listing_watch_channels.tsv"
120
+ rm -f "$SB/tracks/_meta/.listing_watch_state.tsv"
121
+
122
+ # L13: `stat -f` 가 «성공하면서 쓰레기» 를 내는 플랫폼(=GNU)에서도 스로틀이 산다
123
+ cat > "$SB/bin/stat" <<'STUB'
124
+ #!/usr/bin/env bash
125
+ # GNU 흉내: -f 는 성공하며 파일시스템 정보(비숫자)를 낸다 · -c %Y 만 mtime
126
+ if [ "$1" = "-f" ]; then echo " ID: deadbeef Namelen: 255 Type: ext2/ext3"; exit 0; fi
127
+ if [ "$1" = "-c" ]; then echo 1000000000; exit 0; fi
128
+ exit 1
129
+ STUB
130
+ chmod +x "$SB/bin/stat"
131
+ run --force >/dev/null 2>&1 # 스냅샷 생성
132
+ o=$(run 2>&1) # --force 없음 → 스로틀이 조용해야
133
+ case "$o" in
134
+ *"syntax error"*|*"ext2"*) ng "L13 GNU-stat 흉내에서 스로틀 붕괴" "(빈 출력)" "$o" ;;
135
+ "") ok "L13 GNU-stat 흉내에서도 스로틀 정상 (비숫자 mtime 방어)" ;;
136
+ *) ng "L13" "(빈 출력)" "$o" ;;
137
+ esac
138
+ rm -f "$SB/bin/stat"
139
+
140
+ # L14: grep 패턴의 `\t` 를 리터럴 t 로 읽는 플랫폼(=GNU grep)에서도 FAILED 가 보고된다
141
+ # → 실제 탭을 쓰는지 확인. 스크립트가 `\t` 를 패턴에 쓰면 여기서 죽는다.
142
+ cat > "$SB/bin/gh" <<'STUB'
143
+ #!/usr/bin/env bash
144
+ exit 1
145
+ STUB
146
+ chmod +x "$SB/bin/gh"
147
+ cat > "$SB/bin/grep" <<'STUB'
148
+ #!/usr/bin/env bash
149
+ # GNU 흉내: 패턴 안의 백슬래시-t 는 «리터럴 t» 다 (탭이 아니다)
150
+ args=(); for a in "$@"; do case "$a" in *'\t'*) a="${a//\\t/t}" ;; esac; args+=("$a"); done
151
+ exec /usr/bin/grep "${args[@]}"
152
+ STUB
153
+ chmod +x "$SB/bin/grep"
154
+ printf 'r/x\t1\tpr\t-\n' > "$SB/tracks/_meta/listing_watch_channels.tsv"
155
+ rm -f "$SB/tracks/_meta/.listing_watch_state.tsv"
156
+ run --force >/dev/null 2>&1
157
+ o=$(run --force 2>&1)
158
+ case "$o" in *"읽지 못했다"*|*FAILED*) ok "L14 GNU-grep 흉내에서도 FAILED 보고 (실제 탭 사용)" ;; *) ng "L14 grep \\t 이식성" "FAILED 보고" "${o:-(무출력)}" ;; esac
159
+ rm -f "$SB/bin/grep"
160
+
161
+ printf '\nLISTING_WATCH_LANES: %d passed, %d failed\n' "$PASS" "$FAIL"
162
+ [ "$FAIL" -eq 0 ] || exit 1
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env bash
2
+ # test_mapped_tracks_lanes.sh — regression anchor for mapped-track counting across WORKTREES.
3
+ #
4
+ # CLOSES: the mapped-harness signal is the PRESENCE of `tracks/<name>/`, which cannot reach a
5
+ # worktree (tracks/** is gitignored, and at least one mapped track is an EMPTY directory git could
6
+ # not carry regardless). Measured 2026-08-22: main = 11, worktree = 1 — and the synergy skill's
7
+ # Step 3-b closes `skipped(<2 mapped tracks)` as a MANDATORY-PASS value, so a worktree run went
8
+ # green while structurally blind, on the instrument that grades identity ④.
9
+ #
10
+ # HERMETIC: builds its own repo + worktree + tracks fixtures. Never reads the real hub.
11
+ #
12
+ # FIXTURES USE THE BREAKING SPELLINGS ON PURPOSE — an anchor that picks the easy spelling of the
13
+ # thing it guards does not guard it:
14
+ # `the_bible` — underscore in the MIDDLE. A `case *_*` filter eats it. That slip actually happened
15
+ # during the measurement and cost a re-measure; this fixture is why it cannot recur.
16
+ # `pmh-dev` — an EMPTY directory. It is the reason the signal cannot be committed at all, and a
17
+ # counter that skips empty dirs would silently under-report the real hub.
18
+ # `_meta` — LEADING underscore, the only thing that should be excluded.
19
+
20
+ set -uo pipefail
21
+ cd "$(dirname "$0")/.." || exit 1
22
+ SUT="$(pwd -P)/scripts/mapped_tracks.sh"
23
+ PASS=0; FAIL=0
24
+ ok() { echo "✅ $1"; PASS=$((PASS+1)); }
25
+ ng() { echo "❌ $1"; FAIL=$((FAIL+1)); }
26
+
27
+ # 🟥 종료코드는 selfcheck.sh 의 규약을 따른다 — 그 규약은 이미 있었고 초판이 그걸 안 따랐다:
28
+ # 0 = pass · 2 = 볼 때 주체가 없었다 · 10 = 이 스위트 자신의 setup 실패 · 126/127 = 앵커 실행 불가
29
+ # selfcheck 는 2/10/126/127 을 "HARNESS ERROR … 측정 못 한 하네스는 통과한 게 아니다" 로 라벨하고
30
+ # fail=1 을 세운다. 초판은 이 자리들에서 **exit 0** 을 냈고, 그래서 산문은 «not a pass» 라고
31
+ # 적혀 있는데 **기계는 pass 를 냈다** — 부재-단언 관용구가 레인 자신에게 난 형태다.
32
+ # ⚠️ 반대 방향 가드: 정상 통과 경로는 여전히 **exit 0** 이어야 한다. 모든 경로를 비영으로 만들면
33
+ # 그건 수리가 아니라 레인 사망이다(레인 P-4 가 그걸 지킨다).
34
+ [ -f "$SUT" ] || { echo "ⓘ mapped_tracks.sh absent — subject missing when we looked (NOT a pass)"; exit 2; }
35
+
36
+ TMP="$(mktemp -d 2>/dev/null)" || { echo "ⓘ mktemp failed — this suite's own setup broke (NOT a pass)"; exit 10; }
37
+ trap 'rm -rf "$TMP"' EXIT INT TERM
38
+
39
+ git init -q "$TMP/main" 2>/dev/null || { echo "ⓘ git init failed — this suite's own setup broke (NOT a pass)"; exit 10; }
40
+ git -C "$TMP/main" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init 2>/dev/null
41
+ git -C "$TMP/main" worktree add -q -b lanewt "$TMP/wt" 2>/dev/null \
42
+ || { echo "ⓘ git worktree add failed — this suite's own setup broke (NOT a pass)"; exit 10; }
43
+
44
+ mkdir -p "$TMP/main/tracks/the_bible" "$TMP/main/tracks/pmh-dev" \
45
+ "$TMP/main/tracks/qasp" "$TMP/main/tracks/_meta" "$TMP/main/tracks/_audit"
46
+ echo x > "$TMP/main/tracks/the_bible/a.md"
47
+ echo x > "$TMP/main/tracks/qasp/a.md"
48
+ # pmh-dev deliberately left EMPTY
49
+ echo x > "$TMP/main/tracks/_meta/m.md"
50
+ EXPECT=3 # the_bible + pmh-dev + qasp ; _meta and _audit excluded
51
+
52
+ # PREMISE — if the worktree can already see the fixtures, every verdict below is meaningless.
53
+ NAIVE_WT=0
54
+ for d in "$TMP/wt"/tracks/*/; do [ -d "$d" ] || continue; case "$(basename "$d")" in _*) continue;; esac; NAIVE_WT=$((NAIVE_WT+1)); done
55
+ [ "$NAIVE_WT" -lt "$EXPECT" ] \
56
+ && ok "premise: a naive cwd count from the worktree sees $NAIVE_WT of $EXPECT — the blindness is real here" \
57
+ || ng "premise BROKEN: worktree already sees $NAIVE_WT — fixture does not reproduce the defect"
58
+
59
+ run_in() { ( cd "$1" 2>/dev/null && bash "$SUT" 2>&1 ); }
60
+
61
+ # M-1 / M-2: same answer from both standpoints.
62
+ OUT_MAIN=$(run_in "$TMP/main"); OUT_WT=$(run_in "$TMP/wt")
63
+ C_MAIN=$(printf '%s\n' "$OUT_MAIN" | sed -n 's/^count=//p')
64
+ C_WT=$(printf '%s\n' "$OUT_WT" | sed -n 's/^count=//p')
65
+ [ "$C_MAIN" = "$EXPECT" ] && ok "M-1 from MAIN tree → count=$C_MAIN" \
66
+ || ng "M-1 from MAIN tree → count=$C_MAIN, expected $EXPECT"
67
+ [ "$C_WT" = "$EXPECT" ] && ok "M-2 from WORKTREE → count=$C_WT (blindness closed)" \
68
+ || ng "M-2 from WORKTREE → count=$C_WT, expected $EXPECT"
69
+
70
+ # M-3: the worktree says so, rather than passing off the main tree's number as its own.
71
+ case "$OUT_WT" in *in_worktree=yes*) ok "M-3 worktree run declares in_worktree=yes" ;;
72
+ *) ng "M-3 worktree run did not declare its standpoint" ;; esac
73
+ case "$OUT_MAIN" in *in_worktree=no*) ok "M-4 main-tree run declares in_worktree=no (control)" ;;
74
+ *) ng "M-4 main-tree run mislabelled its standpoint" ;; esac
75
+
76
+ # M-5: the breaking spellings are actually counted, not merely tolerated.
77
+ case "$OUT_WT" in *the_bible*) ok "M-5a mid-underscore track (the_bible) is counted" ;;
78
+ *) ng "M-5a the_bible dropped — the 'case *_*' slip has returned" ;; esac
79
+ case "$OUT_WT" in *pmh-dev*) ok "M-5b EMPTY track dir (pmh-dev) is counted" ;;
80
+ *) ng "M-5b empty track dir dropped — under-reports the real hub" ;; esac
81
+ case "$OUT_WT" in *_meta*) ng "M-5c leading-underscore meta dir leaked into the count" ;;
82
+ *) ok "M-5c leading-underscore meta dirs excluded (known-negative)" ;; esac
83
+
84
+ # M-6: not-found is not zero. THE point of the script.
85
+ OUT_OUT=$(cd /tmp && bash "$SUT" 2>&1); RC_OUT=$?
86
+ case "$OUT_OUT" in
87
+ *UNMEASURED*) [ "$RC_OUT" = "3" ] && ok "M-6 outside a repo → UNMEASURED, exit 3 (never count=0)" \
88
+ || ng "M-6 said UNMEASURED but exited $RC_OUT" ;;
89
+ *count=0*) ng "M-6 RENDERED AN UNASKED QUESTION AS ZERO — the exact defect class" ;;
90
+ *) ng "M-6 unexpected output: $OUT_OUT" ;;
91
+ esac
92
+
93
+ # M-7: --count-only stays machine-readable (it is what a caller greps).
94
+ CO=$(cd "$TMP/wt" && bash "$SUT" --count-only 2>&1)
95
+ [ "$CO" = "$EXPECT" ] && ok "M-7 --count-only prints a bare count ($CO)" \
96
+ || ng "M-7 --count-only printed '$CO'"
97
+
98
+ # ── 부재-단언 관용구: 「못 읽었다」가 「없다」로 접히나 (2026-08-23) ─────────────────
99
+ # 🟥 이 축이 초판 레인에 **아예 없었다.** known-negative 가 「레포 밖」 하나뿐이라 M-6 만 재고
100
+ # 있었고, 그래서 10/10 초록이면서 아래 결함이 살아 있었다 — 「컨트롤 있음 ≠ 판별력 있음」의 실물.
101
+ #
102
+ # 권한 조합 실측표 (2026-08-23, 이 레포 · macOS). `-r` 도 `-x` 도 단독으로는 부족하다:
103
+ # chmod 755 → [-r]=r [-x]=x 글롭 항목수 1 ← 셀 수 있다
104
+ # chmod 500 → [-r]=r [-x]=x 글롭 항목수 1 ← 셀 수 있다
105
+ # chmod 111 → [-r]=- [-x]=x 글롭 항목수 0 ← 🟥 `-x` 만 보면 통과시킨다
106
+ # chmod 000 → [-r]=- [-x]=- 글롭 항목수 0
107
+ # ⇒ `[ -r ] && [ -x ]` 가 «글롭이 셀 수 있는가» 와 네 케이스 전부에서 일치한다.
108
+ if [ "$(id -u)" = "0" ]; then
109
+ echo " ⓘ root 로 실행 중 — 권한 레인 UNMEASURED (root 는 퍼미션을 우회한다, 통과 아님)"
110
+ else
111
+ PD=$(mktemp -d); git init -q "$PD" 2>/dev/null
112
+ git -C "$PD" -c user.email=t@t -c user.name=t commit -q --allow-empty -m i 2>/dev/null
113
+ mkdir -p "$PD/tracks/qasp" "$PD/tracks/pmh"
114
+ _perm_run() { ( cd "$PD" 2>/dev/null && bash "$SUT" 2>&1 ); }
115
+ # 전제: 읽을 수 있을 때는 제대로 센다. 이게 아니면 아래 두 레인은 의미가 없다.
116
+ chmod 755 "$PD/tracks"
117
+ chk_c=$(_perm_run | sed -n 's/^count=//p')
118
+ [ "$chk_c" = "2" ] && ok "P-0 전제: readable 일 때 count=2 (계기 판별력)" || ng "P-0 전제 BROKEN: readable 인데 count=$chk_c"
119
+ # 🟥 본체: 못 읽는 디렉터리가 «없다» 로 렌더되면 안 된다.
120
+ chmod 000 "$PD/tracks"; O000=$(_perm_run); chmod 755 "$PD/tracks"
121
+ case "$O000" in
122
+ *UNMEASURED*) ok "P-1 tracks/ 를 못 읽으면 UNMEASURED (count=0 아님)" ;;
123
+ *count=0*) ng "P-1 🔴 못 읽었는데 count=0 — 부재-단언 관용구" ;;
124
+ *) ng "P-1 예상 밖 출력: $(printf '%s' "$O000" | head -1)" ;;
125
+ esac
126
+ chmod 111 "$PD/tracks"; O111=$(_perm_run); chmod 755 "$PD/tracks"
127
+ case "$O111" in
128
+ *UNMEASURED*) ok "P-2 실행만 가능(111)해도 UNMEASURED — \`-x\` 단독 검사로는 못 잡는 자리" ;;
129
+ *count=0*) ng "P-2 🔴 111 에서 count=0 — 판별식이 -x 만 보고 있다" ;;
130
+ *) ng "P-2 예상 밖 출력: $(printf '%s' "$O111" | head -1)" ;;
131
+ esac
132
+ # 🟥 과차단 가드 — 「못 읽음」과 「진짜 0」은 갈려야 한다. 둘 다 막으면 수리가 아니라 회귀다.
133
+ rm -rf "$PD/tracks/qasp" "$PD/tracks/pmh"
134
+ OEMPTY=$(_perm_run); RCE=$?
135
+ case "$OEMPTY" in
136
+ *"status=OK"*count=0*) ok "P-3 과차단 가드: 진짜로 매핑 0개면 여전히 OK count=0 (UNMEASURED 아님)" ;;
137
+ *) ng "P-3 회귀 — 진짜 0을 못 읽음으로 접었다: $(printf '%s' "$OEMPTY" | tr '\n' ' ')" ;;
138
+ esac
139
+ chmod -R 755 "$PD/tracks" 2>/dev/null; rm -rf "$PD"
140
+ fi
141
+
142
+ # 🟥 과차단 가드 — 위 수리가 «모든 경로를 비영으로» 만들지 않았는지. 정상 통과는 exit 0 이어야 한다.
143
+ # 이 레인이 없으면 「측정 못 함을 비영으로」 수리하다가 레인 자체를 죽여도 아무도 모른다.
144
+ # 🟥 재귀 가드 필수 — 이 레인은 자기 스위트를 다시 부른다. 가드가 없으면 중첩 실행이 다시
145
+ # P-4 를 만나 **무한 재귀**한다(초판에서 실제로 그렇게 썼다가 바로 잡았다).
146
+ if [ -z "${MT_LANES_NESTED:-}" ]; then
147
+ # 이 스크립트는 머리에서 레포 루트로 cd 한 상태다(21행). 상대경로가 그래서 성립한다.
148
+ ( MT_LANES_NESTED=1 bash scripts/test_mapped_tracks_lanes.sh >/dev/null 2>&1 )
149
+ _SELF_RC=$?
150
+ [ "$_SELF_RC" = "0" ] && ok "P-4 과차단 가드: 정상 경로는 여전히 exit 0 ($_SELF_RC)" \
151
+ || ng "P-4 🔴 정상 경로가 exit $_SELF_RC — 레인 사망(수리가 아니라 회귀)"
152
+ fi
153
+
154
+ echo "──────────────────────────────────────────────"
155
+ if [ "$FAIL" -eq 0 ]; then
156
+ echo "MAPPED-TRACKS LANES: PASS ($PASS/$PASS)"
157
+ echo " NOT covered: whether the synergy skill (or any other consumer) actually CALLS this."
158
+ echo " A resolver with no caller is prose with a shebang — check the wiring separately."
159
+ exit 0
160
+ else
161
+ echo "MAPPED-TRACKS LANES: FAIL ($FAIL failed · $PASS passed)"; exit 1
162
+ fi
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env bash
2
+ # test_peer_worktree_detect_lanes.sh — regression anchor for ①-c peer detection across WORKTREES.
3
+ #
4
+ # CLOSES: session_close_check.sh ①-c placed peers by DIRECTORY PREFIX ("$FH"/*), which fails
5
+ # structurally for every worktree of the same repo — a worktree lives outside the main tree by
6
+ # definition. Measured 2026-08-22 (tracks/_meta/probe_2026-08-22_A2_replication.md): from the main
7
+ # tree the worktree peer moved NO counter at all; from a worktree the script printed a confident
8
+ # "✅ no live peer" while three live same-repo sessions were running.
9
+ #
10
+ # HERMETIC ON PURPOSE: this builds its OWN throwaway repo + worktree + processes + socket dir. It
11
+ # never reads /tmp/cc-socks and never depends on this repo having a worktree, so it measures the
12
+ # script's logic rather than the machine it happens to run on.
13
+ #
14
+ # KNOWN PAIR — the lane is only trustworthy because it carries both halves:
15
+ # known-POSITIVE : a live session in a different worktree of the SAME repo → must be caught
16
+ # known-NEGATIVE : a live session in a DIFFERENT repo → must NOT be caught,
17
+ # and must not nag (else every close is nagged about unrelated projects, which
18
+ # trains skimming past the lines that matter)
19
+ # A lane that only asserts the positive would pass on a script that flags literally everything.
20
+
21
+ set -uo pipefail
22
+ cd "$(dirname "$0")/.." || exit 1
23
+ REPO_ROOT="$(pwd -P)"
24
+ CC="$REPO_ROOT/scripts/session_close_check.sh"
25
+ PASS=0; FAIL=0
26
+ ok() { echo "✅ $1"; PASS=$((PASS+1)); }
27
+ ng() { echo "❌ $1"; FAIL=$((FAIL+1)); }
28
+
29
+ if [ ! -f "$CC" ]; then
30
+ echo "ⓘ session_close_check.sh absent — lanes UNMEASURED (not a pass)"; exit 0
31
+ fi
32
+
33
+ TMP="$(mktemp -d 2>/dev/null)" || { echo "ⓘ mktemp failed — UNMEASURED"; exit 0; }
34
+ PIDS=""
35
+ cleanup() { for p in $PIDS; do kill "$p" 2>/dev/null; done; rm -rf "$TMP"; }
36
+ trap cleanup EXIT INT TERM
37
+
38
+ # ── fixtures ────────────────────────────────────────────────────────────────────
39
+ mkdir -p "$TMP/socks"
40
+ git init -q "$TMP/main" 2>/dev/null || { echo "ⓘ git init failed — UNMEASURED"; exit 0; }
41
+ git -C "$TMP/main" -c user.email=t@t -c user.name=t commit -q --allow-empty -m init 2>/dev/null
42
+ git -C "$TMP/main" worktree add -q -b lanewt "$TMP/wt" 2>/dev/null \
43
+ || { echo "ⓘ git worktree add failed — UNMEASURED"; exit 0; }
44
+ git init -q "$TMP/otherrepo" 2>/dev/null
45
+
46
+ spawn() { ( cd "$1" && exec sleep 900 >/dev/null 2>&1 </dev/null & echo $! ); }
47
+ P_MAIN=$(spawn "$TMP/main") # known-positive, seen from the worktree's standpoint
48
+ P_WT=$(spawn "$TMP/wt") # known-positive, seen from the main tree's standpoint
49
+ N_OTHER=$(spawn "$TMP/otherrepo") # known-negative
50
+ PIDS="$P_MAIN $P_WT $N_OTHER"
51
+ for p in $PIDS; do touch "$TMP/socks/$p.sock"; done
52
+
53
+ # INSTRUMENT CHECK — if the fixtures did not actually land in different directories, every verdict
54
+ # below is meaningless. Assert the premise before trusting the measurement.
55
+ _cwd_of() {
56
+ if [ -r "/proc/$1/cwd" ]; then readlink "/proc/$1/cwd" 2>/dev/null; return; fi
57
+ command -v lsof >/dev/null 2>&1 || return 0
58
+ lsof -a -p "$1" -d cwd -Fn 2>/dev/null | sed -n 's/^n//p' | head -1
59
+ }
60
+ C_MAIN=$(_cwd_of "$P_MAIN"); C_WT=$(_cwd_of "$P_WT"); C_OTHER=$(_cwd_of "$N_OTHER")
61
+ if [ -z "$C_MAIN" ] || [ -z "$C_WT" ] || [ -z "$C_OTHER" ]; then
62
+ echo "ⓘ cwd of a fixture process is unresolvable here (no /proc, no lsof) — lanes UNMEASURED"; exit 0
63
+ fi
64
+ [ "$C_MAIN" != "$C_WT" ] && [ "$C_WT" != "$C_OTHER" ] \
65
+ && ok "premise: the three fixtures hold three distinct cwds" \
66
+ || ng "premise BROKEN: fixture cwds collide — verdicts below mean nothing"
67
+
68
+ scan() { # $1 = the $FH standpoint to scan from
69
+ FH_PEER_SCAN_FORCE=1 FH_PEER_SOCK_DIR="$TMP/socks" bash "$CC" "$1" 2>&1 | grep '①-c' | head -1
70
+ }
71
+
72
+ # ── W-1/W-2: the same-repo worktree peer is caught from BOTH standpoints ─────────
73
+ # Both directions are asserted because the defect was asymmetric: from the main tree the peer
74
+ # vanished silently; from the worktree the whole set vanished behind a green line.
75
+ OUT_MAIN=$(scan "$TMP/main")
76
+ case "$OUT_MAIN" in
77
+ *"peer CANDIDATE"*"$P_WT"*) ok "W-1 from MAIN tree → the worktree peer ($P_WT) is caught" ;;
78
+ *) ng "W-1 from MAIN tree → worktree peer ($P_WT) NOT caught — got: $OUT_MAIN" ;;
79
+ esac
80
+ OUT_WT=$(scan "$TMP/wt")
81
+ case "$OUT_WT" in
82
+ *"peer CANDIDATE"*"$P_MAIN"*) ok "W-2 from WORKTREE → the main-tree peer ($P_MAIN) is caught" ;;
83
+ *) ng "W-2 from WORKTREE → main-tree peer ($P_MAIN) NOT caught — got: $OUT_WT" ;;
84
+ esac
85
+
86
+ # ── W-3: known-negative — a different repo is NOT claimed as a peer ──────────────
87
+ case "$OUT_WT" in
88
+ *"$N_OTHER"*) ng "W-3 known-negative FAILED — other-repo session ($N_OTHER) claimed as a peer" ;;
89
+ *) ok "W-3 known-negative holds — other-repo session ($N_OTHER) is not claimed as a peer" ;;
90
+ esac
91
+
92
+ # ── W-4: an other-repo peer alone stays GREEN (over-block direction) ─────────────
93
+ # This lane exists to protect the FALSE-POSITIVE direction. A close that nags about every unrelated
94
+ # project trains the runner to skim ①-c, and the same hook carries the destructive-op gate.
95
+ mkdir -p "$TMP/socks_neg"; cp "$TMP/socks/$N_OTHER.sock" "$TMP/socks_neg/"
96
+ OUT_NEG=$(FH_PEER_SCAN_FORCE=1 FH_PEER_SOCK_DIR="$TMP/socks_neg" bash "$CC" "$TMP/wt" 2>&1 | grep '①-c' | head -1)
97
+ case "$OUT_NEG" in
98
+ "✅"*"no live peer"*) ok "W-4 other-repo peer alone → stays green, no nag" ;;
99
+ *) ng "W-4 OVER-BLOCK — other-repo peer alone produced: $OUT_NEG" ;;
100
+ esac
101
+ # ...and it is green about something it actually counted, not by discarding it silently.
102
+ case "$OUT_NEG" in
103
+ *"in other repo(s)"*) ok "W-5 the green line ACCOUNTS for the excluded peer (measured, not dropped)" ;;
104
+ *) ng "W-5 green line hides what it excluded — got: $OUT_NEG" ;;
105
+ esac
106
+
107
+ # ── W-6: cwd readable but in NO repo → UNPLACEABLE, never 'absent' ──────────────
108
+ # not-found != zero. This is the counter whose absence let the original `case` fall through.
109
+ mkdir -p "$TMP/norepo" "$TMP/socks_off"
110
+ N_OFF=$(spawn "$TMP/norepo"); PIDS="$PIDS $N_OFF"; touch "$TMP/socks_off/$N_OFF.sock"
111
+ OUT_OFF=$(FH_PEER_SCAN_FORCE=1 FH_PEER_SOCK_DIR="$TMP/socks_off" bash "$CC" "$TMP/wt" 2>&1 | grep '①-c' | head -1)
112
+ case "$OUT_OFF" in
113
+ *UNPLACEABLE*) ok "W-6 no-repo peer → surfaced as UNPLACEABLE, not as 'no live peer'" ;;
114
+ *) ng "W-6 no-repo peer rendered as absence — got: $OUT_OFF" ;;
115
+ esac
116
+
117
+ # ── W-7: ①-c stays ADVISORY — it must never change the exit code ────────────────
118
+ # The close push blocks on this script. Peer detection is a "go ask someone" signal, not a close
119
+ # invariant, and a new blocking source would train `--no-verify` on the hook that also carries the
120
+ # destructive-op gate. Same $FH, loud vs empty peer set → identical exit code.
121
+ mkdir -p "$TMP/socks_empty"
122
+ FH_PEER_SCAN_FORCE=1 FH_PEER_SOCK_DIR="$TMP/socks" bash "$CC" "$TMP/wt" >/dev/null 2>&1; RC_LOUD=$?
123
+ FH_PEER_SCAN_FORCE=1 FH_PEER_SOCK_DIR="$TMP/socks_empty" bash "$CC" "$TMP/wt" >/dev/null 2>&1; RC_QUIET=$?
124
+ [ "$RC_LOUD" = "$RC_QUIET" ] \
125
+ && ok "W-7 ①-c is advisory — exit code identical with peers ($RC_LOUD) and without ($RC_QUIET)" \
126
+ || ng "W-7 ①-c CHANGED the exit code ($RC_QUIET → $RC_LOUD) — it must not block a close"
127
+
128
+ echo "──────────────────────────────────────────────"
129
+ if [ "$FAIL" -eq 0 ]; then
130
+ echo "PEER-WORKTREE-DETECT LANES: PASS ($PASS/$PASS)"
131
+ echo " Scope: repo-identity placement + the over-block direction. NOT covered: whether the env"
132
+ echo " gate (CLAUDE_CODE_CHILD_SESSION) stands correctly in a real top-level session — every"
133
+ echo " lane here forces the scan with FH_PEER_SCAN_FORCE=1, the same residual ①-c already names."
134
+ exit 0
135
+ else
136
+ echo "PEER-WORKTREE-DETECT LANES: FAIL ($FAIL failed · $PASS passed)"
137
+ exit 1
138
+ fi