interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / forge / tests / run.sh

597 lines · 27178 bytes Raw Blame History
1#!/bin/sh
2# forge/tests/run.sh: build forge/forge.om with the pinned omc, then run the whole suite (decision
3# cases in text and JSON, forge status, forge gate against a local Radicle-shaped storage) on it,
4# and require every mutant in mutants.txt to fail that same suite. Run from anywhere:
5# OMC=/path/to/omc sh forge/tests/run.sh
6# Test glue only (POSIX sh, sed, cmp, sha256sum, mktemp, git, date, head, ls, sleep, kill). The forge logic is
7# forge/forge.om. Exit 0 only when every check passes and every mutant is caught; 3 is NOT_RUN
8# (wrong or missing omc, or not aarch64: the pinned omc emits aarch64 Linux only).
9set -u
10here=$(cd "$(dirname "$0")" && pwd)
11root=$(cd "$here/../.." && pwd)
12OMC=${OMC:-$HOME/work/flux/omega-mv/seed/out/omc}
13PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
14got=$(sha256sum "$OMC" 2>/dev/null | cut -d' ' -f1)
15if [ "$got" != "$PIN" ]; then
16 echo "NOT_RUN omc sha256 '${got:-missing}' is not the pin $PIN (omega-mv f4df8239)"
17 exit 3
18fi
19if [ "$(uname -m)" != aarch64 ]; then
20 echo "NOT_RUN forge is built for aarch64 Linux only (the pinned omc emits aarch64 and the open flags in forge.om are aarch64 values); this machine is $(uname -m)"
21 exit 3
22fi
23T=$(mktemp -d "${TMPDIR:-/tmp}/forge-test.XXXXXX") || exit 2
24trap 'rm -rf "$T"' EXIT INT TERM
25V=$here/verdicts
26R=$here/receipts
27D=$T/derived
28mkdir "$D"
29
30# Derived verdicts: one edit each to a verbatim real verdict. A derivation that changes nothing fails.
31base=$V/omega-mv-215ea39a.verdict.txt
32h1=215ea39afdc0cf1914cfadf43bbb6d23ce68c920
33up=$(printf %s "$h1" | tr a-f A-F)
34cr=$(printf '\r')
35tab=$(printf '\t')
36ctl=$(printf '\001')
37derive() {
38 sed "$2" "$base" > "$D/$1.verdict.txt"
39 if cmp -s "$base" "$D/$1.verdict.txt"; then
40 echo "FAIL derivation $1 changed nothing"
41 exit 1
42 fi
43}
44derive reject '1s/^VERDICT MERGE /VERDICT REJECT /'
45derive trailing '1s/$/x/'
46derive short-head '1s/head=\(........\).*/head=\1/'
47derive upper-head "1s/head=[0-9a-f]*/head=$up/"
48derive crlf "1s/\$/$cr/"
49derive lower-word '1s/^VERDICT MERGE/verdict merge/'
50derive dup-reviewer '2p'
51derive no-reviewer '/^reviewer=/d'
52derive empty-reviewer 's/^reviewer=.*/reviewer=/'
53derive blank-reviewer "s/^reviewer=.*/reviewer= $tab /"
54derive line1-second-word '1s/$/ REJECT by reviewer/'
55derive line1-trailing-space '1s/$/ /'
56derive loud-reviewer "s/^reviewer=.*/reviewer= MANAGER${tab}REVIEWER agent (relayed)/"
57derive bare-reviewer 's/^reviewer=.*/reviewer=Manager reviewer agent/'
58{ cat "$base"; echo "VERDICT REJECT head=$h1"; } > "$D/second-verdict.verdict.txt"
59{ sed -n '1p' "$base"; printf 'reviewer=\000\n'; sed '1d;/^reviewer=/d' "$base"; } > "$D/nul-reviewer.verdict.txt"
60
61# Derived receipts: one edit each to the self-review receipt (author=Manager reviewer agent, the
62# reviewer text of the omega-mv verdict). Each must still be caught as self-review, or as malformed.
63rbase=$R/self-review.receipt
64derive_r() {
65 sed "$2" "$rbase" > "$D/$1.receipt"
66 if cmp -s "$rbase" "$D/$1.receipt"; then
67 echo "FAIL derivation $1 changed nothing"
68 exit 1
69 fi
70}
71derive_r self-lowercase 's/^author=.*/author=manager reviewer agent/'
72derive_r self-uppercase 's/^author=.*/author=MANAGER REVIEWER AGENT/'
73derive_r self-leading-space 's/^author=/author= /'
74derive_r self-double-space 's/^author=Manager /author=Manager /'
75derive_r self-trailing-tab "/^author=/s/\$/$tab/"
76derive_r self-period 's/^author=.*/author=Manager reviewer agent./'
77derive_r self-quoted 's/^author=.*/author="Manager reviewer agent"/'
78derive_r self-bracketed 's/^author=.*/author=(Manager reviewer agent)!/'
79derive_r self-underscore 's/^author=.*/author=Manager_reviewer_agent/'
80derive_r self-hyphen 's/^author=.*/author=manager-reviewer-agent/'
81derive_r blank-author "s/^author=.*/author= $tab /"
82derive_r punct-author 's/^author=.*/author=.-_"/'
83derive_r control-author "s/^author=.*/author=Manager${ctl}x/"
84derive_r other-author 's/^author=.*/author=Manager reviewer agents/'
85
86# Receipt v1 keys (written by forge gate): the real omega-mv receipt plus one key line each.
87mbase=$R/$h1.receipt
88x64=0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
89v1keys="rid=rad:z6do9WDBhuSnvopDkgFdFr1yWA62
90tree=e2b97327c20ce697eab6bc605538acc85bc9d513
91omc=$PIN
92started=2026-11-07T11:00:00Z
93finished=2026-11-07T11:05:09Z
94log_sha256=$x64
95negctl_log_sha256=$x64"
96mkr() {
97 { cat "$mbase"; printf '%s\n' "$2"; } > "$D/$1.receipt"
98}
99mkr v1-full "$v1keys"
100mkr v1-omc-none "$(printf '%s\n' "$v1keys" | sed 's/^omc=.*/omc=none/')"
101mkr v1-short-tree "$(printf '%s\n' "$v1keys" | sed 's/^tree=./tree=/')"
102mkr v1-upper-tree "$(printf '%s\n' "$v1keys" | sed 's/^tree=e/tree=E/')"
103mkr v1-dup-tree "$(printf '%s\n' "$v1keys" | sed '2p')"
104mkr v1-bad-rid "$(printf '%s\n' "$v1keys" | sed 's/^rid=rad:/rid=/')"
105mkr v1-short-omc "$(printf '%s\n' "$v1keys" | sed 's/^omc=./omc=/')"
106mkr v1-bad-started "$(printf '%s\n' "$v1keys" | sed 's/^started=2026-11-07T/started=2026-11-07 /')"
107mkr v1-bad-finished "$(printf '%s\n' "$v1keys" | sed 's/^finished=\(.*\)Z$/finished=\1/')"
108mkr v1-upper-log "$(printf '%s\n' "$v1keys" | sed 's/^log_sha256=0123456789abcdef/log_sha256=0123456789ABCDEF/')"
109mkr v1-short-negctl-log "$(printf '%s\n' "$v1keys" | sed 's/^negctl_log_sha256=./negctl_log_sha256=/')"
110
111# Timeout receipts (rc 124 = the run was killed at the gate timeout): one rc edit each, and the
112# order of the checks (timeout before GATE_FAIL and SELF_REVIEW)
113derive_t() {
114 sed "$3" "$2" > "$D/$1.receipt"
115 if cmp -s "$2" "$D/$1.receipt"; then
116 echo "FAIL derivation $1 changed nothing"
117 exit 1
118 fi
119}
120derive_t gate-timeout "$mbase" 's/^gate_rc=.*/gate_rc=124/'
121derive_t negctl-timeout "$mbase" 's/^negctl_rc=.*/negctl_rc=124/'
122derive_t negctl-timeout-gate-fail "$mbase" 's/^gate_rc=.*/gate_rc=3/;s/^negctl_rc=.*/negctl_rc=124/'
123derive_t gate-timeout-self "$rbase" 's/^gate_rc=.*/gate_rc=124/'
124derive_t gate-timeout-clone "$mbase" 's/^gate_rc=.*/gate_rc=124/;s/^clone=.*/clone=3743d642cf034299009936eb8d458ba96a0a8589/'
125derive_t gate-rc-123 "$mbase" 's/^gate_rc=.*/gate_rc=123/'
126
127# check NAME STATUS: record one check of the suite (STATUS 0 is a pass)
128check() {
129 nchk=$((nchk + 1))
130 if [ "$2" = 0 ]; then
131 [ "$TAG" = base ] && echo "PASS $1"
132 else
133 fails=$((fails + 1))
134 failed="$failed $1"
135 [ "$TAG" = base ] && echo "FAIL $1: ${why:-}"
136 fi
137 why=
138 return 0
139}
140
141# run_cases BIN: replay cases.txt (a name starting "json-" runs "decide --json")
142run_cases() {
143 while IFS='|' read -r name head verdict receipt want_rc want_out; do
144 case $name in '#'*|'') continue ;; esac
145 verdict=$(printf %s "$verdict" | sed "s#^@V#$V#;s#^@R#$R#;s#^@D#$D#")
146 receipt=$(printf %s "$receipt" | sed "s#^@V#$V#;s#^@R#$R#;s#^@D#$D#")
147 set -- "$1" decide
148 case $name in json-*) set -- "$@" --json ;; esac
149 if [ "$receipt" = - ]; then
150 out=$("$@" "$head" "$verdict" 2>&1)
151 else
152 out=$("$@" "$head" "$verdict" "$receipt" 2>&1)
153 fi
154 rc=$?
155 why="got '$out' exit $rc, want '$want_out' exit $want_rc"
156 [ "$out" = "$want_out" ] && [ "$rc" = "$want_rc" ]
157 check "$name" $?
158 done < "$here/cases.txt"
159}
160
161# forge status over a fake rad. 512 listed patches are all examined (exit 0); 513 are reported as
162# TRUNCATED (exit 2) rather than silently cut to 512. One listed patch (head ...aa) with a verdict
163# and one, two or no receipts named *-00000000.receipt.txt shows receipt=<name>, ambiguous, none.
164mkdir -p "$T/bin" "$T/home" "$T/empty" "$T/rev" "$T/rc1" "$T/rc2"
165cat > "$T/bin/rad" <<'EOF'
166#!/bin/sh
167case $2 in
168list)
169 n=$(cat "$HOME/rows")
170 i=0
171 while [ "$i" -lt "$n" ]; do
172 printf '\342\224\202 \342\227\217 %07x fake patch \342\224\202\n' "$i"
173 i=$((i + 1))
174 done
175 ;;
176show)
177 h=00000000000000000000000000000000000000aa
178 printf '\342\224\202 Patch %s \342\224\202\n\342\224\202 Head %s \342\224\202\n\342\224\202 Status open \342\224\202\n' "$h" "$h"
179 ;;
180*) exit 9 ;;
181esac
182EOF
183chmod +x "$T/bin/rad"
184haa=00000000000000000000000000000000000000aa
185sed "1s/head=[0-9a-f]*/head=$haa/" "$base" > "$T/rev/fake-00000000.verdict.txt"
186sed "s/^clone=.*/clone=$haa/" "$mbase" > "$T/rc1/fake-00000000.receipt.txt"
187cp "$T/rc1/fake-00000000.receipt.txt" "$T/rc2/fake-00000000.receipt.txt"
188cp "$T/rc1/fake-00000000.receipt.txt" "$T/rc2/other-00000000.receipt.txt"
189status_case() {
190 echo "$2" > "$T/home/rows"
191 out=$(HOME=$T/home PATH=$T/bin:$PATH "$1" status rad:zFake "$3" "$4" 2>&1)
192 rc=$?
193 why="got '$out' exit $rc, want '$5' exit $6"
194 printf '%s\n' "$out" | grep -qxF -- "$5" && [ "$rc" = "$6" ]
195 check "status-$2-$7" $?
196}
197run_status() {
198 status_case "$1" 512 "$T/empty" "$T/empty" 'forge status rad:zFake patches=512 decided=0 merge=0 hold=0 not_run=512' 0 patches
199 status_case "$1" 513 "$T/empty" "$T/empty" 'TRUNCATED patches=513 examined=512' 2 patches
200 status_case "$1" 1 "$T/rev" "$T/rc1" "patch 0000000 status=open head=$haa verdict=fake-00000000.verdict.txt receipt=fake-00000000.receipt.txt decision=MERGE OK" 0 one-receipt
201 status_case "$1" 1 "$T/rev" "$T/rc2" "patch 0000000 status=open head=$haa verdict=fake-00000000.verdict.txt receipt=ambiguous decision=HOLD RECEIPT_AMBIGUOUS" 0 two-receipts
202 status_case "$1" 1 "$T/rev" "$T/empty" "patch 0000000 status=open head=$haa verdict=fake-00000000.verdict.txt receipt=none decision=HOLD RECEIPT_UNREADABLE" 0 no-receipt
203}
204
205# forge gate fixture: a Radicle-shaped storage RAD_HOME/storage/zForgeGate holding a git repo with
206# two commits (data.bin of 100000 random bytes, then a file "second"), a fake rad for name lookup.
207G=$T/gate
208mkdir -p "$G/rh/storage" "$G/home" "$G/bin"
209git init -q --bare "$G/rh/storage/zForgeGate" || exit 2
210git init -q "$G/w" || exit 2
211head -c 100000 /dev/urandom > "$G/w/data.bin"
212echo two > "$G/w/second"
213(
214 cd "$G/w" &&
215 git add data.bin && git -c user.name=forge-test -c user.email=forge@test commit -qm one &&
216 git add second && git -c user.name=forge-test -c user.email=forge@test commit -qm two &&
217 git push -q "$G/rh/storage/zForgeGate" HEAD:refs/heads/main
218) || { echo "FAIL gate fixture"; exit 2; }
219g1=$(git -C "$G/w" rev-parse HEAD~1)
220g2=$(git -C "$G/w" rev-parse HEAD)
221tr1=$(git -C "$G/w" rev-parse "HEAD~1^{tree}")
222tr2=$(git -C "$G/w" rev-parse "HEAD^{tree}")
223s1=$(printf %.8s "$g1")
224s2=$(printf %.8s "$g2")
225cat > "$G/bin/rad" <<'EOF'
226#!/bin/sh
227[ "$1 $2 $3" = "inspect rad:zForgeGate --payload" ] || exit 9
228printf '{"xyz.radicle.project": {"defaultBranch": "main", "description": "fixture", "name": "gatetest"}}\n'
229EOF
230chmod +x "$G/bin/rad"
231{ echo "VERDICT MERGE head=$g2"; echo "reviewer=Forge test reviewer"; } > "$G/v2.verdict.txt"
232O=$G/out
233A='Forge test agent'
234
235# gate BIN ARGS..: run "forge gate" in an environment holding only HOME, PATH and RAD_HOME
236gate() {
237 b=$1
238 shift
239 gout=$(env -i HOME="$G/home" PATH="$G/bin:$PATH" RAD_HOME="$G/rh" "$b" gate rad:zForgeGate "$@" 2>&1)
240 grc=$?
241 why="got '$gout' exit $grc"
242}
243# key NAME RECEIPT: the value of one receipt key
244key() {
245 sed -n "s/^$1=//p" "$2"
246}
247# during ARGV..: wait up to 10 s for the gate command to write its parent's (forge's) pid to
248# $G/pid, then run ARGV; run in the background while a gate sleeps
249during() {
250 i=0
251 while [ ! -s "$G/pid" ] && [ "$i" -lt 200 ]; do
252 sleep 0.05
253 i=$((i + 1))
254 done
255 "$@"
256}
257# swap: replace the gate log by name wherever a forge run keeps it (the out dir .tmp of
258# cd931dd0..dd78f91a, the temp dir since) with forged bytes; list what was replaced in $G/swapped
259swap() {
260 p=$(cat "$G/pid")
261 for f in "$O/sw-$s2.gate.log.tmp" /tmp/forge-gate-"$p"-*/gate.log; do
262 [ -f "$f" ] || continue
263 printf 'forged\n' > "$f.x" && mv -f "$f.x" "$f" && echo "$f" >> "$G/swapped"
264 done
265}
266sleeper="echo true-output; echo \$PPID > $G/pid; sleep 1"
267run_gate() {
268 b=$1
269 rm -rf "$O" "$G/home/handoffs"
270 mkdir -p "$O"
271 t0=$(date -u +%Y-%m-%dT%H:%M:%SZ)
272 gate "$b" "$g2" --name gt --out "$O" --author "$A" --neg sh -c 'test -f marker' -- sh -c 'touch marker; cat data.bin'
273 t1=$(date -u +%Y-%m-%dT%H:%M:%SZ)
274 rp=$O/gt-$s2.receipt.txt
275 [ "$grc" = 0 ] && [ "$gout" = "forge gate rad:zForgeGate head=$g2 gate_rc=0 negctl_rc=1 receipt=$rp" ]
276 check gate-pass-exit $?
277 why="receipt: $(cat "$rp" 2>&1)"
278 [ "$(key rid "$rp")" = rad:zForgeGate ] && [ "$(key clone "$rp")" = "$g2" ] &&
279 [ "$(key tree "$rp")" = "$tr2" ] && [ "$(key omc "$rp")" = none ] &&
280 [ "$(key gate_rc "$rp")" = 0 ] && [ "$(key negctl_rc "$rp")" = 1 ] &&
281 [ "$(key author "$rp")" = "$A" ] &&
282 [ "$(key gate_cmd "$rp")" = 'sh -c touch marker; cat data.bin' ] &&
283 [ "$(key negctl_cmd "$rp")" = 'sh -c test -f marker' ] &&
284 [ "$(sed -n 1p "$rp")" = 'FORGE-RECEIPT v1' ] && [ "$(wc -l < "$rp")" -eq 14 ]
285 check gate-receipt-fields $?
286 cmp -s "$G/w/data.bin" "$O/gt-$s2.gate.log"
287 check gate-log-is-gate-output $?
288 why="log_sha256 $(key log_sha256 "$rp"), negctl $(key negctl_log_sha256 "$rp")"
289 [ "$(key log_sha256 "$rp")" = "$(sha256sum < "$O/gt-$s2.gate.log" | cut -d' ' -f1)" ] &&
290 [ "$(key negctl_log_sha256 "$rp")" = "$(sha256sum < "$O/gt-$s2.negctl.log" | cut -d' ' -f1)" ]
291 check gate-log-sha256 $?
292 st=$(key started "$rp")
293 fi_=$(key finished "$rp")
294 why="started $st finished $fi_ window $t0..$t1"
295 [ ! "$st" \< "$t0" ] && [ ! "$fi_" \< "$st" ] && [ ! "$t1" \< "$fi_" ]
296 check gate-times-utc $?
297 out=$("$b" decide "$g2" "$G/v2.verdict.txt" "$rp" 2>&1)
298 why="decide: $out"
299 [ "$out" = 'MERGE OK' ]
300 check gate-receipt-decides-merge $?
301 out=$("$b" decide --json "$g2" "$G/v2.verdict.txt" "$rp" 2>&1)
302 why="decide --json: $out"
303 [ "$out" = "{\"schema\":\"forge-decision/1\",\"head\":\"$g2\",\"decision\":\"MERGE\",\"reason\":\"OK\"}" ]
304 check gate-receipt-decides-merge-json $?
305
306 # SHA-256 of the gate log across the padding edges (0, 55, 56, 63, 64, 65 bytes) and many blocks
307 for n in 0 55 56 63 64 65 1000 100000; do
308 gate "$b" "$g2" --name "sz$n" --out "$O" --author "$A" --neg false -- head -c "$n" data.bin
309 lg=$O/sz$n-$s2.gate.log
310 why="size $n: log_sha256 $(key log_sha256 "$O/sz$n-$s2.receipt.txt") log bytes $(wc -c < "$lg")"
311 [ "$grc" = 0 ] && [ "$(wc -c < "$lg")" -eq "$n" ] &&
312 [ "$(key log_sha256 "$O/sz$n-$s2.receipt.txt")" = "$(sha256sum < "$lg" | cut -d' ' -f1)" ]
313 check "gate-log-sha256-$n-bytes" $?
314 done
315
316 # the older head: its own tree, and the later file is absent from its clone
317 gate "$b" "$g1" --name old --out "$O" --author "$A" --neg test ! -f data.bin -- test ! -f second
318 [ "$grc" = 0 ] && [ "$(key tree "$O/old-$s1.receipt.txt")" = "$tr1" ] && [ "$(key clone "$O/old-$s1.receipt.txt")" = "$g1" ]
319 check gate-older-head-tree $?
320
321 gate "$b" "$g2" --name fail --out "$O" --author "$A" --neg false -- sh -c 'exit 3'
322 out=$("$b" decide "$g2" "$G/v2.verdict.txt" "$O/fail-$s2.receipt.txt" 2>&1)
323 why="$why; decide: $out"
324 [ "$grc" = 1 ] && [ "$(key gate_rc "$O/fail-$s2.receipt.txt")" = 3 ] && [ "$out" = 'HOLD GATE_FAIL' ]
325 check gate-fail-holds $?
326
327 gate "$b" "$g2" --name negpass --out "$O" --author "$A" --neg true -- true
328 out=$("$b" decide "$g2" "$G/v2.verdict.txt" "$O/negpass-$s2.receipt.txt" 2>&1)
329 why="$why; decide: $out"
330 [ "$grc" = 1 ] && [ "$out" = 'HOLD NEGCTL_PASSED' ]
331 check gate-negctl-passed-holds $?
332
333 gate "$b" "$g2" --name sig --out "$O" --author "$A" --neg false -- sh -c 'kill -9 $$'
334 [ "$grc" = 1 ] && [ "$(key gate_rc "$O/sig-$s2.receipt.txt")" = 137 ]
335 check gate-killed-is-128-plus-signal $?
336
337 gate "$b" "$g2" --out "$O" --author "$A" --neg false -- true
338 [ "$grc" = 0 ] && [ -f "$O/gatetest-$s2.receipt.txt" ]
339 check gate-name-from-rad-inspect $?
340
341 # the out directory is never created by forge: missing is an error, existing is used
342 gate "$b" "$g2" --name dflt --author "$A" --neg false -- true
343 [ "$grc" = 2 ] && [ ! -e "$G/home/handoffs" ]
344 check gate-missing-out-dir-refused $?
345 mkdir -p "$G/home/handoffs/hive/forge/receipts"
346 gate "$b" "$g2" --name dflt --author "$A" --neg false -- true
347 [ "$grc" = 0 ] && [ -f "$G/home/handoffs/hive/forge/receipts/dflt-$s2.receipt.txt" ]
348 check gate-default-out-dir $?
349
350 gout=$(env -i HOME="$G/home" PATH="$G/bin:$PATH" RAD_HOME="$G/rh" OMC="$OMC" "$b" gate rad:zForgeGate "$g2" --name omc --out "$O" --author "$A" --neg false -- true 2>&1)
351 grc=$?
352 why="got '$gout' exit $grc"
353 [ "$grc" = 0 ] && [ "$(key omc "$O/omc-$s2.receipt.txt")" = "$PIN" ]
354 check gate-omc-sha256 $?
355
356 # errors: exit 2 and no receipt
357 gout=$(env -i HOME="$G/home" PATH="$G/bin:$PATH" RAD_HOME="$G/rh" OMC="$G/no-such-omc" "$b" gate rad:zForgeGate "$g2" --name bad --out "$O" --author "$A" --neg false -- true 2>&1)
358 grc=$?
359 [ "$grc" = 2 ]
360 check gate-unreadable-omc-refused $?
361 gate "$b" abababababababababababababababababababab --name bad --out "$O" --author "$A" --neg false -- true
362 [ "$grc" = 2 ]
363 check gate-unknown-head-refused $?
364 gate "$b" "$s2" --name bad --out "$O" --author "$A" --neg false -- true
365 [ "$grc" = 2 ]
366 check gate-short-head-refused $?
367 gate "$b" "$g2" --name bad --out "$O" --neg false -- true
368 [ "$grc" = 2 ]
369 check gate-author-required $?
370 gate "$b" "$g2" --name bad --out "$O" --author "$A" --neg false -- sh -c 'true
371true'
372 [ "$grc" = 2 ]
373 check gate-newline-refused $?
374 gate "$b" "$g2" --name bad --out "$O" --author "$A" --neg false -- X=1 true
375 [ "$grc" = 2 ]
376 check gate-env-assignment-refused $?
377 gate "$b" "$g2" --name bad --out "$O" --author "$A" --neg -i true -- true
378 [ "$grc" = 2 ]
379 check gate-option-command-refused $?
380 gate "$b" "$g2" --name bad --out "$O" --author "$A" --neg false --
381 [ "$grc" = 2 ]
382 check gate-empty-command-refused $?
383 gate "$b" "$g2" --name bad --out "$O" --author "$A" --neg false true
384 [ "$grc" = 2 ]
385 check gate-missing-separator-refused $?
386 gate "$b" "$g2" --name ../bad --out "$O" --author "$A" --neg false -- true
387 [ "$grc" = 2 ]
388 check gate-name-with-slash-refused $?
389 gate "$b" "$g2" --name bad --name bad2 --out "$O" --author "$A" --neg false -- true
390 [ "$grc" = 2 ]
391 check gate-duplicate-option-refused $?
392 # forge never replaces an out file: a second run under the same name is refused, the first
393 # receipt stays as it was
394 cp "$rp" "$G/gt.receipt.before"
395 gate "$b" "$g2" --name gt --out "$O" --author "$A" --neg false -- true
396 [ "$grc" = 2 ] && cmp -s "$rp" "$G/gt.receipt.before"
397 check gate-existing-out-file-refused $?
398 # a symlink planted at any out path before the run is refused (exit 2) before the gate runs,
399 # never followed, and the planted link is all that is left
400 for sfx in gate.log negctl.log receipt.txt; do
401 rm -f "$O"/sym-* "$G/victim" "$G/ran"
402 printf 'victim\n' > "$G/victim"
403 ln -s "$G/victim" "$O/sym-$s2.$sfx"
404 gate "$b" "$g2" --name sym --out "$O" --author "$A" --neg false -- touch "$G/ran"
405 why="exit $grc, victim now: $(cat "$G/victim"), out: $(ls "$O" | grep '^sym-'), gate ran: $(ls "$G" | grep -c '^ran$')"
406 [ "$grc" = 2 ] && [ "$(cat "$G/victim")" = victim ] && [ ! -e "$G/ran" ] &&
407 [ "$(ls "$O" | grep '^sym-')" = "sym-$s2.$sfx" ]
408 check "gate-planted-symlink-$sfx-refused" $?
409 done
410 # a symlink planted at an out path while the gate sleeps: the O_EXCL create at the end refuses
411 # it, never follows it, and removes the out files this run had already created
412 for sfx in negctl.log receipt.txt; do
413 rm -f "$O"/late-* "$G/victim" "$G/pid"
414 printf 'victim\n' > "$G/victim"
415 during ln -s "$G/victim" "$O/late-$s2.$sfx" &
416 gate "$b" "$g2" --name late --out "$O" --author "$A" --neg false -- sh -c "$sleeper"
417 wait
418 why="exit $grc, victim now: $(cat "$G/victim"), out: $(ls "$O" | grep '^late-')"
419 [ "$grc" = 2 ] && [ "$(cat "$G/victim")" = victim ] && [ "$(ls "$O" | grep '^late-')" = "late-$s2.$sfx" ]
420 check "gate-late-symlink-$sfx-refused" $?
421 done
422 # the logs are read through the fds the commands wrote, never by name: a gate log swapped
423 # while the gate sleeps changes neither the out log nor log_sha256
424 rm -f "$G/pid" "$G/swapped"
425 during swap &
426 gate "$b" "$g2" --name sw --out "$O" --author "$A" --neg false -- sh -c "$sleeper"
427 wait
428 lg=$O/sw-$s2.gate.log
429 why="exit $grc, swapped: $(cat "$G/swapped" 2>&1), log: $(cat "$lg" 2>&1), log_sha256 $(key log_sha256 "$O/sw-$s2.receipt.txt" 2>&1)"
430 [ "$grc" = 0 ] && [ -s "$G/swapped" ] && [ "$(cat "$lg")" = true-output ] &&
431 [ "$(key log_sha256 "$O/sw-$s2.receipt.txt")" = "$(printf 'true-output\n' | sha256sum | cut -d' ' -f1)" ]
432 check gate-log-swap-during-run-ignored $?
433 rm -f "$O"/sym-* "$O"/late-* "$G/victim" "$G/pid" "$G/swapped"
434 # gate timeout: the gate and the negative control are each a shell with a child sleeper in
435 # the background; at --timeout 1 forge kills the whole process group (the child too), records
436 # rc 124, appends its timeout line to the hashed log and still writes the receipt
437 tline='forge: timeout after 1 s, process group killed with SIGKILL, exit status recorded as 124'
438 rm -f "$G/tkid" "$G/nkid"
439 e0=$(date +%s)
440 gate "$b" "$g2" --name tmo --timeout 1 --out "$O" --author "$A" --neg false -- sh -c "echo before-timeout; sleep 20 & echo \$! > $G/tkid; wait"
441 e1=$(date +%s)
442 rp=$O/tmo-$s2.receipt.txt
443 lg=$O/tmo-$s2.gate.log
444 why="exit $grc in $((e1 - e0)) s, out: $gout, receipt: $(cat "$rp" 2>&1), log: $(cat "$lg" 2>&1)"
445 [ "$grc" = 1 ] && [ "$gout" = "forge gate rad:zForgeGate head=$g2 gate_rc=124 negctl_rc=1 receipt=$rp" ] &&
446 [ "$(key gate_rc "$rp")" = 124 ] && [ "$(key negctl_rc "$rp")" = 1 ] && [ "$(wc -l < "$rp")" -eq 14 ] &&
447 [ "$(cat "$lg")" = "before-timeout
448$tline" ] && [ "$(key log_sha256 "$rp")" = "$(sha256sum < "$lg" | cut -d' ' -f1)" ] &&
449 [ $((e1 - e0)) -lt 10 ]
450 check gate-timeout-receipt-and-log $?
451 out=$("$b" decide "$g2" "$G/v2.verdict.txt" "$rp" 2>&1)
452 why="decide: $out"
453 [ "$out" = 'HOLD GATE_TIMEOUT' ]
454 check gate-timeout-holds $?
455 out=$("$b" decide --json "$g2" "$G/v2.verdict.txt" "$rp" 2>&1)
456 why="decide --json: $out"
457 [ "$out" = "{\"schema\":\"forge-decision/1\",\"head\":\"$g2\",\"decision\":\"HOLD\",\"reason\":\"GATE_TIMEOUT\"}" ]
458 check gate-timeout-holds-json $?
459 # the child sleeper died with its group (polled: a killed orphan is reaped by init shortly after)
460 k=$(cat "$G/tkid" 2>/dev/null)
461 i=0
462 while [ -n "$k" ] && kill -0 "$k" 2>/dev/null && [ "$i" -lt 40 ]; do
463 sleep 0.05
464 i=$((i + 1))
465 done
466 why="child sleeper pid '$k' still alive"
467 [ -n "$k" ] && ! kill -0 "$k" 2>/dev/null
468 check gate-timeout-kills-process-group $?
469 # the direct child (pid written by sh, which then execs joinpg in place) joins forge's own
470 # process group and sleeps 20 s, so the group kill misses it: the kill by pid must still end
471 # it at the timeout (a miss waits out the 10 s reap deadline and leaves joinpg alive)
472 rm -f "$G/jkid"
473 e0=$(date +%s)
474 gate "$b" "$g2" --name tjoin --timeout 1 --out "$O" --author "$A" --neg false -- sh -c "echo \$\$ > $G/jkid; exec $T/joinpg"
475 e1=$(date +%s)
476 rp=$O/tjoin-$s2.receipt.txt
477 lg=$O/tjoin-$s2.gate.log
478 k=$(cat "$G/jkid" 2>/dev/null)
479 why="exit $grc in $((e1 - e0)) s, joiner pid '$k', out: $gout, receipt: $(cat "$rp" 2>&1), log: $(cat "$lg" 2>&1)"
480 [ "$grc" = 1 ] && [ "$(key gate_rc "$rp")" = 124 ] && [ "$(key negctl_rc "$rp")" = 1 ] &&
481 [ "$(cat "$lg")" = "$tline" ] && [ $((e1 - e0)) -lt 6 ] &&
482 [ -n "$k" ] && ! kill -0 "$k" 2>/dev/null
483 check gate-timeout-kills-leader-that-left $?
484 e0=$(date +%s)
485 gate "$b" "$g2" --name ntmo --timeout 1 --out "$O" --author "$A" --neg sh -c "sleep 20 & echo \$! > $G/nkid; wait" -- true
486 e1=$(date +%s)
487 rp=$O/ntmo-$s2.receipt.txt
488 lg=$O/ntmo-$s2.negctl.log
489 out=$("$b" decide "$g2" "$G/v2.verdict.txt" "$rp" 2>&1)
490 why="exit $grc in $((e1 - e0)) s, out: $gout, decide: $out, receipt: $(cat "$rp" 2>&1), negctl log: $(cat "$lg" 2>&1)"
491 [ "$grc" = 1 ] && [ "$(key gate_rc "$rp")" = 0 ] && [ "$(key negctl_rc "$rp")" = 124 ] &&
492 [ "$(cat "$lg")" = "$tline" ] && [ "$(key negctl_log_sha256 "$rp")" = "$(sha256sum < "$lg" | cut -d' ' -f1)" ] &&
493 [ "$out" = 'HOLD GATE_TIMEOUT' ] && [ $((e1 - e0)) -lt 10 ]
494 check gate-negctl-timeout-holds $?
495 k=$(cat "$G/nkid" 2>/dev/null)
496 i=0
497 while [ -n "$k" ] && kill -0 "$k" 2>/dev/null && [ "$i" -lt 40 ]; do
498 sleep 0.05
499 i=$((i + 1))
500 done
501 why="negctl child sleeper pid '$k' still alive"
502 [ -n "$k" ] && ! kill -0 "$k" 2>/dev/null
503 check gate-negctl-timeout-kills-process-group $?
504 # a run that ends inside the timeout is unaffected: its child finishes, no timeout line
505 gate "$b" "$g2" --name intime --timeout 5 --out "$O" --author "$A" --neg false -- sh -c 'sleep 1 & wait; echo done'
506 rp=$O/intime-$s2.receipt.txt
507 out=$("$b" decide "$g2" "$G/v2.verdict.txt" "$rp" 2>&1)
508 why="exit $grc, decide: $out, log: $(cat "$O/intime-$s2.gate.log" 2>&1)"
509 [ "$grc" = 0 ] && [ "$(key gate_rc "$rp")" = 0 ] && [ "$(cat "$O/intime-$s2.gate.log")" = done ] && [ "$out" = 'MERGE OK' ]
510 check gate-within-timeout-unaffected $?
511 gate "$b" "$g2" --name tmax --timeout 86400 --out "$O" --author "$A" --neg false -- true
512 [ "$grc" = 0 ]
513 check gate-timeout-86400-accepted $?
514 for tv in 0 86401 1x '' 99999999; do
515 gate "$b" "$g2" --name bad --timeout "$tv" --out "$O" --author "$A" --neg false -- true
516 why="--timeout '$tv': exit $grc, out: $gout"
517 [ "$grc" = 2 ] && [ "$gout" = 'forge: bad --timeout (whole seconds, 1 to 86400)' ]
518 check "gate-timeout-'$tv'-refused" $?
519 done
520 gate "$b" "$g2" --name bad --timeout 5 --timeout 5 --out "$O" --author "$A" --neg false -- true
521 [ "$grc" = 2 ]
522 check gate-duplicate-timeout-refused $?
523 gout=$(env -i HOME="$G/home" PATH="$G/bin:$PATH" RAD_HOME="$G/rh" "$b" gate zForgeGate "$g2" --name bad --out "$O" --author "$A" --neg false -- true 2>&1)
524 grc=$?
525 [ "$grc" = 2 ]
526 check gate-rid-without-rad-refused $?
527 why="left behind: $(ls "$O" "$G" | grep -e '^bad-' -e '^bad2-')"
528 ! ls "$O" "$G" | grep -q -e '^bad-' -e '^bad2-'
529 check gate-errors-write-no-receipt $?
530}
531
532# suite BIN TAG: every check above against one binary; failures counted in $fails, named in $failed
533suite() {
534 TAG=$2
535 fails=0
536 nchk=0
537 failed=
538 run_cases "$1"
539 run_status "$1"
540 run_gate "$1"
541}
542
543if ! "$OMC" < "$root/forge/forge.om" > "$T/forge"; then
544 echo "FAIL forge/forge.om does not compile"
545 exit 1
546fi
547chmod +x "$T/forge"
548if ! "$OMC" < "$here/joinpg.om" > "$T/joinpg"; then
549 echo "FAIL forge/tests/joinpg.om does not compile"
550 exit 1
551fi
552chmod +x "$T/joinpg"
553suite "$T/forge" base
554ncase=$(grep -c '^[a-z]' "$here/cases.txt")
555nbase=$nchk
556case_fail=$fails
557echo "CHECKS $((nbase - case_fail))/$nbase pass (cases.txt $ncase, status, gate)"
558
559mut_fail=0
560nmut=0
561while IFS='|' read -r mname line orig repl; do
562 case $mname in '#'*|'') continue ;; esac
563 nmut=$((nmut + 1))
564 have=$(sed -n "${line}p" "$root/forge/forge.om")
565 if [ "$have" != "$orig" ]; then
566 echo "FAIL mutant $mname: line $line is '$have', not '$orig' (stale mutants.txt)"
567 mut_fail=$((mut_fail + 1))
568 continue
569 fi
570 sed "${line}s/.*/$repl/" "$root/forge/forge.om" > "$T/m.om"
571 if cmp -s "$root/forge/forge.om" "$T/m.om"; then
572 echo "FAIL mutant $mname: mutation changed nothing"
573 mut_fail=$((mut_fail + 1))
574 continue
575 fi
576 if ! "$OMC" < "$T/m.om" > "$T/m" 2> "$T/m.err"; then
577 echo "FAIL mutant $mname: does not compile ($(cat "$T/m.err")), so it proves nothing"
578 mut_fail=$((mut_fail + 1))
579 continue
580 fi
581 chmod +x "$T/m"
582 suite "$T/m" mutant
583 if [ "$fails" -gt 0 ]; then
584 echo "CAUGHT mutant $mname by$failed"
585 else
586 echo "FAIL mutant $mname survived every check"
587 mut_fail=$((mut_fail + 1))
588 fi
589done < "$here/mutants.txt"
590echo "MUTANTS $((nmut - mut_fail))/$nmut caught"
591
592if [ "$case_fail" -eq 0 ] && [ "$mut_fail" -eq 0 ]; then
593 echo "FORGE_PASS checks=$nbase cases=$ncase mutants=$nmut omc=$PIN"
594 exit 0
595fi
596echo "FORGE_FAIL check_failures=$case_fail mutant_failures=$mut_fail"
597exit 1