@chrono-meta/fh-gate 3.24.0 → 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 (50) 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/fh_integration_contract.md +0 -1
  7. package/knowledge/shared/harness-core/fh_opencode_governance_wrapper.md +0 -1
  8. package/knowledge/shared/harness-core/fh_three_layer_canon.md +110 -2
  9. package/knowledge/shared/harness-core/field_verdict_crossfamily_gate.md +22 -0
  10. package/knowledge/shared/harness-core/governance_engineering_definition.md +16 -0
  11. package/knowledge/shared/harness-core/harness_verification_core_extended.md +26 -0
  12. package/knowledge/shared/harness-core/ship_readiness_gate.md +3 -0
  13. package/knowledge/shared/harness-core/sonnet_floor_doctrine.md +19 -0
  14. package/package.json +10 -2
  15. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  16. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  17. package/plugins/fh-meta/CHANGELOG.md +9 -0
  18. package/plugins/fh-meta/skills/install-wizard/SKILL_detail.md +17 -3
  19. package/plugins/fh-meta/skills/verify-bidirectional/SKILL.md +1 -1
  20. package/plugins/fh-preprep/.claude-plugin/plugin.json +2 -2
  21. package/plugins/fh-preprep/README.md +11 -0
  22. package/plugins/fh-preprep/skills/preprep/SKILL.md +47 -1
  23. package/plugins/fh-preprep/skills/preprep/lane_speech_coach.py +1080 -0
  24. package/plugins/fh-preprep/skills/preprep/test_lane_speech_coach.py +705 -0
  25. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  26. package/scripts/cluster_capability_scan.sh +17 -0
  27. package/scripts/compaction_probe.sh +102 -23
  28. package/scripts/count_check.sh +37 -10
  29. package/scripts/field_canon_preload.sh +84 -2
  30. package/scripts/marker_diff_sha.sh +13 -0
  31. package/scripts/mutation_probe.py +1541 -0
  32. package/scripts/revert_probe.sh +5 -6
  33. package/scripts/selfcheck.sh +48 -0
  34. package/scripts/test_axis23_skip_reason_lanes.sh +109 -0
  35. package/scripts/test_count_check_all_plugins_lanes.sh +130 -0
  36. package/scripts/test_field_canon_lanes.sh +33 -0
  37. package/scripts/test_hook_templates_copilot_compat_lanes.sh +250 -0
  38. package/scripts/test_marker_diff_sha_lanes.sh +129 -0
  39. package/scripts/test_mutation_probe_lanes.sh +786 -0
  40. package/scripts/test_preprep_speech_coach_lanes.sh +62 -0
  41. package/scripts/test_skill_canon_preload_lanes.sh +148 -0
  42. package/scripts/universal_guard_check.sh +2 -0
  43. package/templates/.git-hooks/pre-commit +109 -5
  44. package/templates/goal-quench-hook-setup.md +3 -3
  45. package/templates/goal-quench-settings-merged.json +0 -1
  46. package/templates/settings.Compaction.snippet.json +0 -2
  47. package/templates/settings.FieldCanon.snippet.json +0 -1
  48. package/templates/settings.SessionStart.snippet.json +0 -2
  49. package/templates/settings.SubagentStop.snippet.json +0 -1
  50. package/templates/subagent-tally-hook.json +0 -1
@@ -0,0 +1,786 @@
1
+ #!/usr/bin/env bash
2
+ # test_mutation_probe_lanes.sh — known-pair lanes for scripts/mutation_probe.py (2026-10-07).
3
+ #
4
+ # WHAT IS PINNED
5
+ # F the boundary case the tool exists for: `-ge 19` tested only with 20 and 5 → the `-ge→-gt`
6
+ # mutant SURVIVES (known-positive survivor); add the 19 case → it is KILLED (known-negative).
7
+ # C calibration of the mutant GENERATOR itself — the prototype mutated a redirect
8
+ # (`2>/dev/null` → `2>=/dev/null`) and wrote a stray file named `=`. C1 = lines that must yield
9
+ # ZERO mutants (redirects · here-string · quoted operators · comments); C2 = lines that must
10
+ # yield exactly the listed mutants.
11
+ # P python operator set.
12
+ # E every «cannot judge» path exits 2, never 0: baseline red · no mutants · missing lane.
13
+ # R the subject is byte-identical after a run, including a run whose lane times out.
14
+ # RV revert probe: force the tool's kill decision to «always killed» → the F survivor vanishes,
15
+ # so lane F1 would turn red. If it ever stops vanishing, F1 is not measuring the tool.
16
+ #
17
+ # S7 the v7 safety contract (symlink/inode replacement · crossed locks · positive control · final run on
18
+ # the original · setsid escapees · --json only when measured · kernel shebang · mode bits · future
19
+ # mtime · inode-keyed leftovers) — each lane red on v6.
20
+ # G7 the v6 generator defect classes, pinned — fail-closed: an uncertain region yields no mutant.
21
+ # K0 the /proc process counter used by N6/S7-5, on a known pair, before either trusts it.
22
+ #
23
+ # Exit 0 = all lanes behave · 1 = regression (or an UNMEASURED lane — never folded into PASS).
24
+ set -uo pipefail
25
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
26
+ PROBE="$SCRIPT_DIR/mutation_probe.py"
27
+ FAILED=0; PASS=0; UNMEASURED=0
28
+ chk() { if [ "$1" -eq 0 ]; then PASS=$((PASS+1)); echo " ✅ $2"; else FAILED=1; echo " ❌ $2"; fi; }
29
+ [ -f "$PROBE" ] || { echo "FAIL subject $PROBE missing"; exit 1; }
30
+ command -v python3 >/dev/null 2>&1 || { echo "FAIL python3 absent — the probe cannot run, so nothing here was verified"; exit 1; }
31
+
32
+ T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
33
+ cd "$T" || exit 1
34
+
35
+ # ── fixtures ──────────────────────────────────────────────────────────────────
36
+ cat > age.sh <<'EOF'
37
+ #!/usr/bin/env bash
38
+ is_adult() { [ "$1" -ge 19 ]; }
39
+ EOF
40
+ cat > lane_weak.sh <<'EOF'
41
+ . ./age.sh
42
+ is_adult 20 || exit 1
43
+ is_adult 5 && exit 1
44
+ exit 0
45
+ EOF
46
+ cat > lane_strong.sh <<'EOF'
47
+ . ./age.sh
48
+ is_adult 20 || exit 1
49
+ is_adult 19 || exit 1
50
+ is_adult 5 && exit 1
51
+ exit 0
52
+ EOF
53
+
54
+ echo "── F: the boundary survivor (known-positive) and its kill (known-negative)"
55
+ out_w=$(python3 "$PROBE" age.sh lane_weak.sh --timeout 30 2>&1); rc_w=$?
56
+ [ "$rc_w" -eq 0 ] ; chk $? "weak lane: measured → rc 0 (survivors are reported, not failed)"
57
+ grep -q 'SURVIVED L2 \[-ge→-gt\]' <<<"$out_w" ; chk $? "F1 weak lane: -ge→-gt SURVIVES (only 20 and 5 tested — the field report's <→<= case)"
58
+ out_s=$(python3 "$PROBE" age.sh lane_strong.sh --timeout 30 2>&1)
59
+ grep -qE 'mutants=1 killed=1 survived=0( |$)' <<<"$out_s" ; chk $? "F2 strong lane (adds 19): the one mutant is KILLED (not merely «no survivor»)"
60
+ grep -qE 'mutants=1 killed=0 survived=1( |$)' <<<"$out_w" ; chk $? "F3 and the count is exact: one operator on the line → one mutant, survived"
61
+
62
+ echo "── C: generator calibration"
63
+ cat > neg.sh <<'EOF'
64
+ #!/usr/bin/env bash
65
+ echo hi 2>/dev/null
66
+ cmd > out.txt
67
+ cat >> log.txt
68
+ grep x <<< "$y"
69
+ echo "a == b and c -eq d"
70
+ echo 'exit 1 inside quotes'
71
+ # if [ "$a" -eq 1 ]; then exit 1; fi
72
+ x=$(( a >> 2 ))
73
+ EOF
74
+ out=$(python3 "$PROBE" neg.sh --list 2>&1); rc=$?
75
+ grep -qE 'mutants=0( |$)' <<<"$out" ; chk $? "C1 known-negative: redirects · here-string · quoted · commented · shift → ZERO mutants"
76
+ grep -qE 'mutants=0( |$)' <<<"$out" && [ "$rc" -eq 2 ] ; chk $? "C1 and --list over zero mutants exits 2 (nothing measured), not 0"
77
+ cat > pos.sh <<'EOF'
78
+ #!/usr/bin/env bash
79
+ [ "$a" -eq 1 ] && echo one
80
+ (( n >= 3 )) && echo many
81
+ FAILED=1
82
+ exit 1
83
+ EOF
84
+ out=$(python3 "$PROBE" pos.sh --list 2>&1)
85
+ grep -qE 'mutants=4( |$)' <<<"$out" ; chk $? "C2 known-positive: exactly 4 mutants"
86
+ grep -q '\[-eq→-ne\]' <<<"$out" && grep -q '\[>=→>\]' <<<"$out" && grep -q '\[FAILED=1→FAILED=0\]' <<<"$out" && grep -q '\[exit 1→exit 0\]' <<<"$out"
87
+ chk $? "C2 and they are -eq→-ne · >=→> (inside (( ))) · FAILED=1→0 · exit 1→0"
88
+
89
+ echo "── P: python operator set"
90
+ cat > v.py <<'EOF'
91
+ import sys
92
+ def ok(x):
93
+ return x >= 19
94
+ if not ok(int(sys.argv[1])):
95
+ sys.exit(1)
96
+ flag = True
97
+ EOF
98
+ out=$(python3 "$PROBE" v.py --list 2>&1)
99
+ grep -qE 'lang=python mutants=3( |$)' <<<"$out" ; chk $? "P1 python: >= · sys.exit(1) · = True → 3 mutants"
100
+
101
+ echo "── X: the two calibration gaps the first real run found (2026-10-07)"
102
+ cat > emb.sh <<'SH'
103
+ #!/usr/bin/env bash
104
+ [ "$CLS" = internal ] && echo skip
105
+ x=foo
106
+ echo a = b
107
+ r=$(python3 -c '
108
+ import sys
109
+ ok = len(sys.argv) >= 2
110
+ if a < b: pass
111
+ ')
112
+ python3 - <<'PY'
113
+ flag = True
114
+ PY
115
+ echo done > out.txt
116
+ SH
117
+ out=$(python3 "$PROBE" emb.sh --list 2>&1)
118
+ grep -qF '[=→!=] [ "$CLS" != internal ] && echo skip' <<<"$out" ; chk $? "X1 bash single-= string test inside [ ] is mutated"
119
+ grep -qE 'mutants=4( |$)' <<<"$out" && ! grep -qF 'echo a != b' <<<"$out" ; chk $? "X1b a spaced \` = \` OUTSIDE [ ] (echo a = b) is not mutated — the in_test guard is load-bearing"
120
+ grep -qF '[>=→>] ok = len(sys.argv) > 2' <<<"$out" ; chk $? "X2 python inside an open python3 -c ' block gets the python set"
121
+ grep -qF '[<→<=] if a <= b: pass' <<<"$out" ; chk $? "X2b a bare < inside the -c block is mutated — only the python set does that (bash leaves < alone outside (( )))"
122
+ grep -qF '[True→False] flag = False' <<<"$out" ; chk $? "X3 python inside a python3 - <<'PY' heredoc gets the python set"
123
+ grep -qE 'mutants=4( |$)' <<<"$out" && ! grep -qF 'out.txt' <<<"$out" ; chk $? "X4 bash after both blocks close is bash again (its redirect untouched)"
124
+ grep -qE 'mutants=4( |$)' <<<"$out" ; chk $? "X5 exact count: = · >= · < · True → 4"
125
+ printf '#!/usr/bin/env bash\nn=$# # if [ a -eq b ] < c\n[ "$n" -eq 0 ] && echo none # trailing: -ge > ==\n' > cmt.sh
126
+ out=$(python3 "$PROBE" cmt.sh --list 2>&1)
127
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -qF '[-eq→-ne]' <<<"$out" ; chk $? "X6 operators inside a trailing comment are not mutated; \$# is not a comment start"
128
+
129
+
130
+ echo "── E: every «cannot judge» exits 2"
131
+ printf 'exit 1\n' > lane_red.sh
132
+ out=$(python3 "$PROBE" age.sh lane_red.sh --timeout 30 2>&1) ; [ $? -eq 2 ] && grep -q "baseline lane is not green" <<<"$out" ; chk $? "E1 baseline lane red → 2 (else every mutant reads as killed)"
133
+ printf 'echo nothing to mutate\n' > flat.sh
134
+ out=$(python3 "$PROBE" flat.sh lane_weak.sh --timeout 30 2>&1) ; [ $? -eq 2 ] && grep -q "no mutants generated" <<<"$out" ; chk $? "E2 no mutants → 2, not «0 survivors»"
135
+ out=$(python3 "$PROBE" age.sh no_such_lane.sh 2>&1) ; [ $? -eq 2 ] && grep -q "lane suite not found" <<<"$out" ; chk $? "E3 missing lane → 2"
136
+ out=$(python3 "$PROBE" age.sh lane_weak.sh --json /nonexistent_dir/x.json 2>&1) ; [ $? -eq 2 ] && grep -q -- "--json not writable" <<<"$out" ; chk $? "E4 unwritable --json → 2, never a traceback rc 1"
137
+
138
+ echo "── R: the subject is restored byte-for-byte"
139
+ h0=$(python3 -c 'import hashlib,sys;print(hashlib.sha256(open(sys.argv[1],"rb").read()).hexdigest())' age.sh)
140
+ out_r1=$(python3 "$PROBE" age.sh lane_weak.sh --timeout 30 2>&1)
141
+ h1=$(python3 -c 'import hashlib,sys;print(hashlib.sha256(open(sys.argv[1],"rb").read()).hexdigest())' age.sh)
142
+ grep -qE 'mutants=1 killed=0 survived=1( |$)' <<<"$out_r1" && [ "$h0" = "$h1" ] ; chk $? "R1 after a normal run that measured"
143
+ cat > lane_hang.sh <<'EOF'
144
+ . ./age.sh
145
+ if is_adult 19; then exit 0; fi
146
+ sleep 30
147
+ EOF
148
+ out=$(python3 "$PROBE" age.sh lane_hang.sh --timeout 2 2>&1)
149
+ h2=$(python3 -c 'import hashlib,sys;print(hashlib.sha256(open(sys.argv[1],"rb").read()).hexdigest())' age.sh)
150
+ grep -q 'TIMEOUT L2' <<<"$out" && [ "$h0" = "$h2" ] ; chk $? "R2 after a run whose lane hangs on the mutant"
151
+ grep -q 'TIMEOUT L2' <<<"$out" ; chk $? "R3 a hang is reported as TIMEOUT, its own class — not folded into KILLED"
152
+
153
+ echo "── S: in-place safety — each lane is a blocking repro from the 2026-10-07 blind review"
154
+ bkpath() { python3 -c 'import hashlib,os,sys;print("/tmp/mutation_probe-%d/path-%s.backup"%(os.getuid(),hashlib.sha256(os.path.realpath(sys.argv[1]).encode()).hexdigest()[:16]))' "$1"; }
155
+ sha_of() { python3 -c 'import hashlib,sys;print(hashlib.sha256(open(sys.argv[1],"rb").read()).hexdigest())' "$1"; }
156
+ procs_matching() { # count live processes whose WHOLE cmdline is $1 — /proc, not pgrep (pgrep absent → vacuous);
157
+ local n=0 c # exact match, so the counter never counts itself (a substring grep did)
158
+ for c in /proc/[0-9]*/cmdline; do [ -e "$c" ] || continue; [ "$(tr '\0' ' ' < "$c" 2>/dev/null)" = "$1 " ] && n=$((n+1)); done
159
+ echo "$n"
160
+ }
161
+ if [ -d /proc/self ]; then HAVE_PROC=1; else HAVE_PROC=0; fi
162
+
163
+ # B4 — the baseline lane writes its own subject: refuse, and leave the ORIGINAL bytes
164
+ cp age.sh b4.sh; h0=$(sha_of b4.sh)
165
+ printf '. ./b4.sh\nis_adult 20 || exit 1\necho "# stamp" >> b4.sh\nexit 0\n' > lane_b4.sh
166
+ out=$(python3 "$PROBE" b4.sh lane_b4.sh --timeout 30 2>&1); rc=$?
167
+ [ "$rc" -eq 2 ] && grep -q 'baseline lane WROTE the subject' <<<"$out" ; chk $? "B4 a lane that writes its subject → 2 with that reason (v1: rc 0, «restored» to the stamped bytes)"
168
+ grep -q 'baseline lane WROTE the subject' <<<"$out" && [ "$(sha_of b4.sh)" = "$h0" ] ; chk $? "B4b and the subject is back to the ORIGINAL bytes, not the post-baseline ones"
169
+
170
+ # B3 — a second probe on the same subject while the first runs
171
+ cp age.sh b3.sh; h0=$(sha_of b3.sh)
172
+ printf '. ./b3.sh\ntouch b3.started\nsleep 2\nis_adult 20 || exit 1\nis_adult 5 && exit 1\nexit 0\n' > lane_b3.sh
173
+ rm -f b3.started
174
+ python3 "$PROBE" b3.sh lane_b3.sh --timeout 30 > b3_a.out 2>&1 & pa=$!
175
+ for _ in $(seq 1 100); do [ -e b3.started ] && break; sleep 0.1; done # the first probe is past its locks
176
+ out=$(python3 "$PROBE" b3.sh lane_b3.sh --timeout 30 2>&1); rc_b=$?
177
+ wait $pa; rc_a=$?
178
+ [ "$rc_b" -eq 2 ] && grep -q 'another mutation_probe holds' <<<"$out" ; chk $? "B3 the second probe refuses (2) instead of backing up the first one's mutant (v1: both rc 0)"
179
+ [ "$rc_a" -eq 0 ] && [ "$(sha_of b3.sh)" = "$h0" ] ; chk $? "B3b the first probe completes and the subject ends byte-identical"
180
+
181
+ # B2 — SIGHUP mid-run restores; a leftover backup blocks the next run
182
+ cp age.sh b2.sh; h0=$(sha_of b2.sh)
183
+ printf '. ./b2.sh\nif grep -q -- "-gt" b2.sh; then touch b2.live; fi\nsleep 5\nexit 0\n' > lane_b2.sh
184
+ rm -f b2.live
185
+ python3 "$PROBE" b2.sh lane_b2.sh --timeout 30 >/dev/null 2>&1 & pb=$!
186
+ for _ in $(seq 1 150); do [ -e b2.live ] && break; sleep 0.1; done # the lane itself says the mutant is live
187
+ kill -HUP "$pb" 2>/dev/null; wait "$pb"; rc=$?
188
+ [ -e b2.live ] && [ "$rc" -eq 129 ] && [ "$(sha_of b2.sh)" = "$h0" ] ; chk $? "B2 SIGHUP while a mutant is live → restored, exit 129 (v1: left the mutant in place)"
189
+ bk=$(bkpath b2.sh)
190
+ [ -e b2.live ] && [ "$rc" -eq 129 ] && [ ! -e "$bk" ] ; chk $? "B2b a clean signal exit removes its fixed-path backup"
191
+ cp b2.sh "$bk"
192
+ out=$(python3 "$PROBE" b2.sh lane_weak.sh --timeout 30 2>&1); rc=$?
193
+ rm -f "$bk"
194
+ [ "$rc" -eq 2 ] && grep -q 'previous run left a backup' <<<"$out" ; chk $? "B2c a leftover backup (SIGKILL case) blocks the next run and names the path"
195
+
196
+ # B1 — python subject, same-size mutants, the stale-bytecode trap
197
+ cat > gate.py <<'EOF'
198
+ def a(x):
199
+ return x == 1
200
+ def b(x):
201
+ return x == 2
202
+ def c(x):
203
+ return x == 3
204
+ EOF
205
+ printf 'import sys\nsys.path.insert(0, ".")\nimport gate\nassert gate.a(1) and not gate.a(5)\nassert gate.c(3) and not gate.c(5)\n' > lane_b1.py
206
+ touch -d 2020-01-01 gate.py 2>/dev/null || touch -t 202001010000 gate.py
207
+ python3 -c 'import sys;sys.path.insert(0,".");import gate' 2>/dev/null # leave a real __pycache__ behind
208
+ out=$(python3 "$PROBE" gate.py lane_b1.py --timeout 30 2>&1)
209
+ grep -qE 'mutants=3 killed=2 survived=1( |$)' <<<"$out" && grep -q 'SURVIVED L4' <<<"$out" ; chk $? "B1 python: the untested b() survives and only it (v1: killed=3 — stale bytecode)"
210
+
211
+ # N1 — nothing measured is not «measured»
212
+ printf '#!/usr/bin/env bash\nis_adult() { [ "$1" -ge 19 ]; }\n' > n1.sh
213
+ printf '. ./n1.sh\nis_adult 20 && is_adult 19 && exit 0\nsleep 30\n' > lane_n1.sh
214
+ out=$(python3 "$PROBE" n1.sh lane_n1.sh --timeout 2 2>&1); rc=$?
215
+ [ "$rc" -eq 2 ] && grep -q 'nothing was measured' <<<"$out" ; chk $? "N1 only TIMEOUT results → 2, not 0"
216
+ printf 'if (a == b) { process.exit(1) }\n' > n1.js
217
+ out=$(python3 "$PROBE" n1.js lane_weak.sh 2>&1) ; [ $? -eq 2 ] && grep -q 'unsupported language' <<<"$out" ; chk $? "N1b an unsupported language (.js) → 2, never read as bash"
218
+
219
+ # N4 · N5 — bytes in, bytes out
220
+ printf 'import sys\r\nif len(sys.argv) >= 2:\r\n pass\r\n' > crlf.py
221
+ printf 'import sys,subprocess\nd=open("crlf.py","rb").read()\nsys.exit(0 if d.count(b"\\r\\n")==3 else 1)\n' > lane_crlf.py
222
+ out=$(python3 "$PROBE" crlf.py lane_crlf.py --timeout 30 2>&1)
223
+ grep -qE 'mutants=1 killed=0 survived=1( |$)' <<<"$out" ; chk $? "N4 a CRLF subject keeps its line endings in the mutant (v1: the endings, not the operator, were «killed»)"
224
+ printf '#!/usr/bin/env bash\n# caf\xe9\n[ "$a" -eq 1 ]\n' > lat.sh
225
+ out=$(python3 "$PROBE" lat.sh lane_weak.sh 2>&1); rc=$?
226
+ [ "$rc" -eq 2 ] && grep -q 'not UTF-8' <<<"$out" ; chk $? "N5 non-UTF-8 subject → 2 with the reason (v1: traceback rc 1)"
227
+
228
+ # N6 — no orphan keeps running a mutant after a timeout
229
+ printf '. ./n1.sh\nis_adult 19 && exit 0\n( touch n6.started; exec sleep 4747 ) &\nwait\n' > lane_n6.sh
230
+ rm -f n6.started
231
+ out=$(python3 "$PROBE" n1.sh lane_n6.sh --timeout 2 2>&1)
232
+ sleep 0.5
233
+ if [ "$HAVE_PROC" -eq 1 ]; then
234
+ [ -e n6.started ] && grep -q 'TIMEOUT' <<<"$out" && [ "$(procs_matching 'sleep 4747')" -eq 0 ] ; chk $? "N6 the timed-out lane's grandchildren are killed with its process group (counted via /proc — v6 used pgrep, vacuous when absent)"
235
+ else
236
+ echo " ⚠️ N6 UNMEASURED — no /proc"; UNMEASURED=$((UNMEASURED+1))
237
+ fi
238
+
239
+ # N2 · N3 · N7 — generator noise
240
+ cat > noise.sh <<'EOF'
241
+ #!/usr/bin/env bash
242
+ (( $(sort in.txt > sorted.txt; wc -l < sorted.txt) > 0 )) && echo some
243
+ echo -ne "progress\r"
244
+ ls -lt "$d"
245
+ cat <<DOC
246
+ exit 1 when x == 2
247
+ DOC
248
+ test "$x" -eq 0 && echo zero
249
+ EOF
250
+ out=$(python3 "$PROBE" noise.sh --list 2>&1)
251
+ grep -qE 'mutants=2( |$)' <<<"$out" && grep -qF '[>→>=] (( $(sort in.txt > sorted.txt; wc -l < sorted.txt) >= 0 ))' <<<"$out" && grep -qF '[-eq→-ne] test "$x" -ne 0' <<<"$out"
252
+ chk $? "N2·N3·N7 only the real (( )) comparison and the test -eq: not the redirects inside \$( ), echo -ne, ls -lt, or the heredoc body"
253
+ cat > noise.py <<'EOF'
254
+ def f(x):
255
+ """exit code x == 0 means ok"""
256
+ y = x == True
257
+ s = """
258
+ a <= b
259
+ """
260
+ return x >= 1 # a <= b
261
+ EOF
262
+ out=$(python3 "$PROBE" noise.py --list 2>&1)
263
+ grep -qE 'mutants=2( |$)' <<<"$out" && grep -qF '[==→!=] y = x != True' <<<"$out" && grep -qF '[>=→>] return x > 1' <<<"$out"
264
+ chk $? "N7 python: docstring · triple-quoted body · trailing comment untouched, and x == True yields ONE mutant (v1: two)"
265
+
266
+ # R1 must prove a mutant was actually written
267
+ printf '. ./age.sh\nsha256sum age.sh >> seen.log 2>/dev/null || shasum -a 256 age.sh >> seen.log\nis_adult 20 || exit 1\nis_adult 5 && exit 1\nexit 0\n' > lane_seen.sh
268
+ rm -f seen.log
269
+ python3 "$PROBE" age.sh lane_seen.sh --timeout 30 >/dev/null 2>&1
270
+ [ "$(cut -d' ' -f1 seen.log | sort -u | wc -l | tr -d ' ')" -eq 2 ] ; chk $? "R0 the lane saw two different subjects (baseline + mutant) — R1's «unchanged» is not vacuous"
271
+
272
+ echo "── V: second-round blind review (2026-10-07) — each lane red on v2"
273
+
274
+ # ① a `python3 -I` lane ignores the env guards — the mtime must carry the protection, and the
275
+ # restored subject must behave as the ORIGINAL after the probe exits
276
+ mkdir -p v1b && cat > v1b/gate.py <<'EOF'
277
+ def a(x):
278
+ return x == 1
279
+ def b(x):
280
+ return x == 2
281
+ def c(x):
282
+ return x == 3
283
+ EOF
284
+ printf 'import sys\nsys.path.insert(0, "v1b")\nimport gate\nassert gate.a(1) and not gate.a(5)\nassert gate.c(3) and not gate.c(5)\n' > v1b/lane.py
285
+ printf 'exec python3 -I -c "exec(open(\\"v1b/lane.py\\").read())"\n' > v1b/lane.sh
286
+ out=$(python3 "$PROBE" v1b/gate.py v1b/lane.sh --timeout 30 2>&1)
287
+ grep -qE 'mutants=3 killed=2 survived=1( |$)' <<<"$out" && grep -q 'SURVIVED L4' <<<"$out" ; chk $? "V1 a python3 -I lane (env guards ignored) still sees each mutant: b() survives alone"
288
+ r=$(python3 -I -c 'import sys;sys.path.insert(0,"v1b");import gate;print(gate.a(1),gate.c(3),gate.b(2))' 2>&1)
289
+ grep -qE 'mutants=3 killed=2 survived=1( |$)' <<<"$out" && [ "$r" = "True True True" ] ; chk $? "V1b after the probe exits, a plain import runs the ORIGINAL code (v2: the last mutant's bytecode, a(1)/c(3) False)"
290
+
291
+ # ② two probes with DIFFERENT TMPDIRs on the same subject
292
+ mkdir -p v2t/t1 v2t/t2 && cp age.sh v2t/age.sh; h0=$(sha_of v2t/age.sh)
293
+ printf '. ./v2t/age.sh\nsleep 2\nis_adult 20 || exit 1\nis_adult 5 && exit 1\nexit 0\n' > v2t/lane.sh
294
+ TMPDIR="$PWD/v2t/t1" python3 "$PROBE" v2t/age.sh v2t/lane.sh --timeout 30 > v2t/a.out 2>&1 & pa=$!
295
+ sleep 0.5
296
+ out=$(TMPDIR="$PWD/v2t/t2" python3 "$PROBE" v2t/age.sh v2t/lane.sh --timeout 30 2>&1); rc_b=$?
297
+ wait $pa
298
+ [ "$rc_b" -eq 2 ] && grep -q 'another mutation_probe holds' <<<"$out" ; chk $? "V2 a second probe under ANOTHER TMPDIR still sees the lock (it is on the subject's inode)"
299
+ grep -qE 'mutants=1 ' v2t/a.out && [ "$(sha_of v2t/age.sh)" = "$h0" ] ; chk $? "V2b and the subject ends byte-identical (v2: left mutated)"
300
+
301
+ # ③ here-string · shift · python triple-quote lookalikes must not swallow the rest of the file
302
+ cat > v3.sh <<'EOF'
303
+ #!/usr/bin/env bash
304
+ read -r a b <<< 'x y'
305
+ [ "$a" -eq 1 ] && echo one
306
+ mask=$(( 1 << 3 ))
307
+ [ "$b" -gt 50 ] && echo big
308
+ cat <<\EOT
309
+ exit 1 when x == 2
310
+ EOT
311
+ [ "$c" = z ] && echo zed
312
+ EOF
313
+ out=$(python3 "$PROBE" v3.sh --list 2>&1)
314
+ grep -qE 'mutants=3( |$)' <<<"$out" && grep -qF '[-eq→-ne]' <<<"$out" && grep -qF '[-gt→-ge]' <<<"$out" && grep -qF '[=→!=]' <<<"$out"
315
+ chk $? "V3 the lines after a here-string, a (( << )) shift and a <<\\EOT body are still mutated — and that body is not (v2: mutants=0)"
316
+ cat > v3.py <<'EOF'
317
+ SEP = "'''"
318
+ y = """one-liner"""
319
+ def f(v):
320
+ return v >= 1
321
+ EOF
322
+ out=$(python3 "$PROBE" v3.py --list 2>&1)
323
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -qF '[>=→>] return v > 1' <<<"$out" ; chk $? "V3b python: a triple quote inside a string, a comment, or a closed one-liner does not open a string (v2: mutants=0)"
324
+
325
+ printf "x = 1 # docs use ''' quotes\ndef f(v):\n return v >= 1\n" > v3c.py
326
+ out=$(python3 "$PROBE" v3c.py --list 2>&1)
327
+ grep -qE 'mutants=1( |$)' <<<"$out" ; chk $? "V3c a triple quote inside a trailing comment does not open a string (v2: mutants=0)"
328
+
329
+ # non-blocking: test chain · baseline deletes the subject
330
+ printf '#!/usr/bin/env bash\ntest -d "$d" && ls -lt "$d"\n[ "$n" -eq 0 ] && echo z\n' > v4.sh
331
+ out=$(python3 "$PROBE" v4.sh --list 2>&1)
332
+ grep -qE 'mutants=1( |$)' <<<"$out" && ! grep -qF 'ls -le' <<<"$out" ; chk $? "V4 \`test … && ls -lt\` — the test ends at &&, ls -lt is not a comparison"
333
+ cp age.sh v5.sh; h0=$(sha_of v5.sh)
334
+ bk5=$(bkpath v5.sh)
335
+ printf '. ./v5.sh\nrm -f v5.sh\nexit 0\n' > lane_v5.sh
336
+ out=$(python3 "$PROBE" v5.sh lane_v5.sh --timeout 30 2>&1); rc=$?
337
+ [ "$rc" -eq 2 ] && grep -q 'WROTE the subject' <<<"$out" && [ -f v5.sh ] && [ "$(sha_of v5.sh)" = "$h0" ] ; chk $? "V5 a baseline lane that DELETES the subject → restored, 2 (v2: traceback rc 1, no restore)"
338
+ grep -q 'WROTE the subject' <<<"$out" && [ ! -e "$bk5" ] ; chk $? "V5b and no backup is left behind (at the original inode's path) to block the next run"
339
+
340
+ echo "── W: third-round blind review (2026-10-07) — mtime-comparing build steps, self-locking subjects"
341
+ # a make-style step: rebuild dist/ only when the subject is NEWER (bash -nt compares mtimes)
342
+ mkw() { # $1 = dir
343
+ mkdir -p "$1/dist"
344
+ cp age.sh "$1/age.sh"
345
+ printf 'cd "%s"\nif [ ! -e dist/age.sh ] || [ age.sh -nt dist/age.sh ]; then cp age.sh dist/age.sh; fi\n. ./dist/age.sh\nis_adult 20 || exit 1\nis_adult 19 || exit 1\nis_adult 5 && exit 1\nexit 0\n' "$PWD/$1" > "$1/lane.sh"
346
+ }
347
+ # direction a — an OLD subject with a fresh build dir: the mutant must reach dist/ and be killed
348
+ mkw wa; touch -d 2020-01-01 wa/age.sh 2>/dev/null || touch -t 202001010000 wa/age.sh
349
+ out=$(python3 "$PROBE" wa/age.sh wa/lane.sh --timeout 30 2>&1)
350
+ grep -qE 'mutants=1 killed=1 survived=0( |$)' <<<"$out" ; chk $? "W1 old subject + mtime-gated build: the mutant is rebuilt into dist/ and KILLED (v3: survived — orig+8s was still older than dist)"
351
+ # direction b — a just-edited subject: after the probe, dist/ must not keep a mutant while looking current
352
+ mkw wb
353
+ out=$(python3 "$PROBE" wb/age.sh wb/lane.sh --timeout 30 2>&1)
354
+ if [ -e wb/dist/age.sh ] && grep -qE 'mutants=1 killed=1 ' <<<"$out" && { cmp -s wb/age.sh wb/dist/age.sh || [ wb/age.sh -nt wb/dist/age.sh ]; }; then r=0; else r=1; fi
355
+ chk $r "W2 after the probe, dist/ is either the original or visibly stale — never a mutant that looks up to date (v3: restored the old mtime under a mutant build)"
356
+ # the subject's own pyc does not outlive the probe
357
+ mkdir -p wc && cp v1b/gate.py wc/gate.py && sed 's#v1b#wc#' v1b/lane.py > wc/lane.py
358
+ printf 'exec python3 -I -c "exec(open(\\"wc/lane.py\\").read())"\n' > wc/lane.sh
359
+ out_wc=$(python3 "$PROBE" wc/gate.py wc/lane.sh --timeout 30 2>&1)
360
+ pyc=$(python3 -c 'import importlib.util,os,sys;print(importlib.util.cache_from_source(os.path.abspath(sys.argv[1])))' wc/gate.py)
361
+ grep -qE 'mutants=3 killed=2 survived=1( |$)' <<<"$out_wc" && [ ! -e "$pyc" ] ; chk $? "W3 the subject's __pycache__ entry is deleted at the end (a -I lane writes it; v3 left the last mutant's)"
362
+ # a subject that flocks its own path must not read the probe as «already running»
363
+ cat > self.py <<'EOF'
364
+ import fcntl, sys
365
+ fh = open(__file__)
366
+ try:
367
+ fcntl.flock(fh, fcntl.LOCK_EX | fcntl.LOCK_NB)
368
+ except OSError:
369
+ print("already running"); sys.exit(0)
370
+ def ok(x):
371
+ return x >= 19
372
+ sys.exit(0 if ok(int(sys.argv[1])) else 1)
373
+ EOF
374
+ printf 'python3 self.py 20 || exit 1\npython3 self.py 19 || exit 1\npython3 self.py 5 && exit 1\nexit 0\n' > lane_self.sh
375
+ out=$(python3 "$PROBE" self.py lane_self.sh --timeout 30 2>&1)
376
+ grep -qE 'mutants=1 killed=1 survived=0( |$)' <<<"$out" ; chk $? "W4 a self-flocking subject runs normally under the probe (v3: the probe's lock on the subject made it exit «already running»)"
377
+ W5D=$(mktemp -d /tmp/mp_w5.XXXXXX); chmod 755 "$W5D"
378
+ cp "$PROBE" "$W5D/mp.py"; cp age.sh "$W5D/ro.sh"; cp lane_weak.sh "$W5D/lane.sh"; chmod 444 "$W5D/ro.sh"; chmod 644 "$W5D/mp.py" "$W5D/lane.sh"
379
+ if [ "$(id -u)" -ne 0 ]; then AS=""; elif command -v setpriv >/dev/null 2>&1; then AS="setpriv --reuid=65534 --regid=65534 --clear-groups"; else AS=NONE; fi
380
+ if [ "$AS" = NONE ]; then
381
+ echo " ⚠️ W5 UNMEASURED — root and no setpriv to drop privileges"; UNMEASURED=$((UNMEASURED+1))
382
+ else
383
+ out=$(cd "$W5D" && $AS python3 mp.py ro.sh lane.sh --timeout 30 2>&1); rc=$?
384
+ [ "$rc" -eq 2 ] && grep -q 'not writable' <<<"$out" && [ -z "$(ls "$W5D" | grep -v -e '^mp.py$' -e '^ro.sh$' -e '^lane.sh$')" ] ; chk $? "W5 a read-only subject → 2 before anything is written (measured as an unprivileged user when run as root)"
385
+ fi
386
+ rm -rf "$W5D"
387
+
388
+ echo "── Y: defects the capture-recapture detectors found that v4 still had (2026-10-07)"
389
+ cp age.sh y.sh; h0=$(sha_of y.sh)
390
+ out=$(python3 "$PROBE" y.sh lane_weak.sh --timeout 30 --json y.sh 2>&1); rc=$?
391
+ [ "$rc" -eq 2 ] && grep -q 'points at the subject' <<<"$out" && [ "$(sha_of y.sh)" = "$h0" ] ; chk $? "Y1 --json pointing at the subject → 2 and the subject untouched (v4: overwritten with JSON, rc 0)"
392
+ cat > yq.py <<'PY'
393
+ s = 'it\'s'; ok = a < b
394
+ PY
395
+ out=$(python3 "$PROBE" yq.py --list 2>&1)
396
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -qF '[<→<=]' <<<"$out" ; chk $? "Y2 python \\' inside '…' does not hide the < after it (v4: mutants=0)"
397
+ printf '#!/usr/bin/env bash\nr=$(python3 -u -c '"'"'\nimport sys\nok = len(sys.argv) >= 2\n'"'"')\npython3 - "$1" <<PY\nflag = True\nPY\necho please exit 1\n[ -n "$x" ] || exit 1\n' > yu.sh
398
+ out=$(python3 "$PROBE" yu.sh --list 2>&1)
399
+ grep -qF '[>=→>] ok = len(sys.argv) > 2' <<<"$out" ; chk $? "Y3 python3 -u -c ' body gets the python set (v4: only -I was recognised)"
400
+ grep -qF '[True→False] flag = False' <<<"$out" ; chk $? "Y3b python3 - \"\$1\" <<PY (an argument before <<) is still a python heredoc"
401
+ ! grep -qF 'echo please exit 0' <<<"$out" && grep -qF '[exit 1→exit 0] [ -n "$x" ] || exit 0' <<<"$out" ; chk $? "Y4 exit N is mutated at command position only — echo's argument is data"
402
+ python3 "$PROBE" --help >/dev/null 2>&1 ; [ $? -eq 0 ] ; chk $? "Y5 --help → 0 (v4: 2, «cannot judge»)"
403
+ printf '. ./age.sh\nif read -r line; then exit 1; fi\nis_adult 20 || exit 1\nis_adult 19 || exit 1\nis_adult 5 && exit 1\nexit 0\n' > lane_stdin.sh
404
+ out=$(printf 'fed\n' | python3 "$PROBE" age.sh lane_stdin.sh --timeout 30 2>&1)
405
+ grep -qE 'mutants=1 killed=1 survived=0( |$)' <<<"$out" ; chk $? "Y6 the lane does not inherit the probe's stdin (v4: the lane read it and the baseline went red)"
406
+
407
+ echo "── Z: the reps=3 detectors' findings on v5 (2026-10-07) — generator rebuilt in v6"
408
+ # Z1 · Z2 — embedded-python openers inside a comment / a string must not switch modes (6/6 detectors)
409
+ mkdir -p z1 && cd z1
410
+ printf '#!/usr/bin/env bash\n# usage: python3 - <<'"'"'EOF'"'"'\necho hi > out.txt\n[ "$1" -ge 19 ]\n' > z.sh
411
+ printf '. ./z.sh 20 || exit 1\n. ./z.sh 19 || exit 1\n. ./z.sh 5 && exit 1\nexit 0\n' > lane.sh
412
+ out=$(python3 "$PROBE" z.sh lane.sh --timeout 30 2>&1)
413
+ grep -qE 'mutants=1 killed=1 survived=0( |$)' <<<"$out" && [ ! -e '=' ] ; chk $? "Z1 a commented 'python3 - <<EOF' opens nothing: only -ge is mutated, no stray «=» file (v5: redirect mutated, file created)"
414
+ cd ..
415
+ printf '#!/usr/bin/env bash\necho "tip: python3 -c '"'"'"\ncmd > log.txt\n[ "$x" -eq 1 ]\n' > z2.sh
416
+ out=$(python3 "$PROBE" z2.sh --list 2>&1)
417
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -qF '[-eq→-ne]' <<<"$out" ; chk $? "Z2 a quoted 'python3 -c' opens nothing"
418
+ # Z3 — python stdin DATA and another command's heredoc are data
419
+ printf '#!/usr/bin/env bash\npython3 tool.py <<EOF\nthreshold == 3\nEOF\npython3 setup.py && cat <<EOF\nx >= 3\nEOF\n[ "$y" -eq 1 ]\n' > z3.sh
420
+ out=$(python3 "$PROBE" z3.sh --list 2>&1)
421
+ grep -qE 'mutants=1( |$)' <<<"$out" ; chk $? "Z3 'python3 tool.py <<EOF' and '… && cat <<EOF' bodies are data, not code"
422
+ # Z4 · Z5 — comments after ; and glued python comments
423
+ printf '#!/usr/bin/env bash\ntrue;# [ "$a" -ne 1 ]\n[ "$b" -eq 2 ]\n' > z4.sh
424
+ out=$(python3 "$PROBE" z4.sh --list 2>&1)
425
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -qF '[ "$b" -ne 2 ]' <<<"$out" ; chk $? "Z4 ';#' starts a comment"
426
+ printf 'x = 1#a < b\ny = 2 >= 1\n' > z5.py
427
+ out=$(python3 "$PROBE" z5.py --list 2>&1)
428
+ grep -qE 'mutants=1( |$)' <<<"$out" ; chk $? "Z5 a python comment glued to code ('1#a < b') is not mutated"
429
+ # Z6 — command position by WORD, not by suffix; and the positions v5 missed
430
+ cat > z6.sh <<'EOF'
431
+ #!/usr/bin/env bash
432
+ echo todo exit 1
433
+ echo strengthen exit 2
434
+ echo wow! exit 3
435
+ foo & exit 4
436
+ case "$x" in bad) exit 5 ;; esac
437
+ f() { local rc=1; export FAILED=1; return 6; }
438
+ EOF
439
+ out=$(python3 "$PROBE" z6.sh --list 2>&1)
440
+ grep -qE 'mutants=5( |$)' <<<"$out" && ! grep -qE 'echo (todo|strengthen|wow!) exit 0' <<<"$out" ; chk $? "Z6 todo/strengthen/wow! are data; '& exit', 'bad) exit', 'local rc=1', 'export FAILED=1', 'return 6' are mutated (5)"
441
+ # Z7 — the word 'test' as an argument
442
+ printf '#!/usr/bin/env bash\necho test = foo\necho unit test -ne done\ntest "$a" = b\n' > z7.sh
443
+ out=$(python3 "$PROBE" z7.sh --list 2>&1)
444
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -qF 'test "$a" != b' <<<"$out" ; chk $? "Z7 'echo test = foo' is data; only the real test command is mutated"
445
+ # Z8 — line numbers by \n only; U+2028 / \x0c inside strings are not line breaks
446
+ printf 'import sys\n\x0c\ns = "a\xe2\x80\xa8 x >= y"\ndef f(a, b):\n return a < b\n' > z8.py
447
+ out=$(python3 "$PROBE" z8.py --list 2>&1)
448
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -qF 'L5 [<→<=]' <<<"$out" ; chk $? "Z8 a form feed does not shift line numbers and U+2028 does not split a string"
449
+ # Z9 — multi-line strings and another language's program are data
450
+ printf '#!/usr/bin/env bash\nmsg="usage:\n then exit 1 on error\n"\nawk '"'"'\n END { exit 1 }\n'"'"' /dev/null\n[ "$z" -eq 0 ]\n' > z9.sh
451
+ out=$(python3 "$PROBE" z9.sh --list 2>&1)
452
+ grep -qE 'mutants=1( |$)' <<<"$out" ; chk $? "Z9 a multi-line \"…\" string and a multi-line awk '…' body are not mutated"
453
+ # Z10 — triple quotes inside embedded python; code after a closing docstring
454
+ printf '#!/usr/bin/env bash\npython3 - <<'"'"'EOF'"'"'\nDOC = """\n a < b means\n"""\nok = 1 < 2\nEOF\n' > z10.sh
455
+ out=$(python3 "$PROBE" z10.sh --list 2>&1)
456
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -qF 'ok = 1 <= 2' <<<"$out" ; chk $? "Z10 a triple-quoted string inside embedded python is data"
457
+ printf 'x = """\ndoc\n"""; y = a < b\n' > z10.py
458
+ out=$(python3 "$PROBE" z10.py --list 2>&1)
459
+ grep -qF 'y = a <= b' <<<"$out" ; chk $? "Z10b code after a closing docstring on the same line is mutated (v5: skipped)"
460
+ # Z11 · Z12 · Z13 — (( in quotes · $[ ] · two heredocs on one line
461
+ printf '#!/usr/bin/env bash\necho "((" > out.txt ; echo "))"\nx=$[1 << 2]\n[ "$x" -eq 4 ]\ncat <<A <<B\nA body exit 1\nA\nB body -eq\nB\n' > z11.sh
462
+ out=$(python3 "$PROBE" z11.sh --list 2>&1)
463
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -qF '[ "$x" -ne 4 ]' <<<"$out" ; chk $? "Z11 quoted '((' is not arithmetic · \$[1 << 2] is not a heredoc · the 2nd of two heredocs is data"
464
+ # Z14 — versioned interpreter names, python operator coverage
465
+ printf '#!/usr/bin/env bash\npython3.11 -c '"'"'\nimport sys\nif len(sys.argv) > 1: sys.exit(1)\n'"'"'\n' > z14.sh
466
+ out=$(python3 "$PROBE" z14.sh --list 2>&1)
467
+ grep -qE 'mutants=2( |$)' <<<"$out" ; chk $? "Z14 'python3.11 -c' is embedded python (> and sys.exit(1))"
468
+ printf 'def f(a, b, rc):\n if a is not None and a<b:\n return 1\n raise SystemExit(2)\n' > z14.py
469
+ out=$(python3 "$PROBE" z14.py --list 2>&1)
470
+ grep -qF '[is not→is]' <<<"$out" && grep -qF '[<→<=] if a is not None and a<=b:' <<<"$out" && grep -qF '[return 1→return 0]' <<<"$out" && grep -qF '[SystemExit(2)→SystemExit(0)]' <<<"$out" ; chk $? "Z14b python: 'is not', unspaced 'a<b', 'return 1', 'SystemExit(2)' are mutated"
471
+ # Z15 — the baseline lane turns the subject into a directory → restore failed, said as such (3)
472
+ cp age.sh z15.sh
473
+ printf 'rm -f z15.sh; mkdir z15.sh\nexit 0\n' > lane_z15.sh
474
+ out=$(python3 "$PROBE" z15.sh lane_z15.sh --timeout 30 2>&1); rc=$?
475
+ [ "$rc" -eq 3 ] && grep -q 'RESTORE FAILED' <<<"$out" ; chk $? "Z15 a baseline that replaces the subject with a directory → 3 «restore failed», not a traceback rc 1"
476
+ rmdir z15.sh 2>/dev/null; bk=$(bkpath z15.sh); [ -f "$bk" ] && cp "$bk" z15.sh && rm -f "$bk"
477
+ # Z16 — the lane cannot start (interpreter missing) → 2, subject untouched, no leftover
478
+ cp age.sh z16.sh; h0=$(sha_of z16.sh)
479
+ printf '#!/nonexistent/interp\nexit 0\n' > lane_z16.sh
480
+ out=$(python3 "$PROBE" z16.sh lane_z16.sh --timeout 30 2>&1); rc=$?
481
+ [ "$rc" -eq 2 ] && grep -q 'could not be started' <<<"$out" && [ "$(sha_of z16.sh)" = "$h0" ] && [ ! -e "$(bkpath z16.sh)" ] ; chk $? "Z16 a lane that cannot start → 2 with that reason, no backup left behind (v5: traceback rc 1 + blocking leftover)"
482
+ # Z17 — a closed stdout does not lose the run
483
+ cp age.sh z17.sh; h0=$(sha_of z17.sh)
484
+ sed 's#age\.sh#z17.sh#' lane_strong.sh > lane_z17.sh # v6 ran lane_strong here, which never sources z17.sh — the v7 control caught it
485
+ python3 "$PROBE" z17.sh lane_z17.sh --timeout 30 2>z17.err | head -c 1 >/dev/null; rc=${PIPESTATUS[0]}; [ "$rc" -eq 0 ] || { echo " (Z17 rc=$rc)"; sed 's/^/ /' z17.err; }
486
+ [ "$rc" -eq 0 ] && [ "$(sha_of z17.sh)" = "$h0" ] ; chk $? "Z17 stdout closed mid-run → still rc 0 and restored (v5: BrokenPipe traceback rc 1)"
487
+ # Z18 — --json through a hard link to the subject
488
+ cp age.sh z18.sh; ln -f z18.sh z18.json; h0=$(sha_of z18.sh)
489
+ out=$(python3 "$PROBE" z18.sh lane_weak.sh --timeout 30 --json z18.json 2>&1); rc=$?
490
+ [ "$rc" -eq 2 ] && grep -q 'points at the subject' <<<"$out" && [ "$(sha_of z18.sh)" = "$h0" ] ; chk $? "Z18 --json via a hard link to the subject → 2, subject untouched (v5: overwritten, rc 0)"
491
+ # Z19 — a signal v5 did not handle
492
+ cp age.sh z19.sh; h0=$(sha_of z19.sh)
493
+ printf '. ./z19.sh\nif grep -q -- "-gt" z19.sh; then touch z19.live; fi\nsleep 5\nexit 0\n' > lane_z19.sh
494
+ rm -f z19.live
495
+ python3 "$PROBE" z19.sh lane_z19.sh --timeout 30 >/dev/null 2>&1 & pz=$!
496
+ for _ in $(seq 1 100); do [ -e z19.live ] && break; sleep 0.1; done
497
+ kill -USR1 "$pz" 2>/dev/null; wait "$pz"; rc=$?
498
+ [ -e z19.live ] && [ "$rc" -eq "$((128 + $(kill -l USR1)))" ] && [ "$(sha_of z19.sh)" = "$h0" ] && [ ! -e "$(bkpath z19.sh)" ] ; chk $? "Z19 SIGUSR1 while the mutant is live (proved by the lane) → restored, platform signal exit, no leftover (v5: mutant left)"
499
+ # Z20 · Z21 — mode restored · mtime never in the future
500
+ cp age.sh z20.sh; chmod 755 z20.sh
501
+ printf '. ./z20.sh\nchmod 600 z20.sh\nis_adult 20 || exit 1\nis_adult 19 || exit 1\nexit 0\n' > lane_z20.sh
502
+ out=$(python3 "$PROBE" z20.sh lane_z20.sh --timeout 30 2>&1)
503
+ grep -qE 'mutants=1 killed=1 survived=0( |$)' <<<"$out" && [ "$(stat -c %a z20.sh 2>/dev/null || stat -f %Lp z20.sh)" = "755" ] ; chk $? "Z20 the file mode is restored too (v5: a lane's chmod / a re-created file stayed)"
504
+ printf '#!/usr/bin/env bash\n[ "$1" -ge 1 ]\n[ "$1" -ge 2 ]\n[ "$1" -ge 3 ]\n[ "$1" -ge 4 ]\n[ "$1" -ge 5 ]\n[ "$1" -ge 6 ]\n' > z21.sh
505
+ printf '. ./z21.sh 9\nexit 0\n' > lane_z21.sh # runs the subject (v7 control) but checks nothing
506
+ out=$(python3 "$PROBE" z21.sh lane_z21.sh --timeout 30 2>&1)
507
+ python3 -c 'import os,sys,time;sys.exit(0 if os.stat(sys.argv[1]).st_mtime <= time.time() + 0.5 else 1)' z21.sh && grep -qE 'mutants=6 killed=0 survived=6( |$)' <<<"$out" ; chk $? "Z21 six fast mutants later, the subject's mtime is not in the future (v5: +1 s per write accumulated)"
508
+ # Z22 — an unchecked-hash pyc left from before must not hide the mutants
509
+ mkdir -p z22 && cp v1b/gate.py z22/gate.py && sed 's#v1b#z22#' v1b/lane.py > z22/lane.py
510
+ printf 'exec python3 -I -c "exec(open(\\"z22/lane.py\\").read())"\n' > z22/lane.sh
511
+ python3 -c 'import py_compile;py_compile.compile("z22/gate.py",invalidation_mode=py_compile.PycInvalidationMode.UNCHECKED_HASH)'
512
+ out=$(python3 "$PROBE" z22/gate.py z22/lane.sh --timeout 30 2>&1)
513
+ grep -qE 'mutants=3 killed=2 survived=1( |$)' <<<"$out" ; chk $? "Z22 a pre-existing unchecked-hash pyc is dropped before the baseline (v5: every mutant invisible → «survived», rc 0)"
514
+ # Z23 · Z24 · Z25 — lane shebang · --timeout · subject == lane
515
+ printf '#!/usr/bin/env python3\nimport subprocess,sys\nok=lambda n: subprocess.run(["bash","-c",". ./age.sh; is_adult %%d" %% n]).returncode==0\nsys.exit(0 if ok(20) and ok(19) and not ok(5) else 1)\n' > lanepy
516
+ out=$(python3 "$PROBE" age.sh lanepy --timeout 30 2>&1)
517
+ grep -qE 'mutants=1 killed=1 survived=0( |$)' <<<"$out" ; chk $? "Z23 an extension-less lane runs by its python shebang (v5: run with bash → baseline red)"
518
+ out=$(python3 "$PROBE" age.sh lane_weak.sh --timeout 0 2>&1); rc=$?
519
+ [ "$rc" -eq 2 ] && grep -q 'timeout must be > 0' <<<"$out" ; chk $? "Z24 --timeout 0 → 2 with that reason (v5: reported as «baseline not green»)"
520
+ out=$(python3 "$PROBE" age.sh age.sh 2>&1); rc=$?
521
+ [ "$rc" -eq 2 ] && grep -q 'same file' <<<"$out" ; chk $? "Z25 subject == lane → 2"
522
+ # Z26 — the lane writes the subject only while a mutant is live
523
+ cp age.sh z26.sh
524
+ printf '. ./z26.sh\nif grep -q -- "-gt" z26.sh; then echo "# junk" >> z26.sh; fi\nis_adult 20 || exit 1\nexit 0\n' > lane_z26.sh
525
+ out=$(python3 "$PROBE" z26.sh lane_z26.sh --timeout 30 2>&1); rc=$?
526
+ [ "$rc" -eq 2 ] && grep -q 'while a mutant was live' <<<"$out" ; chk $? "Z26 a lane that writes the subject during a mutant → 2 (v5: silently overwritten, its verdict counted)"
527
+ # Z27 — two subjects sharing one lane, concurrently
528
+ cp age.sh z27a.sh; cp age.sh z27b.sh
529
+ printf 'sleep 2\nexit 0\n' > lane_z27.sh
530
+ python3 "$PROBE" z27a.sh lane_z27.sh --timeout 30 >/dev/null 2>&1 & pa=$!
531
+ sleep 0.5
532
+ out=$(python3 "$PROBE" z27b.sh lane_z27.sh --timeout 30 2>&1); rc=$?
533
+ wait $pa
534
+ [ "$rc" -eq 2 ] && grep -q 'holds the lane' <<<"$out" ; chk $? "Z27 a second probe on the same lane is refused (v5: both measured, verdicts cross-contaminated)"
535
+ # Z28 — a POSIX sh subject never gets '=='
536
+ printf '#!/bin/sh\n[ "$a" != b ] && echo d\n[ "$c" = d ] && echo e\n' > z28.sh
537
+ out=$(python3 "$PROBE" z28.sh --list 2>&1)
538
+ ! grep -qF '==' <<<"$out" && grep -qF '[=→!=]' <<<"$out" ; chk $? "Z28 #!/bin/sh: '!=' is not flipped to the non-POSIX '==' (= → != still is)"
539
+
540
+ if [ "$HAVE_PROC" -eq 1 ]; then # the process counter itself, on a known pair, before any lane trusts it
541
+ sleep 4646 & kp=$!; sleep 0.1; k1=$(procs_matching 'sleep 4646'); kill "$kp"; wait "$kp" 2>/dev/null; k0=$(procs_matching 'sleep 4646')
542
+ [ "$k1" -eq 1 ] && [ "$k0" -eq 0 ] ; chk $? "K0 the /proc process counter sees a live sleep (1) and not a dead one (0) — and not itself"
543
+ fi
544
+ echo "── S7: v7 safety contract — each lane red on v6 (2026-10-08, from the v6 capture-recapture detectors)"
545
+
546
+ # S7-1 — the lane swaps the subject for a symlink while a mutant is live → 3, and the link target is NOT written
547
+ cp age.sh s71.sh; printf 'VICTIM\n' > victim71.txt
548
+ bk71i=$(python3 -c 'import os,sys;s=os.stat(sys.argv[1]);print("/tmp/mutation_probe-%d/inode-%d-%d.backup"%(os.getuid(),s.st_dev,s.st_ino))' s71.sh)
549
+ printf '. ./s71.sh\nif grep -q -- "-gt" s71.sh; then rm -f s71.sh; ln -s victim71.txt s71.sh; fi\nis_adult 20 || exit 1\nexit 0\n' > lane_s71.sh
550
+ out=$(python3 "$PROBE" s71.sh lane_s71.sh --timeout 30 2>&1); rc=$?
551
+ [ "$rc" -eq 3 ] && grep -q 'RESTORE FAILED' <<<"$out" && [ "$(cat victim71.txt)" = "VICTIM" ] ; chk $? "S7-1 subject swapped for a symlink → RESTORE FAILED 3, the link target untouched (v6: rc 2 and the victim overwritten)"
552
+ rm -f s71.sh "$(bkpath s71.sh)" "$bk71i" 2>/dev/null # this lane's own backups only — never a wildcard (rev7 #12)
553
+
554
+ # S7-2 — same bytes, new inode (cp+mv) while a mutant is live → 2, and the other hard link is restored
555
+ cp age.sh s72.sh; ln -f s72.sh s72_alias.sh; h0=$(sha_of s72.sh)
556
+ printf '. ./s72.sh\nif grep -q -- "-gt" s72.sh; then cat s72.sh > s72.tmp; mv s72.tmp s72.sh; fi\nis_adult 20 || exit 1\nis_adult 19 || exit 1\nexit 0\n' > lane_s72.sh
557
+ out=$(python3 "$PROBE" s72.sh lane_s72.sh --timeout 30 2>&1); rc=$?
558
+ [ "$rc" -eq 2 ] && grep -q 'REPLACED' <<<"$out" && [ "$(sha_of s72_alias.sh)" = "$h0" ] && [ "$(sha_of s72.sh)" = "$h0" ] ; chk $? "S7-2 inode replaced with the same bytes → 2, both names end original (v6: rc 0, the hard link kept the mutant)"
559
+
560
+ # S7-3 — crossed probes: A mutates x with lane y, B mutates y with lane x → one of them refuses
561
+ printf '#!/usr/bin/env bash\nis_a() { [ "$1" -ge 19 ]; }\n' > x73.sh
562
+ printf '#!/usr/bin/env bash\nis_b() { [ "$1" -ge 19 ]; }\n. ./x73.sh\ntouch s73.started\nsleep 2\nis_a 20 || exit 1\nis_a 19 || exit 1\nis_b 19 >/dev/null; exit 0\n' > y73.sh
563
+ rm -f s73.started
564
+ python3 "$PROBE" x73.sh y73.sh --timeout 30 > s73_a.out 2>&1 & pa=$!
565
+ for _ in $(seq 1 100); do [ -e s73.started ] && break; sleep 0.1; done
566
+ out=$(python3 "$PROBE" y73.sh x73.sh --timeout 30 2>&1); rc_b=$?
567
+ wait $pa
568
+ [ -e s73.started ] && [ "$rc_b" -eq 2 ] && grep -q 'another mutation_probe holds' <<<"$out" ; chk $? "S7-3 a probe whose subject is another probe's lane refuses (v6: both rc 0, each mutating the other's lane)"
569
+
570
+ # S7-4 — whatever the lane builds from the last mutant is rebuilt from the original
571
+ cp age.sh s74.sh
572
+ printf 'cp s74.sh installed74.sh\n. ./installed74.sh\nis_adult 20 || exit 1\nis_adult 19 || exit 1\nexit 0\n' > lane_s74.sh
573
+ out=$(python3 "$PROBE" s74.sh lane_s74.sh --timeout 30 2>&1); rc=$?
574
+ [ "$rc" -eq 0 ] && grep -qE 'mutants=1 killed=1 ' <<<"$out" && cmp -s s74.sh installed74.sh ; chk $? "S7-4 a derived copy ends as the ORIGINAL — the final lane run rebuilds it (v6: installed copy kept -gt)"
575
+
576
+ # S7-5 — a setsid escapee is killed (Linux subreaper); unmeasurable without /proc → UNMEASURED, never PASS
577
+ if [ "$HAVE_PROC" -eq 1 ] && command -v setsid >/dev/null 2>&1; then
578
+ cp age.sh s75.sh; rm -f s75.started
579
+ printf '. ./s75.sh\nsetsid sh -c "touch s75.started; exec sleep 4848" </dev/null >/dev/null 2>&1 &\nsleep 0.3\nis_adult 20 || exit 1\nis_adult 19 || exit 1\nexit 0\n' > lane_s75.sh
580
+ out=$(python3 "$PROBE" s75.sh lane_s75.sh --timeout 30 2>&1)
581
+ sleep 0.3
582
+ [ -e s75.started ] && grep -qE 'mutants=1 ' <<<"$out" && [ "$(procs_matching 'sleep 4848')" -eq 0 ] ; chk $? "S7-5 a setsid descendant of the lane does not outlive the probe (v6: it kept running with the mutant)"
583
+ else
584
+ echo " ⚠️ S7-5 UNMEASURED — no /proc or no setsid"; UNMEASURED=$((UNMEASURED+1))
585
+ fi
586
+
587
+ # S7-6 — a «cannot judge» run writes no --json
588
+ cp age.sh s76.sh; rm -f s76.json
589
+ printf '. ./s76.sh\nif grep -q -- "-gt" s76.sh; then echo "# x" >> s76.sh; fi\nexit 0\n' > lane_s76.sh
590
+ out=$(python3 "$PROBE" s76.sh lane_s76.sh --timeout 30 --json s76.json 2>&1); rc=$?
591
+ [ "$rc" -eq 2 ] && grep -q 'while a mutant was live' <<<"$out" && [ ! -e s76.json ] ; chk $? "S7-6 --json is not written for a «cannot judge» run (v6: wrote counts that read as a measurement)"
592
+ out=$(python3 "$PROBE" age.sh lane_strong.sh --timeout 30 --json s76ok.json 2>&1)
593
+ python3 -c 'import json,sys;d=json.load(open(sys.argv[1]));sys.exit(0 if d.get("measured") is True and d["counts"]["KILLED"]==1 else 1)' s76ok.json ; chk $? "S7-6b and a measured run does write it, marked measured"
594
+
595
+ # S7-7 — a lane that never runs the subject: the positive control survives → 2
596
+ cp age.sh s77.sh; printf 'exit 0\n' > lane_s77.sh
597
+ out=$(python3 "$PROBE" s77.sh lane_s77.sh --timeout 30 2>&1); rc=$?
598
+ [ "$rc" -eq 2 ] && grep -q 'positive control SURVIVED' <<<"$out" ; chk $? "S7-7 a lane that never runs the subject → 2 via the positive control (v6: rc 0, «survived» everything)"
599
+
600
+ # S7-8 — the lane's shebang is read by the kernel (one argument), not shlex
601
+ cp age.sh s78.sh; printf '#!/bin/bash -e -u\n. ./s78.sh\nis_adult 20 || exit 1\nexit 0\n' > lane_s78.sh; chmod +x lane_s78.sh
602
+ out=$(python3 "$PROBE" s78.sh lane_s78.sh --timeout 30 2>&1); rc=$?
603
+ direct=$(./lane_s78.sh >/dev/null 2>&1; echo $?)
604
+ if [ "$direct" -ne 0 ]; then
605
+ [ "$rc" -eq 2 ] && grep -q 'not green' <<<"$out"; result=$?
606
+ else
607
+ [ "$rc" -eq 0 ] && grep -qE 'mutants=1 killed=0 survived=1 ' <<<"$out"; result=$?
608
+ fi
609
+ chk "$result" "S7-8 executable lane follows this kernel: direct=$direct, probe=$rc (Linux and Darwin shebang parsing differ)"
610
+
611
+ # S7-9 — mode bits, not access(): a 0444 subject is refused even for root
612
+ cp age.sh s79.sh; chmod 444 s79.sh; h0=$(sha_of s79.sh)
613
+ out=$(python3 "$PROBE" s79.sh lane_weak.sh --timeout 30 2>&1); rc=$?
614
+ [ "$rc" -eq 2 ] && grep -q 'not writable' <<<"$out" && [ "$(sha_of s79.sh)" = "$h0" ] ; chk $? "S7-9 a read-only subject is refused by its mode bits (v6 as root: mutated in place, rc 0)"
615
+ chmod 644 s79.sh
616
+
617
+ # S7-10 — a subject whose mtime is in the future is refused, not pushed further
618
+ cp age.sh s710.sh; python3 -c 'import os,sys,time;t=time.time()+300;os.utime(sys.argv[1],(t,t))' s710.sh
619
+ m0=$(python3 -c 'import os,sys;print(int(os.stat(sys.argv[1]).st_mtime))' s710.sh)
620
+ out=$(python3 "$PROBE" s710.sh lane_weak.sh --timeout 30 2>&1); rc=$?
621
+ m1=$(python3 -c 'import os,sys;print(int(os.stat(sys.argv[1]).st_mtime))' s710.sh)
622
+ [ "$rc" -eq 2 ] && grep -q 'in the future' <<<"$out" && [ "$m0" = "$m1" ] ; chk $? "S7-10 a future mtime → 2 and left as is (v6: +1 s per write, 105 s in the future after a run)"
623
+
624
+ # S7-11 — a leftover backup is found under another name of the same inode (hard link)
625
+ cp age.sh s711.sh; ln -f s711.sh s711_alias.sh
626
+ ino_bk=$(python3 -c 'import os,sys;s=os.stat(sys.argv[1]);print("/tmp/mutation_probe-%d/inode-%d-%d.backup"%(os.getuid(),s.st_dev,s.st_ino))' s711.sh)
627
+ mkdir -p "/tmp/mutation_probe-$(id -u)"; chmod 700 "/tmp/mutation_probe-$(id -u)"; cp s711.sh "$ino_bk"
628
+ out=$(python3 "$PROBE" s711_alias.sh lane_weak.sh --timeout 30 2>&1); rc=$?
629
+ rm -f "$ino_bk"
630
+ [ "$rc" -eq 2 ] && grep -q 'previous run left a backup' <<<"$out" ; chk $? "S7-11 a SIGKILL leftover blocks a run through a hard-linked name too (v6: keyed by path only — the mutant was backed up as «original»)"
631
+
632
+ echo "── G7: v6 generator classes, pinned (fail-closed: uncertain → no mutant)"
633
+ g7() { # $1 file, $2 content, $3 expected exact --list count
634
+ printf '%b' "$2" > "$1"; python3 "$PROBE" "$1" --list 2>&1
635
+ }
636
+ out=$(g7 g71.sh '#!/bin/bash\n((cd /tmp && ls) > out.txt)\necho hi 2>/dev/null\n[ "$1" -ge 1 ] || exit 3\n')
637
+ grep -qE 'mutants=2( |$)' <<<"$out" && ! grep -qE '\[(>|<)→' <<<"$out" ; chk $? "G7-1 «((cmd) …)» is a subshell: no redirect mutant, and the test + exit after it are still found (v6: >→>= and a file named =)"
638
+ out=$(g7 g72.sh '#!/bin/bash\nx="$(echo "it'"'"'s")"\n[ "$a" -eq 1 ] && exit 1\ny=${x:-"}"}\necho "if x; then exit 1; fi"\n')
639
+ grep -qE 'mutants=2( |$)' <<<"$out" && grep -q 'L3 \[-eq' <<<"$out" && ! grep -q 'L5 ' <<<"$out" ; chk $? "G7-2 nested quotes in \"\$( )\" and \${x:-\"}\"} keep quote polarity (v6: everything after vanished or became code)"
640
+ out=$(g7 g73.sh '#!/bin/bash\npython3 check.py - <<EOF\nthreshold == 3\nEOF\npython3 -m mod -c '"'"'x <= y'"'"'\npython3 run.py -c '"'"'a >= 3'"'"'\npython3 -Sc '"'"'import sys; sys.exit(1 if 2 > 1 else 0)'"'"'\n')
641
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -q 'L7 \[>→' <<<"$out" ; chk $? "G7-3 python only when -c/stdin are INTERPRETER options (-Sc yes; script.py -, -m … -c, run.py -c no)"
642
+ out=$(g7 g74.sh '#!/bin/bash\ncat <<END-X\nEND\n[ 1 -eq 1 ] && exit 1\nEND-X\necho retry then exit 1\ncase "$x" in\n rc=1) echo hi ;;\nesac\nfalse || exit 1>&2\n(true)# note; exit 1\nfunction m { return 2; }\n')
643
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -q 'L12 \[return 2' <<<"$out" ; chk $? "G7-4 heredoc «END-X» · keyword as argument · case pattern · exit 1>&2 · )# comment → data; function body → code"
644
+ out=$(g7 g75.py '#!/usr/bin/env python3\nimport subprocess, sys\ndef f(a=True):\n subprocess.run(["x"], shell=True, check=True)\n ok = True\n return 0x0\ndef g():\n return -1\nsys.exit(-2)\n')
645
+ grep -qE 'mutants=3( |$)' <<<"$out" && grep -q 'L5 \[True' <<<"$out" && grep -q 'L8 \[return -1' <<<"$out" && grep -q 'L9 \[sys.exit(-2)' <<<"$out" ; chk $? "G7-5 python: keyword/default True and zero-equivalents are not mutated; negative exit codes are"
646
+ printf '#!/bin/bash\nx=1\npython3 - <<EOF\nprint($x)\nEOF\n[ "$x" -eq 1 ] || exit 1\n' > g76.sh
647
+ printf 'bash ./g76.sh >/dev/null 2>&1 || exit 1\nexit 0\n' > lane_g76.sh
648
+ out=$(python3 "$PROBE" g76.sh lane_g76.sh --timeout 30 2>&1)
649
+ grep -qE 'invalid=0' <<<"$out" && grep -qE 'mutants=2 killed=1 survived=1 ' <<<"$out" ; chk $? "G7-6 a shell-expanded python heredoc does not make every mutant INVALID (v6: invalid=2, nothing measured)"
650
+
651
+ echo "── R7: blind review of v7 (2026-10-08) — each lane red on fbfe773"
652
+ # R7-1 — a probe that READ the subject while another probe's mutant was live, and locked it only after that
653
+ # probe had restored it, must not adopt the mutant. Deterministic: the subject is large enough that
654
+ # reading + enumerating it outlasts the 0.4 s after which «the other probe» puts the original back.
655
+ printf '#!/usr/bin/env bash\n[ "$a" -ne 1 ] && echo x1\n' > r71.orig
656
+ for k in $(seq 2 6000); do printf '[ "$a" -eq %d ] && echo x%d\n' "$k" "$k"; done >> r71.orig
657
+ sed '2s/-ne 1/-eq 1/' r71.orig > r71.sh # the other probe's mutant is live
658
+ printf 'grep -q "exit 113" r71.sh && exit 1\nexit 0\n' > lane_r71.sh
659
+ s71=$(date +%s%N)
660
+ python3 "$PROBE" r71.sh lane_r71.sh --max 1 --timeout 30 > r71.out 2>&1 & pb=$!
661
+ sleep 0.4; cat r71.orig > r71.sh; t71=$(date +%s%N) # … and now it restores (same inode)
662
+ wait "$pb"; rc=$?
663
+ grep -q 'changed between reading it and locking it' r71.out && [ "$rc" -eq 2 ] && cmp -s r71.sh r71.orig && [ ! -e "$(bkpath r71.sh)" ] ; chk $? "R7-1 a subject that changed between read and lock → 2, the original stays (fbfe773: the stale mutant was backed up as «original» and written back)"
664
+ cp r71.orig r71.sh
665
+
666
+ # R7-2 — the lane hard-links an unrelated file to the subject's path: that file is never written
667
+ cp age.sh r72.sh; printf 'VICTIM\n' > victim72.txt
668
+ printf '. ./r72.sh\nif grep -q -- "-gt" r72.sh; then ln -f victim72.txt r72.sh; fi\nis_adult 20 || exit 1\nexit 0\n' > lane_r72.sh
669
+ out=$(python3 "$PROBE" r72.sh lane_r72.sh --timeout 30 2>&1); rc=$?
670
+ [ "$rc" -eq 2 ] && [ "$(cat victim72.txt)" = "VICTIM" ] && cmp -s r72.sh age.sh ; chk $? "R7-2 a hard link to another file at the path is replaced, not written into (fbfe773: victim overwritten)"
671
+
672
+ # R7-3 — a --json path the lane turns into a symlink to the subject
673
+ cp age.sh r73.sh; rm -f r73.json
674
+ sed 's#age\.sh#r73.sh#' lane_strong.sh > lane_r73.sh; printf '[ -e r73.json ] || ln -s r73.sh r73.json\n' | cat - lane_r73.sh > lane_r73b.sh
675
+ out=$(python3 "$PROBE" r73.sh lane_r73b.sh --timeout 30 --json r73.json 2>&1); rc=$?
676
+ [ "$rc" -eq 2 ] && cmp -s r73.sh age.sh ; chk $? "R7-3 --json through a link the lane planted → 2, subject intact (fbfe773: subject overwritten with JSON, rc 0)"
677
+
678
+ # R7-4 — a positive control that hangs is not «noticed»
679
+ cp age.sh r74.sh
680
+ printf 'if grep -q "exit 113" r74.sh; then sleep 30; fi\n. ./r74.sh\nis_adult 20 || exit 1\nexit 0\n' > lane_r74.sh
681
+ out=$(python3 "$PROBE" r74.sh lane_r74.sh --timeout 2 2>&1); rc=$?
682
+ [ "$rc" -eq 2 ] && grep -q 'positive control did not finish' <<<"$out" ; chk $? "R7-4 a control that times out → 2 (fbfe773: counted as the lane noticing)"
683
+
684
+ # R7-5 … R7-10 — generator: data that sat in code position
685
+ out=$(g7 r75.sh '#!/bin/bash\n[ "$1" = -eq ]\n[ "$a" -eq 1 ] && [ ! "$b" = c ]\n[[ $a == b && $c -gt 2 ]]\n')
686
+ grep -qE 'mutants=5( |$)' <<<"$out" && ! grep -q '\[-eq→-ne\] \[ "$1"' <<<"$out" ; chk $? "R7-5 only the OPERATOR of a test is mutated — an operand spelled -eq is not; ! and && reset the position"
687
+ out=$(g7 r76.sh '#!/bin/bash\ncodes=(exit 1)\nopts=(rc=1 other)\ndiff <(sort a) FAILED=1\nexit 2\n')
688
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -q 'L5 \[exit 2' <<<"$out" ; chk $? "R7-6 array literals and <( ) leave their arguments as data"
689
+ out=$(g7 r77.sh '#!/bin/bash\ncase $x in\n a) case $n in b) echo ;; esac ;;\n rc=1) echo matched ;;\nesac\nrc=1\n')
690
+ grep -qE 'mutants=1( |$)' <<<"$out" && grep -q 'L6 \[rc=1' <<<"$out" ; chk $? "R7-7 a nested case restores the outer case's pattern state"
691
+ out=$(g7 r78.sh '#!/bin/bash\n[ "$x" = y]|| echo bad\necho a = b c == d\nx="$(python3 - <<PY\nok = 1 < 2\nPY\n)"\n[ "$x" = y ] || exit 3\n')
692
+ grep -qE 'mutants=2( |$)' <<<"$out" && grep -q 'L8 \[=' <<<"$out" && grep -q 'L8 \[exit 3' <<<"$out" ; chk $? "R7-8 an unclosed [ does not leak test mode into later lines; a python heredoc inside \"\$( )\" stays quiet"
693
+
694
+ echo "── R8: Codex review regressions — bounded output, lane identity, signals and redirect operands"
695
+ python3 - "$PROBE" <<'R8PY'
696
+ import os, pathlib, signal, subprocess, sys, tempfile, time, unittest
697
+ PROBE = os.path.abspath(sys.argv[1])
698
+ ORIGINAL = '#!/bin/bash\nis_adult() { [ "$1" -ge 19 ]; }\n'
699
+ LANE = '. ./age.sh\nis_adult 20 || exit 1\nis_adult 19 || exit 1\nis_adult 5 && exit 1\nexit 0\n'
700
+
701
+ class ReviewRegressions(unittest.TestCase):
702
+ def setUp(self):
703
+ self.tmp = tempfile.TemporaryDirectory()
704
+ self.root = pathlib.Path(self.tmp.name)
705
+ (self.root / 'age.sh').write_text(ORIGINAL)
706
+ (self.root / 'lane.sh').write_text(LANE)
707
+
708
+ def tearDown(self):
709
+ self.tmp.cleanup()
710
+
711
+ def run_probe(self, *args):
712
+ return subprocess.run([sys.executable, PROBE, *args], cwd=self.root,
713
+ capture_output=True, text=True, timeout=15)
714
+
715
+ def test_fifo_output_is_bounded(self):
716
+ os.mkfifo(self.root / 'out.json')
717
+ result = self.run_probe('age.sh', 'lane.sh', '--json', 'out.json')
718
+ self.assertEqual(result.returncode, 2, result.stdout + result.stderr)
719
+ self.assertEqual((self.root / 'age.sh').read_text(), ORIGINAL)
720
+
721
+ def test_regular_output_control(self):
722
+ import json
723
+ result = self.run_probe('age.sh', 'lane.sh', '--json', 'out.json')
724
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
725
+ self.assertTrue(json.loads((self.root / 'out.json').read_text())['measured'])
726
+
727
+ def test_replaced_lane_is_not_overwritten(self):
728
+ body = ('if [ ! -e replaced ]; then cp lane.sh new.sh; mv new.sh lane.sh; '
729
+ 'ln lane.sh out.json; touch replaced; fi\n' + LANE)
730
+ (self.root / 'lane.sh').write_text(body)
731
+ result = self.run_probe('age.sh', 'lane.sh', '--json', 'out.json')
732
+ self.assertEqual(result.returncode, 2, result.stdout + result.stderr)
733
+ self.assertEqual((self.root / 'lane.sh').read_text(), body)
734
+ self.assertEqual((self.root / 'age.sh').read_text(), ORIGINAL)
735
+
736
+ def test_sigabrt_restores_live_mutant(self):
737
+ (self.root / 'lane.sh').write_text(
738
+ '. ./age.sh\nif grep -q -- "-gt" age.sh; then touch live; sleep 30; fi\n' + LANE)
739
+ proc = subprocess.Popen([sys.executable, PROBE, 'age.sh', 'lane.sh', '--timeout', '40'],
740
+ cwd=self.root, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
741
+ try:
742
+ deadline = time.monotonic() + 12
743
+ while not (self.root / 'live').exists() and proc.poll() is None and time.monotonic() < deadline:
744
+ time.sleep(0.05)
745
+ self.assertTrue((self.root / 'live').exists(), 'no live-mutant control: UNMEASURED')
746
+ proc.send_signal(signal.SIGABRT)
747
+ self.assertEqual(proc.wait(timeout=5), 128 + signal.SIGABRT)
748
+ self.assertEqual((self.root / 'age.sh').read_text(), ORIGINAL)
749
+ finally:
750
+ if proc.poll() is None:
751
+ proc.terminate()
752
+ proc.wait(timeout=5)
753
+
754
+ def test_redirect_targets_are_data_but_following_command_is_code(self):
755
+ (self.root / 'clean.sh').write_text(
756
+ '#!/bin/bash\n>rc=1 printf hi\n2>FAIL=1 printf hi\n'
757
+ '>>failed=1 printf hi\n<>rc=1 printf hi\n&>rc=1 printf hi\n'
758
+ "python3 -c >'exit(1)' 'exit(0)'\n")
759
+ result = self.run_probe('clean.sh', '--list')
760
+ self.assertEqual(result.returncode, 2, result.stdout + result.stderr)
761
+ self.assertIn('mutants=0', result.stdout)
762
+ (self.root / 'positive.sh').write_text('#!/bin/bash\n2>rc=1 exit 2\n')
763
+ result = self.run_probe('positive.sh', '--list')
764
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
765
+ self.assertIn('mutants=1', result.stdout)
766
+ self.assertIn('[exit 2→exit 0]', result.stdout)
767
+
768
+ unittest.main(argv=[sys.argv[0]], verbosity=2)
769
+ R8PY
770
+ chk $? "R8 five review regressions and normal-output/generator controls"
771
+
772
+ echo "── RV: revert probe — neuter the kill decision"
773
+ sed "s/'KILLED' if rc != 0 else 'SURVIVED'/'KILLED'/" "$PROBE" > neutered.py
774
+ grep -q "else ('KILLED')" neutered.py ; chk $? "RV0 the neutering edit actually applied (else this lane measures nothing)"
775
+ out=$(python3 neutered.py age.sh lane_weak.sh --timeout 30 2>&1)
776
+ grep -qE 'mutants=1 killed=1 survived=0( |$)' <<<"$out" ; chk $? "RV1 with kill forced, the F1 survivor is counted killed (mutants=1 ran) — F1 would turn red; a run that produced no mutants cannot pass this"
777
+
778
+ sed "s/^ARITH_ONLY = True/ARITH_ONLY = False/" "$PROBE" > noarith.py
779
+ grep -q '^ARITH_ONLY = False' noarith.py ; chk $? "RV2-0 the redirect-guard neutering applied"
780
+ out=$(python3 noarith.py neg.sh --list 2>&1)
781
+ grep -q '\[>→>=\] cmd >= out.txt' <<<"$out" ; chk $? "RV2 without the (( )) restriction, \`cmd > out.txt\` becomes a mutant — C1 would turn red (the prototype's redirect bug, reproduced)"
782
+
783
+ echo ""
784
+ if [ "$FAILED" -eq 0 ] && [ "$UNMEASURED" -gt 0 ]; then echo "INCOMPLETE mutation probe: $PASS lanes passed, $UNMEASURED UNMEASURED — not a pass"; exit 1; fi
785
+ if [ "$FAILED" -eq 0 ]; then echo "PASS mutation probe: $PASS lanes"; exit 0; fi
786
+ echo "FAIL mutation probe"; exit 1