@chrono-meta/fh-gate 3.42.0 → 3.44.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 (71) hide show
  1. package/.claude/regression/probes_live.yaml +16 -8
  2. package/.claude/rules/fh_4axis_gate.md +8 -0
  3. package/.claude-plugin/marketplace.json +4 -4
  4. package/AGENTS.md +9 -0
  5. package/README.ja.md +2 -0
  6. package/README.ko.md +2 -0
  7. package/README.md +2 -0
  8. package/README.zh.md +2 -0
  9. package/docs/HOW_FH_DIFFERS.en.md +37 -0
  10. package/docs/HOW_FH_DIFFERS.md +39 -0
  11. package/docs/USER_GUIDE.md +208 -2
  12. package/docs/model_tier_expectations.md +8 -4
  13. package/knowledge/shared/harness-core/claude_md_full_reference.md +10 -0
  14. package/knowledge/shared/harness-core/dispatch_conditional_prohibition.md +18 -0
  15. package/knowledge/shared/harness-core/fh_module_contract.md +19 -0
  16. package/knowledge/shared/harness-core/governance_engineering_definition.md +16 -0
  17. package/knowledge/shared/harness-core/measurement-integrity-checklist.md +24 -0
  18. package/knowledge/shared/learnings/subagent_invocations_log.yaml +42 -0
  19. package/knowledge/shared/plugin-catalog/recommended_plugins.md +53 -9
  20. package/package.json +13 -1
  21. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  22. package/plugins/fh-commons/skills/ko-tech-writer/SKILL.md +49 -14
  23. package/plugins/fh-commons/skills/ko-tech-writer/SKILL_detail.md +60 -0
  24. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/sense_negative.md +30 -0
  25. package/plugins/fh-commons/skills/ko-tech-writer/fixtures/sense_positive.md +56 -0
  26. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  27. package/plugins/fh-meta/CHANGELOG.md +55 -2
  28. package/plugins/fh-meta/skills/auto-decorrelation/SKILL.md +45 -1
  29. package/plugins/fh-meta/skills/edit-manifest/SKILL.md +14 -1
  30. package/plugins/fh-meta/skills/harvest-loop/SKILL.md +1 -1
  31. package/plugins/fh-meta/skills/meta-prompt-builder/SKILL.md +19 -0
  32. package/plugins/fh-meta/skills/sim-conductor/SKILL_detail.md +3 -3
  33. package/plugins/fh-meta/skills/steel-quench/SKILL_detail.md +8 -4
  34. package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
  35. package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
  36. package/scripts/agy_launch_guard.sh +49 -0
  37. package/scripts/agy_remote_run.sh +187 -0
  38. package/scripts/capability_registry_check.sh +15 -2
  39. package/scripts/codex_launch_guard.sh +87 -0
  40. package/scripts/finding_fleet.sh +35 -2
  41. package/scripts/finding_verifier.sh +6 -2
  42. package/scripts/ko_tech_writer_calibrate.py +88 -1
  43. package/scripts/live_eval_trace.py +141 -0
  44. package/scripts/package_coverage_check.sh +7 -0
  45. package/scripts/pr_merge_verified.sh +7 -0
  46. package/scripts/prepush_guard_check.sh +33 -20
  47. package/scripts/probe_live_eval.sh +6 -3
  48. package/scripts/probe_live_eval_lib.py +92 -2
  49. package/scripts/remote_marker_gate.sh +56 -0
  50. package/scripts/selfcheck.sh +58 -2
  51. package/scripts/session_checklist.py +109 -5
  52. package/scripts/session_close_check.sh +16 -0
  53. package/scripts/sidecar_calibrate.sh +10 -2
  54. package/scripts/sidecar_wait.sh +21 -1
  55. package/scripts/sim_isolated_run.sh +17 -2
  56. package/scripts/test_agy_launch_guard_lanes.sh +227 -0
  57. package/scripts/test_agy_remote_run_lanes.sh +228 -0
  58. package/scripts/test_codex_launch_guard_lanes.sh +138 -0
  59. package/scripts/test_finding_pipeline_lanes.sh +6 -2
  60. package/scripts/test_fixture_guard_coverage_lanes.sh +71 -10
  61. package/scripts/test_live_eval_trace_lanes.sh +191 -0
  62. package/scripts/test_meta_prompt_restate_lanes.sh +36 -0
  63. package/scripts/test_mutation_probe_lanes.sh +26 -6
  64. package/scripts/test_pr_merge_verified_lanes.sh +23 -0
  65. package/scripts/test_preprep_speech_coach_lanes.sh +18 -2
  66. package/scripts/test_prepush_guard_failure_visibility_lanes.sh +152 -0
  67. package/scripts/test_remote_marker_gate_lanes.sh +96 -0
  68. package/scripts/test_session_checklist_lanes.sh +205 -0
  69. package/scripts/test_session_close_lanes.sh +7 -0
  70. package/scripts/test_sidecar_calibrate_lanes.sh +4 -0
  71. package/scripts/test_sidecar_wait_stdin.sh +18 -0
@@ -0,0 +1,228 @@
1
+ #!/usr/bin/env bash
2
+ # test_agy_remote_run_lanes.sh — lanes for scripts/agy_remote_run.sh (agy only as a remote OS user).
3
+ #
4
+ # HOW. A fake `ssh`/`scp` pair stands in for the remote machine: a temp folder is the remote user's
5
+ # home, and the three PowerShell scripts the runner sends (canary.ps1 · run.ps1 · cleanup.ps1) are
6
+ # EMULATED by the fake ssh, not executed. A fake agy records that it started. No network, no real agy.
7
+ # WHAT IS CHECKED: the local half — refusal without a target or a fresh PASS receipt, refusal on a
8
+ # changed setting, no local fallback when the route is down, argument and file transport, exit codes,
9
+ # and that only the run's own work folder is removed.
10
+ # WHAT IS NOT CHECKED: the PowerShell scripts themselves (no PowerShell here) — they were run for real
11
+ # against a Windows remote on 2026-11-16 (canary PASS 6/6, one agy round trip); and whether the remote
12
+ # OS user is really isolated (that is what --canary measures, on the day it runs).
13
+ # Usage: bash scripts/test_agy_remote_run_lanes.sh Exit: 0 all pass · 1 any fail
14
+ set -uo pipefail
15
+ REPO="$(cd "$(dirname "$0")/.." && pwd)"
16
+ RUN="$REPO/scripts/agy_remote_run.sh"
17
+ GUARD="$REPO/scripts/agy_launch_guard.sh"
18
+ D="$(mktemp -d "${TMPDIR:-/tmp}/agyremote.XXXXXX")" || { echo "ENV-BLOCKED: mktemp failed — unmeasured, not a pass"; exit 1; }
19
+ trap 'rm -rf "$D"' EXIT
20
+ PASS=0; FAIL=0
21
+ ok() { PASS=$((PASS+1)); echo " ✅ $1"; }
22
+ bad() { FAIL=$((FAIL+1)); echo " ❌ $1"; }
23
+ RH="$D/rhome"; mkdir -p "$RH" "$D/bin"
24
+
25
+ # ── fake remote ────────────────────────────────────────────────────────────────────────────────────
26
+ cat > "$D/bin/ssh" <<EOF
27
+ #!/usr/bin/env bash
28
+ RH="$RH"; D="$D"
29
+ [ "\${FAKE_SSH_DOWN:-0}" = 1 ] && exit 255
30
+ while [ \$# -gt 0 ] && [ "\$1" = -o ]; do shift 2; done
31
+ shift # target
32
+ cmd="\$*"
33
+ case "\$cmd" in
34
+ "mkdir "*) mkdir "\$RH/\${cmd#mkdir }" ;;
35
+ powershell*-File*) f="\${cmd##*-File }"; wd="\${f%%\\\\*}"; sc="\${f##*\\\\}"; W="\$RH/\$wd"
36
+ mkdir -p "\$D/seen"; cp "\$W/\$sc" "\$D/seen/\$sc" 2>/dev/null
37
+ case "\$sc" in
38
+ canary.ps1) while IFS= read -r p; do ao=0; case "\$p" in '?'*) ao=1; p="\${p#?}" ;; esac
39
+ if grep -qxF -- "\$p" "\$D/readable" 2>/dev/null; then echo "DENY-FAIL \$p (readable)"
40
+ elif grep -qxF -- "\$p" "\$D/notfound" 2>/dev/null; then [ \$ao = 1 ] && echo "DENY-OK \$p (ItemNotFoundException)" || echo "DENY-FAIL \$p (not measured: ItemNotFoundException)"
41
+ else echo "DENY-OK \$p (UnauthorizedAccessException)"; fi
42
+ done < "\$W/deny.txt"
43
+ [ "\${FAKE_POS_FAIL:-0}" = 1 ] && echo POS-FAIL || echo POS-OK
44
+ exit "\${FAKE_SSH_CANARY_RC:-0}" ;;
45
+ run.ps1) ( cd "\$W" && args=(); while IFS= read -r a; do [ -n "\$a" ] && args+=("\$a"); done < args.txt
46
+ "\$D/fake_agy" -p "\$(cat prompt.txt)" \${args[@]+"\${args[@]}"} --settings "\$W/settings.json"; arc=\$?
47
+ echo "FH_AGY_RC=\$arc"; [ "\${FAKE_LATE_LINE:-0}" = 1 ] && echo "FH_AGY_RC=0"
48
+ exit "\${FAKE_SSH_RUN_RC:-\$arc}" ); exit \$? ;;
49
+ cleanup.ps1) n="\$wd"
50
+ if ! printf '%s' "\$n" | grep -Eq '^fh_agy_[0-9]{14}_[0-9a-f]{6}$'; then echo "CLEANUP-REFUSED \$n"; exit 3; fi
51
+ [ "\${FAKE_CLEANUP_FAIL:-0}" = 1 ] && { echo CLEANUP-FAILED; exit 5; }
52
+ rm -rf "\$W"; echo CLEANUP-OK ;;
53
+ esac ;;
54
+ *) echo "fake ssh: unexpected command: \$cmd" >&2; exit 99 ;;
55
+ esac
56
+ EOF
57
+ cat > "$D/bin/scp" <<EOF
58
+ #!/usr/bin/env bash
59
+ RH="$RH"
60
+ args=(); while [ \$# -gt 0 ]; do case "\$1" in -q) shift ;; -o) shift 2 ;; *) args+=("\$1"); shift ;; esac; done
61
+ dst="\${args[\${#args[@]}-1]}"; unset 'args[\${#args[@]}-1]'
62
+ case "\$dst" in
63
+ *:*) for s in "\${args[@]}"; do cp "\$s" "\$RH/\${dst#*:}" || exit 1; done ;;
64
+ *) for s in "\${args[@]}"; do cp "\$RH/\${s#*:}" "\$dst" || exit 1; done ;;
65
+ esac
66
+ EOF
67
+ cat > "$D/fake_agy" <<EOF
68
+ #!/usr/bin/env bash
69
+ printf '%s\n' "\$@" > "$D/agy_argv"
70
+ echo "fake-output" > out.txt
71
+ echo "FAKE-AGY-RAN"
72
+ [ -n "\${FAKE_AGY_SLEEP:-}" ] && sleep "\$FAKE_AGY_SLEEP"
73
+ [ -n "\${FAKE_AGY_FORGE:-}" ] && echo "FH_AGY_RC=0"
74
+ exit \${FAKE_AGY_RC:-0}
75
+ EOF
76
+ # a recording `agy` on PATH: if the runner ever fell back to a local agy, this would record it
77
+ printf '#!/usr/bin/env bash\n: > "%s/local_agy_ran"\n' "$D" > "$D/bin/agy"
78
+ chmod +x "$D/bin/ssh" "$D/bin/scp" "$D/fake_agy" "$D/bin/agy"
79
+ export PATH="$D/bin:$PATH" # fake ssh/scp by name, first on PATH — the runner has no override switch
80
+ export FH_AGY_REMOTE_RECEIPT_DIR="$D/receipts"
81
+ DENY='C:\Users\admin;C:\Users\Public;D:\'
82
+ # first / newest receipt without an early-exit reader on a pipe (pipefail class-lock)
83
+ first_receipt() { local f; for f in "$D"/receipts/receipt_*.txt; do [ -f "$f" ] && { printf '%s' "$f"; return 0; }; done; return 1; }
84
+ newest_receipt() { local f n=""; for f in "$D"/receipts/receipt_*.txt; do [ -f "$f" ] || continue; { [ -z "$n" ] || [ "$f" -nt "$n" ]; } && n="$f"; done; printf '%s' "$n"; }
85
+ leftover() { find "$RH" -mindepth 1 -maxdepth 1 -name 'fh_agy_*' | wc -l | tr -d ' '; }
86
+ run() { out=$("$@" 2>"$D/err" </dev/null); rc=$?; err=$(cat "$D/err"); }
87
+
88
+ echo "── refusals before any canary"
89
+ run env -u FH_AGY_REMOTE bash "$RUN" -p hi
90
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q AGY-REMOTE-REFUSED && ok "R1 no FH_AGY_REMOTE: rc=3 refused" || bad "R1 no target: rc=$rc"
91
+ export FH_AGY_REMOTE=user@remote FH_AGY_REMOTE_DENY="$DENY"
92
+ run bash "$RUN" -p hi
93
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'no canary receipt' && ok "R2 no receipt: rc=3 refused" || bad "R2 no receipt: rc=$rc err=${err:0:100}"
94
+ run env FH_AGY_REMOTE_DENY= bash "$RUN" --canary
95
+ [ "$rc" -eq 2 ] && ok "R3 canary with an empty deny list: rc=2" || bad "R3 empty deny canary: rc=$rc"
96
+
97
+ echo "── canary"
98
+ : > "$D/readable"
99
+ run bash "$RUN" --canary
100
+ R="$(first_receipt)"
101
+ if [ "$rc" -eq 0 ] && grep -qx 'verdict=PASS' "$R" && grep -qx 'denied=3/3' "$R" && [ "$(leftover)" = 0 ]; then ok "R4 canary all denied: PASS 3/3, receipt written, remote folder removed"
102
+ else bad "R4 canary PASS: rc=$rc receipt=$(head -4 "$R" 2>/dev/null | tr '\n' ' ') left=$(leftover)"; fi
103
+ printf 'C:\\Users\\Public\n' > "$D/readable"
104
+ run bash "$RUN" --canary
105
+ [ "$rc" -eq 1 ] && grep -qx 'verdict=FAIL' "$R" && ok "R5 canary with one readable path: FAIL rc=1" || bad "R5 canary readable: rc=$rc"
106
+ run bash "$RUN" -p hi
107
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'did not pass' && ok "R6 run after a FAIL receipt: rc=3 refused" || bad "R6 run after FAIL: rc=$rc"
108
+ : > "$D/readable"
109
+ run env FAKE_POS_FAIL=1 bash "$RUN" --canary
110
+ [ "$rc" -eq 1 ] && grep -qx 'positive=FAIL' "$R" && ok "R7 canary whose positive control fails: FAIL" || bad "R7 positive fail: rc=$rc"
111
+ run bash "$RUN" --canary
112
+ [ "$rc" -eq 0 ] && ok "R8 canary PASS again (for the run lanes)" || bad "R8 canary PASS again: rc=$rc"
113
+
114
+ echo "── run"
115
+ printf 'frozen input\n' > "$D/in.txt"
116
+ rm -f "$D/agy_argv"
117
+ run bash "$RUN" --input "$D/in.txt" --fetch out.txt --fetch-dir "$D/back" -p "two words prompt" --model m1 --output-format text
118
+ argv="$(tr '\n' '|' < "$D/agy_argv" 2>/dev/null)"
119
+ if [ "$rc" -eq 0 ] && printf '%s' "$out" | grep -q FAKE-AGY-RAN && [ "$(cat "$D/back/out.txt" 2>/dev/null)" = fake-output ] \
120
+ && printf '%s' "$argv" | grep -q '^-p|two words prompt|--model|m1|--output-format|text|--settings|' && [ "$(leftover)" = 0 ]; then
121
+ ok "R9 run: prompt and flags intact, --settings added, fetched file back, remote folder removed"
122
+ else bad "R9 run: rc=$rc argv=$argv left=$(leftover) err=${err:0:120}"; fi
123
+ run env FAKE_AGY_RC=7 bash "$RUN" -p hi
124
+ [ "$rc" -eq 1 ] && printf '%s' "$err" | grep -q 'AGY_RC=7' && ok "R10 remote agy rc 7: runner rc=1 with AGY_RC=7" || bad "R10 agy rc: rc=$rc err=${err:0:80}"
125
+ run env FAKE_CLEANUP_FAIL=1 bash "$RUN" -p hi
126
+ [ "$rc" -eq 5 ] && ok "R11 cleanup not confirmed: rc=5" || bad "R11 cleanup fail: rc=$rc"
127
+ rm -rf "$RH"/fh_agy_*
128
+ run env FAKE_SSH_DOWN=1 bash "$RUN" -p hi
129
+ [ "$rc" -eq 4 ] && printf '%s' "$err" | grep -q 'not falling back' && ok "R12 route down: rc=4, says it does not fall back" || bad "R12 route down: rc=$rc"
130
+ printf 'x' > "$D/bad name.txt"
131
+ run bash "$RUN" --input "$D/bad name.txt" -p hi
132
+ [ "$rc" -eq 2 ] && ok "R13 input name with a space: rc=2" || bad "R13 bad name: rc=$rc"
133
+ mkdir -p "$D/other"; cp "$D/in.txt" "$D/other/in.txt"
134
+ run bash "$RUN" --input "$D/in.txt" --input "$D/other/in.txt" -p hi
135
+ [ "$rc" -eq 2 ] && ok "R14 two inputs with one name: rc=2" || bad "R14 duplicate: rc=$rc"
136
+ run bash "$RUN" -p hi --settings x.json
137
+ [ "$rc" -eq 2 ] && ok "R15 caller --settings: rc=2 (the runner owns it)" || bad "R15 settings: rc=$rc"
138
+
139
+ echo "── receipt freshness and settings"
140
+ R="$(first_receipt)"
141
+ sed -i.bak 's/^epoch=.*/epoch=1000/' "$R"
142
+ run bash "$RUN" -p hi
143
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'older than 7 days' && ok "R16 receipt older than 7 days: rc=3" || bad "R16 stale: rc=$rc"
144
+ run bash "$RUN" --canary
145
+ run env FH_AGY_REMOTE_DENY='C:\Users\admin' bash "$RUN" -p hi
146
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'no canary receipt' && ok "R17 deny list changed since the canary: rc=3 (new settings, no receipt)" || bad "R17 changed: rc=$rc"
147
+ h_t=user@remote; h_d='C:\Users\admin'; h_a='%LOCALAPPDATA%\agy\bin\agy.exe'
148
+ cp "$R" "$D/receipts/receipt_$(printf 'v1|%d:%s|%d:%s|%d:%s' "${#h_t}" "$h_t" "${#h_d}" "$h_d" "${#h_a}" "$h_a" | shasum -a 256 | cut -c1-16).txt"
149
+ run env FH_AGY_REMOTE_DENY='C:\Users\admin' bash "$RUN" -p hi
150
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'different settings' && ok "R18 receipt copied under another name: rc=3 (hash inside does not match)" || bad "R18 copied receipt: rc=$rc err=${err:0:80}"
151
+
152
+ echo "── through the guard"
153
+ run env FH_AGY_ISOLATION=remote-os-user bash "$GUARD" "$RUN" -p hi
154
+ [ "$rc" -eq 0 ] && printf '%s' "$out" | grep -q FAKE-AGY-RAN && ok "R19 guard + remote-os-user + this runner: runs" || bad "R19 guard route: rc=$rc err=${err:0:100}"
155
+ run env -u FH_AGY_ISOLATION bash "$GUARD" "$RUN" -p hi
156
+ [ "$rc" -eq 3 ] && ok "R20 guard without the marker: refused even for this runner" || bad "R20 guard no marker: rc=$rc"
157
+
158
+ echo "── review round 1 holes"
159
+ run bash "$RUN" --canary
160
+ printf '#!/usr/bin/env bash\n: > "%s/override_ran"\n' "$D" > "$D/override"; chmod +x "$D/override"
161
+ run env FH_AGY_REMOTE_SSH="$D/override" FH_AGY_REMOTE_SCP="$D/override" FH_AGY_REMOTE_LANE=1 bash "$RUN" -p hi
162
+ [ ! -e "$D/override_ran" ] && [ "$rc" -eq 0 ] && ok "R22 FH_AGY_REMOTE_SSH/SCP/LANE in the environment have no effect (no override exists)" || bad "R22 override honoured: rc=$rc"
163
+ printf 'x' > "$D/RUN.PS1"
164
+ run bash "$RUN" --input "$D/RUN.PS1" -p hi
165
+ [ "$rc" -eq 2 ] && printf '%s' "$err" | grep -q reserved && ok "R23 input named RUN.PS1 (case differs): rc=2 reserved" || bad "R23 RUN.PS1: rc=$rc"
166
+ run env FH_AGY_REMOTE_AGY="C:\\x$(printf '\342\200\231'); Remove-Item C:\\s #" bash "$RUN" -p hi
167
+ [ "$rc" -eq 2 ] && ok "R24 remote agy path with a smart quote: rc=2" || bad "R24 smart quote: rc=$rc"
168
+ run env FAKE_SSH_RUN_RC=255 bash "$RUN" -p hi
169
+ [ "$rc" -eq 4 ] && ok "R25 ssh exits 255 after agy ran: rc=4 (not success)" || bad "R25 ssh rc: rc=$rc"
170
+ rm -rf "$RH"/fh_agy_*
171
+ run env FAKE_CLEANUP_FAIL=1 bash "$RUN" --canary
172
+ R="$(printf '%s' "$out" | sed -n 's/.*receipt=//p')"
173
+ [ "$rc" -ne 0 ] && grep -qx 'verdict=FAIL' "$R" && ok "R26 canary whose cleanup fails: not PASS" || bad "R26 canary cleanup: rc=$rc verdict=$(sed -n 's/^verdict=//p' "$R")"
174
+ rm -rf "$RH"/fh_agy_*
175
+ : > "$D/afile" # a receipt dir UNDER a regular file cannot be created, even by root
176
+ run env FH_AGY_REMOTE_RECEIPT_DIR="$D/afile/sub" bash "$RUN" --canary
177
+ [ "$rc" -eq 4 ] && ok "R27 receipt cannot be written: rc=4" || bad "R27 unwritable receipt: rc=$rc"
178
+ run env FH_AGY_REMOTE_DENY="$(printf 'C:\\a\nC:\\b')" bash "$RUN" --canary
179
+ [ "$rc" -eq 2 ] && ok "R28 deny list with a line break: rc=2" || bad "R28 newline in deny: rc=$rc"
180
+ # R29 the uploaded scripts themselves carry the probes the emulator stands in for
181
+ if grep -q 'Get-ChildItem -LiteralPath \$p -Force -ErrorAction Stop' "$D/seen/canary.ps1" 2>/dev/null && grep -q "UnauthorizedAccess" "$D/seen/canary.ps1" \
182
+ && grep -q "OpenRead(\$p)" "$D/seen/canary.ps1" && grep -q "POS-OK" "$D/seen/canary.ps1" \
183
+ && grep -qF "'^fh_agy_[0-9]{14}_[0-9a-f]{6}\$'" "$D/seen/cleanup.ps1" && grep -qF '$parent -ne $env:USERPROFILE' "$D/seen/cleanup.ps1" \
184
+ && grep -qF '"FH_AGY_RC=$rc"' "$D/seen/run.ps1" && grep -qF "prompt.txt' -Raw -Encoding UTF8" "$D/seen/run.ps1"; then
185
+ ok "R29 uploaded canary/cleanup/run scripts carry the read probe, the access-denied rule, the name+parent check and the final rc line"
186
+ else bad "R29 uploaded script content missing a probe or check"; fi
187
+ echo "── review round 2 holes"
188
+ printf 'C:\\Users\\Typo\n' > "$D/notfound"
189
+ run env FH_AGY_REMOTE_DENY='C:\Users\Typo;C:\Users\Public' bash "$RUN" --canary
190
+ [ "$rc" -eq 1 ] && printf '%s' "$out" | grep -q 'FAIL' && ok "R30 a deny path that does not exist (no ?): FAIL, not measured" || bad "R30 typo path: rc=$rc"
191
+ run env FH_AGY_REMOTE_DENY='?C:\Users\Typo;C:\Users\Public' bash "$RUN" --canary
192
+ [ "$rc" -eq 0 ] && ok "R31 the same path marked ? (absence accepted): PASS" || bad "R31 ? path: rc=$rc"
193
+ : > "$D/notfound"; rm -rf "$RH"/fh_agy_*
194
+ run env FAKE_SSH_CANARY_RC=255 bash "$RUN" --canary
195
+ [ "$rc" -eq 1 ] && ok "R32 canary whose ssh exits 255 after printing all probes: FAIL" || bad "R32 canary ssh rc: rc=$rc"
196
+ rm -rf "$RH"/fh_agy_*
197
+ run bash "$RUN" --canary
198
+ run env FAKE_AGY_FORGE=1 FAKE_AGY_RC=7 bash "$RUN" -p hi
199
+ [ "$rc" -eq 1 ] && printf '%s' "$err" | grep -q 'AGY_RC=7' && ok "R33 agy prints a forged FH_AGY_RC=0 then exits 7: runner rc=1 (only the last line counts)" || bad "R33 forged rc: rc=$rc"
200
+ printf 'a' > "$D/Evidence.txt"; printf 'b' > "$D/other/evidence.txt"
201
+ run bash "$RUN" --input "$D/Evidence.txt" --input "$D/other/evidence.txt" -p hi
202
+ [ "$rc" -eq 2 ] && ok "R34 inputs Evidence.txt and evidence.txt: rc=2 (Windows ignores case)" || bad "R34 case dup: rc=$rc"
203
+ echo "── narrowed round 3: verdict and destructive paths"
204
+ rm -rf "$RH"/fh_agy_*
205
+ run bash "$RUN" --canary
206
+ run bash "$RUN" --fetch ../outside.txt --fetch-dir "$D/back" -p hi
207
+ [ "$rc" -eq 2 ] && ok "R35 --fetch ../outside.txt: rc=2 (bare names only)" || bad "R35 fetch traversal: rc=$rc"
208
+ R="$(printf '%s' "$out" | sed -n 's/.*receipt=//p')"; [ -n "$R" ] || R="$(newest_receipt)"
209
+ run bash "$RUN" --canary; R="$(printf '%s' "$out" | sed -n 's/.*receipt=//p')"
210
+ sed -i.bak 's/^epoch=.*/epoch=9999999999/' "$R"
211
+ run bash "$RUN" -p hi
212
+ [ "$rc" -eq 3 ] && printf '%s' "$err" | grep -q 'future' && ok "R36 receipt dated in the future: rc=3" || bad "R36 future receipt: rc=$rc"
213
+ run bash "$RUN" --canary
214
+ run env FAKE_AGY_RC=7 FAKE_LATE_LINE=1 bash "$RUN" -p hi
215
+ [ "$rc" -ne 0 ] && ok "R37 agy exits 7, a late line prints FH_AGY_RC=0: not success (rc=$rc)" || bad "R37 late forged line: rc=0"
216
+ rm -rf "$RH"/fh_agy_*
217
+ FAKE_AGY_SLEEP=3 bash "$RUN" -p hi > "$D/int.out" 2> "$D/int.err" < /dev/null &
218
+ ipid=$!; k=0; until ls "$RH"/fh_agy_* >/dev/null 2>&1 || [ "$k" -ge 50 ]; do sleep 0.1; k=$((k+1)); done
219
+ sleep 0.5; kill -TERM "$ipid" 2>/dev/null; wait "$ipid" 2>/dev/null; irc=$?
220
+ if [ "$(leftover)" = 0 ] && [ "$irc" = 130 ]; then ok "R38 TERM during a run: the runner's own handler exits 130 and the remote work folder is removed"
221
+ else bad "R38 interrupt: left=$(leftover) irc=$irc waited=$k out=$(head -c 80 "$D/int.out" | tr "\n" " ") err=$(head -c 120 "$D/int.err")"; fi
222
+ if grep -qF "deny.txt') -Encoding UTF8" "$D/seen/canary.ps1" && grep -qF 'InnerException' "$D/seen/canary.ps1" \
223
+ && grep -qF 'exit $rc' "$D/seen/run.ps1"; then ok "R39 uploaded scripts read the deny list as UTF-8, walk wrapped errors, and exit with agy's code"
224
+ else bad "R39 uploaded script content missing UTF-8 deny read / inner-error walk / exit code"; fi
225
+ [ ! -e "$D/local_agy_ran" ] && ok "R21 no lane started a local agy" || bad "R21 a local agy was started"
226
+ echo
227
+ echo "agy remote run lanes: $PASS passed, $FAIL failed"
228
+ [ "$FAIL" -eq 0 ]
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env bash
2
+ # test_codex_launch_guard_lanes.sh — lanes for scripts/codex_launch_guard.sh and the FH callers that start
3
+ # codex (finding_fleet.sh codex rows · finding_verifier.sh --family codex · sidecar_calibrate.sh probe).
4
+ #
5
+ # WHAT IS CHECKED: codex is not started when the prompt (stdin), an argument or the working folder refers
6
+ # to a configured company-repo root; it is started — with the prompt intact and its own exit code passed
7
+ # back — when nothing does; and an unconfigured list is said out loud, never shown as clean. A FAKE codex
8
+ # records whether it started; no real codex runs. The roots used here are temp folders this lane makes.
9
+ # WHAT IS NOT CHECKED: a company path the prompt carries in another shape (relative path, file content
10
+ # pasted without its path, encoding) — the guard matches root paths as strings, nothing more.
11
+ #
12
+ # Usage: bash scripts/test_codex_launch_guard_lanes.sh Exit: 0 all pass · 1 any fail
13
+ set -uo pipefail
14
+ REPO="$(cd "$(dirname "$0")/.." && pwd)"
15
+ GUARD="$REPO/scripts/codex_launch_guard.sh"
16
+ FLEET="$REPO/scripts/finding_fleet.sh"
17
+ VERIFIER="$REPO/scripts/finding_verifier.sh"
18
+ D="$(mktemp -d "${TMPDIR:-/tmp}/codexguard.XXXXXX")" || { echo "ENV-BLOCKED: mktemp failed — unmeasured, not a pass"; exit 1; }
19
+ trap 'rm -rf "$D"' EXIT
20
+ D="$(cd "$D" && pwd -P)"
21
+ unset FH_COMPANY_ROOTS FH_COMPANY_ROOTS_FILE
22
+ export FH_COMPANY_ROOTS_FILE="$D/no-such-roots-file" # keep the operator's own list out of these lanes
23
+ PASS=0; FAIL=0
24
+ ok() { PASS=$((PASS+1)); echo " ✅ $1"; }
25
+ bad() { FAIL=$((FAIL+1)); echo " ❌ $1"; }
26
+
27
+ cat > "$D/codex_fake" <<EOF
28
+ #!/usr/bin/env bash
29
+ cat > "$D/stdin_seen"
30
+ printf '%s\n' "\$@" > "$D/argv_seen"
31
+ : > "$D/ran"
32
+ echo '{"title":"fake","file":"t.py","line":1,"severity":"B","category":"x","detail":"d","defeater":"df","confidence":0.5}'
33
+ exit \${FAKE_CODEX_RC:-0}
34
+ EOF
35
+ chmod +x "$D/codex_fake"
36
+ mkdir -p "$D/company/repo-a/src" "$D/public"
37
+ ROOT="$D/company/repo-a"
38
+ run() { rm -f "$D/ran" "$D/stdin_seen"; out=$("$@" 2>"$D/err"); rc=$?; err=$(cat "$D/err"); }
39
+
40
+ echo "── guard alone"
41
+ run env -u FH_COMPANY_ROOTS bash "$GUARD" "$D/codex_fake" exec - <<< "review this public diff"
42
+ if [ "$rc" -eq 0 ] && [ -e "$D/ran" ] && printf '%s' "$err" | grep -q 'not checked'; then ok "C1 no list configured: codex runs, and the guard says «not checked» (not «clean»)"
43
+ else bad "C1 unconfigured: rc=$rc ran=$([ -e "$D/ran" ] && echo yes || echo no) err=${err:0:100}"; fi
44
+
45
+ export FH_COMPANY_ROOTS="$ROOT"
46
+ run bash "$GUARD" "$D/codex_fake" exec - <<< "please review $ROOT/src/app.py for bugs"
47
+ if [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q 'CODEX-REFUSED' && printf '%s' "$err" | grep -q 'prompt'; then ok "C2 company root in the prompt: refused rc=3, codex not started, says «prompt»"
48
+ else bad "C2 prompt: rc=$rc ran=$([ -e "$D/ran" ] && echo yes || echo no) err=${err:0:120}"; fi
49
+
50
+ printf 'diff --git a/x.sh b/x.sh\n+echo hi\n' > "$D/public.diff"
51
+ run env FAKE_CODEX_RC=5 bash "$GUARD" "$D/codex_fake" exec --sandbox read-only - < "$D/public.diff"
52
+ if [ "$rc" -eq 5 ] && [ -e "$D/ran" ] && cmp -s "$D/stdin_seen" "$D/public.diff" && [ "$(sed -n 2p "$D/argv_seen")" = "--sandbox" ]; then ok "C3 public diff: codex runs with the prompt byte-for-byte and its own rc (5) comes back"
53
+ else bad "C3 public: rc=$rc ran=$([ -e "$D/ran" ] && echo yes || echo no) same_stdin=$(cmp -s "$D/stdin_seen" "$D/public.diff" && echo yes || echo no)"; fi
54
+
55
+ run bash "$GUARD" "$D/codex_fake" exec -C "$ROOT" - <<< "hello"
56
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q 'argument' && ok "C4 company root in an argument: refused" || bad "C4 argument: rc=$rc err=${err:0:100}"
57
+
58
+ run bash -c 'cd "$1" && bash "$2" "$3" exec - <<< "hello"' _ "$ROOT/src" "$GUARD" "$D/codex_fake"
59
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q 'working folder' && ok "C5 working folder inside a company root: refused" || bad "C5 cwd: rc=$rc err=${err:0:100}"
60
+
61
+ # C6 the same root written another way: /private stripped (macOS /tmp = /private/tmp) and ~ for $HOME
62
+ case "$ROOT" in
63
+ /private/*) alt="${ROOT#/private}"
64
+ run bash "$GUARD" "$D/codex_fake" exec - <<< "look at $alt/src"
65
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && ok "C6a root written without /private: refused" || bad "C6a /private form: rc=$rc" ;;
66
+ *) echo " ➖ C6a /private form not applicable (temp root is not under /private)" ;;
67
+ esac
68
+ HROOT="$HOME/.fh-codex-guard-lane-$$"
69
+ run env FH_COMPANY_ROOTS="$HROOT" bash "$GUARD" "$D/codex_fake" exec - <<< "see ~/.fh-codex-guard-lane-$$/x"
70
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && ok "C6b root under HOME written with ~: refused" || bad "C6b ~ form: rc=$rc"
71
+
72
+ # C7 the list can come from a file (one path per line, # comments) instead of the environment
73
+ printf '# lane roots\n\n%s\n' "$ROOT" > "$D/roots"
74
+ run env -u FH_COMPANY_ROOTS FH_COMPANY_ROOTS_FILE="$D/roots" bash "$GUARD" "$D/codex_fake" exec - <<< "check $ROOT/src"
75
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && ok "C7 roots from a file: refused" || bad "C7 roots file: rc=$rc err=${err:0:100}"
76
+ # C7b a near-miss path (root name as a prefix of another folder) is NOT a match
77
+ run bash "$GUARD" "$D/codex_fake" exec - <<< "check $D/company/repo-ab/src"
78
+ [ "$rc" -eq 0 ] && [ -e "$D/ran" ] && ok "C7b ${ROOT##*/}b is not ${ROOT##*/}: runs (no prefix over-block)" || bad "C7b near-miss: rc=$rc"
79
+
80
+ # C7c a list file that exists but cannot be read is a refusal, not «unconfigured»
81
+ mkdir -p "$D/unreadable_roots" # a directory where a file is expected: open() fails with an error other than not-found
82
+ run env -u FH_COMPANY_ROOTS FH_COMPANY_ROOTS_FILE="$D/unreadable_roots" bash "$GUARD" "$D/codex_fake" exec - <<< "hello"
83
+ [ "$rc" -eq 3 ] && [ ! -e "$D/ran" ] && printf '%s' "$err" | grep -q 'cannot be read' && ok "C7c unreadable roots file: refused (not «not checked»)" || bad "C7c unreadable list: rc=$rc err=${err:0:100}"
84
+
85
+ echo "── callers"
86
+ printf 'def f():\n return "%s/src"\n' "$ROOT" > "$D/t_company.py"
87
+ printf 'def f():\n return 1\n' > "$D/t_public.py"
88
+ printf 'codex|logic|CODEX_BIN exec -\n' > "$D/codex.tbl"
89
+ rm -f "$D/ran"
90
+ FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_company.py" --out "$D/f1" --fleet "$D/codex.tbl" < /dev/null > "$D/f1.out" 2>&1
91
+ if [ ! -e "$D/ran" ] && grep -qs 'CODEX-REFUSED' "$D/f1/err_codex_logic.txt"; then ok "C8 fleet codex row on a file that names a company root: refused"
92
+ else bad "C8 fleet company: started=$([ -e "$D/ran" ] && echo yes || echo no)"; fi
93
+ rm -f "$D/ran"
94
+ FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_public.py" --out "$D/f2" --fleet "$D/codex.tbl" < /dev/null > "$D/f2.out" 2>&1
95
+ [ -e "$D/ran" ] && ok "C8b fleet codex row on a public file: runs (control alive)" || bad "C8b fleet public: not started"
96
+ printf 'codex|logic|codex exec -\n' > "$D/byname.tbl"
97
+ mkdir -p "$D/bin"; cp "$D/codex_fake" "$D/bin/codex"
98
+ rm -f "$D/ran"
99
+ PATH="$D/bin:$PATH" FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_company.py" --out "$D/f3" --fleet "$D/byname.tbl" < /dev/null > "$D/f3.out" 2>&1
100
+ [ ! -e "$D/ran" ] && ok "C8c fleet row calling codex by name on a company file: refused" || bad "C8c by name: started"
101
+ # C8d round 2: round-1 findings from a public file, round 2 aimed at a company file — still refused
102
+ FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_public.py" --out "$D/f4r1" --fleet "$D/codex.tbl" --r1-only < /dev/null > /dev/null 2>&1
103
+ rm -f "$D/ran"
104
+ FH_CODEX_BIN="$D/codex_fake" bash "$FLEET" "$D/t_company.py" --out "$D/f4r2" --reuse-r1 "$D/f4r1" --round2 < /dev/null > "$D/f4r2.out" 2>&1
105
+ if [ ! -e "$D/ran" ] && grep -qs 'CODEX-REFUSED' "$D/f4r2/err2_codex_logic.txt"; then ok "C8d fleet round 2 on a company file: refused"
106
+ else bad "C8d round 2: started=$([ -e "$D/ran" ] && echo yes || echo no) r2err=$(head -c 80 "$D/f4r2/err2_codex_logic.txt" 2>/dev/null)"; fi
107
+ # C8e a guard refusal seen through sidecar_wait is HARNESS-ERROR (nothing was reviewed), not COMPLETE
108
+ SW="$REPO/scripts/sidecar_wait.sh"
109
+ rm -f "$D/ran"
110
+ printf 'review %s/src\n' "$ROOT" | SIDECAR_POLL=1 bash "$SW" "$D/sw.out" 20 -- bash "$GUARD" "$D/codex_fake" exec - > "$D/sw.txt" 2>&1; swrc=$?
111
+ grep -q 'SIDECAR_VERDICT=HARNESS-ERROR.*reason=guard-refused' "$D/sw.txt" && [ "$swrc" -eq 3 ] && [ ! -e "$D/ran" ] \
112
+ && ok "C8e guard refusal through sidecar_wait: HARNESS-ERROR reason=guard-refused (rc 3)" || bad "C8e sidecar_wait: rc=$swrc verdict=$(grep -m1 SIDECAR_VERDICT "$D/sw.txt")"
113
+ printf '%s\n' '{"id":"x1","title":"t","file":"t.py","line":1,"severity":"B","category":"x","detail":"d","defeater":"df","confidence":0.5}' > "$D/claims.jsonl"
114
+ rm -f "$D/ran"
115
+ FH_CODEX_BIN="$D/codex_fake" bash "$VERIFIER" --family codex --target "$D/t_company.py" < "$D/claims.jsonl" > "$D/v1.out" 2> "$D/v1.err"; vrc=$?
116
+ [ ! -e "$D/ran" ] && [ "$vrc" -ne 0 ] && ok "C9 verifier --family codex on a company file: not started (rc=$vrc)" || bad "C9 verifier company: rc=$vrc started=$([ -e "$D/ran" ] && echo yes || echo no)"
117
+ rm -f "$D/ran"
118
+ FH_CODEX_BIN="$D/codex_fake" bash "$VERIFIER" --family codex --target "$D/t_public.py" < "$D/claims.jsonl" > /dev/null 2>&1
119
+ [ -e "$D/ran" ] && ok "C9b verifier on a public file: runs (control alive)" || bad "C9b verifier public: not started"
120
+
121
+ echo "── static"
122
+ # C10 shipped scripts start codex only through the guard. Comment lines are skipped; lanes and the guard
123
+ # itself are excluded. Residual: a launch assembled from pieces is not seen by a line scan.
124
+ hits=$(cd "$REPO/scripts" && grep -nE '(^|[[:space:](="])("?\$\{?CODEX\}?"?|codex)[[:space:]]+exec([[:space:]]|$)' \
125
+ $(ls *.sh | grep -vE '^(test_|codex_launch_guard\.sh$|docker_phase1_verify\.sh$|fh-goal\.sh$|fh-gate\.sh$|fh-run\.sh$)') 2>/dev/null | grep -vE ':[0-9]+:[[:space:]]*#' | grep -v 'CODEX_GUARD' || true)
126
+ # Excluded by name, on purpose:
127
+ # · docker_phase1_verify.sh — runs codex INSIDE a container with a fixed «reply OK» prompt; no file of
128
+ # this machine can reach that call.
129
+ # · fh-goal.sh · fh-gate.sh · fh-run.sh — runtime adapters: codex there is the user's chosen agent doing
130
+ # the user's own work, not a verifier arm handed someone else's material. Guarding them would block a
131
+ # consumer whose organisation allows codex. This guard covers verifier arms only.
132
+ [ -z "$hits" ] && ok "C10 no shipped script starts codex around the guard" || { bad "C10 unguarded codex launch(es):"; printf ' %s\n' "$hits"; }
133
+ printf 'out=$(codex exec -)\n' > "$D/probe.sh"
134
+ grep -qE '(^|[[:space:](="])("?\$\{?CODEX\}?"?|codex)[[:space:]]+exec([[:space:]]|$)' "$D/probe.sh" && ok "C11 static pattern sees a known unguarded line (control alive)" || bad "C11 static pattern blind"
135
+
136
+ echo
137
+ echo "codex launch guard lanes: $PASS passed, $FAIL failed"
138
+ [ "$FAIL" -eq 0 ]
@@ -7,6 +7,10 @@
7
7
  # verifier that cannot be reached, a family grading its own findings. Each lane below pins one of
8
8
  # those, and the mutant lane checks that removing the guard actually turns a lane red.
9
9
  set -uo pipefail
10
+ # Every agy in this file is a FAKE (a stub script), and agy_launch_guard.sh refuses any agy launch
11
+ # without an isolation marker. The guard's own refusal is tested in test_agy_launch_guard_lanes.sh;
12
+ # here the marker only lets the fakes through so these lanes keep measuring what they measure.
13
+ export FH_AGY_ISOLATION=container
10
14
  HERE="$(cd "$(dirname "$0")" && pwd)"
11
15
  FLEET="$HERE/finding_fleet.sh"; VERIFY="$HERE/finding_verify.py"
12
16
  PASS=0; FAIL=0
@@ -244,7 +248,7 @@ bash "$PIPE" "$D/tgt.py" --out "$D/pipe22" --fleet "$D/fleet0.tbl" >"$D/p22" 2>&
244
248
  # verifier 를 찾으므로, 뮤턴트만 임시 디렉터리에 두면 프로브는 «가드가 죽었나» 가 아니라
245
249
  # «파일이 없나» 를 잰다 — 빨간색이 나오지만 이유가 다르다(실측 2026-09-09, 이 레인의 첫 판).
246
250
  MUTD="$D/mut"; mkdir -p "$MUTD"
247
- cp "$HERE/finding_fleet.sh" "$HERE/finding_verify.py" "$HERE/finding_verifier.sh" "$MUTD/"
251
+ cp "$HERE/finding_fleet.sh" "$HERE/finding_verify.py" "$HERE/finding_verifier.sh" "$HERE/agy_launch_guard.sh" "$MUTD/"
248
252
  MUTP="$MUTD/finding_pipeline.sh"
249
253
  MUT_ERR="$D/mut23.err"
250
254
  /usr/bin/python3 - "$PIPE" "$MUTP" 2>"$MUT_ERR" <<'PY'
@@ -1113,7 +1117,7 @@ fi
1113
1117
  # 🟥 사본의 HERE 는 사본이 있는 디렉터리다 — 형제 스크립트를 같이 옮기지 않으면 «missing …
1114
1118
  # skipped, NOT passed» 로 exit 3 이 나서 rc 만 맞는 거짓 초록이 된다(초판이 그랬고, 아래
1115
1119
  # coverage 단언이 그것을 잡았다 — rc 하나만 봤으면 통과했다).
1116
- /bin/cp "$HERE/finding_fleet.sh" "$HERE/finding_verify.py" "$HERE/finding_verifier.sh" "$D/" 2>/dev/null
1120
+ /bin/cp "$HERE/finding_fleet.sh" "$HERE/finding_verify.py" "$HERE/finding_verifier.sh" "$HERE/agy_launch_guard.sh" "$D/" 2>/dev/null
1117
1121
  /usr/bin/sed 's|done < "$ROSTER"|done < "$OUT/families.txt"|g' "$PIPE" > "$D/pipe_rev.sh"
1118
1122
  NREV=$(/usr/bin/grep -c 'done < "\$OUT/families.txt"' "$D/pipe_rev.sh" 2>/dev/null); NREV=${NREV:-0}
1119
1123
  if [ "$NREV" -ge 2 ]; then
@@ -11,20 +11,46 @@
11
11
  # before the first git invocation. Readers are included on purpose: under an exported GIT_DIR a
12
12
  # read-only lane inspects the wrong repo and reports on it — a wrong answer, not just a leak.
13
13
  #
14
- # NOT SEEN (named residuals): git reached through a variable (`G=git; "$G" commit`), and a guard line
15
- # that sits inside a heredoc or an unexecuted branch — the scan reads lines, not control flow.
14
+ # SEEN since 2026-11-14: git captured into a variable (`G=$(command -v git)`, `G=/usr/bin/git`) and a
15
+ # guard line inside a heredoc body (not counted). NOT SEEN (named residuals): git reached through
16
+ # indirection the assignment regex does not name (`eval`, arrays, a function wrapping git), and a guard
17
+ # in an unexecuted branch (`if false; then . …; fi`) — the scan reads lines, not control flow.
18
+ # Known over-block (fail-closed, red not green): a quoted `"<<EOF"` in text opens heredoc state, so a
19
+ # real guard right after it is not counted until a line equal to EOF appears. The heredoc tracker is a
20
+ # line scanner, not a shell parser: two codex rounds each found new delimiter shapes (R1 numeric ·
21
+ # multiple; R2 tab strip · `EOF-X`), all fixed with fixtures C15–C17; further shapes are this residual.
16
22
  #
17
23
  # SUBJECT: the scan below, run over the live scripts/ directory (L-live) and over planted fixtures
18
24
  # (calibration). Revert probe: delete the guard line from any one lane → L-live goes red naming it.
19
25
  . "$(dirname "${BASH_SOURCE[0]}")/fixture_guard_lib.sh" # scrub inherited GIT_* env first (#1088)
20
26
  set -u
27
+ SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")"
21
28
  cd "$(dirname "${BASH_SOURCE[0]}")/.."
22
- pass=0; fail=0
29
+ pass=0; fail=0; skipped=0
30
+ sk() { skipped=$((skipped+1)); echo " SKIP $1"; }
23
31
  chk() { if [ "$1" -eq 0 ]; then pass=$((pass+1)); echo " PASS $2"; else fail=$((fail+1)); echo " FAIL $2"; fi; }
24
32
 
25
33
  GIT_RE='(^|[^A-Za-z0-9_.-])(/[A-Za-z0-9_./-]*/)?"?git"?[[:space:]]+(-[A-Za-z-]|[a-z])'
26
34
  SRC_RE='^[[:space:]]*(\.|source)[[:space:]]+("[^"#]*("[^"#]*"[^"#]*)*fixture_guard_lib\.sh"|[^[:space:]"#]*fixture_guard_lib\.sh)[[:space:]]*(#.*)?$'
27
35
 
36
+ # git captured into a variable (`G=git`, `G=/usr/bin/git`, `G=$(command -v git)`, `$(which git)`): the
37
+ # assignment line counts as the first git reference, so a lane that only ever runs "$G" is in scope.
38
+ VAR_RE='^[[:space:]]*(export[[:space:]]+|local[[:space:]]+)?[A-Za-z_][A-Za-z0-9_]*=("|'"'"')?((/[A-Za-z0-9_./-]*/)?git|\$\((command -v|which)[[:space:]]+git\))("|'"'"')?([[:space:];]|$)'
39
+ # guard_line <file> → line number of the first guard source line that is NOT inside a heredoc body
40
+ # (a `. …fixture_guard_lib.sh` written into a here-document is data for another file, not a guard here).
41
+ guard_line() {
42
+ SRC_RE="$SRC_RE" awk 'BEGIN { re = ENVIRON["SRC_RE"]; np = 0; qi = 0 }
43
+ qi < np { t = $0; if (dash[qi]) sub(/^\t+/, "", t); if (t == q[qi]) qi++; next }
44
+ /^[[:space:]]*#/ { next }
45
+ $0 ~ re { print NR; exit }
46
+ { l = $0; gsub(/<<</, "", l)
47
+ while (match(l, /<<-?[[:space:]]*[^[:space:]<>|&;()]+/)) {
48
+ tag = substr(l, RSTART, RLENGTH); dash[np] = (tag ~ /^<<-/)
49
+ sub(/^<<-?[[:space:]]*/, "", tag); gsub(/["\047\\]/, "", tag)
50
+ q[np++] = tag; l = substr(l, RSTART + RLENGTH) } }
51
+ ' "$1"
52
+ }
53
+
28
54
  # scan <dir> → prints one line per offending file; exit 0 when none, 1 when any, 2 when nothing scanned
29
55
  scan() {
30
56
  _n=0; _bad=0; _seen=""
@@ -33,10 +59,10 @@ scan() {
33
59
  case "$f" in "$1"/test_*_lanes.sh) case " $_seen " in *" $f "*) continue ;; esac ;; esac
34
60
  _seen="${_seen:-} $f"
35
61
  case "$f" in */fixture_guard_lib.sh) continue ;; esac
36
- g="$(grep -nE "$GIT_RE" "$f" | grep -vE '^[0-9]+:[[:space:]]*#' | head -1 | cut -d: -f1)"
62
+ g="$(grep -nE "$GIT_RE|$VAR_RE" "$f" | grep -vE '^[0-9]+:[[:space:]]*#' | head -1 | cut -d: -f1)"
37
63
  [ -n "$g" ] || continue
38
64
  _n=$((_n+1))
39
- s="$(grep -nE "$SRC_RE" "$f" | head -1 | cut -d: -f1)"
65
+ s="$(guard_line "$f")"
40
66
  if [ -z "$s" ]; then echo "UNGUARDED $f (first git call line $g, no fixture_guard_lib.sh source)"; _bad=$((_bad+1))
41
67
  elif [ "$s" -gt "$g" ]; then echo "LATE-GUARD $f (guard line $s after first git call line $g)"; _bad=$((_bad+1)); fi
42
68
  done
@@ -70,11 +96,46 @@ out="$(scan "$T/c8")"; rc=$?; [ "$rc" -eq 1 ] && [ "$(printf '%s\n' "$out" | gre
70
96
  mkdir "$T/c9"; for form in 'git -p status' 'git -C"$d" status' '/usr/bin/git status' '"git" status'; do printf '#!/bin/bash\n%s\n' "$form" > "$T/c9/test_$(printf '%s' "$form" | tr -c 'a-z' _)_lanes.sh"; done
71
97
  out="$(scan "$T/c9")"; rc=$?; [ "$rc" -eq 1 ] && [ "$(printf '%s\n' "$out" | grep -c UNGUARDED)" -eq 4 ]; chk $? "C9 git -p · git -C\"…\" · /usr/bin/git · \"git\" are all seen (rc=$rc, codex R2)"
72
98
 
99
+ # C10: the same file run from a non-git copy (an installed package's shape) must SKIP L-live by name,
100
+ # exit 0, and NOT print a PASS for it. The checkout run below is the opposite arm (L-live measured).
101
+ if [ -z "${FGCOV_INNER:-}" ]; then
102
+ mkdir -p "$T/pkg/scripts"; cp "$SELF" scripts/fixture_guard_lib.sh "$T/pkg/scripts/"
103
+ out="$(cd "$T/pkg" && FGCOV_INNER=1 bash scripts/test_fixture_guard_coverage_lanes.sh 2>&1)"; rc=$?
104
+ [ "$rc" -eq 0 ] && printf '%s\n' "$out" | grep -q '^ SKIP L-live — NOT-APPLICABLE' \
105
+ && ! printf '%s\n' "$out" | grep -q 'PASS L-live' && printf '%s\n' "$out" | grep -q '1 skipped (not a pass)'
106
+ chk $? "C10 non-git tree (installed package) → L-live SKIPPED by name, not red, not counted as pass (rc=$rc)"
107
+ fi
108
+
109
+ mkdir "$T/c11"; printf '#!/bin/bash\nG=$(command -v git)\n"$G" -C "$d" commit -q\n' > "$T/c11/test_var_lanes.sh"; printf '#!/bin/bash\nREALGIT=/usr/bin/git\n"$REALGIT" status\n' > "$T/c11/test_var2_lanes.sh"
110
+ out="$(scan "$T/c11")"; rc=$?; [ "$rc" -eq 1 ] && [ "$(printf '%s\n' "$out" | grep -c UNGUARDED)" -eq 2 ]; chk $? "C11 git only through a variable (\$(command -v git) · /usr/bin/git) is seen (rc=$rc)"
111
+ mkdir "$T/c12"; printf '#!/bin/bash\n%s\nG=$(command -v git)\n"$G" status\n' "$GUARD" > "$T/c12/test_vok_lanes.sh"
112
+ out="$(scan "$T/c12")"; rc=$?; [ "$rc" -eq 0 ]; chk $? "C12 control: guarded variable lane stays green (rc=$rc)"
113
+ mkdir "$T/c13"; printf '#!/bin/bash\ncat > "$d/x.sh" <<EOF\n%s\nEOF\ngit -C "$d" status\n' "$GUARD" > "$T/c13/test_hd_lanes.sh"
114
+ out="$(scan "$T/c13")"; rc=$?; [ "$rc" -eq 1 ] && printf '%s' "$out" | grep -q 'UNGUARDED.*test_hd_lanes'; chk $? "C13 guard line inside a heredoc body does not count (rc=$rc)"
115
+ mkdir "$T/c14"; printf '#!/bin/bash\ncat > "$d/x.sh" <<'"'"'EOF'"'"'\necho hi\nEOF\n%s\ngit -C "$d" status\n' "$GUARD" > "$T/c14/test_hdok_lanes.sh"
116
+ out="$(scan "$T/c14")"; rc=$?; [ "$rc" -eq 0 ]; chk $? "C14 control: heredoc closes, real guard after it counts (rc=$rc)"
117
+
118
+ mkdir "$T/c15"; printf '#!/bin/bash\ncat <<123\n%s\n123\ngit status\n' "$GUARD" > "$T/c15/test_num_lanes.sh"; printf '#!/bin/bash\ncat <<ONE <<TWO\nfirst\nONE\n%s\nTWO\ngit status\n' "$GUARD" > "$T/c15/test_two_lanes.sh"
119
+ out="$(scan "$T/c15")"; rc=$?; [ "$rc" -eq 1 ] && [ "$(printf '%s\n' "$out" | grep -c UNGUARDED)" -eq 2 ]; chk $? "C15 numeric heredoc delimiter and two heredocs on one line are both tracked (rc=$rc, codex R1)"
120
+
121
+ mkdir "$T/c16"; printf '#!/bin/bash\ncat <<EOF\n\tEOF\n%s\nEOF\ngit status\n' "$GUARD" > "$T/c16/test_tab_lanes.sh"; printf '#!/bin/bash\ncat <<EOF-X\nEOF\n%s\nEOF-X\ngit status\n' "$GUARD" > "$T/c16/test_dash_lanes.sh"
122
+ out="$(scan "$T/c16")"; rc=$?; [ "$rc" -eq 1 ] && [ "$(printf '%s\n' "$out" | grep -c UNGUARDED)" -eq 2 ]; chk $? "C16 tab-prefixed terminator closes only <<- heredocs · delimiter EOF-X is not closed by EOF (rc=$rc, codex R2)"
123
+ mkdir "$T/c17"; printf '#!/bin/bash\ncat <<-EOF\n\tbody\n\tEOF\n%s\ngit status\n' "$GUARD" > "$T/c17/test_dok_lanes.sh"
124
+ out="$(scan "$T/c17")"; rc=$?; [ "$rc" -eq 0 ]; chk $? "C17 control: <<- heredoc closed by a tab-indented terminator, guard after it counts (rc=$rc)"
125
+
73
126
  # ── live ──
74
- out="$(scan scripts)"; rc=$?
75
- printf '%s\n' "$out" | grep -vE '^SCANNED' | sed 's/^/ /'
76
- n="$(printf '%s\n' "$out" | sed -n 's/^SCANNED //p')"
77
- [ "$rc" -eq 0 ] && [ "${n:-0}" -ge 80 ]; chk $? "L-live every git-calling lane sources the guard first (scanned ${n:-0}, floor 80 — measured 86 on 2026-11-13; a sharp drop means the scan regex broke)"
127
+ # The floor 80 is a CHECKOUT number: an installed npm package ships fewer lanes (70 in 3.41.0), so run
128
+ # there the scan is not wrong, it is measuring a different tree. Same test selfcheck uses for package
129
+ # mode (`[ ! -e .git ]`). Non-git → the live lane is SKIPPED by name and the summary says so; it is
130
+ # never counted as a pass. Calibration C1–C9 above still runs — the scanner itself works anywhere.
131
+ if [ ! -e .git ]; then
132
+ sk "L-live — NOT-APPLICABLE: not a git checkout (installed package mode); the floor 80 counts the checkout's lanes. Run in a clone to measure. Not a pass."
133
+ else
134
+ out="$(scan scripts)"; rc=$?
135
+ printf '%s\n' "$out" | grep -vE '^SCANNED' | sed 's/^/ /'
136
+ n="$(printf '%s\n' "$out" | sed -n 's/^SCANNED //p')"
137
+ [ "$rc" -eq 0 ] && [ "${n:-0}" -ge 80 ]; chk $? "L-live every git-calling lane sources the guard first (scanned ${n:-0}, floor 80 — measured 86 on 2026-11-13; a sharp drop means the scan regex broke)"
138
+ fi
78
139
 
79
- echo "fixture-guard coverage lanes: $pass passed, $fail failed"
140
+ echo "fixture-guard coverage lanes: $pass passed, $fail failed$( [ "$skipped" -gt 0 ] && printf ', %s skipped (not a pass)' "$skipped")"
80
141
  [ "$fail" -eq 0 ]