@chrono-meta/fh-gate 3.24.0 → 3.25.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 +14 -1
- package/.claude-plugin/marketplace.json +4 -4
- package/CLAUDE.md +5 -4
- package/README.md +8 -6
- package/knowledge/shared/harness-core/claude_md_gate_details.md +34 -0
- package/knowledge/shared/harness-core/fh_integration_contract.md +0 -1
- package/knowledge/shared/harness-core/fh_opencode_governance_wrapper.md +0 -1
- package/knowledge/shared/harness-core/fh_three_layer_canon.md +110 -2
- package/knowledge/shared/harness-core/field_verdict_crossfamily_gate.md +22 -0
- package/knowledge/shared/harness-core/governance_engineering_definition.md +16 -0
- package/knowledge/shared/harness-core/harness_verification_core_extended.md +26 -0
- package/knowledge/shared/harness-core/ship_readiness_gate.md +3 -0
- package/knowledge/shared/harness-core/sonnet_floor_doctrine.md +19 -0
- package/package.json +10 -2
- 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 +17 -0
- package/plugins/fh-meta/skills/install-wizard/SKILL_detail.md +17 -3
- package/plugins/fh-meta/skills/sim-conductor/SKILL.md +3 -3
- package/plugins/fh-meta/skills/sim-conductor/SKILL_detail.md +4 -2
- package/plugins/fh-meta/skills/verify-bidirectional/SKILL.md +1 -1
- package/plugins/fh-preprep/.claude-plugin/plugin.json +2 -2
- package/plugins/fh-preprep/README.md +11 -0
- package/plugins/fh-preprep/skills/preprep/SKILL.md +47 -1
- package/plugins/fh-preprep/skills/preprep/lane_speech_coach.py +1090 -0
- package/plugins/fh-preprep/skills/preprep/test_lane_speech_coach.py +751 -0
- package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
- package/scripts/cluster_capability_scan.sh +17 -0
- package/scripts/compaction_probe.sh +102 -23
- package/scripts/count_check.sh +37 -10
- package/scripts/field_canon_preload.sh +84 -2
- package/scripts/marker_diff_sha.sh +13 -0
- package/scripts/mutation_probe.py +1541 -0
- package/scripts/revert_probe.sh +5 -6
- package/scripts/selfcheck.sh +48 -0
- package/scripts/test_axis23_skip_reason_lanes.sh +109 -0
- package/scripts/test_channel_inventory_lanes.sh +7 -1
- package/scripts/test_count_check_all_plugins_lanes.sh +130 -0
- package/scripts/test_field_canon_lanes.sh +33 -0
- package/scripts/test_hook_templates_copilot_compat_lanes.sh +250 -0
- package/scripts/test_marker_diff_sha_lanes.sh +129 -0
- package/scripts/test_mutation_probe_lanes.sh +786 -0
- package/scripts/test_preprep_speech_coach_lanes.sh +62 -0
- package/scripts/test_skill_canon_preload_lanes.sh +148 -0
- package/scripts/universal_guard_check.sh +2 -0
- package/templates/.git-hooks/pre-commit +109 -5
- package/templates/goal-quench-hook-setup.md +3 -3
- package/templates/goal-quench-settings-merged.json +0 -1
- package/templates/settings.Compaction.snippet.json +0 -2
- package/templates/settings.FieldCanon.snippet.json +0 -1
- package/templates/settings.SessionStart.snippet.json +0 -2
- package/templates/settings.SubagentStop.snippet.json +0 -1
- package/templates/subagent-tally-hook.json +0 -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
|