@chrono-meta/fh-gate 3.21.0 → 3.22.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.
- package/.claude-plugin/marketplace.json +4 -4
- package/CLAUDE.md +62 -281
- package/knowledge/shared/harness-core/checkout_layer_drift.md +11 -0
- package/knowledge/shared/harness-core/claude_md_gate_details.md +343 -0
- package/knowledge/shared/harness-core/dispatch_conditional_prohibition.md +89 -0
- package/knowledge/shared/harness-core/fh_detail_protocols.md +88 -0
- package/knowledge/shared/harness-core/fh_three_layer_canon.md +49 -0
- package/knowledge/shared/harness-core/field_verdict_crossfamily_gate.md +29 -0
- package/knowledge/shared/learnings/subagent_invocations_log.yaml +20 -0
- package/package.json +4 -1
- package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-meta/CHANGELOG.md +17 -0
- package/plugins/fh-preprep/.claude-plugin/plugin.json +1 -1
- package/plugins/fh-qp/.claude-plugin/plugin.json +1 -1
- package/scripts/fh_session_load.sh +46 -0
- package/scripts/selfcheck.sh +41 -0
- package/scripts/sidecar_calibrate.sh +168 -13
- package/scripts/test_claude_md_size_lanes.sh +74 -0
- package/scripts/test_fh_audit_check_lanes.sh +140 -0
- package/scripts/test_ollama_panel_lanes.sh +69 -10
- package/scripts/test_session_load_mirror_fp_lanes.sh +122 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Lanes for templates/fh_audit_check.zsh — the terminal «Audit Reminders» banner.
|
|
3
|
+
#
|
|
4
|
+
# Usage: bash scripts/test_fh_audit_check_lanes.sh [NEW_SCRIPT] [ORIG_SCRIPT]
|
|
5
|
+
# NEW_SCRIPT default: templates/fh_audit_check.zsh (the script under test)
|
|
6
|
+
# ORIG_SCRIPT optional: the pre-fix script. When given, every fail-before lane is run against it
|
|
7
|
+
# and MUST emit the false line (proves the fixture reproduces the defect).
|
|
8
|
+
#
|
|
9
|
+
# Never touches the real HOME, ~/.cc_sentinels or ~/.zshrc: every run is `zsh -f` (no rc files)
|
|
10
|
+
# with a fake HOME and fixture dirs under mktemp.
|
|
11
|
+
set -u
|
|
12
|
+
REPO="$(cd "$(dirname "$0")/.." && pwd)"
|
|
13
|
+
NEW="${1:-$REPO/templates/fh_audit_check.zsh}"
|
|
14
|
+
ORIG="${2:-}"
|
|
15
|
+
[ -f "$NEW" ] || { echo "HARNESS-ERROR: script under test not found: $NEW"; exit 3; }
|
|
16
|
+
command -v zsh >/dev/null 2>&1 || { echo "HARNESS-ERROR: zsh not installed"; exit 3; }
|
|
17
|
+
|
|
18
|
+
T="$(mktemp -d "${TMPDIR:-/tmp}/fhaudit.XXXXXX")" || exit 3
|
|
19
|
+
[ -n "$T" ] && [ -d "$T" ] || { echo "HARNESS-ERROR: mktemp"; exit 3; }
|
|
20
|
+
trap 'rm -rf "$T"' EXIT
|
|
21
|
+
PASS=0; FAIL=0
|
|
22
|
+
|
|
23
|
+
# N days ago as a touch -t stamp (BSD date first, GNU fallback — both checked for non-empty)
|
|
24
|
+
ago() { local s; s=$(date -v-"$1"d +%Y%m%d%H%M 2>/dev/null) || s=$(date -d "$1 days ago" +%Y%m%d%H%M 2>/dev/null); [ -n "$s" ] || { echo "HARNESS-ERROR: date"; exit 3; }; echo "$s"; }
|
|
25
|
+
mk() { mkdir -p "$(dirname "$1")"; : > "$1"; touch -t "$(ago "$2")" "$1"; }
|
|
26
|
+
|
|
27
|
+
# banner SCRIPT HUB SENT → stdout+stderr, ANSI stripped. FH_DIR=CC_HUB_DIR=HUB.
|
|
28
|
+
banner() {
|
|
29
|
+
env -i PATH="$PATH" HOME="$T/fakehome" FH_DIR="$2" CC_HUB_DIR="$2" CC_SENTINELS_DIR="$3" \
|
|
30
|
+
zsh -f -c 'source "$1"; _fh_audit_check' _ "$1" 2>&1 | sed $'s/\033\\[[0-9;]*m//g'
|
|
31
|
+
}
|
|
32
|
+
ok() { PASS=$((PASS+1)); echo " PASS $1"; }
|
|
33
|
+
bad() { FAIL=$((FAIL+1)); echo " FAIL $1"; echo "$2" | sed 's/^/ | /'; }
|
|
34
|
+
has() { local o; o=$(banner "$1" "$2" "$3"); if echo "$o" | grep -qF -- "$4"; then ok "$5"; else bad "$5 (expected: $4)" "$o"; fi; }
|
|
35
|
+
hasnt() { local o; o=$(banner "$1" "$2" "$3"); if echo "$o" | grep -qF -- "$4"; then bad "$5 (unexpected: $4)" "$o"; else ok "$5"; fi; }
|
|
36
|
+
|
|
37
|
+
# bannerk: same as banner but the caller shell has KSH_ARRAYS on (as a user's own zshrc might)
|
|
38
|
+
bannerk() {
|
|
39
|
+
env -i PATH="$PATH" HOME="$T/fakehome" FH_DIR="$2" CC_HUB_DIR="$2" CC_SENTINELS_DIR="$3" \
|
|
40
|
+
zsh -f -c 'setopt KSH_ARRAYS; source "$1"; _fh_audit_check' _ "$1" 2>&1 | sed $'s/\033\\[[0-9;]*m//g'
|
|
41
|
+
}
|
|
42
|
+
hasntk() { local o; o=$(bannerk "$1" "$2" "$3"); if echo "$o" | grep -qF -- "$4"; then bad "$5 (unexpected: $4)" "$o"; else ok "$5"; fi; }
|
|
43
|
+
hub() { local h="$T/$1"; mkdir -p "$h/tracks/_meta" "$h/tracks/_audit" "$h/knowledge/shared/harness-core"; mkdir -p "$T/$1.sent"; echo "$h"; }
|
|
44
|
+
|
|
45
|
+
# ── fixtures ────────────────────────────────────────────────────────────────
|
|
46
|
+
# F1: weekly audit 2d old, no harvest_* (the operator's real shape) — nothing is overdue
|
|
47
|
+
F1=$(hub f1); mk "$F1/tracks/_audit/weekly_audit_x.md" 2; mk "$F1/tracks/_meta/frontier_digest_x.md" 1; mk "$F1/tracks/_meta/sim_x_area_B.md" 3
|
|
48
|
+
# F2: weekly audit genuinely overdue (10d)
|
|
49
|
+
F2=$(hub f2); mk "$F2/tracks/_audit/weekly_audit_x.md" 10; mk "$F2/tracks/_meta/frontier_digest_x.md" 1; mk "$F2/tracks/_meta/sim_x_area_B.md" 3
|
|
50
|
+
# F3: no weekly audit at all
|
|
51
|
+
F3=$(hub f3); mk "$F3/tracks/_meta/frontier_digest_x.md" 1; mk "$F3/tracks/_meta/sim_x_area_B.md" 3
|
|
52
|
+
# F4: Area B 40d old but a recent area_D report (2d) — old glob resets the B clock
|
|
53
|
+
F4=$(hub f4); mk "$F4/tracks/_audit/weekly_audit_x.md" 1; mk "$F4/tracks/_meta/sim_x_area_B.md" 40; mk "$F4/tracks/_meta/sim_y_area_D_split.md" 2
|
|
54
|
+
# F5: Area B 116d (the operator's real shape — a TRUE alarm)
|
|
55
|
+
F5=$(hub f5); mk "$F5/tracks/_audit/weekly_audit_x.md" 1; mk "$F5/tracks/_meta/sim_x_area_BD.md" 116
|
|
56
|
+
# F6: sentinels — 4 state markers + 1 genuine custom audit sentinel, all past 90d
|
|
57
|
+
F6=$(hub f6); S6="$T/f6.sent"; mk "$F6/tracks/_audit/weekly_audit_x.md" 1; mk "$F6/tracks/_meta/sim_x_area_B.md" 3
|
|
58
|
+
mk "$S6/projA_mapping_skipped" 100; mk "$S6/projB_wizard_done" 121; mk "$S6/projC_wizard_declined" 100
|
|
59
|
+
mk "$S6/projD_wizard_reminder_muted" 100; mk "$S6/myproj_pfd" 100
|
|
60
|
+
# F7: empty sentinels dir (zsh unmatched-glob error class)
|
|
61
|
+
F7=$(hub f7); S7="$T/f7.sent"; mk "$F7/tracks/_audit/weekly_audit_x.md" 1; mk "$F7/tracks/_meta/sim_x_area_B.md" 3
|
|
62
|
+
# F8: frontier — only an old diagnosis file (100d), a fresh digest (1d)
|
|
63
|
+
F8=$(hub f8); mk "$F8/tracks/_audit/weekly_audit_x.md" 1; mk "$F8/tracks/_meta/sim_x_area_B.md" 3
|
|
64
|
+
mk "$F8/knowledge/shared/harness-core/harness_frontier_diagnosis_x.md" 100; mk "$F8/tracks/_meta/frontier_digest_x.md" 1
|
|
65
|
+
# F10: two weekly audits — newest 1d, older 17d. Under the caller's KSH_ARRAYS a `[1]` index picks the older
|
|
66
|
+
F10=$(hub f10); mk "$F10/tracks/_audit/weekly_audit_old.md" 17; mk "$F10/tracks/_audit/weekly_audit_new.md" 1; mk "$F10/tracks/_meta/frontier_digest_x.md" 1; mk "$F10/tracks/_meta/sim_x_area_B.md" 3
|
|
67
|
+
# F9: frontier digest genuinely overdue (10d)
|
|
68
|
+
F9=$(hub f9); mk "$F9/tracks/_audit/weekly_audit_x.md" 1; mk "$F9/tracks/_meta/sim_x_area_B.md" 3; mk "$F9/tracks/_meta/frontier_digest_x.md" 10
|
|
69
|
+
|
|
70
|
+
# ORIG aborts the whole function on ANY unmatched glob (zsh NOMATCH: `ls -t …diagnosis_*.md` and
|
|
71
|
+
# `for f in dir/*` on an empty dir) — so for a fail-before to test the line it names, the other
|
|
72
|
+
# globs must match. Seed a fresh (1d) diagnosis file and a fresh custom sentinel everywhere except F7.
|
|
73
|
+
for h in f1 f2 f3 f4 f5 f6 f8 f9; do
|
|
74
|
+
[ "$h" = f8 ] || mk "$T/$h/knowledge/shared/harness-core/harness_frontier_diagnosis_seed.md" 1 # F8 keeps ONLY its 100d file
|
|
75
|
+
mk "$T/$h.sent/fresh_pfd" 1
|
|
76
|
+
done
|
|
77
|
+
# control: fixture mtimes actually landed (a dead touch would make every «silent» lane vacuous)
|
|
78
|
+
c=$(( ( $(date +%s) - $(stat -c %Y "$S6/myproj_pfd" 2>/dev/null || stat -f %m "$S6/myproj_pfd") ) / 86400 ))
|
|
79
|
+
echo "control: myproj_pfd fixture age = ${c}d (expect 100)"
|
|
80
|
+
[ "$c" -ge 99 ] && [ "$c" -le 101 ] || { echo "HARNESS-ERROR: fixture mtime did not land"; exit 3; }
|
|
81
|
+
|
|
82
|
+
run_new() {
|
|
83
|
+
local S="$1"
|
|
84
|
+
echo "── ① weekly audit"
|
|
85
|
+
hasnt "$S" "$F1" "$T/f1.sent" "harvest" "L1 fresh weekly audit, no harvest_* → no harvest line"
|
|
86
|
+
hasnt "$S" "$F1" "$T/f1.sent" "weekly_audit" "L1b fresh weekly audit → no weekly line"
|
|
87
|
+
has "$S" "$F2" "$T/f2.sent" "weekly_audit 10d" "L2 KP: weekly audit 10d → warns"
|
|
88
|
+
has "$S" "$F3" "$T/f3.sent" "No weekly audit history" "L3 KP: no weekly audit → warns (not-found ≠ zero)"
|
|
89
|
+
echo "── ② frontier digest"
|
|
90
|
+
hasnt "$S" "$F8" "$T/f8.sent" "frontier" "L8 old diagnosis file, fresh digest → silent"
|
|
91
|
+
has "$S" "$F9" "$T/f9.sent" "frontier_digest 10d" "L9 KP: digest 10d → warns"
|
|
92
|
+
echo "── ③ sim Area B"
|
|
93
|
+
has "$S" "$F4" "$T/f4.sent" "FH internal sim 40d" "L4 area_D run does not reset Area B clock"
|
|
94
|
+
has "$S" "$F5" "$T/f5.sent" "FH internal sim 116d" "L5 KP: Area B 116d → warns (true alarm kept)"
|
|
95
|
+
hasnt "$S" "$F1" "$T/f1.sent" "FH internal sim" "L5b Area B 3d → silent"
|
|
96
|
+
echo "── ④ sentinels"
|
|
97
|
+
for m in projA_mapping_skipped projB_wizard_done projC_wizard_declined projD_wizard_reminder_muted; do
|
|
98
|
+
hasnt "$S" "$F6" "$S6" "$m sentinel" "L6 state marker $m not aged"
|
|
99
|
+
done
|
|
100
|
+
has "$S" "$F6" "$S6" "myproj_pfd sentinel 100d" "L6b KP: custom audit sentinel 100d → warns"
|
|
101
|
+
hasnt "$S" "$F7" "$S7" "no matches found" "L7 empty sentinels dir → no zsh glob error"
|
|
102
|
+
hasntk "$S" "$F10" "$T/f10.sent" "weekly_audit" "L10 caller KSH_ARRAYS does not flip newest→older (emulate -L zsh)"
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
echo "=== script under test: $NEW"
|
|
106
|
+
run_new "$NEW"
|
|
107
|
+
|
|
108
|
+
if [ -n "$ORIG" ]; then
|
|
109
|
+
echo "=== fail-before against ORIG: $ORIG (each MUST reproduce the false/missed line)"
|
|
110
|
+
has "$ORIG" "$F1" "$T/f1.sent" "No harvest history found" "FB① ORIG emits unsatisfiable harvest line on fresh hub"
|
|
111
|
+
has "$ORIG" "$F8" "$T/f8.sent" "frontier_diagnosis 100d" "FB② ORIG ages a file /frontier-digest never writes"
|
|
112
|
+
hasnt "$ORIG" "$F4" "$T/f4.sent" "FH internal sim" "FB③ ORIG misses overdue Area B (area_D reset the clock)"
|
|
113
|
+
has "$ORIG" "$F6" "$S6" "projA_mapping_skipped sentinel" "FB④ ORIG ages a state marker (mapping_skipped)"
|
|
114
|
+
has "$ORIG" "$F6" "$S6" "projB_wizard_done sentinel" "FB④b ORIG ages a state marker (wizard_done)"
|
|
115
|
+
has "$ORIG" "$F7" "$S7" "no matches found" "FB⑤ ORIG raises zsh NOMATCH (empty sentinels dir / no diagnosis file) and aborts"
|
|
116
|
+
fi
|
|
117
|
+
|
|
118
|
+
# ── revert probes: undo ONE fix in a copy → apply-check → run the lane → must go RED → discard ──
|
|
119
|
+
echo "=== revert probes (each mutant must turn its lane red)"
|
|
120
|
+
probe() { # name sed-expr lane-fn
|
|
121
|
+
local m="$T/mutant_$1.zsh"
|
|
122
|
+
sed "$2" "$NEW" > "$m"
|
|
123
|
+
if cmp -s "$m" "$NEW"; then bad "RP-$1 mutant did not apply (sed matched nothing) — HARNESS-ERROR" ""; return; fi
|
|
124
|
+
local before=$FAIL; "$3" "$m" >/dev/null
|
|
125
|
+
if [ "$FAIL" -gt "$before" ]; then FAIL=$before; ok "RP-$1 revert turns lane red"; else bad "RP-$1 revert stayed GREEN — lane is decorative" ""; fi
|
|
126
|
+
rm -f "$m"
|
|
127
|
+
}
|
|
128
|
+
lane1() { hasnt "$1" "$F1" "$T/f1.sent" "weekly audit history" "L1-probe"; }
|
|
129
|
+
lane2() { hasnt "$1" "$F8" "$T/f8.sent" "frontier" "L8-probe"; has "$1" "$F9" "$T/f9.sent" "frontier_digest 10d" "L9-probe"; }
|
|
130
|
+
lane3() { has "$1" "$F4" "$T/f4.sent" "FH internal sim 40d" "L4-probe"; }
|
|
131
|
+
lane4() { hasnt "$1" "$F6" "$S6" "projA_mapping_skipped sentinel" "L6-probe"; }
|
|
132
|
+
probe weekly 's#tracks/_audit"/weekly_audit_\*\.md#tracks/_audit"/harvest_*.md#' lane1
|
|
133
|
+
probe frontier 's#tracks/_meta"/frontier_digest_\*\.md#knowledge/shared/harness-core"/harness_frontier_diagnosis_*.md#' lane2
|
|
134
|
+
probe sim 's#sim_\*_area_B\*\.md#sim_*.md#' lane3
|
|
135
|
+
probe sentinel '/\*_wizard_done|\*_mapping_skipped/d' lane4
|
|
136
|
+
lane5() { hasntk "$1" "$F10" "$T/f10.sent" "weekly_audit" "L10-probe"; }
|
|
137
|
+
probe emulate '/^ emulate -L zsh$/d' lane5
|
|
138
|
+
|
|
139
|
+
echo "=== RESULT: PASS=$PASS FAIL=$FAIL"
|
|
140
|
+
[ "$FAIL" -eq 0 ]
|
|
@@ -35,7 +35,7 @@ trap 'stop_stub' EXIT
|
|
|
35
35
|
# The stub is written to a file so the heredoc cannot collide with the lane script's own quoting.
|
|
36
36
|
STUB="$(mktemp -d)/stub.py"
|
|
37
37
|
cat > "$STUB" <<'PY'
|
|
38
|
-
import json, sys
|
|
38
|
+
import json, sys, time
|
|
39
39
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
40
40
|
PORT = int(sys.argv[1]); MODE = sys.argv[2]
|
|
41
41
|
|
|
@@ -46,8 +46,17 @@ class H(BaseHTTPRequestHandler):
|
|
|
46
46
|
self.send_response(code); self.send_header("Content-Type", "application/json")
|
|
47
47
|
self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b)
|
|
48
48
|
def do_GET(self):
|
|
49
|
-
if self.path == "/api/version":
|
|
50
|
-
|
|
49
|
+
if self.path == "/api/version":
|
|
50
|
+
if MODE == "notollama": self._send({"error": "not found"}, 404); return
|
|
51
|
+
if MODE == "fake200": # answers 200 to everything, but is not Ollama
|
|
52
|
+
b = b"<html>ok</html>"
|
|
53
|
+
self.send_response(200); self.send_header("Content-Type", "text/html")
|
|
54
|
+
self.send_header("Content-Length", str(len(b))); self.end_headers(); self.wfile.write(b); return
|
|
55
|
+
self._send({"version": "stub"})
|
|
56
|
+
elif self.path == "/api/tags":
|
|
57
|
+
if MODE == "tags500": self._send({"error": "listing failed"}, 500); return
|
|
58
|
+
if MODE == "tagsdrop": self.close_connection = True; return
|
|
59
|
+
self._send({"models": [{"name": "stub-model:1b"}]})
|
|
51
60
|
else: self._send({}, 404)
|
|
52
61
|
def do_POST(self):
|
|
53
62
|
n = int(self.headers.get("Content-Length", 0))
|
|
@@ -57,8 +66,26 @@ class H(BaseHTTPRequestHandler):
|
|
|
57
66
|
# BOGUS control. 'accept' mode is the dangerous server: it serves SOMETHING for a name
|
|
58
67
|
# that cannot exist, so the pin is never validated at all.
|
|
59
68
|
if MODE == "accept": self._send({"model": m, "response": "PASS"})
|
|
69
|
+
elif MODE == "ctl500": self._send({"error": "llama runner crashed"}, 500)
|
|
60
70
|
else: self._send({"error": f"model '{m}' not found"})
|
|
61
71
|
return
|
|
72
|
+
# Real Ollama refuses with a 4xx + {"error": ...}. The G1 incident (2026-09-24) was exactly
|
|
73
|
+
# these two bodies rendered as UNREACHABLE because `curl -sf` threw them away.
|
|
74
|
+
if MODE == "notfound":
|
|
75
|
+
self._send({"error": f"model '{m}' not found"}, 404); return
|
|
76
|
+
if MODE == "invalid":
|
|
77
|
+
self._send({"error": "invalid model name"}, 400); return
|
|
78
|
+
if MODE == "srv500":
|
|
79
|
+
self._send({"error": "llama runner process has terminated"}, 500); return
|
|
80
|
+
if MODE == "drop": # no HTTP answer at all -> curl http_code 000 (empty reply)
|
|
81
|
+
self.close_connection = True; return
|
|
82
|
+
if MODE == "fake200": # echoes the pin — would be PIN-OK if the host were trusted
|
|
83
|
+
self._send({"model": m, "response": "PASS"}); return
|
|
84
|
+
if MODE == "stall": # full-looking JSON, but Content-Length promises more; then hang
|
|
85
|
+
b = json.dumps({"model": m, "response": "PASS"}).encode()
|
|
86
|
+
self.send_response(200); self.send_header("Content-Type", "application/json")
|
|
87
|
+
self.send_header("Content-Length", str(len(b) + 64)); self.end_headers()
|
|
88
|
+
self.wfile.write(b); self.wfile.flush(); time.sleep(6); return
|
|
62
89
|
if MODE == "substitute": # the agy failure, in this protocol
|
|
63
90
|
self._send({"model": "some-other-model:9b", "response": "PASS"}); return
|
|
64
91
|
if MODE == "starved": # reasoning model spent the whole budget thinking
|
|
@@ -74,24 +101,31 @@ start_stub() {
|
|
|
74
101
|
python3 "$STUB" "$PORT" "$1" >/dev/null 2>&1 &
|
|
75
102
|
SRV_PID=$!
|
|
76
103
|
for _ in $(seq 1 40); do
|
|
77
|
-
|
|
104
|
+
# Ready = ANY HTTP answer, not a 2xx: the notollama mode answers /api/version with a 404 on
|
|
105
|
+
# purpose, and `-f` would read that as "stub never came up".
|
|
106
|
+
_c="$(curl -s -o /dev/null --max-time 1 -w '%{http_code}' "http://127.0.0.1:$PORT/api/version" 2>/dev/null)"
|
|
107
|
+
[ "${_c:-000}" != "000" ] && return 0
|
|
78
108
|
sleep 0.25
|
|
79
109
|
done
|
|
80
110
|
return 1
|
|
81
111
|
}
|
|
82
112
|
|
|
83
|
-
# expect <label> <mode> <expect-in-panel: YES|NO> [needle]
|
|
113
|
+
# expect <label> <mode> <expect-in-panel: YES|NO> [needle] [forbid]
|
|
114
|
+
# forbid — a string that must NOT appear. A needle alone passes when the right label AND the wrong
|
|
115
|
+
# one are both printed; the G1 lanes need "MODEL-ERROR and NOT UNREACHABLE", not just the former.
|
|
116
|
+
# MODELS (env) overrides FH_OLLAMA_MODELS for the input-contract lanes; unset = the usual pin.
|
|
84
117
|
expect() {
|
|
85
|
-
local label="$1" mode="$2" want="$3" needle="${4:-}" out inpanel
|
|
118
|
+
local label="$1" mode="$2" want="$3" needle="${4:-}" forbid="${5:-}" out inpanel forbidden=0
|
|
86
119
|
start_stub "$mode" || { printf ' ❌ %-44s stub failed to start\n' "$label"; fail=$((fail+1)); return; }
|
|
87
|
-
out=$( FH_OLLAMA_HOST="http://127.0.0.1:$PORT" FH_OLLAMA_MODELS="stub-model:1b" \
|
|
88
|
-
bash "$CAL" --only ollama --quiet 2>&1 )
|
|
120
|
+
out=$( FH_OLLAMA_HOST="http://127.0.0.1:$PORT" FH_OLLAMA_MODELS="${MODELS-stub-model:1b}" \
|
|
121
|
+
FH_OLLAMA_GEN_TIMEOUT="${GEN_TIMEOUT:-240}" bash "$CAL" --only ollama --quiet 2>&1 )
|
|
89
122
|
stop_stub
|
|
90
123
|
if printf '%s' "$out" | grep -q 'PANEL:.*ollama:stub-model:1b'; then inpanel=YES; else inpanel=NO; fi
|
|
91
|
-
if [
|
|
124
|
+
if [ -n "$forbid" ]; then case "$out" in *"$forbid"*) forbidden=1 ;; esac; fi
|
|
125
|
+
if [ "$inpanel" = "$want" ] && [ "$forbidden" -eq 0 ] && { [ -z "$needle" ] || printf '%s' "$out" | grep -q "$needle"; }; then
|
|
92
126
|
printf ' ✅ %-44s in-panel=%s\n' "$label" "$inpanel"; pass=$((pass+1))
|
|
93
127
|
else
|
|
94
|
-
printf ' ❌ %-44s in-panel=%s (expected %s%s)\n' "$label" "$inpanel" "$want" "${needle:+, needle '$needle'}"
|
|
128
|
+
printf ' ❌ %-44s in-panel=%s (expected %s%s%s)\n' "$label" "$inpanel" "$want" "${needle:+, needle '$needle'}" "${forbid:+, forbid '$forbid'}"
|
|
95
129
|
printf ' out: %s\n' "$(printf '%s' "$out" | head -4)"; fail=$((fail+1))
|
|
96
130
|
fi
|
|
97
131
|
}
|
|
@@ -103,6 +137,31 @@ expect "S3 empty answer (budget starvation)" starved NO "larger FH_OLLAM
|
|
|
103
137
|
expect "S4 prose answer cannot carry a verdict" prose NO "VERDICT-UNPARSEABLE"
|
|
104
138
|
expect "S5 server accepts a bogus model name" accept YES "accepts-bogus"
|
|
105
139
|
|
|
140
|
+
# ── G1 (2026-09-24): a server that ANSWERS with a refusal is not an unreachable server ─────────
|
|
141
|
+
# The known-positive for UNREACHABLE is S7 (no HTTP answer); the known-negatives are S8/S9 (a real
|
|
142
|
+
# 4xx body). Reverting `_http` to `curl -sf` turns S8/S9 red and leaves S7 green — the revert probe.
|
|
143
|
+
expect "S7 no HTTP answer (connection dropped)" drop NO "UNREACHABLE-THIS-RUN" "MODEL-ERROR"
|
|
144
|
+
expect "S8 404 model not found → MODEL-ERROR" notfound NO "MODEL-ERROR(model 'stub-model:1b' not found)" "UNREACHABLE"
|
|
145
|
+
expect "S9 400 invalid model name → MODEL-ERROR" invalid NO "MODEL-ERROR(invalid model name)" "UNREACHABLE"
|
|
146
|
+
expect "S10 500 from server → SERVER-ERROR" srv500 NO "SERVER-ERROR(http 500" "UNREACHABLE"
|
|
147
|
+
expect "S11 non-Ollama host → HOST-ERROR" notollama NO "HOST-ERROR" "ABSENT"
|
|
148
|
+
MODELS="" expect "S12 /api/tags 500 ≠ empty listing" tags500 NO "model list UNMEASURED" "no models listed"
|
|
149
|
+
|
|
150
|
+
# ── cross-family review 2026-09-26: four more places where a non-answer read as an answer ──────
|
|
151
|
+
expect "S15 any-200 host is not Ollama → HOST-ERROR" fake200 NO "not the Ollama shape" "PIN-OK"
|
|
152
|
+
expect "S16 control 5xx is not rejection" ctl500 YES "control: unmeasured" "rejects-bogus"
|
|
153
|
+
MODELS="" expect "S17 tags 000 does not claim REACHABLE" tagsdrop NO "model list UNMEASURED (tags call got no HTTP answer" "REACHABLE"
|
|
154
|
+
GEN_TIMEOUT=2 \
|
|
155
|
+
expect "S18 200 then mid-body stall → UNMEASURED" stall NO "UNMEASURED-THIS-RUN (http 200" "PIN-OK"
|
|
156
|
+
MODELS=" , " \
|
|
157
|
+
expect "S19 explicit-but-empty list → INPUT-ERROR" ok NO "no model names after trimming" "PIN-OK"
|
|
158
|
+
|
|
159
|
+
# ── FH_OLLAMA_MODELS contract: comma-separated. Inner whitespace is rejected, not guessed. ─────
|
|
160
|
+
MODELS="stub-model:1b other:2b" \
|
|
161
|
+
expect "S13 space-separated list → INPUT-ERROR" ok NO "did you mean: FH_OLLAMA_MODELS=\"stub-model:1b,other:2b\"" "UNREACHABLE"
|
|
162
|
+
MODELS=" stub-model:1b , " \
|
|
163
|
+
expect "S14 padding around commas is trimmed" ok YES "PIN-OK(envelope)" "INPUT-ERROR"
|
|
164
|
+
|
|
106
165
|
# S6 — absence must be MEASURED, never assumed. No server at the host at all.
|
|
107
166
|
out=$( FH_OLLAMA_HOST="http://127.0.0.1:$((PORT+7))" bash "$CAL" --only ollama --quiet 2>&1 )
|
|
108
167
|
if printf '%s' "$out" | grep -q 'ABSENT — no server at the configured host'; then
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# test_session_load_mirror_fp_lanes.sh — lanes for fh_session_load.sh §3 «NEWER THAN SESSION CARD».
|
|
3
|
+
#
|
|
4
|
+
# Defect (measured 2026-09-26): sync-to-be.sh rewrites every tracks/_meta mirror it touches, so a
|
|
5
|
+
# mirror's mtime is «when the sync ran», not «when its content was new». Two result files the card
|
|
6
|
+
# had already absorbed were listed under «READ THESE BEFORE ACTING». The fix demotes a $TM mirror
|
|
7
|
+
# whose line 1 is EXACTLY the sync banner, whose remaining bytes equal the hub canonical copy, AND
|
|
8
|
+
# whose content the companion git committed at/before the card (clean tree).
|
|
9
|
+
#
|
|
10
|
+
# The lanes are a known pair plus the fail-open guards: the FP (L1) must stay quiet, and every
|
|
11
|
+
# case that is NOT provably old-and-identical (L2–L6, L8–L11) must still be listed. L0 is the instrument
|
|
12
|
+
# control — the hook actually reached the freshness block — so a script that dies early cannot
|
|
13
|
+
# pass L1 by printing nothing.
|
|
14
|
+
set -uo pipefail
|
|
15
|
+
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
16
|
+
SUBJECT="$HERE/fh_session_load.sh"
|
|
17
|
+
[ -f "$SUBJECT" ] || { echo "HARNESS-ERROR subject missing: $SUBJECT"; exit 2; }
|
|
18
|
+
|
|
19
|
+
T="$(mktemp -d "${TMPDIR:-/tmp}/fhsl_mirror.XXXXXX")" || { echo "HARNESS-ERROR mktemp"; exit 2; }
|
|
20
|
+
trap 'rm -rf "$T"' EXIT
|
|
21
|
+
HUB="$T/hub"; BE="$T/be"
|
|
22
|
+
mkdir -p "$HUB/tracks/_meta/sub" "$BE/tracks-meta/sub" "$BE/handoff"
|
|
23
|
+
git -C "$BE" init -q 2>/dev/null || { echo "HARNESS-ERROR git init"; exit 2; }
|
|
24
|
+
|
|
25
|
+
BANNER='<!-- MIRROR COPY — synced from the forge-harness hub. Do NOT edit here; the next sync overwrites it. Edit the canonical file under the hub instead. -->'
|
|
26
|
+
mirror() { { printf '%s\n' "$BANNER"; cat "$1"; } > "$2"; } # $1 = hub file, $2 = mirror path
|
|
27
|
+
|
|
28
|
+
echo card > "$HUB/tracks/_meta/reference_next_session_starter.md"
|
|
29
|
+
touch -t 202601010000 "$HUB/tracks/_meta/reference_next_session_starter.md" # card = old
|
|
30
|
+
|
|
31
|
+
# L1 FP: identical mirror, restamped by sync (mtime newer than card)
|
|
32
|
+
printf 'result body\nline2\n' > "$HUB/tracks/_meta/same.md"
|
|
33
|
+
mirror "$HUB/tracks/_meta/same.md" "$BE/tracks-meta/same.md"
|
|
34
|
+
printf 'nested\n' > "$HUB/tracks/_meta/sub/nested_same.md"
|
|
35
|
+
mirror "$HUB/tracks/_meta/sub/nested_same.md" "$BE/tracks-meta/sub/nested_same.md"
|
|
36
|
+
# L2 known-positive: genuine non-mirror file, newer
|
|
37
|
+
printf 'genuinely new\n' > "$BE/tracks-meta/genuine.md"
|
|
38
|
+
# L3 mirror whose content differs from the hub copy
|
|
39
|
+
printf 'hub version\n' > "$HUB/tracks/_meta/differs.md"
|
|
40
|
+
{ printf '%s\n' "$BANNER"; printf 'remote version\n'; } > "$BE/tracks-meta/differs.md"
|
|
41
|
+
# L4 mirror whose hub canonical is absent (arrived from another machine)
|
|
42
|
+
{ printf '%s\n' "$BANNER"; printf 'only remote\n'; } > "$BE/tracks-meta/nohub.md"
|
|
43
|
+
# L5 line 1 merely MENTIONS the phrase — not the exact banner; rest identical to a hub file
|
|
44
|
+
printf 'body\n' > "$HUB/tracks/_meta/lookalike.md"
|
|
45
|
+
{ printf 'notes on MIRROR COPY handling\n'; cat "$HUB/tracks/_meta/lookalike.md"; } > "$BE/tracks-meta/lookalike.md"
|
|
46
|
+
# L6 outside $TM: a bannered identical file under handoff/ is NOT demoted
|
|
47
|
+
printf 'handoff body\n' > "$HUB/tracks/_meta/ho.md"
|
|
48
|
+
mirror "$HUB/tracks/_meta/ho.md" "$BE/handoff/ho.md"
|
|
49
|
+
# L7 identical mirror OLDER than the card: neither listed nor noted
|
|
50
|
+
printf 'old\n' > "$HUB/tracks/_meta/old_same.md"
|
|
51
|
+
mirror "$HUB/tracks/_meta/old_same.md" "$BE/tracks-meta/old_same.md"
|
|
52
|
+
touch -t 202512010000 "$BE/tracks-meta/old_same.md"
|
|
53
|
+
|
|
54
|
+
# L8 cross-family [high]: identical mirror, but first committed AFTER the card (written today)
|
|
55
|
+
printf 'todays result\n' > "$HUB/tracks/_meta/new_today.md"
|
|
56
|
+
mirror "$HUB/tracks/_meta/new_today.md" "$BE/tracks-meta/new_today.md"
|
|
57
|
+
# L9 identical mirror whose committed version is OLD but the tree is dirty (new content, unsynced commit)
|
|
58
|
+
printf 'v1\n' > "$HUB/tracks/_meta/dirty.md"; mirror "$HUB/tracks/_meta/dirty.md" "$BE/tracks-meta/dirty.md"
|
|
59
|
+
# L10 identical mirror never committed (untracked)
|
|
60
|
+
printf 'untracked\n' > "$HUB/tracks/_meta/untracked.md"
|
|
61
|
+
|
|
62
|
+
G() { git -C "$BE" -c user.name=t -c user.email=t@t "$@"; }
|
|
63
|
+
OLD='2025-12-15T00:00:00' # before the card (2026-01-01)
|
|
64
|
+
G add tracks-meta/same.md tracks-meta/sub/nested_same.md tracks-meta/old_same.md tracks-meta/dirty.md \
|
|
65
|
+
tracks-meta/genuine.md tracks-meta/differs.md tracks-meta/nohub.md tracks-meta/lookalike.md handoff/ho.md >/dev/null
|
|
66
|
+
GIT_AUTHOR_DATE="$OLD" GIT_COMMITTER_DATE="$OLD" G commit -qm old >/dev/null || { echo "HARNESS-ERROR commit old"; exit 2; }
|
|
67
|
+
G add tracks-meta/new_today.md >/dev/null; G commit -qm today >/dev/null || { echo "HARNESS-ERROR commit today"; exit 2; }
|
|
68
|
+
printf 'v2\n' > "$HUB/tracks/_meta/dirty.md"; mirror "$HUB/tracks/_meta/dirty.md" "$BE/tracks-meta/dirty.md"
|
|
69
|
+
mirror "$HUB/tracks/_meta/untracked.md" "$BE/tracks-meta/untracked.md"
|
|
70
|
+
touch "$BE/tracks-meta/same.md" "$BE/tracks-meta/sub/nested_same.md" # the sync restamp
|
|
71
|
+
touch -t 202512010000 "$BE/tracks-meta/old_same.md" # re-assert L7 (older than card)
|
|
72
|
+
|
|
73
|
+
OUT="$(printf '{"source":"startup"}' | HUB_DIR="$HUB" BE_DIR="$BE" bash "$SUBJECT" 2>&1)"
|
|
74
|
+
# The NEWER list = the « - » lines right after the header.
|
|
75
|
+
LIST="$(printf '%s\n' "$OUT" | awk '/NEWER THAN SESSION CARD/{on=1;next} on&&/^ - /{print;next} on{exit}')"
|
|
76
|
+
NOTE="$(printf '%s\n' "$OUT" | /usr/bin/grep -A1 'mirror cop(y/ies) newer than the card' || true)"
|
|
77
|
+
|
|
78
|
+
pass=0; fail=0
|
|
79
|
+
ok() { echo "PASS $1"; pass=$((pass+1)); }
|
|
80
|
+
bad() { echo "FAIL $1"; fail=$((fail+1)); }
|
|
81
|
+
# Substring tests use `case`, not `printf | grep -q`: under pipefail an early-exiting grep can
|
|
82
|
+
# SIGPIPE the printf and flip the verdict (pipefail class-lock lane L12c).
|
|
83
|
+
has() { case "$1" in *"$2"*) return 0 ;; esac; return 1; }
|
|
84
|
+
listed() { has "$LIST" "- $1"; }
|
|
85
|
+
|
|
86
|
+
has "$OUT" 'NEWER THAN SESSION CARD' \
|
|
87
|
+
&& ok "L0 control — hook reached the NEWER block" \
|
|
88
|
+
|| { bad "L0 control — NEWER block never printed (instrument dead)"; printf '%s\n' "$OUT" | tail -15; }
|
|
89
|
+
|
|
90
|
+
listed "tracks-meta/same.md" && bad "L1 FP — identical mirror listed as NEWER" || ok "L1 FP — identical mirror not listed"
|
|
91
|
+
listed "tracks-meta/sub/nested_same.md" && bad "L1b FP — nested identical mirror listed" || ok "L1b FP — nested identical mirror not listed"
|
|
92
|
+
has "$NOTE" 'same.md' && has "$NOTE" ' ⓘ 2 ' \
|
|
93
|
+
&& ok "L1c demoted mirrors are NAMED in the note (not silently dropped), count=2" \
|
|
94
|
+
|| bad "L1c demoted mirrors missing from the note: [$NOTE]"
|
|
95
|
+
listed "tracks-meta/genuine.md" && ok "L2 known-positive — genuine newer file listed" || bad "L2 genuine newer file NOT listed (fail-open)"
|
|
96
|
+
listed "tracks-meta/differs.md" && ok "L3 differing mirror listed" || bad "L3 differing mirror NOT listed (fail-open)"
|
|
97
|
+
listed "tracks-meta/nohub.md" && ok "L4 mirror with no hub copy listed" || bad "L4 mirror with no hub copy NOT listed (fail-open)"
|
|
98
|
+
listed "tracks-meta/lookalike.md" && ok "L5 non-exact banner listed" || bad "L5 non-exact banner NOT listed (substring match = fail-open)"
|
|
99
|
+
listed "handoff/ho.md" && ok "L6 bannered file outside \$TM listed" || bad "L6 outside-\$TM file demoted"
|
|
100
|
+
{ listed "tracks-meta/old_same.md" || has "$NOTE" 'old_same'; } \
|
|
101
|
+
&& bad "L7 older-than-card mirror surfaced" || ok "L7 older-than-card mirror stays quiet"
|
|
102
|
+
|
|
103
|
+
listed "tracks-meta/new_today.md" && ok "L8 identical mirror committed AFTER the card listed" || bad "L8 today's identical mirror hidden (fail-open — cross-family [high])"
|
|
104
|
+
listed "tracks-meta/dirty.md" && ok "L9 identical-but-dirty mirror listed" || bad "L9 dirty mirror hidden (fail-open)"
|
|
105
|
+
listed "tracks-meta/untracked.md" && ok "L10 identical-but-untracked mirror listed" || bad "L10 untracked mirror hidden (fail-open)"
|
|
106
|
+
|
|
107
|
+
# L11 git unavailable → demotion OFF (mirror listed) AND the output says so — never silently.
|
|
108
|
+
NOGIT="$T/nogit"; mkdir -p "$NOGIT"
|
|
109
|
+
for x in /bin/* /usr/bin/*; do
|
|
110
|
+
b="${x##*/}"; [ "$b" = git ] && continue; [ -e "$NOGIT/$b" ] || ln -s "$x" "$NOGIT/$b" 2>/dev/null
|
|
111
|
+
done
|
|
112
|
+
OUT2="$(printf '{"source":"startup"}' | PATH="$NOGIT" HUB_DIR="$HUB" BE_DIR="$BE" /bin/bash "$SUBJECT" 2>&1)"
|
|
113
|
+
LIST2="$(printf '%s\n' "$OUT2" | awk '/NEWER THAN SESSION CARD/{on=1;next} on&&/^ - /{print;next} on{exit}')"
|
|
114
|
+
if has "$LIST2" "- tracks-meta/same.md" \
|
|
115
|
+
&& has "$OUT2" 'git unavailable — mirror-copy demotion is OFF'; then
|
|
116
|
+
ok "L11 git unavailable → mirror listed + stated"
|
|
117
|
+
else
|
|
118
|
+
bad "L11 git unavailable → silent or demoted"; printf '%s\n' "$OUT2" | tail -8
|
|
119
|
+
fi
|
|
120
|
+
|
|
121
|
+
echo "── mirror-FP lanes: pass=$pass fail=$fail"
|
|
122
|
+
[ "$fail" -eq 0 ]
|