@chrono-meta/fh-gate 2.8.0 → 2.9.1
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.
- package/.claude/rules/fh_4axis_gate.md +33 -5
- package/.claude-plugin/marketplace.json +2 -2
- package/AGENTS.md +5 -0
- package/CLAUDE.md +47 -12
- package/README.ja.md +44 -29
- package/README.ko.md +43 -28
- package/README.md +48 -33
- package/README.zh.md +41 -28
- package/docs/ETHOS.md +48 -8
- package/docs/GATE_DAY.md +235 -0
- package/docs/OUTPUT_EVIDENCE.md +13 -2
- package/docs/codex-compat.md +10 -2
- package/knowledge/shared/harness-core/agents_md_runtime_details.md +10 -3
- package/knowledge/shared/harness-core/fh_three_layer_canon.md +20 -2
- package/knowledge/shared/harness-core/field_verdict_crossfamily_gate.md +23 -5
- package/knowledge/shared/harness-core/harness_incubator_doctrine.md +6 -1
- package/knowledge/shared/harness-core/measurement-integrity-checklist.md +31 -0
- package/knowledge/shared/harness-core/ship_readiness_gate.md +2 -2
- package/knowledge/shared/learnings/subagent_invocations_log.yaml +31 -0
- package/knowledge/shared/rules/multi_session_close_protocol.md +8 -1
- package/package.json +17 -3
- package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/CHANGELOG.md +122 -0
- package/plugins/fh-meta/skills/cross-ecosystem-synergy-detection/SKILL.md +93 -3
- package/scripts/chamber_candidate_collect.sh +71 -13
- package/scripts/compaction_probe.sh +17 -2
- package/scripts/fh-gate.sh +58 -0
- package/scripts/files_manifest_shipping_check.sh +314 -0
- package/scripts/mapped_tracks.sh +113 -0
- package/scripts/package_coverage_check.sh +54 -0
- package/scripts/postinstall_notice.js +9 -2
- package/scripts/prior_art_prompt.sh +49 -2
- package/scripts/selfcheck.sh +58 -2
- package/scripts/session_close_check.sh +56 -3
- package/scripts/test_chamber_sig_lanes.sh +151 -0
- package/scripts/test_files_manifest_shipping_lanes.sh +260 -0
- package/scripts/test_leak_scan_control_lanes.sh +163 -0
- package/scripts/test_mapped_tracks_lanes.sh +162 -0
- package/scripts/test_peer_worktree_detect_lanes.sh +138 -0
- package/scripts/test_prepush_destructive_lanes.sh +366 -0
- package/scripts/test_prior_art_prompt_lanes.sh +48 -0
- package/scripts/test_regression_guard_ci_lanes.sh +124 -0
- package/templates/predelete_check.test.sh +56 -0
- package/templates/regression_guard.sh +75 -3
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# test_leak_scan_control_lanes.sh — anchors for the ONE required check's leak scan.
|
|
3
|
+
#
|
|
4
|
+
# SUBJECT: the "Check for operator-private token residue" step of .github/workflows/validate.yml.
|
|
5
|
+
#
|
|
6
|
+
# WHY (measured 2026-08-22 — a production fail-open on the only required check of this repo):
|
|
7
|
+
# the step was `FOUND=$(grep … || true)` followed by `[ -n "$FOUND" ]`. Three arms, one variable
|
|
8
|
+
# changed at a time, run against the extracted step body:
|
|
9
|
+
#
|
|
10
|
+
# leak present · instrument healthy rc=1 FAIL: … residue found ✅
|
|
11
|
+
# clean tree rc=0 PASS: no … residue ✅
|
|
12
|
+
# leak present · grep exits 2 (broken) rc=0 PASS: no … residue 🟥
|
|
13
|
+
#
|
|
14
|
+
# `|| true` folds grep's ERROR (2) into its NO-MATCH (1), so the PASS token is produced on the
|
|
15
|
+
# failure branch: a dead scanner renders byte-identically to a clean surface. This is the
|
|
16
|
+
# absence-assertion class, and it sat on an IRREVERSIBLE surface (a leak does not un-happen) with
|
|
17
|
+
# zero controls of any kind.
|
|
18
|
+
#
|
|
19
|
+
# The repair copies an instrument this repo already runs — scripts/env_purity_scan.sh's
|
|
20
|
+
# "컨트롤 사망 → 수치 무효, exit 10" — rather than inventing a second shape:
|
|
21
|
+
# ① grep's exit code is READ; rc >= 2 is an instrument error, never a clean scan.
|
|
22
|
+
# ② a known-positive control is planted in the scanned tree and MUST be found; zero control hits
|
|
23
|
+
# means the scan never ran over this tree, so its zero findings are void.
|
|
24
|
+
#
|
|
25
|
+
# These lanes assert both closures AND include revert probes, because the two closures are
|
|
26
|
+
# independent fail-closed layers: neutralizing one alone leaves the other catching the same arm.
|
|
27
|
+
# The probe that matters is therefore R3 — neutralize BOTH and the original bug returns exactly.
|
|
28
|
+
#
|
|
29
|
+
# Usage: bash scripts/test_leak_scan_control_lanes.sh Exit: 0 = all behave; 1 = regression.
|
|
30
|
+
|
|
31
|
+
set -uo pipefail
|
|
32
|
+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
33
|
+
WF="$REPO_ROOT/.github/workflows/validate.yml"
|
|
34
|
+
T=$(mktemp -d) || { echo "❌ HARNESS-ERROR — mktemp failed"; exit 10; }
|
|
35
|
+
trap 'rm -rf "$T"' EXIT
|
|
36
|
+
FAIL=0
|
|
37
|
+
|
|
38
|
+
[ -f "$WF" ] || { echo "❌ HARNESS-ERROR — subject workflow missing: $WF"; exit 2; }
|
|
39
|
+
|
|
40
|
+
# ── instrument calibration: prove the step body actually extracted ───────────────────────────
|
|
41
|
+
# An empty extraction would let every lane "pass" against nothing — the exact class this suite
|
|
42
|
+
# exists to close. stdlib only (PyYAML is not a declared dependency and this suite runs inside
|
|
43
|
+
# selfcheck.sh, where a missing module would block unrelated commits with an error about the
|
|
44
|
+
# wrong thing).
|
|
45
|
+
python3 - "$WF" > "$T/body.sh" <<'PYX'
|
|
46
|
+
import sys
|
|
47
|
+
lines = open(sys.argv[1], encoding="utf-8").read().split("\n")
|
|
48
|
+
NAME = "- name: Check for operator-private token residue"
|
|
49
|
+
try:
|
|
50
|
+
i = next(k for k, l in enumerate(lines) if l.strip() == NAME)
|
|
51
|
+
except StopIteration:
|
|
52
|
+
sys.exit(0) # emit nothing -> the calibration check below aborts loudly
|
|
53
|
+
j = next(k for k in range(i, len(lines)) if lines[k].strip().startswith("run:"))
|
|
54
|
+
indent = len(lines[j + 1]) - len(lines[j + 1].lstrip())
|
|
55
|
+
body = []
|
|
56
|
+
for l in lines[j + 1:]:
|
|
57
|
+
if l.strip() and (len(l) - len(l.lstrip())) < indent:
|
|
58
|
+
break
|
|
59
|
+
body.append(l[indent:])
|
|
60
|
+
sys.stdout.write("\n".join(body) + "\n")
|
|
61
|
+
PYX
|
|
62
|
+
for _need in 'INSTRUMENT DEAD' 'INSTRUMENT ERROR' 'PASS: no generic operator-private residue'; do
|
|
63
|
+
if ! grep -qF -- "$_need" "$T/body.sh"; then
|
|
64
|
+
echo "❌ HARNESS-ERROR — the leak-scan step body did not extract from $WF"
|
|
65
|
+
echo " (missing marker: '$_need'). Lanes below would measure an empty script. Aborting"
|
|
66
|
+
echo " rather than reporting green."
|
|
67
|
+
exit 1
|
|
68
|
+
fi
|
|
69
|
+
done
|
|
70
|
+
|
|
71
|
+
# ── fixtures ─────────────────────────────────────────────────────────────────────────────────
|
|
72
|
+
# Home-path literals are ASSEMBLED, never written out: a tracked file carrying the real shape is
|
|
73
|
+
# blocked by this repo's own pre-commit confidentiality scan (verified 2026-08-22, reports MED).
|
|
74
|
+
mkdir -p "$T/clean/docs" "$T/leaky/docs" "$T/shim"
|
|
75
|
+
printf '# nothing operator-private here\n' > "$T/clean/docs/x.md"
|
|
76
|
+
printf 'a planted leak for the FAIL arm:\n' > "$T/leaky/docs/x.md"
|
|
77
|
+
printf '/Users/%s/projects/secret\n' "plantedhome" >> "$T/leaky/docs/x.md"
|
|
78
|
+
|
|
79
|
+
# grep shim that breaks ONLY the recursive scan (the `-rIE` invocation). Breaking every grep would
|
|
80
|
+
# not attribute the failure to the branch under test.
|
|
81
|
+
REAL_GREP=$(command -v grep) || { echo "❌ HARNESS-ERROR — no grep on PATH"; exit 10; }
|
|
82
|
+
cat > "$T/shim/grep" <<SH
|
|
83
|
+
#!/bin/sh
|
|
84
|
+
for a in "\$@"; do case "\$a" in -rIE) exit 2 ;; esac; done
|
|
85
|
+
exec "$REAL_GREP" "\$@"
|
|
86
|
+
SH
|
|
87
|
+
chmod +x "$T/shim/grep"
|
|
88
|
+
|
|
89
|
+
run_body() { # $1=body file $2=tree $3=broken|ok ; echoes "rc|first verdict-ish line"
|
|
90
|
+
local out rc
|
|
91
|
+
if [ "$3" = "broken" ]; then
|
|
92
|
+
out=$(cd "$2" && PATH="$T/shim:$PATH" bash "$1" 2>&1); rc=$?
|
|
93
|
+
else
|
|
94
|
+
out=$(cd "$2" && bash "$1" 2>&1); rc=$?
|
|
95
|
+
fi
|
|
96
|
+
printf '%s|%s' "$rc" "$(printf '%s\n' "$out" | grep -E '^(PASS|FAIL|❌|⛔)' | head -1)"
|
|
97
|
+
}
|
|
98
|
+
lane() { # $1=id $2=body $3=tree $4=broken|ok $5=expected rc $6=expected substring
|
|
99
|
+
local r rc msg
|
|
100
|
+
r=$(run_body "$2" "$3" "$4"); rc="${r%%|*}"; msg="${r#*|}"
|
|
101
|
+
if [ "$rc" = "$5" ] && printf '%s' "$msg" | grep -qF -- "$6"; then
|
|
102
|
+
printf ' ✅ %-28s rc=%s %s\n' "$1" "$rc" "$(printf '%s' "$msg" | cut -c1-60)"
|
|
103
|
+
else
|
|
104
|
+
printf ' ❌ %-28s expected rc=%s /%s/, got rc=%s %s\n' "$1" "$5" "$6" "$rc" "$msg"; FAIL=1
|
|
105
|
+
fi
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
echo "== leak-scan lanes (subject: validate.yml operator-private residue step) =="
|
|
109
|
+
lane L1-clean-tree "$T/body.sh" "$T/clean" ok 0 "PASS: no generic operator-private residue"
|
|
110
|
+
lane L2-leak-detected "$T/body.sh" "$T/leaky" ok 1 "FAIL: operator-private token residue found"
|
|
111
|
+
lane L3-instrument-dead "$T/body.sh" "$T/leaky" broken 10 "INSTRUMENT ERROR"
|
|
112
|
+
|
|
113
|
+
# L4 — the control fixture itself is the second anchor: remove its planting and the scan must
|
|
114
|
+
# refuse to certify, even though the tree is genuinely clean. "Clean" and "not looked at" must not
|
|
115
|
+
# render the same, which is the whole thesis of this file.
|
|
116
|
+
sed "s|^ *printf '/Users/%s/projects/example.*|:|" "$T/body.sh" > "$T/body_noctl.sh"
|
|
117
|
+
if diff -q "$T/body.sh" "$T/body_noctl.sh" >/dev/null; then
|
|
118
|
+
echo " ❌ L4-control-removed neutralization was a no-op — the probe measured nothing"; FAIL=1
|
|
119
|
+
else
|
|
120
|
+
lane L4-control-removed "$T/body_noctl.sh" "$T/clean" ok 10 "INSTRUMENT DEAD"
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
echo "== revert probes — are the two closures load-bearing, or decoration? =="
|
|
124
|
+
# R1: disarm the exit-code read alone. The arm stays RED (the control layer catches it), but the
|
|
125
|
+
# ATTRIBUTION must move — that is what proves this branch, not its neighbour, fires first.
|
|
126
|
+
sed 's|if \[ "$rc" -ge 2 \]; then|if false; then|' "$T/body.sh" > "$T/body_r1.sh"
|
|
127
|
+
if diff -q "$T/body.sh" "$T/body_r1.sh" >/dev/null; then
|
|
128
|
+
echo " ❌ R1-rc-branch neutralization was a no-op — the probe measured nothing"; FAIL=1
|
|
129
|
+
else
|
|
130
|
+
r=$(run_body "$T/body_r1.sh" "$T/leaky" broken)
|
|
131
|
+
if ! printf '%s' "${r#*|}" | grep -qF 'grep exited'; then
|
|
132
|
+
printf ' ✅ %-28s disarmed → verdict re-attributes to %s\n' "R1-rc-branch" "$(printf '%s' "${r#*|}" | cut -c1-40)"
|
|
133
|
+
else
|
|
134
|
+
echo " ❌ R1-rc-branch still reports 'grep exited' with the branch disarmed"; FAIL=1
|
|
135
|
+
fi
|
|
136
|
+
fi
|
|
137
|
+
|
|
138
|
+
# R2: disarm the control-liveness branch alone → L4's arm must go GREEN again, i.e. a scan that
|
|
139
|
+
# cannot find a planted leak once more certifies the surface as clean.
|
|
140
|
+
sed 's|if \[ "$ctl" -eq 0 \]; then|if false; then|' "$T/body_noctl.sh" > "$T/body_r2.sh"
|
|
141
|
+
if diff -q "$T/body_noctl.sh" "$T/body_r2.sh" >/dev/null; then
|
|
142
|
+
echo " ❌ R2-control-branch neutralization was a no-op — the probe measured nothing"; FAIL=1
|
|
143
|
+
else
|
|
144
|
+
r=$(run_body "$T/body_r2.sh" "$T/clean" ok)
|
|
145
|
+
if [ "${r%%|*}" = "0" ]; then
|
|
146
|
+
echo " ✅ R2-control-branch disarmed → dead-fixture scan passes again → anchor is alive"
|
|
147
|
+
else
|
|
148
|
+
echo " ❌ R2-control-branch disarmed branch STILL blocks — the lane is not testing it"; FAIL=1
|
|
149
|
+
fi
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
# R3: disarm BOTH → the ORIGINAL 2026-08-22 bug must return exactly: a real leak, a dead scanner,
|
|
153
|
+
# and a green PASS. This is the fail-before measurement, mechanized so it cannot drift back.
|
|
154
|
+
sed 's|if \[ "$ctl" -eq 0 \]; then|if false; then|' "$T/body_r1.sh" > "$T/body_r3.sh"
|
|
155
|
+
r=$(run_body "$T/body_r3.sh" "$T/leaky" broken)
|
|
156
|
+
if [ "${r%%|*}" = "0" ] && printf '%s' "${r#*|}" | grep -qF 'PASS: no generic'; then
|
|
157
|
+
echo " ✅ R3-both-disarmed both off → leak+dead scanner renders PASS (the closed hole)"
|
|
158
|
+
else
|
|
159
|
+
echo " ❌ R3-both-disarmed expected rc=0 PASS, got $r — the lanes are not measuring the hole"; FAIL=1
|
|
160
|
+
fi
|
|
161
|
+
|
|
162
|
+
[ $FAIL -eq 0 ] && { echo "✅ all leak-scan control lanes behave"; exit 0; }
|
|
163
|
+
echo "❌ leak-scan control lane regression"; 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
|