interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tools / trit / test.sh

324 lines · 27378 bytes Raw Blame History
1#!/bin/sh
2# test.sh -- fixture tests for tools/trit.
3# Usage: ./test.sh from tools/trit, or sh tools/trit/test.sh from the repo root.
4# BIN defaults to <repo>/build/trit/trit if present, else trit.bin beside this script.
5# CBIN defaults to <repo>/build/codebook/codebook, else codebook.bin beside tools/codebook.
6# Every case builds its own DIR/inbox under $FIX/<case> (kept as the fixture), runs the binary, and
7# compares stdout, stderr and exit status exactly. Expected tokens and cursor hashes come from
8# coreutils (head, wc, sha256sum), not from the program.
9set -u
10HERE=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
11ROOT=$(CDPATH= cd -- "$HERE/../.." && pwd)
12if [ -z "${BIN:-}" ]; then
13 if [ -x "$ROOT/build/trit/trit" ]; then BIN=$ROOT/build/trit/trit
14 elif [ -x "$HERE/trit.bin" ]; then BIN=$HERE/trit.bin
15 else echo "test.sh: no trit binary ($ROOT/build/trit/trit or $HERE/trit.bin)" >&2; exit 2
16 fi
17fi
18case $BIN in /*) ;; *) BIN=$(pwd)/$BIN ;; esac
19if [ -z "${CBIN:-}" ]; then
20 if [ -x "$ROOT/build/codebook/codebook" ]; then CBIN=$ROOT/build/codebook/codebook
21 elif [ -x "$HERE/../codebook/codebook.bin" ]; then CBIN=$HERE/../codebook/codebook.bin
22 else echo "test.sh: no codebook binary" >&2; exit 2
23 fi
24fi
25CBT=${CBT:-$HERE/../codebook/codebook.tsv}
26FIX=${FIX:-${TMPDIR:-/tmp}/trit-fixtures.$$}
27rm -rf "$FIX"; mkdir -p "$FIX"; chmod 700 "$FIX"
28KEY=$FIX/.key; KEY2=$FIX/.key2; (umask 077; head -c 32 /dev/urandom > "$KEY"; head -c 32 /dev/urandom > "$KEY2")
29chmod 600 "$KEY" "$KEY2"
30printf 'BIN %s\nFIX %s\n' "$BIN" "$FIX"
31pass=0; fail=0; skip=0
32ok() { pass=$((pass+1)); printf 'PASS %s\n' "$1"; }
33no() { fail=$((fail+1)); printf 'FAIL %s: %s\n' "$1" "$2"; }
34skip() { skip=$((skip+1)); printf 'SKIP %s\n' "$1"; }
35# ELF e_machine: 183=AArch64, 62=x86-64. Prefer native strace -f when the binary runs natively;
36# otherwise qemu-user -strace if qemu is on PATH; else SKIP (never PASS).
37elf_em() { od -An -N2 -j 18 -t u2 "$1" | tr -d ' \n'; }
38host_em() { case "$(uname -m)" in aarch64|arm64) echo 183;; x86_64|amd64) echo 62;; *) echo 0;; esac; }
39pick_tracer() {
40 TRC=
41 if [ "$(elf_em "$1")" = "$(host_em)" ] && command -v strace >/dev/null 2>&1; then
42 TRC=strace
43 elif command -v qemu-aarch64-static >/dev/null 2>&1; then
44 TRC=$(command -v qemu-aarch64-static)
45 elif command -v qemu-aarch64 >/dev/null 2>&1; then
46 TRC=$(command -v qemu-aarch64)
47 fi
48}
49# Every fixture gets DIR/codebook/{codebook.tsv,key} (a fresh random test key, never printed).
50new() { D="$FIX/$1"; mkdir -p "$D/inbox" "$D/codebook"; cp "$CBT" "$D/codebook/codebook.tsv"; cp "$KEY" "$D/codebook/key"; chmod 600 "$D/codebook/key"; C=$1; LANE=n; TO=a; }
51L() { printf '%s|%s|%s|%s|-\n' "$1" "$2" "$3" "$4"; }
52# S TS SENDER TAG TEXT COUNTER DIGITS [KEYFILE]: a 6-field line signed as ocb2 (lane=$LANE, to=$TO).
53sg() { printf '%s|%s|%s|%s|%s|%s|%s|%s|%s\n' "${LANE:-n}" "$1" "$2" "${TO:-a}" "$3" "$4" "-" "$5" "$6" | "$CBIN" sign "$CBT" "${7:-$KEY}"; }
54S() { printf '%s|%s|%s|%s|%s|%s|%s\n' "$1" "$2" "${TO:-a}" "$3" "$4" "-" "$(sg "$1" "$2" "$3" "$4" "$5" "$6" "${7:-}")"; }
55Se() { LANE=e S "$@"; LANE=n; }
56HDR='# Inbox: a
57One line per note: `YYYY-MM-DDTHH:MM|from|tag|text|ref`.'
58# tokf LANE FILE: L<offset of the end of the last complete line>:<sha256 of that line>
59tokf() {
60 nl=$(tr -dc '\n' < "$2" | wc -c | tr -d ' ')
61 off=$(head -n "$nl" "$2" | wc -c | tr -d ' ')
62 h=$(head -c "$off" "$2" | sha256sum | cut -c1-64)
63 printf '%s%s:%s' "$1" "$off" "$h"
64}
65# ex LANE BOT TRIT: the expected output line (nothing for 0: silence)
66ex() {
67 if [ "$3" = 0 ]; then return; fi
68 if [ "$1" = e ]; then f="$D/inbox/$2.emergency.md"; else f="$D/inbox/$2.md"; fi
69 printf '%s %s %s' "$2" "$3" "$(tokf "$1" "$f")"
70}
71# run NAME EXPECT_STDOUT EXPECT_STDERR ARGS... (exit 0 when a line is printed, 1 when silent)
72run() {
73 n=$1; eo=$2; ee=$3; shift 3
74 wrc=0; [ -z "$eo" ] && wrc=1
75 o=$("$BIN" "$D" "$@" 2>"$D/.err"); rc=$?; e=$(cat "$D/.err"); rm -f "$D/.err"
76 if [ "$rc" = "$wrc" ] && [ "$o" = "$eo" ] && [ "$e" = "$ee" ]; then ok "$C/$n"; else no "$C/$n" "rc=$rc out=[$o] err=[$e] want=$wrc [$eo] [$ee]"; fi
77}
78# refuse NAME RC ARGS...: expects that exit status, no stdout, and cursor files unchanged
79refuse() {
80 n=$1; want=$2; shift 2
81 before=$(cat "$D"/inbox/*.cur 2>/dev/null | sha256sum)
82 o=$("$BIN" "$D" "$@" 2>/dev/null); rc=$?
83 after=$(cat "$D"/inbox/*.cur 2>/dev/null | sha256sum)
84 if [ "$rc" = "$want" ] && [ -z "$o" ] && [ "$before" = "$after" ]; then ok "$C/$n"; else no "$C/$n" "rc=$rc out=[$o] cursor-changed=$([ "$before" = "$after" ] && echo no || echo yes)"; fi
85}
86tok() { "$BIN" "$D" a 2>/dev/null | cut -d' ' -f3; }
87T1=2026-11-15T12:00; T2=2026-11-15T12:05; T3=2026-11-15T12:10
88
89new zero-header-only; printf '%s\n' "$HDR" > "$D/inbox/a.md"; run t "" "" a
90new one-unread; { printf '%s\n' "$HDR"; L $T1 drake-bot turn "do it"; } > "$D/inbox/a.md"; run t "$(ex n a 1)" "" a
91new stop-tag-unsigned; L $T1 drake-bot stop halt > "$D/inbox/a.md"; run is-1 "$(ex n a 1)" "" a
92new stop-text-unsigned; L $T1 drake-bot fyi "STOP now" > "$D/inbox/a.md"; run is-1 "$(ex n a 1)" "" a
93new stop-to-field; printf '%s|drake-bot|a|stop|halt|-\n' $T1 > "$D/inbox/a.md"; run is-1 "$(ex n a 1)" "" a
94new empty-inbox; : > "$D/inbox/a.md"; run t "" "" a
95new missing-inbox; run t "" "" a
96new partial-line; { printf '%s\n' "$HDR"; printf '%s|x|turn|half|-' $T1; } > "$D/inbox/a.md"; run before-newline "" "" a
97 printf '\n' >> "$D/inbox/a.md"; run after-newline "$(ex n a 1)" "" a
98new multi-bot; L $T1 x turn t > "$D/inbox/a.md"; : > "$D/inbox/b.md"; TO=c S $T1 drake stop s 1 300 > "$D/inbox/c.md"; TO=a
99 run t "$(ex n a 1)
100$(ex n c 2)" "" a b c
101
102# Signed lines (tools/codebook format, last '|' field ocb1:<cbsha>:<counter>:<digits>:<mac>).
103new signed; S $T1 drake stop halt 1 300 > "$D/inbox/a.md"; run verified-300-is-2 "$(ex n a 2)" "" a
104 S $T1 drake turn work 1 100 > "$D/inbox/a.md"; run verified-100-is-1 "$(ex n a 1)" "" a
105 S $T1 drake fyi note 1 100 > "$D/inbox/a.md"; run verified-fyi-100-silent "" "" a
106 S $T1 drake fyi note 1 301 > "$D/inbox/a.md"; run verified-fyi-301-is-2 "$(ex n a 2)" "" a
107 S $T1 drake turn x 1 900300 > "$D/inbox/a.md"; run escape-then-300-unknown-is-1 "$(ex n a 1)" "" a
108 S $T1 drake fyi n 1 100 > "$D/inbox/a.md"; run to-format-sig-stripped-fyi-silent "" "" a
109 S $T1 drake turn "STOP" 1 001 > "$D/inbox/a.md"; run verified-non-3xx-STOP-is-1 "$(ex n a 1)" "" a
110 if [ -e "$D/inbox/a.drake.ctr" ]; then no "$C/read-does-not-write-counter" "ctr exists"; else ok "$C/read-does-not-write-counter"; fi
111new tampered; S $T1 drake stop h 1 300 | sed 's/:300:/:301:/' > "$D/inbox/a.md"; run digits-changed-is-1 "$(ex n a 1)" "" a
112 S $T1 drake stop h 1 300 | sed 's/|drake|/|b|/' > "$D/inbox/a.md"; run sender-changed-is-1 "$(ex n a 1)" "" a
113 S $T1 drake stop h 1 300 "$KEY2" > "$D/inbox/a.md"; run other-key-is-1 "$(ex n a 1)" "" a
114 S $T1 drake stop h 1 300 | sed 's/:1:300:/:2:300:/' > "$D/inbox/a.md"; run counter-changed-is-1 "$(ex n a 1)" "" a
115 printf '%s|drake|stop|h|-|ocb1:%064d:1:300:%064d\n' $T1 0 0 > "$D/inbox/a.md"; run wrong-cbsha-is-1 "$(ex n a 1)" "" a
116 printf '%s|drake|stop|STOP|-\n' $T1 > "$D/inbox/a.md"; run unsigned-STOP-is-1 "$(ex n a 1)" "" a
117new stale; printf '5\n' > "$D/inbox/a.drake.ctr"; S $T1 drake stop h 5 300 > "$D/inbox/a.md"; run equal-counter-is-1 "$(ex n a 1)" "" a
118 S $T1 drake stop h 6 300 > "$D/inbox/a.md"; run higher-counter-is-2 "$(ex n a 2)" "" a
119 printf 'junk\n' > "$D/inbox/a.drake.ctr"; run malformed-counter-file-is-1 "$(ex n a 1)" "" a
120 rm -f "$D/inbox/a.drake.ctr"; { S $T1 drake turn a 5 100; S $T2 drake stop b 3 300; } > "$D/inbox/a.md"
121 run lower-counter-later-in-batch-is-1 "$(ex n a 1)" "" a
122new replay; S $T1 drake stop h 1 300 > "$D/inbox/a.md"; cp "$D/inbox/a.md" "$D/line"
123 run first-is-2 "$(ex n a 2)" "" a
124 t=$(tok); run ack "a 0" "" --ack a "$t"
125 if [ "$(cat "$D/inbox/a.drake.ctr")" = "1 $T1" ]; then ok "$C/ack-advanced-counter"; else no "$C/ack-advanced-counter" "$(cat "$D/inbox/a.drake.ctr" 2>&1)"; fi
126 if [ "$(stat -c %a "$D/inbox/a.drake.ctr")" = 600 ]; then ok "$C/counter-mode-600"; else no "$C/counter-mode-600" "$(stat -c %a "$D/inbox/a.drake.ctr")"; fi
127 if [ -e "$D/inbox/a.ctr.lock" ] && [ ! -e "$D/inbox/a.drake.ctr.tmp" ]; then ok "$C/lock-file-no-tmp"; else no "$C/lock-file-no-tmp" "$(ls "$D/inbox")"; fi
128 cat "$D/line" >> "$D/inbox/a.md"; run replayed-copy-is-1 "$(ex n a 1)" "" a
129 cp "$D/line" "$D/inbox/b.md"; run other-bot-copy-is-1 "$(ex n b 1)" "" b
130new no-codebook; rm -rf "$D/codebook"; S $T1 drake stop h 1 300 > "$D/inbox/a.md"; run no-codebook-is-1 "$(ex n a 1)" "" a
131 mkdir -p "$D/codebook"; cp "$CBT" "$D/codebook/codebook.tsv"; run no-key-is-1 "$(ex n a 1)" "" a
132 cp "$KEY" "$D/codebook/key"; printf 'bad\n' >> "$D/codebook/codebook.tsv"
133 "$BIN" "$D" a >/dev/null 2>&1; rc=$?; if [ "$rc" = 4 ]; then ok "$C/invalid-codebook-exit-4"; else no "$C/invalid-codebook-exit-4" "rc=$rc"; fi
134new syscalls; S $T1 drake stop h 1 300 > "$D/inbox/a.md"; t=$(tok)
135 pick_tracer "$BIN"
136 if [ -z "$TRC" ]; then
137 echo "note: no strace/qemu tracer; syscall order not checked"
138 skip "$C/lock-ctr-rename-dirsync-unlock-cursor-rename-dirsync"
139 else
140 if [ "$TRC" = strace ]; then
141 strace -f -o "$D/trace" "$BIN" "$D" --ack a "$t" > /dev/null 2> "$D/err" || true
142 else
143 "$TRC" -strace "$BIN" "$D" --ack a "$t" > /dev/null 2> "$D/trace" || true
144 fi
145 got=$(awk -v inbox="$D/inbox" '
146 /flock\([0-9]+, *(2|LOCK_EX)/ { printf "L"; next }
147 /flock\([0-9]+, *(8|LOCK_UN)/ { printf "U"; next }
148 /renameat2/ { printf "R"; next }
149 /[^a-z]fsync\(/ || /^[0-9]+ fsync\(/ || / fsync\(/ { printf "F"; next }
150 index($0, "openat(AT_FDCWD, \"" inbox "\"") || index($0, "openat(AT_FDCWD,\"" inbox "\"") { printf "D"; next }
151 ' "$D/trace")
152 if [ "$got" = LFRDFUFRDF ]; then ok "$C/lock-ctr-rename-dirsync-unlock-cursor-rename-dirsync"; else no "$C/syscall-order" "$got"; fi
153 fi
154
155new ack-advances; { printf '%s\n' "$HDR"; L $T1 x turn one; S $T2 drake stop two 1 300; } > "$D/inbox/a.md"
156 run before "$(ex n a 2)" "" a
157 t=$(tok); run ack "a 0" "" --ack a "$t"
158 run after "" "" a
159 off=$(wc -c < "$D/inbox/a.md" | tr -d ' ')
160 want=$(sha256sum < "$D/inbox/a.md" | cut -c1-64)
161 if [ "$(cat "$D/inbox/a.md.cur")" = "$off $want" ]; then ok "$C/cursor-is-offset-and-sha256"; else no "$C/cursor" "$(cat "$D/inbox/a.md.cur") want $off $want"; fi
162 if [ -e "$D/inbox/a.md.cur.tmp" ]; then no "$C/no-temp-left" "tmp exists"; else ok "$C/no-temp-left"; fi
163 run reack-same-token-is-noop "a 0" "" --ack a "$t"
164 L $T3 x turn three >> "$D/inbox/a.md"; run new-line "$(ex n a 1)" "" a
165 S $T3 drake stop p 2 300 | tr -d '\n' >> "$D/inbox/a.md"; run partial-not-counted "$(ex n a 1)" "" a
166 t=$(tok); run ack2 "a 0" "" --ack a "$t"
167 printf '\n' >> "$D/inbox/a.md"; run partial-completed "$(ex n a 2)" "" a
168new ack-race; L $T1 x turn read-me > "$D/inbox/a.md"
169 t=$(tok); S $T2 drake stop arrived-after-read 1 300 >> "$D/inbox/a.md"
170 run ack-keeps-late-line-unread "a 0
171$(ex n a 2)" "" --ack a "$t"
172 o=${t%%:*}; if [ "$(cat "$D/inbox/a.md.cur")" = "${o#n} ${t#*:}" ]; then ok "$C/cursor-is-exactly-the-token"; else no "$C/cursor-is-exactly-the-token" "$(cat "$D/inbox/a.md.cur") vs $t"; fi
173 if [ -e "$D/inbox/a.drake.ctr" ]; then no "$C/late-line-counter-not-advanced" "advanced"; else ok "$C/late-line-counter-not-advanced"; fi
174 t=$(tok); run ack-late-line "a 0" "" --ack a "$t"
175new ack-race-emerg; L $T1 x turn n1 > "$D/inbox/a.md"
176 t=$(tok); Se $T2 drake alert fire 1 300 >> "$D/inbox/a.emergency.md"
177 run normal-ack-leaves-emergency "a 0
178$(ex e a 2)" "" --ack a "$t"
179 t=$(tok); Se $T3 drake alert fire2 2 301 >> "$D/inbox/a.emergency.md"
180 run emerg-ack-keeps-late-emergency "a 0
181$(ex e a 2)" "" --ack a "$t"
182 t=$(tok); run emerg-cleared "a 0" "" --ack a "$t"
183new ack-refusals; { L $T1 x turn one; L $T2 x turn two; } > "$D/inbox/a.md"
184 t1=$(tokf n "$D/inbox/a.md"); h1=${t1#*:}; o1=${t1%%:*}; o1=${o1#n}
185 first=$(head -n 1 "$D/inbox/a.md"); fo=$(printf '%s\n' "$first" | wc -c | tr -d ' ')
186 fh=$(printf '%s\n' "$first" | sha256sum | cut -c1-64)
187 refuse not-line-boundary 3 --ack a "n$((o1-1)):$h1"
188 refuse mid-line-with-matching-hash 3 --ack a "n$((o1-1)):$(head -c $((o1-1)) "$D/inbox/a.md" | sha256sum | cut -c1-64)"
189 refuse past-eof 3 --ack a "n$((o1+1)):$h1"
190 refuse zero-offset 3 --ack a "n0:$h1"
191 refuse wrong-hash 3 --ack a "n$o1:$fh"
192 refuse wrong-lane 3 --ack a "e$o1:$h1"
193 refuse bad-lane-letter 3 --ack a "x$o1:$h1"
194 refuse no-colon 3 --ack a "n$o1"
195 refuse short-hex 3 --ack a "n$o1:$(printf '%s' "$h1" | cut -c1-63)"
196 refuse upper-hex 3 --ack a "n$o1:$(printf '%s' "$h1" | tr a-f A-F)"
197 refuse no-digits 3 --ack a "n:$h1"
198 refuse plain-ack-removed 2 --ack a
199 run ack-first-line "a 0
200$(ex n a 1)" "" --ack a "n$fo:$fh"
201 run ack-all "a 0" "" --ack a "$t1"
202 refuse stale-behind-cursor 3 --ack a "n$fo:$fh"
203 { L $T1 x turn one; L $T2 x turn TWO; } > "$D/inbox/a.md"
204 refuse rewritten-since-read 3 --ack a "$t1"
205 run rewritten-shows-unread "$(ex n a 1)" "" a
206new oracle-cursor; { L $T1 x turn one; L $T2 x turn two; } > "$D/inbox/a.md"
207 h=$(sha256sum < "$D/inbox/a.md" | cut -c1-64)
208 printf '%s %s\n' "$(wc -c < "$D/inbox/a.md" | tr -d ' ')" "$h" > "$D/inbox/a.md.cur"; run external-cursor-accepted "" "" a
209new torn-write; { L $T1 x turn one; L $T2 x turn two; } > "$D/inbox/a.md"; t=$(tok); run ack "a 0" "" --ack a "$t"
210 printf 'garbage-from-a-crash' > "$D/inbox/a.md.cur.tmp"; run stale-tmp-ignored "" "" a
211 head -c 40 "$D/inbox/a.md.cur" > "$D/x" && mv "$D/x" "$D/inbox/a.md.cur"; run torn-cursor-fails-safe-unread "$(ex n a 1)" "" a
212 : > "$D/inbox/a.md.cur"; run empty-cursor-unread "$(ex n a 1)" "" a
213 t=$(tok); run ack-replaces-torn "a 0" "" --ack a "$t"
214 if [ -e "$D/inbox/a.md.cur.tmp" ]; then no "$C/tmp-renamed-away" "tmp exists"; else ok "$C/tmp-renamed-away"; fi
215new cursor-past-eof; { L $T1 x turn one; L $T2 x turn two; } > "$D/inbox/a.md"; t=$(tok); run ack "a 0" "" --ack a "$t"
216 L $T1 x turn one > "$D/inbox/a.md"; run truncated "$(ex n a 1)" "" a
217 printf '99999 %064d\n' 0 > "$D/inbox/a.md.cur"; run huge-offset "$(ex n a 1)" "" a
218new rewritten-file; { L $T1 x turn one; L $T2 x turn two; } > "$D/inbox/a.md"; t=$(tok); run ack "a 0" "" --ack a "$t"
219 { L $T1 x turn one; L $T2 x turn TWO; } > "$D/inbox/a.md"; run same-size-new-hash "$(ex n a 1)" "" a
220new mid-line-cursor; { L $T1 x turn one; L $T2 x turn two; } > "$D/inbox/a.md"; o=$(($(wc -c < "$D/inbox/a.md")-1))
221 printf '%s %s\n' "$o" "$(head -c "$o" "$D/inbox/a.md" | sha256sum | cut -c1-64)" > "$D/inbox/a.md.cur"
222 run hash-matching-mid-line-cursor-ignored "$(ex n a 1)" "" a
223new bad-cursor; L $T1 x turn one > "$D/inbox/a.md"; printf 'garbage\n' > "$D/inbox/a.md.cur"; run t "$(ex n a 1)" "" a
224new read-stop-ignored; L $T1 x stop old > "$D/inbox/a.md"; t=$(tok); run ack "a 0" "" --ack a "$t"
225 L $T2 x turn new >> "$D/inbox/a.md"; run t "$(ex n a 1)" "" a
226
227# Emergency lane: DIR/inbox/<bot>.emergency.md. Allowlist = drake + any slug with DIR/inbox/<slug>.md.
228# Only a verified 3xx is a 2 and jumps the normal lane; other admitted lines are 1 and wait for it.
229new emerg-jumps-line; { L $T1 x turn n1; L $T2 x turn n2; } > "$D/inbox/a.md"; Se $T1 drake alert fire 1 300 > "$D/inbox/a.emergency.md"
230 run pending "$(ex e a 2)" "" a
231 t=$(tok); run ack-clears-emergency-only "a 0
232$(ex n a 1)" "" --ack a "$t"
233 if [ -f "$D/inbox/a.md.cur" ]; then no "$C/normal-untouched" "normal cursor written"; else ok "$C/normal-untouched"; fi
234 t=$(tok); run ack-normal "a 0" "" --ack a "$t"
235new emerg-unsigned-waits; L $T1 x turn n > "$D/inbox/a.md"; L $T1 drake alert fire > "$D/inbox/a.emergency.md"
236 run normal-first "$(ex n a 1)" "" a
237 t=$(tok); run then-emergency-1 "a 0
238$(ex e a 1)" "" --ack a "$t"
239new emerg-over-stop; S $T1 drake stop halt 3 301 > "$D/inbox/a.md"; Se $T1 drake alert f 2 300 > "$D/inbox/a.emergency.md"
240 run t "$(ex e a 2)" "" a
241 t=$(tok); run ack-then-higher-counter-stop-visible "a 0
242$(ex n a 2)" "" --ack a "$t"
243 Se $T1 drake alert g 1 300 > "$D/inbox/a.emergency.md"; rm -f "$D/inbox/a.emergency.md.cur"; run lower-counter-emergency-is-1-and-waits "$(ex n a 2)" "" a
244new emerg-known-bot; : > "$D/inbox/a.md"; : > "$D/inbox/six-sigma.md"; Se $T1 six-sigma alert x 1 310 > "$D/inbox/a.emergency.md"; run t "$(ex e a 2)" "" a
245new emerg-unknown; L $T1 x turn n > "$D/inbox/a.md"; Se $T1 mallory alert x 1 300 > "$D/inbox/a.emergency.md"; run t "$(ex n a 1)" "rejected a 1" a
246new emerg-bad-slug; : > "$D/inbox/a.md"; { L $T1 ../a fyi x; L $T1 Drake fyi x; L $T1 '' fyi x; } > "$D/inbox/a.emergency.md"; run t "" "rejected a 3" a
247new emerg-bad-time; : > "$D/inbox/a.md"; { L 2026-11-15T25:00 drake alert x; L 2026-13-15T12:00 drake alert x; L 2026-11-15T12 drake alert x; } > "$D/inbox/a.emergency.md"; run t "" "rejected a 3" a
248new emerg-partial; : > "$D/inbox/a.md"; printf '%s|drake|fyi|x|-' $T1 > "$D/inbox/a.emergency.md"; run t "" "" a
249new emerg-header-only; : > "$D/inbox/a.md"; printf '# Emergency: a\n' > "$D/inbox/a.emergency.md"; run t "" "" a
250new emerg-flood; : > "$D/inbox/a.md"
251 i=0; for m in 00 10 20 30 40; do i=$((i+1)); Se 2026-11-15T12:$m drake alert "f$m" $i 300; done > "$D/inbox/a.emergency.md"
252 run five-in-window "$(ex e a 2)" "rejected a 2" a
253 t=$(tok); run ack "a 0" "" --ack a "$t"
254 Se 2026-11-15T12:50 drake alert f50 6 300 >> "$D/inbox/a.emergency.md"; run ack-does-not-refill "" "rejected a 1" a
255 Se 2026-11-15T13:21 drake alert f81 7 300 >> "$D/inbox/a.emergency.md"; run window-slides "$(ex e a 2)" "rejected a 1" a
256new emerg-forged-flood; : > "$D/inbox/a.md"
257 { for m in 00 01 02 03 04 05; do Se 2026-11-15T12:$m drake alert forged 9$m 300 "$KEY2"; done; Se 2026-11-15T12:06 drake alert real 1 300; Se 2026-11-15T12:07 drake alert real2 2 300; Se 2026-11-15T12:08 drake alert real3 3 301; } > "$D/inbox/a.emergency.md"
258 run forged-lines-use-no-quota "$(ex e a 2)" "" a
259new emerg-replay-flood; : > "$D/inbox/a.md"; Se 2026-11-15T12:00 drake alert r 1 300 > "$D/line"
260 { for j in 1 2 3 4 5; do cat "$D/line"; done; Se 2026-11-15T12:06 drake alert new 2 300; Se 2026-11-15T12:07 drake alert new3 3 300; } > "$D/inbox/a.emergency.md"
261 run replays-counted-once "$(ex e a 2)" "" a
262 Se 2026-11-15T12:08 drake alert new4 4 300 >> "$D/inbox/a.emergency.md"; run fourth-distinct-rejected "$(ex e a 2)" "rejected a 1" a
263new emerg-per-sender; : > "$D/inbox/a.md"; : > "$D/inbox/b.md"
264 { i=0; for m in 00 01 02 03; do i=$((i+1)); Se 2026-11-15T12:$m drake alert d $i 300; done; Se 2026-11-15T12:04 b alert b 1 300; } > "$D/inbox/a.emergency.md"
265 run t "$(ex e a 2)" "rejected a 1" a
266new emerg-day-wrap; : > "$D/inbox/a.md"
267 { Se 2026-12-31T23:30 drake alert x 1 300; Se 2026-12-31T23:40 drake alert x 2 300; Se 2026-12-31T23:50 drake alert x 3 300; Se 2027-01-01T00:20 drake alert x 4 300; Se 2027-01-01T00:41 drake alert x 5 300; } > "$D/inbox/a.emergency.md"
268 run year-boundary-window "$(ex e a 2)" "rejected a 1" a
269new emerg-rewritten; : > "$D/inbox/a.md"; Se $T1 drake alert x 1 300 > "$D/inbox/a.emergency.md"; t=$(tok); run ack "a 0" "" --ack a "$t"
270 Se $T1 drake alert y 2 300 > "$D/inbox/a.emergency.md"; run t "$(ex e a 2)" "" a
271
272# Silence, exact STOP (now at most 1 unsigned), fyi, full-prefix cursor hash.
273new silent; : > "$D/inbox/a.md"; : > "$D/inbox/b.md"; L $T1 x turn t > "$D/inbox/c.md"
274 run all-silent-exit-1 "" "" a b
275 run one-wakes-exit-0 "$(ex n c 1)" "" a b c
276new stop-exact; for t in "STOPWATCH x" "STOPS" "stop" "STOP-now" "Stop"; do L $T1 x turn "$t"; done > "$D/inbox/a.md"
277 run near-misses-are-1 "$(ex n a 1)" "" a
278 printf '%s|x|a|turn|STOP|-\n' $T1 > "$D/inbox/a.md"; run to-format-text-STOP-unsigned-is-1 "$(ex n a 1)" "" a
279 printf '%s|x|turn|STOP: halt|-\n' $T1 > "$D/inbox/a.md"; run STOP-colon-unsigned-is-1 "$(ex n a 1)" "" a
280new fyi; L $T1 x fyi "note only" > "$D/inbox/a.md"; run fyi-silent "" "" a
281 L $T2 x turn work >> "$D/inbox/a.md"; run fyi-plus-turn "$(ex n a 1)" "" a
282 L $T1 x fyi "STOP now" > "$D/inbox/a.md"; run fyi-STOP-wakes-1 "$(ex n a 1)" "" a
283 L $T1 drake fyi heads-up > "$D/inbox/a.emergency.md"; : > "$D/inbox/a.md"; run emergency-fyi-silent "" "" a
284new prefix-hash; { L $T1 x turn one; L $T2 x turn two; } > "$D/inbox/a.md"; t=$(tok); run ack "a 0" "" --ack a "$t"
285 { L $T1 x stop one; L $T2 x turn two; } > "$D/inbox/a.md"; run earlier-line-rewritten-in-place "$(ex n a 1)" "" a
286 refuse old-token-after-earlier-rewrite 3 --ack a "$t"
287new receipt; L $T1 x turn one > "$D/inbox/a.md"; t=$(tok)
288 run receipt-only "a 0" "" --ack a "$t"
289 run silent-after "" "" a
290
291
292# Binding (ocb2): a keyless copy or edit of a signed 3xx line is 1, never 2.
293new binding; S $T1 drake stop h 1 300 > "$D/inbox/a.md"; cp "$D/inbox/a.md" "$D/line"
294 run first-is-2 "$(ex n a 2)" "" a
295 TO=b S $T1 drake stop h 1 300 > "$D/inbox/a.md"; run to-mismatch-is-1 "$(ex n a 1)" "" a
296 cp "$D/line" "$D/inbox/a.emergency.md"; : > "$D/inbox/a.md"; run lane-copy-is-1 "$(ex e a 1)" "" a
297 cat "$D/line" | sed 's/|h|/|HACK|/' > "$D/inbox/a.md"; rm -f "$D/inbox/a.emergency.md"
298 run text-edit-is-1 "$(ex n a 1)" "" a
299 cat "$D/line" | sed 's/|stop|/|turn|/' > "$D/inbox/a.md"; run tag-edit-is-1 "$(ex n a 1)" "" a
300 cat "$D/line" | sed 's/|-|/|REF|/' > "$D/inbox/a.md"; run ref-edit-is-1 "$(ex n a 1)" "" a
301 cat "$D/line" | sed 's/2026-11-15T12:00/2027-11-15T12:00/' > "$D/inbox/a.md"
302 run ts-edit-is-1 "$(ex n a 1)" "" a
303 printf '1 %s\n' "$T2" > "$D/inbox/a.drake.ctr"; S $T1 drake stop h 2 300 > "$D/inbox/a.md"
304 run ts-regress-is-1 "$(ex n a 1)" "" a
305 printf '%s|drake|a|stop|h|-|ocb1:%064d:1:300:%064d\n' $T1 0 0 > "$D/inbox/a.md"
306 run ocb1-is-1 "$(ex n a 1)" "" a
307new key-mode; S $T1 drake stop h 1 300 > "$D/inbox/a.md"; chmod 644 "$D/codebook/key"
308 "$BIN" "$D" a >/dev/null 2>&1; rc=$?; if [ "$rc" = 5 ]; then ok "$C/world-readable-key-exit-5"; else no "$C/world-readable-key-exit-5" "rc=$rc"; fi
309new boards-key; D="$FIX/boards/kcase"; mkdir -p "$D/inbox" "$D/codebook"; C=boards-key
310 cp "$CBT" "$D/codebook/codebook.tsv"; cp "$KEY" "$D/codebook/key"; chmod 600 "$D/codebook/key"
311 S $T1 drake stop h 1 300 > "$D/inbox/a.md"
312 "$BIN" "$D" a >/dev/null 2>&1; rc=$?; if [ "$rc" = 5 ]; then ok "$C/key-inside-boards-exit-5"; else no "$C/key-inside-boards-exit-5" "rc=$rc"; fi
313
314new usage; : > "$D/inbox/a.md"
315 for args in "../x" "A" "--ack" "--ack a" "--ack a b c" "--trust-unsigned a"; do
316 "$BIN" "$D" $args >/dev/null 2>&1; rc=$?
317 if [ "$rc" = 2 ]; then ok "$C/refuse[$args]"; else no "$C/refuse[$args]" "rc=$rc"; fi
318 done
319 "$BIN" >/dev/null 2>&1; rc=$?; if [ "$rc" = 2 ]; then ok "$C/no-args"; else no "$C/no-args" "rc=$rc"; fi
320 S $T1 drake stop h 1 300 | sed 's/:300:/:301:/' > "$D/inbox/a.md"
321 "$BIN" --trust-unsigned "$D" a >/dev/null 2>&1; rc=$?; if [ "$rc" = 2 ]; then ok "$C/trust-flag-removed"; else no "$C/trust-flag-removed" "rc=$rc"; fi
322
323printf 'TOTAL pass=%d fail=%d skip=%d\n' "$pass" "$fail" "$skip"
324[ "$fail" = 0 ]