checkwright 0.24.0 → 0.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.
- package/README.md +3 -3
- package/package.json +2 -2
- package/payload/artifact/x86_64-unknown-linux-gnu/checkwright-gates +0 -0
- package/payload/artifact/x86_64-unknown-linux-gnu/checkwright-gates.sha256 +1 -1
- package/payload/canon-kit/README.md +2 -0
- package/payload/canon-kit/SPEC.md +329 -15
- package/payload/canon-kit/checks/check-amendment-update-target.gate +3 -0
- package/payload/canon-kit/checks/check-unmarked-claim.gate +3 -0
- package/payload/canon-kit/gate-tests/check-amendment-update-target/bad/SPEC-thing.md +26 -0
- package/payload/canon-kit/gate-tests/check-amendment-update-target/bad/expect.txt +8 -0
- package/payload/canon-kit/gate-tests/check-amendment-update-target/good/SPEC-widget.md +47 -0
- package/payload/canon-kit/gate-tests/check-amendment-update-target/good/expect.txt +1 -0
- package/payload/canon-kit/gate-tests/check-amendment-update-target.test.sh +82 -0
- package/payload/canon-kit/gate-tests/check-unmarked-claim/bad/SPEC.md +11 -0
- package/payload/canon-kit/gate-tests/check-unmarked-claim/bad/expect.txt +3 -0
- package/payload/canon-kit/gate-tests/check-unmarked-claim/bad/scripts/canon-config.sh +6 -0
- package/payload/canon-kit/gate-tests/check-unmarked-claim/good/SPEC.md +18 -0
- package/payload/canon-kit/gate-tests/check-unmarked-claim/good/expect.txt +1 -0
- package/payload/canon-kit/gate-tests/check-unmarked-claim/good/scripts/canon-config.sh +6 -0
- package/payload/canon-kit/gate-tests/check-unmarked-claim.test.sh +85 -0
- package/payload/canon-kit/lib/spec.sh +16 -0
- package/payload/canon-kit/smoke/install.sh +2 -0
- package/payload/canon-kit/templates/SPEC-amendment.md +17 -2
- package/payload/context-kit/SPEC.md +16 -5
- package/payload/delegation-kit/README.md +11 -1
- package/payload/delegation-kit/SPEC.md +392 -26
- package/payload/delegation-kit/bin/wait-probe.sh +184 -0
- package/payload/delegation-kit/gate-tests/subagent-stop-liveness.test.sh +99 -0
- package/payload/delegation-kit/smoke/install.sh +20 -0
- package/payload/delegation-kit/templates/agent-execution.md +26 -9
- package/payload/delegation-kit/templates/subagent-stop-liveness.sh +56 -0
- package/payload/gate-sdk/README.md +7 -2
- package/payload/gate-sdk/SPEC.md +800 -66
- package/payload/gate-sdk/bin/build-native.sh +66 -1
- package/payload/gate-sdk/bin/run-gates.sh +136 -34
- package/payload/gate-sdk/checks/check-action-run-shell.sh +1 -1
- package/payload/gate-sdk/checks/check-gate-assertions.gate +3 -0
- package/payload/gate-sdk/checks/check-gate-substrate-parity.sh +55 -2
- package/payload/gate-sdk/checks/check-tree-terms.gate +3 -0
- package/payload/gate-sdk/gate-tests/check-gate-assertions/bad/expect.txt +5 -1
- package/payload/gate-sdk/gate-tests/check-gate-assertions/bad/scripts/SPEC.md +22 -0
- package/payload/gate-sdk/gate-tests/check-gate-assertions/bad/scripts/check-count.sh +11 -0
- package/payload/gate-sdk/gate-tests/check-gate-assertions/bad/scripts/check-extra.sh +14 -0
- package/payload/gate-sdk/gate-tests/check-gate-assertions/bad/scripts/check-zero.sh +7 -0
- package/payload/gate-sdk/gate-tests/check-gate-assertions/good/expect.txt +1 -1
- package/payload/gate-sdk/gate-tests/check-gate-assertions/good/scripts/SPEC.md +27 -0
- package/payload/gate-sdk/gate-tests/check-gate-assertions/good/scripts/check-qux.sh +13 -0
- package/payload/gate-sdk/gate-tests/check-gate-assertions.test.sh +117 -0
- package/payload/gate-sdk/gate-tests/check-gate-substrate-parity/bad/expect.txt +2 -0
- package/payload/gate-sdk/gate-tests/check-gate-substrate-parity/bad/kit-spec.md +6 -0
- package/payload/gate-sdk/gate-tests/check-gate-substrate-parity/bad/scripts/check-nospec.sh +4 -0
- package/payload/gate-sdk/gate-tests/check-gate-substrate-parity/bad/scripts/check-ungrounded.sh +5 -0
- package/payload/gate-sdk/gate-tests/check-gate-substrate-parity/bad/scripts/gates.list +2 -0
- package/payload/gate-sdk/gate-tests/check-gate-substrate-parity/good/expect.txt +1 -1
- package/payload/gate-sdk/gate-tests/check-gate-substrate-parity/good/kit-spec.md +12 -0
- package/payload/gate-sdk/gate-tests/check-gate-substrate-parity/good/scripts/check-held.sh +1 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/bad/expect.txt +5 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/bad/tree/multi.txt +4 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/bad/tree/second-leak.txt +2 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/expect.txt +1 -1
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/patterns.list +3 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/tree/anchored.txt +4 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/tree/msg-patterns.list +2 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/tree/msg-patterns.local.list +3 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/tree/worktrees/vendored-note.txt +3 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms.test.sh +94 -0
- package/payload/gate-sdk/smoke/install.sh +23 -0
- package/payload/guard-kit/README.md +4 -3
- package/payload/guard-kit/SPEC.md +409 -57
- package/payload/guard-kit/bin/compare-settings-allow.sh +36 -12
- package/payload/guard-kit/bin/run-guard-tests.sh +22 -4
- package/payload/guard-kit/gate-tests/compare-settings-allow.test.sh +46 -1
- package/payload/guard-kit/guard-tests/background-cases.tsv +14 -0
- package/payload/guard-kit/guard-tests/cases.tsv +41 -11
- package/payload/guard-kit/lib/guard.sh +213 -34
- package/payload/guard-kit/templates/bash-guard.sh +2 -0
- package/payload/guard-kit/templates/close-triage.md +10 -3
- package/payload/guard-kit/templates/guard-config.sh +3 -0
- package/payload/lifecycle-kit/SPEC.md +2 -2
- package/payload/lifecycle-kit/templates/lead.md +8 -0
- package/payload/queue-kit/SPEC.md +78 -0
- package/payload/site-kit/SPEC.md +12 -0
- package/payload/gate-sdk/checks/check-gate-assertions.sh +0 -149
- package/payload/gate-sdk/checks/check-tree-terms.sh +0 -67
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spec: delegation-kit/SPEC.md §bin/wait-probe — the instrument, its trial grammar, its closed cause list and its honest limit
|
|
3
|
+
# usage: wait-probe.sh <subcommand> [args] ('-h' or '--help' prints the subcommand roster; exit 2 on misuse)
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
|
|
6
|
+
SCRATCH="${GATE_SDK_TMP_DIR:-.tmp}"
|
|
7
|
+
WORK="$SCRATCH/wait-probe"
|
|
8
|
+
EVIDENCE="${GATE_SDK_WORKFLOW_DIR:-.workflow}/wait-primitive-evidence.txt"
|
|
9
|
+
SWEEP_MS=(10000 100000 200000)
|
|
10
|
+
|
|
11
|
+
usage() {
|
|
12
|
+
cat <<'EOF'
|
|
13
|
+
usage: wait-probe.sh <subcommand> [args]
|
|
14
|
+
|
|
15
|
+
produce <key> <duration_ms> stand a producer up: sleep <duration_ms>, then write the marker.
|
|
16
|
+
Records its pid at launch in <scratch>/<key>.run.
|
|
17
|
+
waiter <key> <form> the wait body itself: until <marker>; do sleep 1; done.
|
|
18
|
+
Identical across every form; whoever arms it names the form.
|
|
19
|
+
arm-local <key> arm `waiter` as a detached shell child (the harness-uninvolved control).
|
|
20
|
+
record <key> <form> <ms> append one trial line for an armed-and-finished waiter.
|
|
21
|
+
report classify the recorded trials and print the verdict.
|
|
22
|
+
sweep the self-contained local run: produce + arm-local + record over the
|
|
23
|
+
declared duration sweep. This is the reproducer a second machine runs.
|
|
24
|
+
|
|
25
|
+
Scratch resolves through GATE_SDK_TMP_DIR; the evidence file through GATE_SDK_WORKFLOW_DIR.
|
|
26
|
+
EOF
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
now_ms() {
|
|
30
|
+
local t
|
|
31
|
+
t="$(date +%s%3N)"
|
|
32
|
+
case "$t" in
|
|
33
|
+
*[!0-9]*) t="$(date +%s)000" ;;
|
|
34
|
+
esac
|
|
35
|
+
printf '%s\n' "$t"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# spec: delegation-kit/SPEC.md §bin/wait-probe — the producer's own pid is recorded at launch and never logged in a trial line
|
|
39
|
+
cmd_produce() {
|
|
40
|
+
local key="$1" ms="$2" pid
|
|
41
|
+
mkdir -p "$WORK"
|
|
42
|
+
rm -f "$WORK/$key.marker" "$WORK/$key.t0" "$SCRATCH/$key.run"
|
|
43
|
+
now_ms > "$WORK/$key.t0"
|
|
44
|
+
nohup bash -c 'sleep "$(( $2 / 1000 ))"; date +%s%3N > "$1"' _ "$WORK/$key.marker" "$ms" \
|
|
45
|
+
>/dev/null 2>&1 &
|
|
46
|
+
pid=$!
|
|
47
|
+
printf 'pid=%s run=%s\n' "$pid" "$key" > "$SCRATCH/$key.run"
|
|
48
|
+
printf 'wait-probe: producer %s pid=%s duration_ms=%s marker=%s\n' "$key" "$pid" "$ms" "$WORK/$key.marker"
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
# spec: delegation-kit/SPEC.md §bin/wait-probe — one wait body for every form, so no form's result rests on a differently-shaped trial
|
|
52
|
+
cmd_waiter() {
|
|
53
|
+
local key="$1" form="$2" pred="${3:-marker}"
|
|
54
|
+
local marker="$WORK/$key.marker" hb="$WORK/$key.$form.hb"
|
|
55
|
+
local t0 ppid_rec alive
|
|
56
|
+
WAITER_ST="$WORK/$key.$form.st"
|
|
57
|
+
t0="$(cat "$WORK/$key.t0")"
|
|
58
|
+
ppid_rec="$(sed -n 's/^pid=\([0-9]*\) .*/\1/p' "$SCRATCH/$key.run")"
|
|
59
|
+
printf '%s\n' "$pred" > "$WORK/$key.$form.pred"
|
|
60
|
+
: > "$hb"
|
|
61
|
+
rm -f "$WAITER_ST"
|
|
62
|
+
trap 'printf "%s\n" "$?" > "$WAITER_ST"' EXIT
|
|
63
|
+
trap 'exit 143' TERM
|
|
64
|
+
trap 'exit 130' INT
|
|
65
|
+
trap 'exit 129' HUP
|
|
66
|
+
if [ "$pred" = liveness ]; then
|
|
67
|
+
until kill -0 "$ppid_rec" 2>/dev/null; do
|
|
68
|
+
waiter_beat "$t0" "$ppid_rec" "$hb"
|
|
69
|
+
sleep 1
|
|
70
|
+
done
|
|
71
|
+
else
|
|
72
|
+
until [ -f "$marker" ]; do
|
|
73
|
+
waiter_beat "$t0" "$ppid_rec" "$hb"
|
|
74
|
+
sleep 1
|
|
75
|
+
done
|
|
76
|
+
fi
|
|
77
|
+
waiter_beat "$t0" "$ppid_rec" "$hb"
|
|
78
|
+
printf 'wait-probe: condition true for %s (%s/%s)\n' "$key" "$form" "$pred"
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
waiter_beat() {
|
|
82
|
+
local t0="$1" ppid_rec="$2" hb="$3" alive=0
|
|
83
|
+
kill -0 "$ppid_rec" 2>/dev/null && alive=1
|
|
84
|
+
printf '%s %s\n' "$(( $(now_ms) - t0 ))" "$alive" > "$hb"
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
cmd_arm_local() {
|
|
88
|
+
local key="$1" pred="${2:-marker}" pid
|
|
89
|
+
nohup bash "$0" waiter "$key" local "$pred" > "$WORK/$key.local.out" 2>&1 &
|
|
90
|
+
pid=$!
|
|
91
|
+
printf 'pid=%s run=%s-local\n' "$pid" "$key" > "$SCRATCH/$key-local.run"
|
|
92
|
+
printf 'wait-probe: local waiter for %s pid=%s\n' "$key" "$pid"
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
cmd_record() {
|
|
96
|
+
local key="$1" form="$2" ms="$3"
|
|
97
|
+
local t0 marker="$WORK/$key.marker" hb="$WORK/$key.$form.hb" st="$WORK/$key.$form.st"
|
|
98
|
+
local marker_at="-" waiter_at="-" waiter_exit="killed" alive="-" class pred="marker"
|
|
99
|
+
[ -s "$WORK/$key.$form.pred" ] && pred="$(cat "$WORK/$key.$form.pred")"
|
|
100
|
+
t0="$(cat "$WORK/$key.t0")"
|
|
101
|
+
[ -f "$marker" ] && marker_at="$(( $(cat "$marker") - t0 ))"
|
|
102
|
+
if [ -s "$hb" ]; then
|
|
103
|
+
waiter_at="$(cut -d' ' -f1 < "$hb")"
|
|
104
|
+
alive="$(cut -d' ' -f2 < "$hb")"
|
|
105
|
+
fi
|
|
106
|
+
[ -s "$st" ] && waiter_exit="$(cat "$st")"
|
|
107
|
+
class="$(classify "$marker_at" "$waiter_at" "$waiter_exit" "$alive")"
|
|
108
|
+
mkdir -p "$(dirname "$EVIDENCE")"
|
|
109
|
+
printf 'form=%s predicate=%s producer_ms=%s waiter_exit=%s marker_at_ms=%s waiter_at_ms=%s producer_alive_at_exit=%s class=%s\n' \
|
|
110
|
+
"$form" "$pred" "$ms" "$waiter_exit" "$marker_at" "$waiter_at" "$alive" "$class" >> "$EVIDENCE"
|
|
111
|
+
tail -n 1 "$EVIDENCE"
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
# spec: delegation-kit/SPEC.md §bin/wait-probe — the closed cause list, 'unexplained' included, and (ii) is cross-trial so it is named by `report` and never by a line
|
|
115
|
+
classify() {
|
|
116
|
+
local marker_at="$1" waiter_at="$2" waiter_exit="$3" alive="$4"
|
|
117
|
+
if [ "$marker_at" != "-" ] && [ "$waiter_at" != "-" ] && [ "$waiter_at" -ge "$marker_at" ]; then
|
|
118
|
+
printf 'ok\n'; return
|
|
119
|
+
fi
|
|
120
|
+
if [ "$waiter_exit" = "0" ] && [ "$marker_at" = "-" ]; then
|
|
121
|
+
printf 'predicate\n'; return # (iii) clean zero, condition never expressible
|
|
122
|
+
fi
|
|
123
|
+
if [ "$alive" = "1" ] && [ "$waiter_exit" != "0" ]; then
|
|
124
|
+
printf 'reaped\n'; return # (i) died with the producer verifiably alive
|
|
125
|
+
fi
|
|
126
|
+
printf 'unexplained\n' # (iv)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
# spec: delegation-kit/SPEC.md §bin/wait-probe — cause (ii)'s tell is a threshold across the sweep, so the report is the only reader that can see it
|
|
130
|
+
cmd_report() {
|
|
131
|
+
[ -s "$EVIDENCE" ] || { echo "wait-probe: no trials recorded in $EVIDENCE" >&2; return 1; }
|
|
132
|
+
printf '=== trials ===\n'
|
|
133
|
+
cat "$EVIDENCE"
|
|
134
|
+
printf '\n=== verdict ===\n'
|
|
135
|
+
awk '
|
|
136
|
+
{ split($0, f, " "); for (i in f) { split(f[i], kv, "="); v[kv[1]] = kv[2] }
|
|
137
|
+
fo = v["form"]; pr = v["predicate"]; ms = v["producer_ms"] + 0; cls = v["class"]
|
|
138
|
+
cell = fo "/" pr
|
|
139
|
+
n[cell]++; forms[fo]; preds[pr]
|
|
140
|
+
if (cls == "ok") { okc[cell]++; if (ms > okmax[cell]) okmax[cell] = ms; okform[fo]++; okpred[pr]++ }
|
|
141
|
+
else { bad[cell]++; if (badmin[cell] == 0 || ms < badmin[cell]) badmin[cell] = ms
|
|
142
|
+
badform[fo]++; badpred[pr]++; badcls[cls]++ } }
|
|
143
|
+
END {
|
|
144
|
+
for (c in n) printf "%-18s %d trial(s), %d ok, %d early; longest clean wait=%dms\n",
|
|
145
|
+
c ":", n[c], okc[c], bad[c], okmax[c]
|
|
146
|
+
for (c in n) if (bad[c] && okc[c] && badmin[c] > okmax[c])
|
|
147
|
+
printf " ceiling tell HOLDS for %s: every early exit outlasts every clean wait (threshold between %dms and %dms) -> cause (ii)\n", c, okmax[c], badmin[c]
|
|
148
|
+
for (p in badpred) { np++; lastp = p }
|
|
149
|
+
for (fo in badform) nff++
|
|
150
|
+
for (fo in okform) nof++
|
|
151
|
+
if (np == 1 && nff > 1)
|
|
152
|
+
printf "\nEvery early exit carries predicate=%s, across %d of the %d forms measured, and no form is early on any other predicate.\nThe early exits are predicate-shaped, not form-shaped: the wait form is exonerated and the condition is the cause (iii).\n", lastp, nff, nof
|
|
153
|
+
else if (np == 0) printf "\nNo early exit recorded.\n"
|
|
154
|
+
else printf "\nEarly exits span %d predicate(s) and %d form(s) -- read the class column; no single-cause reading is licensed.\n", np, nff }
|
|
155
|
+
' "$EVIDENCE"
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
cmd_sweep() {
|
|
159
|
+
local ms key
|
|
160
|
+
mkdir -p "$WORK"
|
|
161
|
+
for ms in "${SWEEP_MS[@]}"; do
|
|
162
|
+
key="sweep$ms"
|
|
163
|
+
cmd_produce "$key" "$ms"
|
|
164
|
+
cmd_arm_local "$key"
|
|
165
|
+
done
|
|
166
|
+
for ms in "${SWEEP_MS[@]}"; do
|
|
167
|
+
key="sweep$ms"
|
|
168
|
+
while kill -0 "$(sed -n 's/^pid=\([0-9]*\) .*/\1/p' "$SCRATCH/$key-local.run")" 2>/dev/null; do sleep 1; done
|
|
169
|
+
cmd_record "$key" local "$ms"
|
|
170
|
+
rm -f "$SCRATCH/$key.run" "$SCRATCH/$key-local.run"
|
|
171
|
+
done
|
|
172
|
+
cmd_report
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
case "${1:-}" in
|
|
176
|
+
produce) shift; [ $# -eq 2 ] || { usage >&2; exit 2; }; cmd_produce "$@" ;;
|
|
177
|
+
waiter) shift; [ $# -ge 2 ] && [ $# -le 3 ] || { usage >&2; exit 2; }; cmd_waiter "$@" ;;
|
|
178
|
+
arm-local) shift; [ $# -ge 1 ] && [ $# -le 2 ] || { usage >&2; exit 2; }; cmd_arm_local "$@" ;;
|
|
179
|
+
record) shift; [ $# -eq 3 ] || { usage >&2; exit 2; }; cmd_record "$@" ;;
|
|
180
|
+
report) shift; [ $# -eq 0 ] || { usage >&2; exit 2; }; cmd_report ;;
|
|
181
|
+
sweep) shift; [ $# -eq 0 ] || { usage >&2; exit 2; }; cmd_sweep ;;
|
|
182
|
+
-h|--help) usage ;;
|
|
183
|
+
*) usage >&2; exit 2 ;;
|
|
184
|
+
esac
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Behavioral test of templates/subagent-stop-liveness.sh — the SubagentStop probe.
|
|
3
|
+
# The two properties nothing else can assert: the exit is 0 on every path including the
|
|
4
|
+
# failure ones, and stdout stays empty (a byte on stdout would be hook JSON, which is the
|
|
5
|
+
# blocking variant by accident). The reader is driven by stub scripts, one per exit class,
|
|
6
|
+
# so every verdict arm is reached without a real producer.
|
|
7
|
+
#
|
|
8
|
+
# Run by run-gate-tests.sh (any <tests-dir>/*.test.sh; must exit 0).
|
|
9
|
+
set -uo pipefail
|
|
10
|
+
source "$(dirname "${BASH_SOURCE[0]}")/../../gate-sdk/lib/test-hermetic.sh"
|
|
11
|
+
|
|
12
|
+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # delegation-kit/
|
|
13
|
+
HOOK="$DIR/templates/subagent-stop-liveness.sh"
|
|
14
|
+
|
|
15
|
+
fails=0
|
|
16
|
+
tmp="$(mktemp -d)"
|
|
17
|
+
trap 'rm -rf "$tmp"' EXIT
|
|
18
|
+
|
|
19
|
+
PAYLOAD='{"session_id":"s-1","transcript_path":"/x/y.jsonl","hook_event_name":"SubagentStop","stop_hook_active":false}'
|
|
20
|
+
|
|
21
|
+
stub() { # $1=name $2=exit-code
|
|
22
|
+
printf '#!/usr/bin/env bash\nexit %s\n' "$2" >"$tmp/$1"
|
|
23
|
+
printf '%s\n' "$tmp/$1"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# fire <name> <log> <reader> <run-dir> <payload> — runs the probe, asserting exit 0 and silent stdout
|
|
27
|
+
fire() {
|
|
28
|
+
local name="$1" log="$2" reader="$3" rundir="$4" payload="$5" out rc
|
|
29
|
+
out="$( printf '%s' "$payload" | DELEGATION_KIT_STOP_LOG="$log" \
|
|
30
|
+
DELEGATION_KIT_LIVENESS_CMD="$reader" GATE_SDK_TMP_DIR="$rundir" bash "$HOOK" 2>/dev/null )"
|
|
31
|
+
rc=$?
|
|
32
|
+
[[ "$rc" -eq 0 ]] || { echo " FAIL: $name exited $rc, not 0"; fails=$((fails + 1)); }
|
|
33
|
+
[[ -z "$out" ]] || { echo " FAIL: $name wrote '$out' to stdout; the probe emits no hook JSON"; fails=$((fails + 1)); }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
want() { # $1=name $2=line $3.. = substrings the line must carry
|
|
37
|
+
local name="$1" line="$2"; shift 2
|
|
38
|
+
local s
|
|
39
|
+
for s in "$@"; do
|
|
40
|
+
grep -qF -- "$s" <<<"$line" || { echo " FAIL: $name line lacks '$s': $line"; fails=$((fails + 1)); }
|
|
41
|
+
done
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
runs="$tmp/runs"; mkdir -p "$runs"
|
|
45
|
+
|
|
46
|
+
# A — no reader at all (the knob emptied): the probe still logs, and says so rather than
|
|
47
|
+
# reporting a clean tree it never asked about.
|
|
48
|
+
log="$tmp/a.log"
|
|
49
|
+
fire no-reader "$log" "" "$runs" "$PAYLOAD"
|
|
50
|
+
want no-reader "$(cat "$log")" "event=SubagentStop" "session=s-1" "live=no" "verdict=unavailable" "records=0" "keys=session_id,transcript_path,hook_event_name,stop_hook_active"
|
|
51
|
+
|
|
52
|
+
# B/C/D — one firing per reader exit class, each with one record on disk so `records` is
|
|
53
|
+
# non-zero and a `live=no` is informative rather than vacuous.
|
|
54
|
+
printf 'pid=1 run=k\n' >"$runs/k.run"
|
|
55
|
+
for case_spec in "green 0 live=no" "red 1 live=yes" "corrupt 2 live=no"; do
|
|
56
|
+
read -r verdict code liveness <<<"$case_spec"
|
|
57
|
+
log="$tmp/$verdict.log"
|
|
58
|
+
fire "reader-$verdict" "$log" "$(stub "reader-$verdict" "$code")" "$runs" "$PAYLOAD"
|
|
59
|
+
want "reader-$verdict" "$(cat "$log")" "verdict=$verdict" "$liveness" "records=1"
|
|
60
|
+
done
|
|
61
|
+
|
|
62
|
+
# E — a reader that cannot be run at all (an unresolvable path) is the vendoring prerequisite
|
|
63
|
+
# failing, and it degrades to `unavailable` rather than to a wedged turn.
|
|
64
|
+
log="$tmp/e.log"
|
|
65
|
+
fire absent-reader "$log" "$tmp/nowhere/check.sh" "$runs" "$PAYLOAD"
|
|
66
|
+
want absent-reader "$(cat "$log")" "verdict=unavailable" "live=no"
|
|
67
|
+
|
|
68
|
+
# F — an unwritable log: the line cannot be recorded anywhere, so it is dropped silently and
|
|
69
|
+
# the turn still ends. This is the path where "record the failure where it can be" has
|
|
70
|
+
# nowhere left to record it.
|
|
71
|
+
printf 'not a directory\n' >"$tmp/blocker"
|
|
72
|
+
fire unwritable-log "$tmp/blocker/probe.log" "" "$runs" "$PAYLOAD"
|
|
73
|
+
|
|
74
|
+
# G — a payload whose values carry whitespace must not split the space-delimited line: the
|
|
75
|
+
# field count is the assertion, because a split is invisible in a substring match.
|
|
76
|
+
log="$tmp/g.log"
|
|
77
|
+
fire spacey-payload "$log" "" "$runs" '{"session_id":"a b\tc","hook_event_name":"Subagent Stop"}'
|
|
78
|
+
nf="$(awk '{print NF}' "$log")"
|
|
79
|
+
[[ "$nf" == "7" ]] || { echo " FAIL: spacey-payload produced $nf fields, want 7: $(cat "$log")"; fails=$((fails + 1)); }
|
|
80
|
+
|
|
81
|
+
# H — an empty payload (no stdin at all): the payload-derived fields degrade to '-' and the
|
|
82
|
+
# liveness half of the line is still bought.
|
|
83
|
+
log="$tmp/h.log"
|
|
84
|
+
fire empty-payload "$log" "$(stub reader-h 1)" "$runs" ""
|
|
85
|
+
want empty-payload "$(cat "$log")" "event=-" "session=-" "keys=-" "live=yes"
|
|
86
|
+
|
|
87
|
+
# I — one firing appends exactly one line, so the log is a firing count as well as a record.
|
|
88
|
+
log="$tmp/i.log"
|
|
89
|
+
fire append-1 "$log" "" "$runs" "$PAYLOAD"
|
|
90
|
+
fire append-2 "$log" "" "$runs" "$PAYLOAD"
|
|
91
|
+
lines="$(grep -c . "$log")"
|
|
92
|
+
[[ "$lines" == "2" ]] || { echo " FAIL: two firings wrote $lines line(s), want 2"; fails=$((fails + 1)); }
|
|
93
|
+
|
|
94
|
+
if [[ "$fails" -gt 0 ]]; then
|
|
95
|
+
echo "subagent-stop-liveness.test: $fails assertion(s) failed"
|
|
96
|
+
exit 1
|
|
97
|
+
fi
|
|
98
|
+
echo "subagent-stop-liveness.test: ok (exit 0 and silent stdout on every path; verdict green/red/corrupt/unavailable mapped; whitespace in a payload cannot split the line; one firing, one line)"
|
|
99
|
+
exit 0
|
|
@@ -59,5 +59,25 @@ cmp -s "$pp/usage.before" "$pp/usage.txt" || {
|
|
|
59
59
|
echo "delegation-kit/smoke: poller fetch failure touched the snapshot" >&2; exit 1; }
|
|
60
60
|
rm -rf "$pp"
|
|
61
61
|
|
|
62
|
+
# spec: delegation-kit/SPEC.md §The turn-end liveness probe (template) — the probe is exercised in place with a crafted payload: it must exit 0 and append exactly one grammar-conformant line, whatever the reader's verdict
|
|
63
|
+
sp="$PWD/.tmp/stop-probe-smoke"
|
|
64
|
+
rm -rf "$sp"; mkdir -p "$sp"
|
|
65
|
+
printf 'pid=1 run=smoke\n' > "$sp/smoke.run"
|
|
66
|
+
printf '{"session_id":"smoke","hook_event_name":"SubagentStop"}' | \
|
|
67
|
+
DELEGATION_KIT_STOP_LOG="$sp/probe.log" \
|
|
68
|
+
DELEGATION_KIT_LIVENESS_CMD="" \
|
|
69
|
+
GATE_SDK_TMP_DIR="$sp" \
|
|
70
|
+
bash "$SMOKE_KIT_ROOT/templates/subagent-stop-liveness.sh" || {
|
|
71
|
+
echo "delegation-kit/smoke: the SubagentStop probe did not exit 0" >&2; exit 1; }
|
|
72
|
+
probe_line="$(cat "$sp/probe.log")"
|
|
73
|
+
case "$probe_line" in
|
|
74
|
+
*"event=SubagentStop"*"session=smoke"*"live=no"*"verdict=unavailable"*"records=1"*"keys="*) ;;
|
|
75
|
+
*) echo "delegation-kit/smoke: probe line off grammar: $probe_line" >&2; exit 1 ;;
|
|
76
|
+
esac
|
|
77
|
+
if [[ "$(grep -c . "$sp/probe.log")" -ne 1 ]]; then
|
|
78
|
+
echo "delegation-kit/smoke: the probe wrote more than one line for one firing" >&2; exit 1
|
|
79
|
+
fi
|
|
80
|
+
rm -rf "$sp"
|
|
81
|
+
|
|
62
82
|
bash "$SDK/bin/gen-pre-commit.sh" --write >/dev/null
|
|
63
83
|
bash "$SDK/bin/run-gates.sh" --emit graph > scripts/CHECK-GRAPH.html
|
|
@@ -45,18 +45,34 @@ drift: do not delete it on sight, and when either rule changes here, propagate.
|
|
|
45
45
|
`Agent`'s completion notification, a channel a supervisor has;
|
|
46
46
|
condition-waiting is the only one a dispatched role has.
|
|
47
47
|
**Which primitive — the one whose wait ends when the condition goes true, not
|
|
48
|
-
when a duration expires.** The harness offers two forms with
|
|
48
|
+
when a duration expires.** The harness offers two forms with different
|
|
49
49
|
reactivity, and the difference is exactly the wall-clock property this rule
|
|
50
50
|
exists to buy. **Background a command that *exits* on the condition** — a
|
|
51
51
|
`run_in_background` shell command wrapping `until <cond>; do sleep N; done` —
|
|
52
52
|
and it fires one notification the moment the condition holds, then ends: that
|
|
53
|
-
is the sanctioned form
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
is the sanctioned form, and it holds that place on measurement rather than on
|
|
54
|
+
preference (delegation-kit/SPEC.md §bin/wait-probe). The harness's
|
|
55
|
+
**event-stream form**, armed with a command and a deadline, emits one event per
|
|
56
|
+
occurrence and stays armed to its deadline after the event fires **when the
|
|
57
|
+
command it was armed with is unbounded** — a `tail -f`, a `while true` — so
|
|
58
|
+
pointed at a single completion by way of such a command it converts a wait that
|
|
59
|
+
should end in seconds into one that ends at the timeout. Armed with a command
|
|
60
|
+
that *exits*, that watch ends too: it is the second choice for a single
|
|
61
|
+
completion, not a broken one, and it is named here because a reader told only
|
|
58
62
|
about the first form reaches for this one the next time the shape looks close.
|
|
59
63
|
Never a bare foreground `sleep`, which ends on neither.
|
|
64
|
+
**Get the loop's polarity right — the two rules in this bullet compose into a
|
|
65
|
+
trap, and it is the one that has actually fired.** `until` ends when its
|
|
66
|
+
condition becomes **true**, so `until` takes a *done* predicate:
|
|
67
|
+
`until [ -f <marker> ]; do sleep N; done`. Liveness is a *still-running*
|
|
68
|
+
predicate, so it takes `while`: `while kill -0 "$pid" 2>/dev/null; do sleep N;
|
|
69
|
+
done`. Composing "wrap `until <cond>`" with "loop on the recorded PID's
|
|
70
|
+
liveness" literally gives `until kill -0 "$pid"`, whose condition is true while
|
|
71
|
+
the producer is **alive** — so it exits at once. **The tell** is a waiter that
|
|
72
|
+
exited **zero**, in milliseconds, with its producer still running and its
|
|
73
|
+
condition never met. Four attested instances read as evidence against this
|
|
74
|
+
primitive until they were measured and found to be this instead; neither keyword
|
|
75
|
+
costs anything at the guard, which reads the loop's span and not its keyword.
|
|
60
76
|
**What you wait *on* splits two ways, and the split is what makes the artifact
|
|
61
77
|
reachable.** An **`Agent` dispatch** is awaited by its **completion
|
|
62
78
|
notification** — that record is the harness's, not the session's — so never go
|
|
@@ -68,8 +84,9 @@ drift: do not delete it on sight, and when either rule changes here, propagate.
|
|
|
68
84
|
agent writes, scratch reset sweeps** bullet below sends a journal, repo-local
|
|
69
85
|
gitignored scratch in the main checkout, on that bullet's stated survivability
|
|
70
86
|
grounds — widened here from the journal to any artifact a session waits on.
|
|
71
|
-
That record *is* the wait target: loop on its PID's liveness
|
|
72
|
-
|
|
87
|
+
That record *is* the wait target: loop on its PID's liveness —
|
|
88
|
+
`while kill -0 "$pid" 2>/dev/null; do sleep N; done`, on the polarity rule above
|
|
89
|
+
— and the loop ends when the PID stops answering. Write it at the launch, not after, and leave it
|
|
73
90
|
behind — a completion marker answers *is it done* to a live observer, and the
|
|
74
91
|
case this rule exists for is the one where the observer is gone, where a
|
|
75
92
|
liveness record still answers *is it still running* to whoever arrives next.
|
|
@@ -89,7 +106,7 @@ drift: do not delete it on sight, and when either rule changes here, propagate.
|
|
|
89
106
|
matches the waiter's own argv — the harness's wrapper argv matches too — so
|
|
90
107
|
`until ! pgrep -f '<script>'; do …; done` can never go false and never exits,
|
|
91
108
|
reddening nothing while it burns the whole foreground cap. Where liveness *is*
|
|
92
|
-
the condition, match a **recorded PID** (`kill -0 "$pid"`) and never a pattern —
|
|
109
|
+
the condition, match a **recorded PID** (`while kill -0 "$pid" 2>/dev/null`) and never a pattern —
|
|
93
110
|
one rule, whoever started the producer, your own backgrounded child included: a
|
|
94
111
|
PID is an identity, a pattern is a guess about a process table that includes the
|
|
95
112
|
guesser. The
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# spec: delegation-kit/SPEC.md §The turn-end liveness probe (template) — a SubagentStop probe that logs one line per firing, emits no hook JSON, and exits 0 unconditionally
|
|
3
|
+
set -uo pipefail
|
|
4
|
+
|
|
5
|
+
LOG="${DELEGATION_KIT_STOP_LOG:-${GATE_SDK_WORKFLOW_DIR:-.workflow}/subagent-stop-liveness.log}"
|
|
6
|
+
# spec: delegation-kit/SPEC.md §The turn-end liveness probe (template) — the unset-form default, so an explicitly empty knob is the supported way to run with no reader at all
|
|
7
|
+
LIVENESS_CMD="${DELEGATION_KIT_LIVENESS_CMD-evidence-kit/checks/check-producer-liveness.sh}"
|
|
8
|
+
RUN_DIR="${GATE_SDK_TMP_DIR:-.tmp}"
|
|
9
|
+
|
|
10
|
+
# spec: delegation-kit/SPEC.md §The turn-end liveness probe (template) — every value is one whitespace-free token, so a payload string can never split the space-delimited line
|
|
11
|
+
sanitize() {
|
|
12
|
+
local v="${1//[[:space:]]/_}"
|
|
13
|
+
printf '%s' "${v:--}"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
payload="$(cat 2>/dev/null)"
|
|
17
|
+
|
|
18
|
+
event='-'
|
|
19
|
+
session='-'
|
|
20
|
+
keys='-'
|
|
21
|
+
if [[ -n "$payload" ]] && command -v jq >/dev/null 2>&1; then
|
|
22
|
+
event="$(sanitize "$(printf '%s' "$payload" | jq -r '.hook_event_name // "-"' 2>/dev/null)")"
|
|
23
|
+
session="$(sanitize "$(printf '%s' "$payload" | jq -r '.session_id // "-"' 2>/dev/null)")"
|
|
24
|
+
keys="$(sanitize "$(printf '%s' "$payload" | jq -r 'keys_unsorted | join(",")' 2>/dev/null)")"
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
shopt -s nullglob
|
|
28
|
+
records=("$RUN_DIR"/*.run)
|
|
29
|
+
shopt -u nullglob
|
|
30
|
+
|
|
31
|
+
verdict=unavailable
|
|
32
|
+
live=no
|
|
33
|
+
if [[ -n "$LIVENESS_CMD" && -r "$LIVENESS_CMD" ]]; then
|
|
34
|
+
# spec: delegation-kit/SPEC.md §The turn-end liveness probe (template) — the bounded call: a reader that hung would refuse the turn end by accident, which is the blocking variant this one is not
|
|
35
|
+
if command -v timeout >/dev/null 2>&1; then
|
|
36
|
+
timeout 10 bash "$LIVENESS_CMD" "$RUN_DIR" >/dev/null 2>&1
|
|
37
|
+
else
|
|
38
|
+
bash "$LIVENESS_CMD" "$RUN_DIR" >/dev/null 2>&1
|
|
39
|
+
fi
|
|
40
|
+
case "$?" in
|
|
41
|
+
0) verdict=green ;;
|
|
42
|
+
1) verdict=red; live=yes ;;
|
|
43
|
+
2) verdict=corrupt ;;
|
|
44
|
+
*) verdict=unavailable ;;
|
|
45
|
+
esac
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
ts="$(date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null)"
|
|
49
|
+
printf -v line '%s event=%s session=%s live=%s verdict=%s records=%s keys=%s' \
|
|
50
|
+
"${ts:--}" "$event" "$session" "$live" "$verdict" "${#records[@]}" "$keys"
|
|
51
|
+
|
|
52
|
+
logdir="${LOG%/*}"
|
|
53
|
+
[[ "$logdir" == "$LOG" || -d "$logdir" ]] || mkdir -p "$logdir" 2>/dev/null
|
|
54
|
+
{ printf '%s\n' "$line" >> "$LOG"; } 2>/dev/null
|
|
55
|
+
|
|
56
|
+
exit 0
|
|
@@ -7,7 +7,7 @@ agents do the writing: a stateless agent session cannot be trusted to
|
|
|
7
7
|
*remember* conventions, so the conventions are enforced by machine-run gates
|
|
8
8
|
that block the commit instead.
|
|
9
9
|
|
|
10
|
-
A **gate** is a small
|
|
10
|
+
A **gate** is a small program checking one invariant across one or more
|
|
11
11
|
governed surfaces. The kit ships the machinery that keeps a gate family
|
|
12
12
|
honest:
|
|
13
13
|
|
|
@@ -15,7 +15,10 @@ honest:
|
|
|
15
15
|
parser must never read as "clean"), the fixture-tree prune adapters, and the
|
|
16
16
|
registry/resolution helpers.
|
|
17
17
|
- `bin/run-gates.sh` — the aggregate battery: every gate in your `gates.list`,
|
|
18
|
-
one shot, per-gate timings.
|
|
18
|
+
one shot, per-gate timings. Two selectors narrow it without losing the config
|
|
19
|
+
bridge or the output contract: `--only <name>...` runs the gates you name (in
|
|
20
|
+
registry order; an unregistered name is a refusal), and `--for <path>...` runs
|
|
21
|
+
the gates coupling to the paths you name, exactly as the generated hook would.
|
|
19
22
|
- `bin/run-gate-tests.sh` — the golden-fixture runner: every gate proves it
|
|
20
23
|
accepts a `good/` case and rejects a `bad/` case with the right error text.
|
|
21
24
|
- `bin/run-consumer-smoke.sh` — the end-to-end check no fixture makes: builds a
|
|
@@ -81,6 +84,8 @@ bash gate-sdk/bin/run-gates.sh --emit enforcement-map > docs/enforcement.md # th
|
|
|
81
84
|
bash gate-sdk/bin/install-hooks.sh # opt in this clone
|
|
82
85
|
|
|
83
86
|
bash gate-sdk/bin/run-gates.sh # the full battery
|
|
87
|
+
bash gate-sdk/bin/run-gates.sh --only check-graph # one gate's verdict
|
|
88
|
+
bash gate-sdk/bin/run-gates.sh --for scripts/gates.list # the gates coupling to a path
|
|
84
89
|
bash gate-sdk/bin/run-gate-tests.sh gate-sdk/gate-tests gate-sdk/checks # the kit's own tests
|
|
85
90
|
```
|
|
86
91
|
|