@chrono-meta/fh-gate 3.23.1 → 3.25.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 (54) hide show
  1. package/.claude/rules/fh_4axis_gate.md +14 -1
  2. package/.claude-plugin/marketplace.json +4 -4
  3. package/CLAUDE.md +5 -4
  4. package/README.md +8 -6
  5. package/knowledge/shared/harness-core/claude_md_gate_details.md +34 -0
  6. package/knowledge/shared/harness-core/dispatch_conditional_prohibition.md +30 -0
  7. package/knowledge/shared/harness-core/fh_integration_contract.md +0 -1
  8. package/knowledge/shared/harness-core/fh_opencode_governance_wrapper.md +0 -1
  9. package/knowledge/shared/harness-core/fh_three_layer_canon.md +172 -2
  10. package/knowledge/shared/harness-core/field_verdict_crossfamily_gate.md +22 -0
  11. package/knowledge/shared/harness-core/governance_engineering_definition.md +16 -0
  12. package/knowledge/shared/harness-core/harness_verification_core_extended.md +26 -0
  13. package/knowledge/shared/harness-core/ship_readiness_gate.md +3 -0
  14. package/knowledge/shared/harness-core/sonnet_floor_doctrine.md +19 -0
  15. package/knowledge/shared/learnings/subagent_invocations_log.yaml +30 -0
  16. package/package.json +12 -2
  17. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  18. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  19. package/plugins/fh-meta/CHANGELOG.md +17 -0
  20. package/plugins/fh-meta/skills/install-wizard/SKILL_detail.md +17 -3
  21. package/plugins/fh-meta/skills/verify-bidirectional/SKILL.md +1 -1
  22. package/plugins/fh-preprep/.claude-plugin/plugin.json +2 -2
  23. package/plugins/fh-preprep/README.md +11 -0
  24. package/plugins/fh-preprep/skills/preprep/SKILL.md +47 -1
  25. package/plugins/fh-preprep/skills/preprep/lane_speech_coach.py +1080 -0
  26. package/plugins/fh-preprep/skills/preprep/test_lane_speech_coach.py +705 -0
  27. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  28. package/scripts/cluster_capability_scan.sh +17 -0
  29. package/scripts/compaction_probe.sh +102 -23
  30. package/scripts/count_check.sh +37 -10
  31. package/scripts/field_canon_preload.sh +84 -2
  32. package/scripts/marker_diff_sha.sh +13 -0
  33. package/scripts/mutation_probe.py +1541 -0
  34. package/scripts/resident_cost.py +371 -0
  35. package/scripts/revert_probe.sh +5 -6
  36. package/scripts/selfcheck.sh +62 -0
  37. package/scripts/test_axis23_skip_reason_lanes.sh +109 -0
  38. package/scripts/test_count_check_all_plugins_lanes.sh +130 -0
  39. package/scripts/test_field_canon_lanes.sh +33 -0
  40. package/scripts/test_hook_templates_copilot_compat_lanes.sh +250 -0
  41. package/scripts/test_marker_diff_sha_lanes.sh +129 -0
  42. package/scripts/test_mutation_probe_lanes.sh +786 -0
  43. package/scripts/test_preprep_speech_coach_lanes.sh +62 -0
  44. package/scripts/test_resident_cost_lanes.sh +182 -0
  45. package/scripts/test_skill_canon_preload_lanes.sh +148 -0
  46. package/scripts/universal_guard_check.sh +2 -0
  47. package/templates/.git-hooks/pre-commit +109 -5
  48. package/templates/goal-quench-hook-setup.md +3 -3
  49. package/templates/goal-quench-settings-merged.json +0 -1
  50. package/templates/settings.Compaction.snippet.json +0 -2
  51. package/templates/settings.FieldCanon.snippet.json +0 -1
  52. package/templates/settings.SessionStart.snippet.json +0 -2
  53. package/templates/settings.SubagentStop.snippet.json +0 -1
  54. package/templates/subagent-tally-hook.json +0 -1
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env bash
2
+ # test_count_check_all_plugins_lanes.sh — known-pair anchor: the README «N skills · M agents» header
3
+ # is checked against the sum over EVERY plugin, not a hand-picked subset.
4
+ #
5
+ # WHY THIS EXISTS
6
+ # Until 2026-10-01 `count_check.sh` rendered the README header from fh-meta + fh-commons only. Two
7
+ # plugins added later (fh-qp 4 skills, fh-preprep 1) were outside the sum, so a README saying
8
+ # «41 skills» PASSED while the disk held 46 — the gate was green on exactly the drift it exists to
9
+ # catch, and the operator found it by reading the README.
10
+ #
11
+ # HOW: a disposable copy of exactly the files count_check.sh reads, plus ONE SYNTHETIC PLUGIN
12
+ # (`zz-lane-probe`, 1 skill, manifest + marketplace entry consistent) added by the lane itself. The
13
+ # defect is «a plugin outside the sum», so the lane brings its own extra plugin: it means the same
14
+ # thing in a repo with 4 plugins or with 2 (a downstream harness). The README is rewritten to just
15
+ # the header line, so a localized README elsewhere cannot change what the arms see. Expected values
16
+ # use count_check's own active-skill rule (first 20 lines carry no deprecation marker).
17
+ # Arms assert the README line AND that it is the only FAIL, so a run failing for another reason
18
+ # never counts as the README check firing.
19
+ set -uo pipefail
20
+
21
+ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
22
+ pass=0; fail=0
23
+ ok() { printf ' \342\234\205 %s\n' "$1"; pass=$((pass+1)); }
24
+ bad() { printf ' \342\235\214 %s\n' "$1"; fail=$((fail+1)); }
25
+
26
+ WORK=$(mktemp -d "${TMPDIR:-/tmp}/count-all-plugins.XXXXXX") || { echo "mktemp failed"; exit 1; }
27
+ trap 'rm -rf "$WORK"' EXIT
28
+ PROBE=zz-lane-probe
29
+
30
+ active_skills() { # active_skills <dir> — same rule as count_check.sh count_active
31
+ local n=0 s
32
+ for s in "$1"/plugins/*/skills/*/SKILL.md; do
33
+ [ -f "$s" ] || continue
34
+ head -20 "$s" | grep -qE 'deprecated: true|DEPRECATED' || n=$((n+1))
35
+ done
36
+ echo "$n"
37
+ }
38
+ agents() { ls "$1"/plugins/*/agents/*.md 2>/dev/null | wc -l | tr -d ' '; }
39
+
40
+ mkcopy() { # mkcopy <dir> — count_check's inputs from this tree + the synthetic plugin
41
+ local p
42
+ mkdir -p "$1/scripts" "$1/templates" || return 1
43
+ for p in plugins .claude-plugin scripts/count_check.sh templates/local_fh_context.md; do
44
+ [ -e "$REPO_ROOT/$p" ] || { echo " missing input: $p"; return 1; }
45
+ cp -R "$REPO_ROOT/$p" "$1/$p" || return 1
46
+ done
47
+ mkdir -p "$1/plugins/$PROBE/.claude-plugin" "$1/plugins/$PROBE/skills/probe-skill" || return 1
48
+ printf '{"name":"%s","description":"Lane probe plugin: 1 skills + 0 agents"}\n' "$PROBE" \
49
+ > "$1/plugins/$PROBE/.claude-plugin/plugin.json"
50
+ printf -- '---\nname: probe-skill\ndescription: lane probe\n---\n# probe\n' \
51
+ > "$1/plugins/$PROBE/skills/probe-skill/SKILL.md"
52
+ python3 - "$1/.claude-plugin/marketplace.json" "$PROBE" <<'PY' || return 1
53
+ import json, sys
54
+ p, name = sys.argv[1], sys.argv[2]
55
+ d = json.load(open(p))
56
+ d["plugins"].append({"name": name, "source": "./plugins/" + name,
57
+ "description": "Lane probe plugin: 1 skills + 0 agents"})
58
+ json.dump(d, open(p, "w"), ensure_ascii=False, indent=2)
59
+ PY
60
+ }
61
+ readme() { printf '# fixture\n\n## %s skills · %s agents\n' "$2" "$3" > "$1/README.md"; }
62
+ fails_other_than_readme() { printf '%s\n' "$1" | grep '^FAIL ' | grep -v 'FAIL count: README header' | head -3; }
63
+
64
+ echo "== count_check README header = sum over all plugins — known pair =="
65
+
66
+ # A1 — README states the full sum including the probe plugin → PASS, no FAIL lines at all.
67
+ if mkcopy "$WORK/a1"; then
68
+ N=$(active_skills "$WORK/a1"); M=$(agents "$WORK/a1"); readme "$WORK/a1" "$N" "$M"
69
+ out=$(bash "$WORK/a1/scripts/count_check.sh" 2>&1); rc=$?
70
+ if [ "$rc" -eq 0 ] && printf '%s' "$out" | grep -q "PASS count: README header"; then
71
+ ok "A1 README = all-plugin sum (${N} skills incl. the probe plugin) — PASS"
72
+ else bad "A1 expected PASS (rc=$rc): $(printf '%s' "$out" | grep -E '^FAIL' | head -3)"; fi
73
+ else bad "A1 fixture could not be built"; fi
74
+
75
+ # A2 — README omits the probe plugin (the shape of the 2026-10-01 defect) → FAIL on README only.
76
+ if mkcopy "$WORK/a2"; then
77
+ N=$(active_skills "$WORK/a2"); M=$(agents "$WORK/a2"); readme "$WORK/a2" "$((N - 1))" "$M"
78
+ out=$(bash "$WORK/a2/scripts/count_check.sh" 2>&1); rc=$?
79
+ other=$(fails_other_than_readme "$out")
80
+ if [ "$rc" -ne 0 ] && printf '%s' "$out" | grep -q "FAIL count: README header — expected \"${N} skills" && [ -z "$other" ]; then
81
+ ok "A2 README missing one plugin's skill (${N}-1) — FAIL on README header only"
82
+ else bad "A2 stale README not caught as the sole failure (rc=$rc): $(printf '%s' "$out" | grep -E '^FAIL' | head -3)"; fi
83
+ else bad "A2 fixture could not be built"; fi
84
+
85
+ # A3 — a deprecated skill in the probe plugin is NOT counted (same rule as the gate).
86
+ if mkcopy "$WORK/a3"; then
87
+ N=$(active_skills "$WORK/a3"); M=$(agents "$WORK/a3")
88
+ mkdir -p "$WORK/a3/plugins/$PROBE/skills/old-skill"
89
+ printf -- '---\nname: old-skill\ndeprecated: true\n---\n# old\n' > "$WORK/a3/plugins/$PROBE/skills/old-skill/SKILL.md"
90
+ readme "$WORK/a3" "$N" "$M"
91
+ out=$(bash "$WORK/a3/scripts/count_check.sh" 2>&1); rc=$?
92
+ if [ "$rc" -eq 0 ] && printf '%s' "$out" | grep -q "PASS count: README header"; then
93
+ ok "A3 deprecated skill in a later plugin leaves the header at ${N} — PASS"
94
+ else bad "A3 deprecated skill changed the expected header (rc=$rc): $(printf '%s' "$out" | grep -E '^FAIL' | head -3)"; fi
95
+ else bad "A3 fixture could not be built"; fi
96
+
97
+ # A4 — a skill-bearing directory without a manifest is not silently left out of the sum.
98
+ if mkcopy "$WORK/a4"; then
99
+ N=$(active_skills "$WORK/a4"); M=$(agents "$WORK/a4"); readme "$WORK/a4" "$N" "$M"
100
+ mkdir -p "$WORK/a4/plugins/zz-orphan/skills/a"; printf '# a\n' > "$WORK/a4/plugins/zz-orphan/skills/a/SKILL.md"
101
+ out=$(bash "$WORK/a4/scripts/count_check.sh" 2>&1); rc=$?
102
+ if [ "$rc" -ne 0 ] && printf '%s' "$out" | grep -q "plugins/zz-orphan 에 스킬이 있는데 .claude-plugin/plugin.json 이 없다"; then
103
+ ok "A4 orphan skill directory without plugin.json — FAIL by name"
104
+ else bad "A4 orphan skill directory passed silently (rc=$rc): $(printf '%s' "$out" | grep -E '^FAIL' | head -3)"; fi
105
+ else bad "A4 fixture could not be built"; fi
106
+
107
+ # A5 — --staged counts the INDEX: a plugin staged but gone from the worktree is still in the sum.
108
+ if mkcopy "$WORK/a5" && command -v git >/dev/null 2>&1; then
109
+ N=$(active_skills "$WORK/a5"); M=$(agents "$WORK/a5"); readme "$WORK/a5" "$N" "$M"
110
+ ( cd "$WORK/a5" && git init -q && git add -A ) || bad "A5 git index could not be built"
111
+ mkdir -p "$WORK/a5/plugins/zz-staged/.claude-plugin" "$WORK/a5/plugins/zz-staged/skills/s"
112
+ printf '{"name":"zz-staged","description":"1 skills + 0 agents"}\n' > "$WORK/a5/plugins/zz-staged/.claude-plugin/plugin.json"
113
+ printf '# s\n' > "$WORK/a5/plugins/zz-staged/skills/s/SKILL.md"
114
+ python3 - "$WORK/a5/.claude-plugin/marketplace.json" <<'PY'
115
+ import json, sys
116
+ p = sys.argv[1]; d = json.load(open(p))
117
+ d["plugins"].append({"name": "zz-staged", "source": "./plugins/zz-staged", "description": "1 skills + 0 agents"})
118
+ json.dump(d, open(p, "w"), ensure_ascii=False, indent=2)
119
+ PY
120
+ ( cd "$WORK/a5" && git add plugins/zz-staged .claude-plugin/marketplace.json && rm -rf plugins/zz-staged )
121
+ out=$(cd "$WORK/a5" && bash scripts/count_check.sh --staged 2>&1); rc=$?
122
+ other=$(fails_other_than_readme "$out")
123
+ if [ "$rc" -ne 0 ] && printf '%s' "$out" | grep -q "FAIL count: README header — expected \"$((N + 1)) skills" && [ -z "$other" ]; then
124
+ ok "A5 --staged sees a staged-only plugin — README header expects $((N + 1)), sole failure"
125
+ else bad "A5 staged-only plugin left out of the sum (rc=$rc): $(printf '%s' "$out" | grep -E '^FAIL|README' | head -3)"; fi
126
+ else bad "A5 fixture could not be built (needs git)"; fi
127
+
128
+ echo "----"
129
+ echo "count_check all-plugins lanes: $pass passed, $fail failed"
130
+ [ "$fail" -eq 0 ] || exit 1
@@ -162,5 +162,38 @@ w2=$(printf '%s' '{"session_id":"RX2","prompt":"q.sp 를 보자"}' \
162
162
  [ -n "$w2" ] && ok "⑭-b ★컨트롤: 정확히 'q.sp' 는 잡힌다(⑭ 의 침묵이 공허하지 않다)" \
163
163
  || no "⑭-b 컨트롤" "정확한 이름도 못 잡는다 — ⑭ 는 무엇도 증명하지 않는다"
164
164
 
165
+ # ⑮ (2026-10-03 2라운드) 긴 여러 줄 프롬프트 — 매핑 루프의 `printf "$PROMPT" | grep -qiF "$name"` 은
166
+ # grep -q 가 첫 줄 일치에 파이프를 닫으면 printf 가 SIGPIPE 로 죽어(pipefail → 141) «안 맞음」으로
167
+ # 읽혔다. 수리 전 실측: «qasp 보자\n」 + x 1,000,000 → 3/3 MISS. 픽스처는 파일 리다이렉트(레인 쪽 파이프 없음).
168
+ python3 -c 'import json,sys; sys.stdout.write(json.dumps({"prompt":"qasp 보자\n"+"x"*1000000}))' > "$TMP/big15.json" 2>/dev/null
169
+ if [ -s "$TMP/big15.json" ]; then
170
+ out=$(env CLAUDE_PROJECT_DIR="$FHUB" FIELD_CANON_PROJECT_ROOT="$FPROJ" FIELD_CANON_SENTINEL_DIR="$TMP/15" bash "$H" < "$TMP/big15.json" 2>&1)
171
+ case "$out" in *qasp*README.md*) ok "⑮ 긴 여러 줄 프롬프트의 첫 줄 «qasp」 → 정본 경로 제시 (SIGPIPE 로 놓치지 않는다)" ;;
172
+ *) no "⑮ 긴 여러 줄 프롬프트" "첫 줄의 매핑 이름을 놓쳤다" ;; esac
173
+ out=$(run '{"prompt":"QASP 보자"}' "$TMP/15b")
174
+ case "$out" in *qasp*README.md*) ok "⑮-b 대소문자 무시는 유지된다 («QASP」 → 잡힌다, grep -i 와 같은 의미)" ;;
175
+ *) no "⑮-b 대소문자" "«QASP」를 못 잡는다 — case 전환이 -i 의미를 잃었다" ;; esac
176
+ else
177
+ no "⑮ CONTROL" "1MB 픽스처 생성 실패 — 레인 무효"
178
+ fi
179
+
180
+ # ⑯ (2026-10-03 3라운드) 빈 프로젝트 이름 — `*""*` 는 모든 프롬프트에 맞는다. 단어 분할로는 빈 이름이
181
+ # 안 생기므로 운영상 도달하지 않는다(방어 가드). 훅 사본의 루프에 빈 이름을 끼워 잰다.
182
+ mkdir -p "$TMP/h16"; cp "$HERE/fh_track_resolve.sh" "$TMP/h16/" # 훅이 형제 라이브러리를 소스한다
183
+ HC16="$TMP/h16/field_canon_preload.sh"
184
+ # 🔍 빈 이름은 **두 겹으로** 운영상 도달 불가다: ① 단어 분할이 빈 이름을 안 만든다 ② 센티넬 검사
185
+ # `[ -e "$SENT_DIR/$name" ]` 가 빈 이름이면 디렉터리 `$SENT_DIR/` 자체라 참 → continue(되돌림 실측:
186
+ # 가드를 지워도 이 레인이 초록이었다). 그래서 사본에서 ②도 걷어 **가드만** 남긴 상태를 잰다.
187
+ sed -e 's/^for name in \$mapped; do$/for name in "" $mapped; do/' \
188
+ -e 's/^ \[ -n "\$SENT_DIR" \] && \[ -e "\$SENT_DIR\/\$name" \] && continue.*$/ :/' "$H" > "$HC16"
189
+ if grep -q '^for name in "" \$mapped; do$' "$HC16" && ! grep -q 'SENT_DIR/\$name" \] && continue' "$HC16"; then
190
+ out=$(printf '%s' '{"prompt":"오늘 날씨 어때"}' | env CLAUDE_PROJECT_DIR="$FHUB" FIELD_CANON_PROJECT_ROOT="$FPROJ" FIELD_CANON_SENTINEL_DIR="$TMP/16" bash "$HC16" 2>&1)
191
+ [ -z "$out" ] && ok "⑯ 빈 프로젝트 이름이 무관한 프롬프트에 걸리지 않는다" || no "⑯ 빈 이름" "무관한 프롬프트에 출력: $out"
192
+ out=$(printf '%s' '{"prompt":"qasp 보자"}' | env CLAUDE_PROJECT_DIR="$FHUB" FIELD_CANON_PROJECT_ROOT="$FPROJ" FIELD_CANON_SENTINEL_DIR="$TMP/16b" bash "$HC16" 2>&1)
193
+ case "$out" in *qasp*README.md*) ok "⑯-b CONTROL: 같은 사본에서 진짜 이름은 잡힌다" ;; *) no "⑯-b CONTROL" "사본이 안 돈다" ;; esac
194
+ else
195
+ no "⑯ CONTROL" "훅 사본 수정 실패 — 레인 무효"
196
+ fi
197
+
165
198
  echo "── PASS $PASS · FAIL $FAIL"
166
199
  [ "$FAIL" -eq 0 ] || exit 1
@@ -0,0 +1,250 @@
1
+ #!/usr/bin/env bash
2
+ # test_hook_templates_copilot_compat_lanes.sh — no shipped hook template may carry `"matcher": ""`.
3
+ #
4
+ # WHY (measured 2026-10-01, operator machine, GitHub Copilot CLI v1.0.78): opening this repo with
5
+ # `gh copilot` printed
6
+ # Repository settings file '.claude/settings.json' could not be loaded:
7
+ # Settings config error: hooks.preCompact[0].matcher: matcher cannot be empty
8
+ # and Copilot then ignored the WHOLE settings file — not just that hook. The cause was the empty
9
+ # matcher our own templates ship. In Claude Code the empty string is not needed at all: the hooks
10
+ # doc («Matcher patterns», code.claude.com/docs/en/hooks) lists `"*"`, `""`, or omitted → «Match
11
+ # all — fires on every occurrence of the event». So OMITTING the key means the same thing to Claude
12
+ # Code and loads in Copilot. That is the whole fix; these lanes keep it from growing back.
13
+ #
14
+ # SUBJECTS
15
+ # S1 every tracked *.json under templates/ plugins/ knowledge/ docs/ .claude-plugin/ hooks/ —
16
+ # parsed, walked structurally (a dict carrying `matcher == ""`).
17
+ # S2 every ```json / ```jsonc fenced block in tracked *.md under the same dirs + repo-root *.md —
18
+ # these are what a user copies into their settings by hand. Prose mentioning the defect sits
19
+ # outside fences and is not scanned (it has to be able to name the thing it forbids).
20
+ # S3 what install-wizard WRITES. Both python merge blocks are EXTRACTED from the shipped
21
+ # SKILL_detail.md at run time (never retyped — a retyped copy would keep validating the old
22
+ # code) and executed against a fixture that already holds a user group with `"matcher": ""`.
23
+ # The written file must hold no empty matcher and the user's hook must survive.
24
+ # S4 hook_drift_check.sh must NOT call an old install STALE only because it spells match-all as
25
+ # `""` while the template now omits the key — same meaning, and a false STALE is noise that
26
+ # teaches people to ignore the checker. A different real matcher must still be STALE (control).
27
+ #
28
+ # CALIBRATION: the scanner runs on a known-positive (empty matcher → flagged) and a known-negative
29
+ # (omitted → clean) in the same run, and on a revert probe (a real shipped template with the key put
30
+ # back → flagged). A scanner that flags nothing on the positive is a dead instrument → exit 1.
31
+ # Exit: 0 = all lanes pass · 1 = a lane failed or the instrument/extraction broke.
32
+
33
+ set -uo pipefail
34
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
35
+ ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
36
+ WIZ="$ROOT/plugins/fh-meta/skills/install-wizard/SKILL_detail.md"
37
+ DRIFT="$ROOT/scripts/hook_drift_check.sh"
38
+ PY="$(command -v python3 || true)"
39
+ [ -n "$PY" ] || { echo "❌ HARNESS-ERROR: python3 not found — lanes NOT run (not a pass)"; exit 1; }
40
+
41
+ TMPROOT=$(mktemp -d "${TMPDIR:-/tmp}/fh_copilot_compat.XXXXXX") \
42
+ || { echo "❌ HARNESS-ERROR: mktemp -d failed — lanes NOT run (not a pass)"; exit 1; }
43
+ [ -n "$TMPROOT" ] && [ -d "$TMPROOT" ] || { echo "❌ HARNESS-ERROR: empty TMPROOT — lanes NOT run"; exit 1; }
44
+ trap 'rm -rf "$TMPROOT"' EXIT
45
+ FAILED=0; PASSED=0
46
+ _pass() { echo "✅ $1"; PASSED=$((PASSED+1)); }
47
+ _fail() { echo "❌ $1"; FAILED=1; }
48
+ _eq() { if [ "$2" = "$3" ]; then _pass "$1 ($2)"; else _fail "$1 — got [$2], expected [$3]"; fi; }
49
+
50
+ # ── the scanner (S1+S2) ─────────────────────────────────────────────────────────
51
+ # Args: <root> <file>... Prints one "HIT <file>: <where>" per empty matcher, "ERR <file>: …" for an
52
+ # unreadable JSON file, and a final "SCANNED json=N md_blocks=M". Exit 0 always — callers count.
53
+ SCAN="$TMPROOT/scan.py"
54
+ cat > "$SCAN" <<'PYEOF'
55
+ import json, os, re, sys
56
+ root, files = sys.argv[1], sys.argv[2:]
57
+ EMPTY = re.compile(r'"matcher"\s*:\s*""')
58
+ FENCE = re.compile(r'^\s*```\s*(json|jsonc|json5)\b.*$', re.I) # ```JSON, ```json title=x
59
+ nj = nb = 0
60
+ def walk(o, path):
61
+ if isinstance(o, dict):
62
+ if o.get("matcher") == "":
63
+ yield path or "$"
64
+ for k, v in o.items():
65
+ yield from walk(v, f"{path}.{k}")
66
+ elif isinstance(o, list):
67
+ for i, v in enumerate(o):
68
+ yield from walk(v, f"{path}[{i}]")
69
+ for rel in files:
70
+ p = os.path.join(root, rel)
71
+ if not os.path.isfile(p):
72
+ continue
73
+ if rel.endswith(".json"):
74
+ nj += 1
75
+ try:
76
+ d = json.load(open(p, encoding="utf-8"))
77
+ except Exception as e:
78
+ print(f"ERR {rel}: unparsable ({e.__class__.__name__})"); continue
79
+ for where in walk(d, ""):
80
+ print(f"HIT {rel}: {where}")
81
+ elif rel.endswith((".jsonc", ".json5")): # comments allowed → not json.load-able; line scan
82
+ nj += 1
83
+ for n, line in enumerate(open(p, encoding="utf-8", errors="replace"), 1):
84
+ if EMPTY.search(line):
85
+ print(f"HIT {rel}:{n}")
86
+ elif rel.endswith(".md"):
87
+ inside, start = False, 0
88
+ for n, line in enumerate(open(p, encoding="utf-8", errors="replace"), 1):
89
+ if not inside and FENCE.match(line):
90
+ inside, start = True, n; nb += 1; continue
91
+ if inside and line.strip().startswith("```"):
92
+ inside = False; continue
93
+ if inside and EMPTY.search(line):
94
+ print(f"HIT {rel}:{n} (json block from line {start})")
95
+ print(f"SCANNED json={nj} md_blocks={nb}")
96
+ PYEOF
97
+
98
+ _shipped_files() { # tracked files if this is a git checkout, else a find over the same dirs
99
+ # git only when ROOT IS the work-tree top. An npm-installed copy under a consumer's repo
100
+ # (node_modules, usually gitignored) is «inside a work tree» but ls-files there lists nothing.
101
+ local top; top=$(git -C "$ROOT" rev-parse --show-toplevel 2>/dev/null || true)
102
+ if [ -n "$top" ] && [ "$(cd "$top" && pwd -P)" = "$(cd "$ROOT" && pwd -P)" ]; then
103
+ git -C "$ROOT" ls-files -- templates plugins knowledge docs .claude-plugin hooks '*.md' \
104
+ | /usr/bin/grep -E '\.(json|jsonc|json5|md)$' | /usr/bin/grep -vE '^tracks/'
105
+ else
106
+ ( cd "$ROOT" && find templates plugins knowledge docs .claude-plugin hooks -type f \
107
+ \( -name '*.json' -o -name '*.jsonc' -o -name '*.json5' -o -name '*.md' \) 2>/dev/null; ls *.md 2>/dev/null )
108
+ fi
109
+ }
110
+
111
+ echo "══ calibration: the scanner separates a known pair ══"
112
+ CAL="$TMPROOT/cal"; mkdir -p "$CAL"
113
+ printf '%s\n' '{"hooks":{"PreCompact":[{"matcher":"","hooks":[{"type":"command","command":"x"}]}]}}' > "$CAL/pos.json"
114
+ printf '%s\n' '{"hooks":{"PreCompact":[{"hooks":[{"type":"command","command":"x"}]}]}}' > "$CAL/neg.json"
115
+ printf '%s\n' 'Prose may say `"matcher": ""` is forbidden.' '' '```json' '{ "Stop": [ { "matcher": "", "hooks": [] } ] }' '```' > "$CAL/pos.md"
116
+ printf '%s\n' 'Prose may say `"matcher": ""` is forbidden.' '' '```json' '{ "Stop": [ { "hooks": [] } ] }' '```' > "$CAL/neg.md"
117
+ printf '%s\n' '```JSON title=settings' '{ "Stop": [ { "matcher": "", "hooks": [] } ] }' '```' > "$CAL/pos_upper.md"
118
+ printf '%s\n' '// comment' '{ "Stop": [ { "matcher" : "", "hooks": [] } ] }' > "$CAL/pos.jsonc"
119
+ _hits() { "$PY" "$SCAN" "$1" "${@:2}" | /usr/bin/grep -c '^HIT ' ; }
120
+ _eq "CAL-1 known-positive json (empty matcher) → flagged" "$(_hits "$CAL" pos.json)" 1
121
+ _eq "CAL-2 known-negative json (matcher omitted) → clean" "$(_hits "$CAL" neg.json)" 0
122
+ _eq "CAL-3 known-positive md fenced json block → flagged" "$(_hits "$CAL" pos.md)" 1
123
+ _eq "CAL-4 known-negative md (prose mention only) → clean" "$(_hits "$CAL" neg.md)" 0
124
+ _eq "CAL-5 fence variant \`\`\`JSON title=… → flagged" "$(_hits "$CAL" pos_upper.md)" 1
125
+ _eq "CAL-6 .jsonc (comments, not json.load-able) → flagged" "$(_hits "$CAL" pos.jsonc)" 1
126
+
127
+ echo
128
+ echo "══ S1+S2: shipped templates, snippets and copy-paste docs ══"
129
+ LIST="$TMPROOT/files.txt"; _shipped_files > "$LIST"
130
+ NFILES=$(wc -l < "$LIST" | tr -d ' ')
131
+ OUT=$(cd "$ROOT" && xargs "$PY" "$SCAN" "$ROOT" < "$LIST")
132
+ SUMMARY=$(printf '%s\n' "$OUT" | tail -1)
133
+ NJ=$(printf '%s' "$SUMMARY" | sed -n 's/.*json=\([0-9]*\).*/\1/p')
134
+ if [ "$NFILES" -lt 20 ] || [ "${NJ:-0}" -lt 5 ]; then
135
+ _fail "S1-0 instrument: only $NFILES files / ${NJ:-0} json scanned — enumeration broke, NOT a pass"
136
+ else
137
+ _pass "S1-0 instrument alive ($NFILES files · $SUMMARY)"
138
+ fi
139
+ ERRS=$(printf '%s\n' "$OUT" | /usr/bin/grep '^ERR ' || true)
140
+ [ -z "$ERRS" ] && _pass "S1-1 every shipped json parses" || { _fail "S1-1 unparsable shipped json (cannot be checked):"; printf ' %s\n' "$ERRS"; }
141
+ HITS=$(printf '%s\n' "$OUT" | /usr/bin/grep '^HIT ' || true)
142
+ if [ -z "$HITS" ]; then
143
+ _pass "S1-2 zero empty-string matchers in shipped templates/snippets/docs"
144
+ else
145
+ _fail "S1-2 empty-string matcher found — omit the key instead (Claude Code: omitted = match all; Copilot CLI rejects \"\"):"
146
+ printf ' %s\n' "$HITS"
147
+ fi
148
+ # the six templates named in the 2026-10-01 report must be in the scanned set (else S1-2 is vacuous for them)
149
+ for t in goal-quench-settings-merged.json settings.Compaction.snippet.json settings.FieldCanon.snippet.json \
150
+ settings.SessionStart.snippet.json settings.SubagentStop.snippet.json subagent-tally-hook.json; do
151
+ /usr/bin/grep -qx "templates/$t" "$LIST" && _pass "S1-3 scanned: templates/$t" \
152
+ || _fail "S1-3 templates/$t not in the scanned set — lane is blind to it"
153
+ done
154
+
155
+ echo
156
+ echo "══ revert probe: put the empty matcher back into a real shipped template ══"
157
+ RV="$TMPROOT/revert"; mkdir -p "$RV/templates"
158
+ cp "$ROOT/templates/settings.Compaction.snippet.json" "$RV/templates/"
159
+ "$PY" - "$RV/templates/settings.Compaction.snippet.json" <<'PYEOF'
160
+ import json, sys
161
+ p = sys.argv[1]; d = json.load(open(p))
162
+ g = d["project_settings_json"]["hooks"]["PreCompact"][0]
163
+ d["project_settings_json"]["hooks"]["PreCompact"][0] = {"matcher": "", **g}
164
+ json.dump(d, open(p, "w"), indent=2)
165
+ PYEOF
166
+ APPLIED=$(/usr/bin/grep -c '"matcher": ""' "$RV/templates/settings.Compaction.snippet.json")
167
+ _eq "RV-0 mutation applied (empty matcher present in the copy)" "$APPLIED" 1
168
+ _eq "RV-1 scanner flags the reverted template" "$(_hits "$RV" templates/settings.Compaction.snippet.json)" 1
169
+
170
+ echo
171
+ echo "══ S3: what install-wizard writes ══"
172
+ [ -f "$WIZ" ] || { _fail "S3-0 subject missing: $WIZ"; }
173
+ MERGE="$TMPROOT/merge.py"; LOCALPY="$TMPROOT/local.py"
174
+ awk '/^python3 - "\$FH_DIR" <<.PY.$/{f=1;next} f&&/^PY$/{exit} f' "$WIZ" > "$MERGE"
175
+ awk '/^[[:space:]]*python3 - "\$HUB_DIR" "\$BE_DIR" <<.PY.$/{f=1;next} f&&/^PY$/{exit} f' "$WIZ" > "$LOCALPY"
176
+ MN=$(wc -l < "$MERGE" | tr -d ' '); LN=$(wc -l < "$LOCALPY" | tr -d ' ')
177
+ if [ "$MN" -lt 10 ] || [ "$LN" -lt 10 ]; then
178
+ _fail "S3-0 extraction broke (merge=$MN lines, local=$LN lines) — NOT a pass"
179
+ else
180
+ _pass "S3-0 both wizard blocks extracted from the shipped file (merge=$MN · local=$LN lines)"
181
+ H="$TMPROOT/hub"; mkdir -p "$H/templates" "$H/.claude" "$H/scripts"
182
+ cp "$ROOT"/templates/settings.*.snippet.json "$H/templates/"
183
+ cat > "$H/.claude/settings.json" <<'J'
184
+ {"hooks":{"PreCompact":[{"matcher":"","hooks":[{"type":"command","command":"bash my_own_precompact.sh"}]}],
185
+ "SessionStart":[{"matcher":"","hooks":[{"type":"command","command":"bash my_telemetry.sh"}]}]}}
186
+ J
187
+ # the settings.local.json block only rewrites SessionStart, so its fixture holds only that event
188
+ printf '%s\n' '{"hooks":{"SessionStart":[{"matcher":"","hooks":[{"type":"command","command":"bash my_telemetry.sh"}]}]}}' \
189
+ > "$H/.claude/settings.local.json"
190
+ MOUT=$("$PY" "$MERGE" "$H" 2>&1); MRC=$?
191
+ _eq "S3-1 settings.json merge exits 0" "$MRC" 0
192
+ _eq "S3-2 settings.json written with zero empty matchers" "$(_hits "$H" .claude/settings.json)" 0
193
+ /usr/bin/grep -q 'my_own_precompact' "$H/.claude/settings.json" && /usr/bin/grep -q 'my_telemetry' "$H/.claude/settings.json" \
194
+ && _pass "S3-3 the user's own hooks survive the normalization" \
195
+ || _fail "S3-3 a user hook was dropped while normalizing its matcher"
196
+ LOUT=$("$PY" "$LOCALPY" "$H" "/nonexistent-store" 2>&1); LRC=$?
197
+ _eq "S3-4 settings.local.json block exits 0" "$LRC" 0
198
+ _eq "S3-5 settings.local.json written with zero empty matchers" "$(_hits "$H" .claude/settings.local.json)" 0
199
+ /usr/bin/grep -q 'my_telemetry' "$H/.claude/settings.local.json" \
200
+ && _pass "S3-6 the user's own SessionStart hook survives in settings.local.json" \
201
+ || _fail "S3-6 user hook dropped from settings.local.json"
202
+ # control: the normalization must be the reason, not luck — the fixture really did carry "".
203
+ cp "$H/.claude/settings.json.prewizard" "$H/before.json" 2>/dev/null
204
+ _eq "S3-7 control: the wizard's own backup (.prewizard) of the fixture held the empty matchers" \
205
+ "$(_hits "$H" before.json)" 2
206
+ # FileChanged is deliberately NOT normalized (there the matcher also seeds the watch list, and the
207
+ # doc spells out omitted vs "*" for it, never ""). A future FileChanged snippet must leave a user's
208
+ # "" group exactly as it was.
209
+ H2="$TMPROOT/hub_fc"; mkdir -p "$H2/templates" "$H2/.claude"
210
+ printf '%s\n' '{"project_settings_json":{"hooks":{"FileChanged":[{"matcher":".envrc","hooks":[{"type":"command","command":"bash \"$CLAUDE_PROJECT_DIR/scripts/zzz_watch.sh\""}]}]}}}' \
211
+ > "$H2/templates/settings.Zzz.snippet.json"
212
+ printf '%s\n' '{"hooks":{"FileChanged":[{"matcher":"","hooks":[{"type":"command","command":"bash my_watch.sh"}]}]}}' \
213
+ > "$H2/.claude/settings.json"
214
+ "$PY" "$MERGE" "$H2" >/dev/null 2>&1; FRC=$?
215
+ _eq "S3-8 FileChanged fixture merge exits 0" "$FRC" 0
216
+ _eq "S3-9 FileChanged: the user's \"\" group is left untouched (1 empty matcher remains)" \
217
+ "$(_hits "$H2" .claude/settings.json)" 1
218
+ fi
219
+
220
+ echo
221
+ echo "══ S4: hook_drift_check treats \"\" and omitted as the same matcher ══"
222
+ if [ ! -f "$DRIFT" ]; then
223
+ _fail "S4-0 subject missing: $DRIFT"
224
+ else
225
+ D="$TMPROOT/drift"; mkdir -p "$D/templates"
226
+ cp "$ROOT/templates/subagent-tally-hook.json" "$D/templates/"
227
+ _mk() { # $1=out $2=matcher mode: omit | empty | Bash
228
+ "$PY" - "$ROOT/templates/subagent-tally-hook.json" "$1" "$2" <<'PYEOF'
229
+ import json, sys
230
+ src, out, mode = sys.argv[1:4]
231
+ g = json.load(open(src))["hooks"]["SubagentStop"][0]
232
+ g = {k: v for k, v in g.items() if k != "matcher"}
233
+ if mode == "empty": g = {"matcher": "", **g}
234
+ elif mode != "omit": g = {"matcher": mode, **g}
235
+ json.dump({"hooks": {"SubagentStop": [g]}}, open(out, "w"), indent=2)
236
+ PYEOF
237
+ }
238
+ _v() { bash "$DRIFT" --templates "$D/templates" --settings "$1" --verdict 2>/dev/null; }
239
+ _mk "$D/omit.json" omit; _mk "$D/empty.json" empty; _mk "$D/bash.json" Bash
240
+ _eq "S4-1 local omitted · template omitted → CURRENT" "$(_v "$D/omit.json")" CURRENT
241
+ _eq "S4-2 local \"\" (old install) · template omitted → CURRENT, not STALE" "$(_v "$D/empty.json")" CURRENT
242
+ _eq "S4-3 control: local matcher \"Bash\" · template omitted → STALE" "$(_v "$D/bash.json")" STALE
243
+ fi
244
+
245
+ echo "──────────────────────────────────────────────"
246
+ if [ "$FAILED" -eq 0 ]; then
247
+ echo "COPILOT-COMPAT LANES: PASS ($PASSED lanes)"; exit 0
248
+ else
249
+ echo "COPILOT-COMPAT LANES: FAIL"; exit 1
250
+ fi
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env bash
2
+ # test_marker_diff_sha_lanes.sh — regression fixtures for pre-commit's validate_diff_sha_leg
3
+ # (2026-10-03, fh_signal_2026-10-03_marker-branch-date-key).
4
+ #
5
+ # WHY: the 4-axis marker is addressed by «branch + date» only, so a diff that changed AFTER the axes
6
+ # ran (same branch, same day) commits through the old marker. `diff-sha:` records which staged bytes
7
+ # the axes ran against; the hook recomputes and compares. Optional while DIFF_SHA_REQUIRED_DATE is
8
+ # empty (operator decision).
9
+ #
10
+ # Lanes run in a throwaway git repo so the staged diff is real. Both directions (known-pair):
11
+ # match passes · mismatch blocks · absent passes (grace) · absent blocks once the date constant is set ·
12
+ # malformed/near-miss keys block · a chain with one matching value passes · helper-script output equals
13
+ # the hook function · revert probe: neuter the comparison and the mismatch lane must turn red.
14
+ #
15
+ # Usage: bash scripts/test_marker_diff_sha_lanes.sh Exit: 0 = all behave; 1 = regression.
16
+ set -uo pipefail
17
+ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
18
+ HOOK="$REPO_ROOT/templates/.git-hooks/pre-commit"
19
+ T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
20
+
21
+ { grep -E '^DIFF_SHA_REQUIRED_DATE=' "$HOOK"
22
+ sed -n '/^_staged_diff_sha()/,/^}/p' "$HOOK"
23
+ sed -n '/^validate_diff_sha_leg()/,/^}/p' "$HOOK"; } > "$T/fn.sh"
24
+ if ! grep -q '^validate_diff_sha_leg()' "$T/fn.sh" || ! grep -q '^_staged_diff_sha()' "$T/fn.sh"; then
25
+ echo "❌ HARNESS-ERROR — validate_diff_sha_leg/_staged_diff_sha did not extract from $HOOK."
26
+ exit 1
27
+ fi
28
+
29
+ R="$T/repo"; mkdir -p "$R"
30
+ ( cd "$R" && git init -q && git config user.email t@t && git config user.name t \
31
+ && printf 'a\n' > f.txt && git add f.txt && git commit -qm init \
32
+ && printf 'a\nb\n' > f.txt && git add f.txt ) || { echo "❌ HARNESS-ERROR — fixture repo"; exit 1; }
33
+ SHA_B=$(cd "$R" && bash -c '. "$1"; _staged_diff_sha' _ "$T/fn.sh")
34
+ [ ${#SHA_B} -eq 64 ] || { echo "❌ HARNESS-ERROR — fixture sha not computed ('$SHA_B')"; exit 1; }
35
+ OTHER=$(printf '%064d' 0)
36
+
37
+ FAIL=0
38
+ lane() { # $1 id $2 expect $3 marker body [$4 needle] [$5 fn file]
39
+ local id="$1" expect="$2" body="$3" needle="${4:-}" fn="${5:-$T/fn.sh}" rc out got=PASS
40
+ printf '%s\n' "$body" > "$T/m.marker"
41
+ out=$( cd "$R" && bash -c 'set -uo pipefail; . "$1"; validate_diff_sha_leg "$2"' _ "$fn" "$T/m.marker" 2>&1 ); rc=$?
42
+ [ $rc -ne 0 ] && got=BLOCK
43
+ if [ "$got" != "$expect" ]; then
44
+ printf ' ❌ %-36s expected %s, got %s\n %s\n' "$id" "$expect" "$got" "$(printf '%s' "$out" | head -3)"; FAIL=1; return
45
+ fi
46
+ if [ -n "$needle" ] && ! printf '%s' "$out" | grep -qF -- "$needle"; then
47
+ printf ' ❌ %-36s %s but diagnostic «%s» missing\n' "$id" "$got" "$needle"; FAIL=1; return
48
+ fi
49
+ printf ' ✅ %-36s %s\n' "$id" "$got"
50
+ }
51
+
52
+ echo "== diff-sha: lanes =="
53
+ # d0 — absent marker file must fail-closed as HARNESS-ERROR (found by codex wave 2).
54
+ out=$( cd "$R" && bash -c 'set -uo pipefail; . "$1"; validate_diff_sha_leg "$2"' _ "$T/fn.sh" "$T/nonexistent.marker" 2>&1 ); rc=$?
55
+ if [ $rc -ne 0 ] && printf '%s' "$out" | grep -qF "존재하지 않는다"; then
56
+ printf ' ✅ %-36s %s\n' d0-missing-marker-blocks BLOCK
57
+ else
58
+ printf ' ❌ %-36s expected BLOCK on missing marker file\n %s\n' d0-missing-marker-blocks "$out"; FAIL=1
59
+ fi
60
+ lane d1-match-passes PASS "axes-run: ⓐ=codex
61
+ diff-sha: $SHA_B"
62
+ lane d2-mismatch-blocks BLOCK "diff-sha: $OTHER" "staged diff 와 다르다"
63
+ lane d3-absent-grace-passes PASS "axes-run: ⓐ=codex"
64
+ lane d4-chain-one-match PASS "diff-sha: $OTHER
65
+ diff-sha: $SHA_B"
66
+ lane d5-malformed-value BLOCK "diff-sha: abc123" "64자리"
67
+ lane d6-empty-value BLOCK "diff-sha:" "64자리"
68
+ lane d7-nearmiss-underscore BLOCK "diff_sha: $SHA_B
69
+ diff-sha: $SHA_B" "정확히 'diff-sha:'"
70
+ lane d7b-nearmiss-diff-fp BLOCK "diff-fp: $SHA_B" "정확히 'diff-sha:'"
71
+ lane d7c-nearmiss-capital BLOCK "Diff-sha: $SHA_B" "정확히 'diff-sha:'"
72
+ lane d8-indented-match PASS " diff-sha: $SHA_B"
73
+
74
+ # d10 — once the operator sets the date constant, absence blocks.
75
+ sed 's/^DIFF_SHA_REQUIRED_DATE=.*/DIFF_SHA_REQUIRED_DATE="2000-01-01"/' "$T/fn.sh" > "$T/fn_req.sh"
76
+ lane d10-absent-after-date BLOCK "axes-run: ⓐ=codex" "필수" "$T/fn_req.sh"
77
+
78
+ # d11 — the diff changes after the marker was written: same marker must now block.
79
+ ( cd "$R" && printf 'a\nb\nc\n' > f.txt && git add f.txt )
80
+ lane d11-diff-changed-blocks BLOCK "diff-sha: $SHA_B" "staged diff 와 다르다"
81
+ ( cd "$R" && printf 'a\nb\n' > f.txt && git add f.txt )
82
+
83
+ # d9 — helper script and hook function must agree (two hand-copies would drift silently).
84
+ H=$( cd "$R" && HOOK_OVERRIDE= bash -c 'eval "$(sed -n "/^_staged_diff_sha()/,/^}/p" "$1")"; _staged_diff_sha' _ "$HOOK" )
85
+ S=$( cd "$R" && bash "$REPO_ROOT/scripts/marker_diff_sha.sh" 2>&1 )
86
+ if [ "$S" = "$SHA_B" ] && [ "$H" = "$SHA_B" ]; then printf ' ✅ %-36s %s\n' d9-helper-equals-hook PASS
87
+ else printf ' ❌ %-36s helper=%s hook=%s fixture=%s\n' d9-helper-equals-hook "$S" "$H" "$SHA_B"; FAIL=1; fi
88
+
89
+ # d12 — diff config of the user must not change the fingerprint.
90
+ ( cd "$R" && git config diff.noprefix true && git config diff.mnemonicprefix true )
91
+ lane d12-user-diff-config PASS "diff-sha: $SHA_B"
92
+ ( cd "$R" && git config --unset diff.noprefix; git config --unset diff.mnemonicprefix )
93
+
94
+ # d13 — codex R1(2026-10-04): diff rendering knobs (context · algorithm · ignoreSubmodules) must not move the
95
+ # fingerprint either — the fingerprint is tree identity, not rendered diff text.
96
+ ( cd "$R" && git config diff.context 0 && git config diff.algorithm patience && git config diff.ignoreSubmodules all )
97
+ lane d13-diff-render-config PASS "diff-sha: $SHA_B"
98
+ ( cd "$R" && git config --unset diff.context; git config --unset diff.algorithm; git config --unset diff.ignoreSubmodules )
99
+
100
+ # d14 — a staged gitlink (submodule commit) change must move the fingerprint even under ignoreSubmodules=all.
101
+ ( cd "$R" && git config diff.ignoreSubmodules all \
102
+ && git update-index --add --cacheinfo 160000,1111111111111111111111111111111111111111,vendor/sub )
103
+ lane d14-gitlink-change-moves BLOCK "diff-sha: $SHA_B" "staged diff 와 다르다"
104
+ ( cd "$R" && git update-index --force-remove vendor/sub; git config --unset diff.ignoreSubmodules )
105
+ lane d14b-gitlink-removed-back PASS "diff-sha: $SHA_B"
106
+
107
+ echo "== revert probe (apply-check → run → expect red) =="
108
+ # Neuter the comparison: every value counts as a match. The mismatch lane MUST go red.
109
+ sed 's/\[ "\$v" = "\$cur" \] && ok=1/ok=1/' "$T/fn.sh" > "$T/fn_mut.sh"
110
+ if cmp -s "$T/fn.sh" "$T/fn_mut.sh"; then
111
+ echo " ❌ HARNESS-ERROR — mutant identical to original (sed did not apply). Revert probe is void."; FAIL=1
112
+ else
113
+ printf 'diff-sha: %s\n' "$OTHER" > "$T/m_mismatch.marker"
114
+ out=$( cd "$R" && bash -c '. "$1"; validate_diff_sha_leg "$2"' _ "$T/fn_mut.sh" "$T/m_mismatch.marker" 2>&1 ); rc=$?
115
+ if [ $rc -eq 0 ]; then printf ' ✅ %-36s mutant passes mismatch (lane d2 would turn red)\n' r1-revert-comparison
116
+ else printf ' ❌ %-36s mutant still blocks — d2 is not anchored on the comparison\n' r1-revert-comparison; FAIL=1; fi
117
+ fi
118
+ # Neuter the grace-date check: d10 must go red.
119
+ sed 's/\[ -n "\$DIFF_SHA_REQUIRED_DATE" \] \&\&/false \&\&/' "$T/fn_req.sh" > "$T/fn_mut2.sh"
120
+ if cmp -s "$T/fn_req.sh" "$T/fn_mut2.sh"; then
121
+ echo " ❌ HARNESS-ERROR — date mutant identical (sed did not apply)."; FAIL=1
122
+ else
123
+ printf 'axes-run: x\n' > "$T/m_date.marker"
124
+ out=$( cd "$R" && bash -c '. "$1"; validate_diff_sha_leg "$2"' _ "$T/fn_mut2.sh" "$T/m_date.marker" 2>&1 ); rc=$?
125
+ if [ $rc -eq 0 ]; then printf ' ✅ %-36s mutant passes absence (lane d10 would turn red)\n' r2-revert-date
126
+ else printf ' ❌ %-36s mutant still blocks\n' r2-revert-date; FAIL=1; fi
127
+ fi
128
+
129
+ if [ "$FAIL" -eq 0 ]; then echo "ALL diff-sha lanes behave."; exit 0; else echo "REGRESSION in diff-sha lanes."; exit 1; fi