@chrono-meta/fh-gate 1.4.86 → 1.4.87

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.
@@ -0,0 +1,202 @@
1
+ #!/usr/bin/env bash
2
+ # test_wizard_snippet_merge_lanes.sh — lanes for the SessionStart snippet → settings.json merge.
3
+ #
4
+ # SUBJECT: the python block in plugins/fh-meta/skills/install-wizard/SKILL_detail.md
5
+ # §Step4-Baseline-Bash that reads templates/settings.SessionStart.snippet.json and merges its
6
+ # `project_settings_json` entry into the user's .claude/settings.json.
7
+ #
8
+ # The subject is EXTRACTED FROM THE SHIPPED FILE at run time, never retyped. A retyped copy is the
9
+ # divergent-copy class this repo has already paid for: the lane would keep validating the OLD merge
10
+ # while the shipped one drifted, and stay green throughout. Extraction failure is a FAIL, not a skip.
11
+ #
12
+ # WHY THIS MATTERS MORE THAN AN ORDINARY PARSER LANE: the hook being registered here is
13
+ # fh_node_check.sh — the one thing that tells an operator at turn 0 that their machine's floors are
14
+ # missing. If the registration silently does not happen, the detector that would have said so is the
15
+ # detector that did not get installed. That loop has to be broken from outside, and the lanes below
16
+ # measure whether anything does.
17
+ #
18
+ # CALIBRATION: every absence lane names its known-positive and builds it in the same run.
19
+ # ⓘ GAP lanes pin behaviour believed wrong without failing the suite.
20
+ # Exit 0 = calibrated · 1 = the instrument (or the extraction) is wrong.
21
+
22
+ set -uo pipefail
23
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24
+ ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
25
+ WIZ="$ROOT/plugins/fh-meta/skills/install-wizard/SKILL_detail.md"
26
+ DOC="$ROOT/plugins/fh-meta/skills/install-doctor/SKILL.md"
27
+ SNIPPET="$ROOT/templates/settings.SessionStart.snippet.json"
28
+
29
+ TMPROOT=$(mktemp -d "${TMPDIR:-/tmp}/fh_snippet_lanes.XXXXXX")
30
+ trap 'rm -rf "$TMPROOT"' EXIT
31
+ FAILED=0; PASSED=0; GAPS=0
32
+ _pass() { echo "✅ $1"; PASSED=$((PASSED+1)); }
33
+ _fail() { echo "❌ $1"; FAILED=1; }
34
+ _rc() { if [ "$2" = "$3" ]; then _pass "$1 (exit=$2, expected=$3)"; else _fail "$1 — exit=$2, expected=$3"; fi; }
35
+ _eq() { if [ "$2" = "$3" ]; then _pass "$1 ($2)"; else _fail "$1 — got [$2], expected [$3]"; fi; }
36
+ _gap() { if [ "$2" = "1" ]; then echo "ⓘ GAP (still open) $1"; echo " ↳ $3"; GAPS=$((GAPS+1));
37
+ else echo "🎉 GAP CLOSED — $1 : behaviour changed, promote this lane"; fi; }
38
+
39
+ for f in "$WIZ" "$DOC" "$SNIPPET"; do
40
+ [ -f "$f" ] || { echo "❌ subject missing: $f"; exit 1; }
41
+ done
42
+
43
+ echo "══ extraction (the instrument itself) ══"
44
+ MERGE="$TMPROOT/merge.py"
45
+ awk '/^python3 - "\$FH_DIR" <<.PY.$/{f=1;next} f&&/^PY$/{exit} f' "$WIZ" > "$MERGE"
46
+ N=$(wc -l < "$MERGE" | tr -d ' ')
47
+ if [ "$N" -lt 10 ]; then
48
+ _fail "EX-1 could not extract the merge block from SKILL_detail.md (got $N lines) — NOT a pass"
49
+ echo "──────────────────────────────────────────────"; echo "SNIPPET MERGE LANES: FAIL (extraction)"; exit 1
50
+ fi
51
+ _pass "EX-1 merge block extracted from the shipped SKILL_detail.md ($N lines)"
52
+ grep -q 'project_settings_json' "$MERGE" && _pass "EX-2 extracted block reads project_settings_json" \
53
+ || _fail "EX-2 extracted block does not mention project_settings_json — wrong region captured"
54
+
55
+ DOCPY="$TMPROOT/doctor.py"
56
+ # NOTE the leading-whitespace tolerance: this block is indented inside an `if` in the SKILL, and a
57
+ # ^-anchored pattern extracted 0 lines. That failure surfaced as a red lane rather than a green
58
+ # vacuous one only because EX-3 treats an empty extraction as FAIL — keep it that way.
59
+ awk '/^[[:space:]]*python3 - "\$FH" <<.PY.$/{f=1;next} f&&/^[[:space:]]*PY$/{exit} f' "$DOC" > "$DOCPY"
60
+ DN=$(wc -l < "$DOCPY" | tr -d ' ')
61
+ [ "$DN" -ge 5 ] && _pass "EX-3 install-doctor registration check extracted ($DN lines)" \
62
+ || _fail "EX-3 could not extract install-doctor's registration check (got $DN lines) — NOT a pass"
63
+
64
+ # ── fixture ─────────────────────────────────────────────────────────────────────
65
+ _hub() { # $1=name $2=snippet-content ("@SHIPPED" = the real tracked file) → echoes path
66
+ local h="$TMPROOT/$1"
67
+ mkdir -p "$h/templates" "$h/.claude"
68
+ if [ "$2" = "@SHIPPED" ]; then cp "$SNIPPET" "$h/templates/settings.SessionStart.snippet.json"
69
+ else printf '%s' "$2" > "$h/templates/settings.SessionStart.snippet.json"; fi
70
+ printf '%s' "$h"
71
+ }
72
+ _merge() { OUT=$(python3 "$MERGE" "$1" 2>&1); RC=$?; } # RC read directly off python, no pipe
73
+ _registered() { # 1 = fh_node_check present in the written settings.json
74
+ [ -f "$1/.claude/settings.json" ] && grep -q 'fh_node_check' "$1/.claude/settings.json" && echo 1 || echo 0
75
+ }
76
+ _claims_ok() { printf '%s\n' "$OUT" | grep -q 'hook registered' && echo 1 || echo 0; }
77
+
78
+ echo
79
+ echo "══ the happy path (known-positive for every absence lane below) ══"
80
+ H=$(_hub good @SHIPPED); _merge "$H"
81
+ _rc "MG-P shipped snippet → exit 0" "$RC" 0
82
+ _eq "MG-P → fh_node_check actually present in settings.json" "$(_registered "$H")" 1
83
+ _eq "MG-P → success line printed" "$(_claims_ok)" 1
84
+
85
+ # the documented merge promise (SKILL_detail.md: 'Merge at HOOK level, not group level') —
86
+ # a foreign hook sharing a group with the FH one must survive.
87
+ H=$(_hub coexist @SHIPPED)
88
+ cat > "$H/.claude/settings.json" <<'J'
89
+ {"hooks":{"SessionStart":[{"matcher":"","hooks":[
90
+ {"type":"command","command":"bash my_telemetry.sh"},
91
+ {"type":"command","command":"bash $CLAUDE_PROJECT_DIR/scripts/fh_node_check.sh"}]}]}}
92
+ J
93
+ _merge "$H"
94
+ grep -q 'my_telemetry' "$H/.claude/settings.json" && _pass "MG-P2 foreign hook in the FH group survives the merge" \
95
+ || _fail "MG-P2 foreign hook was dropped — the documented hook-level merge is not happening"
96
+ _eq "MG-P2 → and fh_node_check is (re)registered" "$(_registered "$H")" 1
97
+ DUP=$(grep -c 'fh_node_check' "$H/.claude/settings.json")
98
+ _eq "MG-P2 → old FH entry replaced, not duplicated" "$DUP" 1
99
+
100
+ echo
101
+ echo "══ malformed snippet: fails loudly, writes nothing ══"
102
+ # These four are the F10 question as posed (malformed / truncated / empty). The merge turns out to
103
+ # be fail-CLOSED here — worth pinning precisely so a future 'robustness' refactor that swallows the
104
+ # exception is caught as the regression it would be.
105
+ SHIPPED_TXT=$(cat "$SNIPPET")
106
+ i=0
107
+ for name in empty notjson truncated missingkey; do
108
+ i=$((i+1))
109
+ case "$name" in
110
+ empty) body="" ;;
111
+ notjson) body="oops not json at all" ;;
112
+ truncated) body=$(printf '%s' "$SHIPPED_TXT" | head -c 400) ;;
113
+ missingkey) body='{"hooks":{"SessionStart":[]}}' ;;
114
+ esac
115
+ H=$(_hub "bad_$name" "$body"); _merge "$H"
116
+ _rc "MG-N$i $name snippet → non-zero exit" "$RC" 1
117
+ _eq "MG-N$i $name → nothing registered (paired with MG-P)" "$(_registered "$H")" 0
118
+ _eq "MG-N$i $name → no success line" "$(_claims_ok)" 0
119
+ done
120
+
121
+ echo
122
+ echo "══ malformed EXISTING settings.json: the user's file is not destroyed ══"
123
+ H=$(_hub badtarget @SHIPPED); printf '{ oops' > "$H/.claude/settings.json"
124
+ _merge "$H"
125
+ _rc "MG-T unparsable target → non-zero exit" "$RC" 1
126
+ _eq "MG-T → the user's file is left byte-identical" "$(cat "$H/.claude/settings.json")" '{ oops'
127
+ [ -f "$H/.claude/settings.json.prewizard" ] \
128
+ && _fail "MG-T → a .prewizard backup of an unread file was written (misleading artifact)" \
129
+ || _pass "MG-T → no misleading backup artifact left behind"
130
+
131
+ echo
132
+ echo "══ ⓘ GAP lanes ══"
133
+
134
+ # GAP 1 — the ONLY validation is what `kept + entry` incidentally requires: that entry is a list.
135
+ # Any list-shaped value is written to the user's real settings.json and reported as success. The
136
+ # success message is not conditioned on what was actually written.
137
+ BADSCHEMA_HITS=0; BADSCHEMA_TOTAL=0; DETAIL=""
138
+ for name in emptylist nocommand wrongscript juststring; do
139
+ case "$name" in
140
+ emptylist) body='{"project_settings_json":{"hooks":{"SessionStart":[]}}}' ;;
141
+ nocommand) body='{"project_settings_json":{"hooks":{"SessionStart":[{"matcher":"","hooks":[{"type":"command"}]}]}}}' ;;
142
+ wrongscript) body='{"project_settings_json":{"hooks":{"SessionStart":[{"matcher":"","hooks":[{"type":"command","command":"bash /some/other/script.sh"}]}]}}}' ;;
143
+ juststring) body='{"project_settings_json":{"hooks":{"SessionStart":["not even an object"]}}}' ;;
144
+ esac
145
+ H=$(_hub "schema_$name" "$body"); _merge "$H"
146
+ BADSCHEMA_TOTAL=$((BADSCHEMA_TOTAL+1))
147
+ if [ "$RC" = 0 ] && [ "$(_claims_ok)" = 1 ] && [ "$(_registered "$H")" = 0 ]; then
148
+ BADSCHEMA_HITS=$((BADSCHEMA_HITS+1)); DETAIL="$DETAIL $name"
149
+ fi
150
+ done
151
+ _g=0; [ "$BADSCHEMA_HITS" -gt 0 ] && _g=1
152
+ _gap "valid-JSON / invalid-SCHEMA snippet → written, reported as success, node hook absent" "$_g" \
153
+ "$BADSCHEMA_HITS of $BADSCHEMA_TOTAL cases:$DETAIL. exit 0 and 'node-check SessionStart hook \
154
+ registered ->' are printed while fh_node_check is NOT in the file that was just written. The success \
155
+ message is unconditional — it does not re-read what it wrote. One-line fix: after the write, assert \
156
+ fh_node_check appears in the serialized result, else exit non-zero."
157
+
158
+ # GAP 2 — the corruption from GAP 1 is LATENT: the bad value lands in the user's settings.json and
159
+ # detonates on the NEXT wizard run, in the kept-loop, far from where it was introduced.
160
+ H=$(_hub latent '{"project_settings_json":{"hooks":{"SessionStart":["not even an object"]}}}')
161
+ _merge "$H"; FIRST_RC=$RC
162
+ _merge "$H"; SECOND_RC=$RC
163
+ _g=0; { [ "$FIRST_RC" = 0 ] && [ "$SECOND_RC" != 0 ]; } && _g=1
164
+ _gap "the bad write detonates on the NEXT run, not the run that made it" "$_g" \
165
+ "run1 exit=$FIRST_RC (reported success), run2 exit=$SECOND_RC (AttributeError in the kept-loop: \
166
+ g.get on a str). The user's settings.json is now un-mergeable and the traceback points at the \
167
+ survivor filter, not at the snippet that caused it."
168
+
169
+ # GAP 3 — INSTRUMENT COVERAGE, measured not asserted. Build the exact post-failure state (companion
170
+ # hook registered, node hook absent) and run install-doctor's registration check on it. The
171
+ # known-positive is in the same run: the companion line must fire, proving the check executed.
172
+ H="$TMPROOT/doctor_state"; mkdir -p "$H/.claude"
173
+ cat > "$H/.claude/settings.local.json" <<'J'
174
+ {"hooks":{"SessionStart":[{"matcher":"","hooks":[
175
+ {"type":"command","command":"bash $CLAUDE_PROJECT_DIR/scripts/fh_session_load.sh"}]}]}}
176
+ J
177
+ printf '{}' > "$H/.claude/settings.json"
178
+ DOUT=$(python3 "$DOCPY" "$H" 2>&1); DRC=$?
179
+ if printf '%s\n' "$DOUT" | grep -q 'companion-load SessionStart registered'; then
180
+ _pass "DR-P install-doctor's check RAN on this fixture (known-positive: companion line fired, exit=$DRC)"
181
+ else
182
+ _fail "DR-P install-doctor's check did not fire at all — the GAP lane below would pass vacuously"
183
+ fi
184
+ _g=0; printf '%s\n' "$DOUT" | grep -qi 'node_check\|node check' || _g=1
185
+ _gap "nothing downstream verifies that fh_node_check is registered" "$_g" \
186
+ "The node hook is absent from this fixture and install-doctor's registration check says nothing \
187
+ about it — it only greps for fh_session_load. install-doctor's ① checks the git hook FILES, not the \
188
+ SessionStart REGISTRATION of the script that reports on them. So the wizard's unconditional success \
189
+ message (GAP 1) is never contradicted by anything, and the check whose job is announcing an unwired \
190
+ machine can itself be unwired silently."
191
+
192
+ echo
193
+ echo "──────────────────────────────────────────────"
194
+ if [ "$FAILED" -ne 0 ]; then
195
+ echo "SNIPPET MERGE LANES: FAIL — instrument miscalibrated (do not trust its verdict)"
196
+ echo " asserting lanes passed: $PASSED · open gaps: $GAPS"
197
+ exit 1
198
+ fi
199
+ echo "SNIPPET MERGE LANES: PASS ($PASSED asserting lanes) · $GAPS KNOWN GAP(S) open (see ⓘ above)"
200
+ echo " Green covers: happy path, hook-level merge promise, malformed-snippet fail-closed,"
201
+ echo " unparsable-target preservation. Green does NOT cover the three gaps above."
202
+ exit 0
@@ -79,7 +79,10 @@ EOF
79
79
 
80
80
  ### Automatic Response to Issues
81
81
 
82
- <!-- [CUSTOMIZE] Adjust report tool/path to match your project -->
82
+ <!-- [CUSTOMIZE] DOMAIN-SCOPED delete this whole section if the project has no test-report
83
+ artifact to analyse. The old wording here said "adjust report tool/path", which assumes the
84
+ tool exists and reads as a config note rather than a delete instruction; the same measurement
85
+ that found the two sections below inert found this one inert for the same reason. -->
83
86
 
84
87
  #### Automatic Check Trigger
85
88
 
@@ -98,9 +101,27 @@ When the user mentions a problem, **automatically** locate and analyze the lates
98
101
 
99
102
  ### Code Writing Principles
100
103
 
101
- <!-- [CUSTOMIZE] Adjust to match your project's coding conventions. The 5 principles below are universal and valid for any project. -->
102
-
103
- Be conscious of all 5 principles **before** writing code directly reduces back-and-forth where Claude rushes to create something and the user has to correct it.
104
+ <!-- [CUSTOMIZE] Adjust to match your project's coding conventions.
105
+ THREE of the five below are universal (#1 #2 #5). TWO are DOMAIN-SCOPED and belong only to
106
+ UI/mobile-QA projects (#3 locator stability, #4 flakiness)DELETE them outright if this
107
+ project has no UI automation. Do not keep them "just in case": measured 2026-08-03 across
108
+ THREE repos that inherited this file. One (a bash/python wiki engine) carried both for its
109
+ entire 11-day life before being pruned; the other two are byte-identical to this template
110
+ right now and still carry them.
111
+ If you delete a section, also fix any sentence that counts them — the wiki engine shipped
112
+ "all 5 principles" over three for an hour before an outside reviewer caught it.
113
+ What the fix here does and does NOT do, measured as a before/after pair (Sonnet, reps=3).
114
+ The gain depends on how explicitly the asker names what the project lacks:
115
+ * question naming no-UI/no-mobile only -> before: #3 3/3, #4 **1/3**; after: both 3/3
116
+ * question also naming no-test-reports -> before: 8 of 9 cells; after: 9 of 9
117
+ So the honest claim is narrow: the old wording is mostly adequate for someone who spells out
118
+ every absence, and loses a section for someone who does not. Both numbers are recorded because
119
+ citing only the first would overstate this edit.
120
+ THE FIELD CAUSE IS STILL OPEN, and it is a different moment: the wiki engine did not prune
121
+ either section, which means nobody was asked. `light-harness init` copies this file whole,
122
+ with no pruning step. A marker only works on a reader who has stopped to read it. -->
123
+
124
+ Be conscious of every principle below **before** writing code — directly reduces back-and-forth where Claude rushes to create something and the user has to correct it.
104
125
 
105
126
  #### 1. Reference Existing Code (Consistency First)
106
127
 
@@ -116,7 +137,7 @@ Be conscious of all 5 principles **before** writing code — directly reduces ba
116
137
 
117
138
  #### 3. Locator and Identifier Stability (UI code only)
118
139
 
119
- <!-- [CUSTOMIZE] Can be removed for non-mobile QA / non-web QA projects -->
140
+ <!-- [CUSTOMIZE] DOMAIN-SCOPED delete this whole section for non-UI projects (see the note above #1) -->
120
141
 
121
142
  - Do not depend on dynamically generated attributes (auto-generated id, timestamps in content-desc)
122
143
  - Avoid absolute XPath — fragile to structural changes
@@ -125,6 +146,8 @@ Be conscious of all 5 principles **before** writing code — directly reduces ba
125
146
 
126
147
  #### 4. Flakiness Risk Management
127
148
 
149
+ <!-- [CUSTOMIZE] DOMAIN-SCOPED — delete this whole section for projects without UI automation -->
150
+
128
151
  - **No `time.sleep`** — use explicit waits (implicit/explicit wait) + condition-based polling
129
152
  - No unbounded waits without a timeout
130
153
  - Allow tolerance in screenshot-based assertions
@@ -706,8 +706,15 @@ run_universal_guards
706
706
  # not a reversible-surface concern — it disables the commit gate itself.
707
707
  GATE_IMPL=$(echo "$STAGED" \
708
708
  | grep -E '(templates/\.git-hooks/pre-commit|templates/regression_guard\.sh|\.claude/rules/fh_4axis_gate\.md|scripts/gate_pathspec_check\.sh)' || true)
709
- if [ -n "$GATE_IMPL" ]; then
710
- echo "[Gate] gate implementation staged path-coverage known-pair anchor..."
709
+ # CLAUDE.md carries a canonical asset list that gate_pathspec_check §5 verifies, so editing it must
710
+ # RUN the anchor. It is deliberately NOT added to GATE_IMPL: that variable also feeds $LOADBEARING,
711
+ # which demands a cross-family acknowledgment line in the marker. Enrolling every CLAUDE.md prose
712
+ # edit into cross-family review is a different job from path coverage, and over-blocking is how an
713
+ # override becomes muscle memory (CLAUDE.md §Destructive-Op — the same reasoning that keeps the
714
+ # session-close check advisory on ordinary pushes). Separate trigger, same anchor.
715
+ ASSETLIST_IMPL=$(echo "$STAGED" | grep -E '^CLAUDE\.md$' || true)
716
+ if [ -n "$GATE_IMPL" ] || [ -n "$ASSETLIST_IMPL" ]; then
717
+ echo "[Gate] gate implementation or asset list staged — path-coverage known-pair anchor..."
711
718
  PSCHECK="$REPO_ROOT/scripts/gate_pathspec_check.sh"
712
719
  if [ ! -f "$PSCHECK" ]; then
713
720
  echo " ❌ FAIL — scripts/gate_pathspec_check.sh missing while a gate file is being changed."