spark-connector
aien-dev/spark-connector
Brought by drakestapleton
spark-connector / gates / run.sh
| 1 | #!/bin/sh |
| 2 | # gates/run.sh -- the community runner gate. Builds the runner, a test copy of the hub (forged with the |
| 3 | # community slice, on a private port with scratch data), the test tools and the mutants, then runs |
| 4 | # every case; each case has a negative control that must fail the same check. This script only |
| 5 | # builds programs, runs them and compares bytes and exit codes. |
| 6 | # OMEGA_SRC omega-mv at b2ad967e (runner pin: seed/out/omc sha256 f4fa7951...) |
| 7 | # FORGE_SRC interplane-forge with community/ (hub pin: omc sha256 3ad9f10f..., FORGE_OMV) |
| 8 | # FORGE_OMV omega-mv at f4df8239 (default ~/work/flux/omega-mv), the forge's and salvage's pin |
| 9 | # GATE_PORT private port for the test hub (default 19631); GATE_CORES (default 8,9) |
| 10 | # KEEP=1 keep the scratch directory |
| 11 | # Exit 0 only when every case passes. Output: one PASS/FAIL line per check, then a summary. |
| 12 | set -u |
| 13 | R=$(cd "$(dirname "$0")/.." && pwd) |
| 14 | OMEGA_SRC=${OMEGA_SRC:-$R/../omega-mv} |
| 15 | FORGE_SRC=${FORGE_SRC:-$R/../interplane-forge} |
| 16 | FORGE_OMV=${FORGE_OMV:-$HOME/work/flux/omega-mv} |
| 17 | PORT=${GATE_PORT:-19631} |
| 18 | CORES=${GATE_CORES:-8,9} |
| 19 | RPIN=f4fa7951816bbd09c5eaaae6692852a70c3c305164b365027c5b683dec7d63e9 |
| 20 | HPIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194 |
| 21 | ROMC=$OMEGA_SRC/seed/out/omc |
| 22 | HOMC=$FORGE_OMV/seed/out/omc |
| 23 | T=$(mktemp -d /tmp/ipcc-gate.XXXXXX) |
| 24 | PASS=0; FAIL=0 |
| 25 | ok() { PASS=$((PASS+1)); echo "PASS $*"; } |
| 26 | bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } |
| 27 | check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; } |
| 28 | HUBPID=; LPID= |
| 29 | cleanup() { |
| 30 | [ -n "$HUBPID" ] && kill "$HUBPID" 2>/dev/null |
| 31 | for h in "$T"/m*/.interplane-runner; do [ -d "$h" ] && INTERPLANE_RUNNER_HOME=$h "$T/runner" stop >/dev/null 2>&1; done |
| 32 | [ -n "${KEEP:-}" ] || rm -rf "$T" |
| 33 | } |
| 34 | trap cleanup EXIT |
| 35 | |
| 36 | # ---- 0. compiler pins first; the negative control is a compiler with any other hash |
| 37 | [ "$(sha256sum < "$ROMC" | cut -d' ' -f1)" = "$RPIN" ] && ok "runner compiler pin $RPIN" || { bad "runner compiler is not the pin"; exit 1; } |
| 38 | [ "$(sha256sum < "$HOMC" | cut -d' ' -f1)" = "$HPIN" ] && ok "hub and job compiler pin $HPIN" || { bad "hub compiler is not the pin"; exit 1; } |
| 39 | cp "$HOMC" "$T/fakeomc" && printf x >> "$T/fakeomc" |
| 40 | rc=0; OMC=$T/fakeomc OMEGA_SRC=$OMEGA_SRC RUNNER_OUT=$T/x "$R/build.sh" > /dev/null 2>&1 || rc=$? |
| 41 | check "$rc" 2 "control: build.sh refuses a compiler that is not the pin" |
| 42 | |
| 43 | # ---- 1. build: runner, mutants, tools, test hub, seed fixture |
| 44 | b() { OMEGA_SRC=$OMEGA_SRC RUNNER_OUT=$T/$1 RUNNER_MUTANT=${2:-} "$R/build.sh" > "$T/$1.log" 2>&1 || { bad "build $1: $(tail -3 "$T/$1.log")"; exit 1; }; } |
| 45 | b runner |
| 46 | b liar "$R/gates/mutant-liar.sed" |
| 47 | b open "$R/gates/mutant-opencell.sed" |
| 48 | tool() { # tool NAME OMC UNITS... |
| 49 | n=$1; o=$2; shift 2 |
| 50 | { printf 'om2\n'; cat "$@"; } > "$T/$n.om" |
| 51 | "$o" < "$T/$n.om" > "$T/$n" 2> "$T/$n.err" || { bad "build $n: $(cat "$T/$n.err")"; exit 1; } |
| 52 | chmod +x "$T/$n" |
| 53 | } |
| 54 | TLS=$OMEGA_SRC/om/tls |
| 55 | tool signer "$ROMC" "$TLS/sha2.om" "$TLS/ec.om" "$TLS/ecdh.om" "$R/runner/00base.om" "$R/runner/10key.om" "$R/gates/signer.om" |
| 56 | tool celldrv "$ROMC" "$TLS/sha2.om" "$R/runner/00base.om" "$R/runner/30cell.om" "$R/gates/celldrv.om" |
| 57 | sed 's/^v = execpure pk 0 add 4 n$/v = execprog pk 0 add 4 n/' "$R/runner/30cell.om" > "$T/30cell-open.om" |
| 58 | tool celldrvo "$ROMC" "$TLS/sha2.om" "$R/runner/00base.om" "$T/30cell-open.om" "$R/gates/celldrv.om" |
| 59 | grep -q '^v = execprog' "$T/30cell-open.om" && ok "mutant cell built (execpure replaced by execprog)" || bad "mutant cell not built" |
| 60 | ( cd "$FORGE_SRC" && FORGE_TRY=community OMV=$FORGE_OMV ./run.sh units ) > "$T/units" 2>/dev/null || { bad "forge units"; exit 1; } |
| 61 | { printf 'om2\n'; while read -r f; do cat "$FORGE_SRC/$f" 2>/dev/null || cat "$f"; done < "$T/units"; } \ |
| 62 | | sed -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" -e "s/18480/$PORT/g" > "$T/hub.om" |
| 63 | mkdir -p "$T/data/logs" |
| 64 | taskset -c "$CORES" nice -n 10 "$HOMC" < "$T/hub.om" > "$T/hub" 2> "$T/hub.err" || { bad "build hub: $(cat "$T/hub.err")"; exit 1; } |
| 65 | chmod +x "$T/hub" |
| 66 | { sed 's/^fn main to int$/fn fmainx to int/' "$T/hub.om"; cat "$FORGE_SRC/community/tests/seed.om"; } > "$T/seed.om" |
| 67 | taskset -c "$CORES" nice -n 10 "$HOMC" < "$T/seed.om" > "$T/seed" 2> "$T/seed.err" || { bad "build seed: $(cat "$T/seed.err")"; exit 1; } |
| 68 | chmod +x "$T/seed" |
| 69 | ok "built runner $(sha256sum < "$T/runner" | cut -c1-16), hub $(sha256sum < "$T/hub" | cut -c1-16), tools and mutants" |
| 70 | |
| 71 | # ---- 2. scratch salvage store with published parts, then the hub |
| 72 | S=$T/salvage/; C=$T/community/; P=$T/pub/ |
| 73 | mkdir -m 700 "$S" "$C" "$P" "$P/dist"; : > "$P/deny" |
| 74 | H=$R/gates/hostile |
| 75 | publish() { # publish NAME SOURCE STDIN EXPECTED -> part id in $T/part.NAME |
| 76 | OMEGA_COMPILER=$HOMC taskset -c "$CORES" "$T/seed" "$S" "$2" "$3" "$4" "$1" > "$T/part.$1" 2> "$T/seed.$1.err" \ |
| 77 | && [ "$(wc -c < "$T/part.$1")" = 65 ] && ok "published part $1 $(cut -c1-16 "$T/part.$1")" || { bad "publish $1: $(cat "$T/seed.$1.err")"; exit 1; } |
| 78 | } |
| 79 | : > "$T/empty" |
| 80 | printf 'hello from a community machine\n' > "$T/hello.exp" |
| 81 | publish hello "$H/hello.om" "$T/empty" "$T/hello.exp" |
| 82 | printf 'socket -1\n' > "$T/net.exp"; printf '%s\n' "$PORT" > "$T/net.in" |
| 83 | publish probe "$H/net.om" "$T/net.in" "$T/net.exp" |
| 84 | PH=$(cut -c1-64 "$T/part.hello"); PP=$(cut -c1-64 "$T/part.probe") |
| 85 | startHub() { |
| 86 | INTERPLANE_SALVAGE_DIR=$S INTERPLANE_COMMUNITY_DIR=$C INTERPLANE_COMMUNITY_PUB=$P taskset -c "$CORES" nice -n 10 "${1:-$T/hub}" 2>> "$T/hub.stderr" & |
| 87 | HUBPID=$! |
| 88 | for i in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PORT/community/" && return 0; sleep 0.1; done |
| 89 | bad "hub did not start: $(tail -3 "$T/hub.stderr")"; exit 1 |
| 90 | } |
| 91 | startHub |
| 92 | B=http://127.0.0.1:$PORT |
| 93 | code() { curl -s -o "$T/body" -w '%{http_code}' "$@"; } |
| 94 | check "$(code $B/community/)" 200 "hub /community/ answers" |
| 95 | check "$(code $B/community/nope)" 404 "control: an unknown community path is 404" |
| 96 | |
| 97 | # a machine: its own state directory with the pinned job compiler, as the join line leaves it |
| 98 | machine() { mkdir -p "$T/$1/.interplane-runner/bin"; cp "$HOMC" "$T/$1/.interplane-runner/bin/omc"; } |
| 99 | run() { m=$1; shift; INTERPLANE_RUNNER_HOME=$T/$m/.interplane-runner "$@"; } |
| 100 | # the state folder must be named .interplane-runner, so leave can never remove anything else |
| 101 | mkdir -p "$T/mx/home" |
| 102 | rc=0; echo no | INTERPLANE_RUNNER_HOME=$T/mx/home "$T/runner" join "$B" > "$T/mx.out" 2>&1 || rc=$? |
| 103 | check "$rc:$(ls -A "$T/mx/home" | wc -l)" "2:0" "a state folder not named .interplane-runner is refused before anything is written" |
| 104 | rm -rf "$T/mx" |
| 105 | # the hub needs both roots: without INTERPLANE_COMMUNITY_PUB the slice is off |
| 106 | kill "$HUBPID"; wait "$HUBPID" 2>/dev/null |
| 107 | INTERPLANE_SALVAGE_DIR=$S INTERPLANE_COMMUNITY_DIR=$C taskset -c "$CORES" nice -n 10 "$T/hub" > /dev/null 2>> "$T/hub.stderr" & |
| 108 | HUBPID=$!; for i in $(seq 50); do curl -s -o /dev/null "$B/salvage/" && break; sleep 0.1; done |
| 109 | check "$(code $B/community/):$(curl -s -o /dev/null -w '%{http_code}' --data-binary 'ipcc1 next' "$B/community/api")" "404:503" "control: without the read-only root the community pages are 404 and the API answers off" |
| 110 | kill "$HUBPID"; wait "$HUBPID" 2>/dev/null |
| 111 | startHub |
| 112 | |
| 113 | # ---- 3. join / leave round trip leaves no file and no process |
| 114 | machine m0 |
| 115 | rc=0; echo no | run m0 "$T/runner" join "$B" > "$T/m0.join" 2>&1 || rc=$? |
| 116 | check "$rc:$(ls -A "$T/m0" | wc -l)" "1:0" "join answered 'no': exit 1, folder removed, nothing registered" |
| 117 | check "$(ls "$C/keys" | wc -l)" 0 "control: no key was registered after 'no'" |
| 118 | machine m0 |
| 119 | rc=0; echo no | run m0 "$T/runner" join https://x.io > /dev/null 2>&1 || rc=$? |
| 120 | check "$rc:$(ls -A "$T/m0" | wc -l)" "1:0" "a short hub address (https://x.io, shorter than the 17-byte test prefix) is parsed, then 'no' cancels" |
| 121 | machine m0 |
| 122 | rc=0; echo yes | run m0 "$T/runner" join "$B" > "$T/m0.join" 2>&1 || rc=$? |
| 123 | check "$rc" 0 "join answered 'yes'" |
| 124 | grep -q 'never leaves this computer' "$T/m0.join" && grep -q 'at most 30 checks an hour' "$T/m0.join" \ |
| 125 | && ok "join showed what it does, the limits and the volunteer's own setting" || bad "join statement missing" |
| 126 | K0=$(run m0 "$T/signer" pub | cut -d' ' -f2) |
| 127 | check "$(ls "$C/keys")" "$K0" "the hub registered the key $K0" |
| 128 | P0=$(cat "$T/m0/.interplane-runner/runner.pid" 2>/dev/null) |
| 129 | [ -n "$P0" ] && kill -0 "$P0" 2>/dev/null && ok "background runner running as process $P0" || bad "background runner not running" |
| 130 | # no inbound listen: the socket table of the runner process (and its worker children) |
| 131 | pids="$P0 $(pgrep -P "$P0" | tr '\n' ' ')" |
| 132 | ss -Htlnup > "$T/ss.txt" 2>/dev/null |
| 133 | n=0; for p in $pids; do grep -q "pid=$p," "$T/ss.txt" && n=$((n+1)); done |
| 134 | check "$n" 0 "runner processes ($pids) hold no listening TCP or UDP socket (ss -tlnup)" |
| 135 | grep -q "pid=$HUBPID," "$T/ss.txt" && ok "control: the same ss check sees the test hub's listener (pid $HUBPID)" || bad "control: ss did not show the hub listener" |
| 136 | cp "$T/ss.txt" "$T/evidence-ss.txt" |
| 137 | rc=0; run m0 "$T/runner" leave > "$T/m0.leave" 2>&1 || rc=$? |
| 138 | sleep 0.3 |
| 139 | check "$rc:$(ls -A "$T/m0" | wc -l)" "0:0" "leave: exit 0 and nothing left under the machine's folder" |
| 140 | kill -0 "$P0" 2>/dev/null && bad "runner process $P0 still alive after leave" || ok "no runner process left after leave" |
| 141 | check "$(awk '{print $NF}' "$C/keys/$K0")" l "the hub marks the key as left" |
| 142 | touch "$T/m0/stray"; check "$(ls -A "$T/m0" | wc -l)" 1 "control: the empty-folder check sees a stray file"; rm "$T/m0/stray" |
| 143 | machine m4; echo yes | run m4 "$T/runner" join "$B" > /dev/null 2>&1 |
| 144 | printf 'mine\n' > "$T/m4/.interplane-runner/notes.txt" |
| 145 | run m4 "$T/runner" leave > /dev/null 2>&1; sleep 0.3 |
| 146 | check "$(ls -A "$T/m4/.interplane-runner" | tr '\n' ' ')" "notes.txt " "leave removes the runner's own files by name and keeps a file it did not make (and so the folder)" |
| 147 | rm -rf "$T/m4" |
| 148 | |
| 149 | # ---- 3b. the one line: the join script from the hub, the downloads checked by SHA-256 |
| 150 | OMEGA_SRC=$OMEGA_SRC JOB_OMC=$HOMC "$R/dist.sh" "$B" "$P/dist" > "$T/dist.log" 2>&1 || { bad "dist.sh: $(tail -3 "$T/dist.log")"; exit 1; } |
| 151 | check "$(code $B/community/join):$(sha256sum < "$T/body" | cut -c1-64)" "200:$(sha256sum < "$P/dist/join.sh" | cut -c1-64)" "GET /community/join is the generated join.sh" |
| 152 | check "$(code $B/community/dl/SHA256SUMS):$(sha256sum < "$T/body" | cut -c1-64)" "200:$(sha256sum < "$P/dist/SHA256SUMS" | cut -c1-64)" "GET /community/dl/SHA256SUMS" |
| 153 | check "$(code "$B/community/dl/../keys"):$(code "$B/community/dl/.hidden")" "404:404" "control: no other file is served under /community/dl/" |
| 154 | mkdir -p "$T/jh" |
| 155 | cp "$P/dist/join.sh" "$T/join.sh" |
| 156 | # what volunteers download comes only from the read-only root: a join.sh and a deny planted in the |
| 157 | # writable record store (what a compromised server could write) are not used |
| 158 | mkdir -p "$C/dist"; printf 'echo planted\n' > "$C/dist/join.sh"; printf 'key %s\n' "$(printf '%064d' 0)" > "$C/deny" |
| 159 | check "$(code $B/community/join):$(sha256sum < "$T/body" | cut -c1-64)" "200:$(sha256sum < "$P/dist/join.sh" | cut -c1-64)" "a join.sh planted in the record store is not served (the read-only root is)" |
| 160 | rm -rf "$C/dist" "$C/deny" |
| 161 | # the literal line, in a pseudo-terminal (script(1)) so that the runner reads the yes from /dev/tty |
| 162 | rc=0; (sleep 3; printf 'yes\n') | HOME=$T/jh script -qec "curl -fsSL $B/community/join | sh" /dev/null > "$T/jh.out" 2>&1 || rc=$? |
| 163 | check "$rc:$(grep -c 'Joined. This computer' "$T/jh.out")" "0:1" "curl -fsSL <hub>/community/join | sh joined this machine (fresh HOME, a terminal answering yes)" |
| 164 | grep -q "interplane-runner sha256 $(sha256sum < "$T/runner" | cut -c1-64)" "$T/jh.out" && ok "the script printed the runner's sha256 and where to compare it" || bad "no sha256 line: $(head -5 "$T/jh.out")" |
| 165 | check "$(HOME=$T/jh "$T/jh/.interplane-runner/bin/interplane-runner" status | sed -n 's/^running: \(yes\).*/\1/p')" yes "the joined runner is running in the background" |
| 166 | HOME=$T/jh "$T/jh/.interplane-runner/bin/interplane-runner" leave > /dev/null 2>&1 |
| 167 | check "$(ls -A "$T/jh" | wc -l)" 0 "leave after the one-line join leaves nothing in HOME" |
| 168 | f=$(ls "$P/dist" | grep '^interplane-runner-'); cp "$P/dist/$f" "$T/good"; printf x >> "$P/dist/$f" |
| 169 | rc=0; echo yes | HOME=$T/jh sh "$T/join.sh" > "$T/jh.bad" 2>&1 || rc=$? |
| 170 | check "$rc:$(ls -A "$T/jh" | wc -l)" "1:0" "control: a download whose sha256 differs is refused and nothing is installed" |
| 171 | cp "$T/good" "$P/dist/$f" |
| 172 | |
| 173 | # ---- 4. a job runs, its signed result verifies (and an independent verifier, OpenSSL, agrees) |
| 174 | # join starts the background runner, which asks for work at once; with both parts deny-listed while |
| 175 | # the three machines join and stop, it gets "none", so every count below comes from `once` |
| 176 | for m in m1 m2 m3; do machine $m; done |
| 177 | printf 'part %s\npart %s\n' "$PH" "$PP" > "$P/deny" |
| 178 | echo yes | run m1 "$T/runner" join "$B" > /dev/null 2>&1; run m1 "$T/runner" stop > /dev/null |
| 179 | echo yes | run m2 "$T/runner" join "$B" > /dev/null 2>&1; run m2 "$T/runner" stop > /dev/null |
| 180 | echo yes | run m3 "$T/runner" join "$B" > /dev/null 2>&1; run m3 "$T/runner" stop > /dev/null |
| 181 | : > "$P/deny" |
| 182 | K1=$(run m1 "$T/signer" pub | cut -d' ' -f2); K2=$(run m2 "$T/signer" pub | cut -d' ' -f2); K3=$(run m3 "$T/signer" pub | cut -d' ' -f2) |
| 183 | rc=0; run m1 "$T/runner" once > "$T/m1.once" 2>&1 || rc=$? |
| 184 | check "$rc" 0 "machine 1 ran a job and the hub counted it" |
| 185 | grep -q ' -> ipcc1 ok counted' "$T/m1.once" && ok "machine 1 log: $(grep ' -> ' "$T/m1.once" | head -1 | cut -c1-120)" || bad "no counted line: $(cat "$T/m1.once")" |
| 186 | M1=$(awk -v k="$K1" '$2=="result" && $3==k {print $4}' "$C/ledger" | head -1) |
| 187 | [ -n "$M1" ] && ok "ledger holds the result message $M1" || bad "no result in the ledger" |
| 188 | # OpenSSL check: public key (SEC1) -> DER SubjectPublicKeyInfo, r||s -> DER ECDSA-Sig-Value |
| 189 | osslverify() { # osslverify MSGFILE PUBHEX -> exit of openssl dgst -verify |
| 190 | sed '$d' "$1" > "$T/v.msg" |
| 191 | sig=$(tail -1 "$1" | cut -d' ' -f2) |
| 192 | r=$(echo "$sig" | cut -c1-64); s=$(echo "$sig" | cut -c65-128) |
| 193 | der_int() { h=$1; while [ "${h#00}" != "$h" ] && [ ${#h} -gt 2 ]; do h=${h#00}; done |
| 194 | case $h in [89a-f]*) h=00$h ;; esac; printf '02%02x%s' $((${#h}/2)) "$h"; } |
| 195 | ri=$(der_int "$r"); si=$(der_int "$s") |
| 196 | printf '30%02x%s%s' $(((${#ri}+${#si})/2)) "$ri" "$si" | xxd -r -p > "$T/v.sig" |
| 197 | printf '3059301306072a8648ce3d020106082a8648ce3d030107034200%s' "$2" | xxd -r -p > "$T/v.der" |
| 198 | openssl dgst -sha256 -verify "$T/v.der" -keyform DER -signature "$T/v.sig" "$T/v.msg" > /dev/null 2>&1 |
| 199 | } |
| 200 | PUB1=$(run m1 "$T/signer" pub | cut -d' ' -f1) |
| 201 | osslverify "$C/msgs/$M1" "$PUB1" && ok "OpenSSL verifies the stored signed result with machine 1's public key" || bad "OpenSSL refused the stored result" |
| 202 | cp "$C/msgs/$M1" "$T/flip.msg"; sed -i '1s/result/resulT/' "$T/flip.msg" |
| 203 | osslverify "$T/flip.msg" "$PUB1" && bad "control: OpenSSL accepted a changed message" || ok "control: OpenSSL refuses the same message with one byte changed" |
| 204 | |
| 205 | # ---- 5. flipped signature byte; different revision; different compiler; replay |
| 206 | post() { curl -s -o "$T/body" -w '%{http_code}' --data-binary "@$1" -H 'Content-Type: text/plain' "$B/community/api"; } |
| 207 | flipsig() { awk 'BEGIN{FS=OFS=" "} /^sig /{c=substr($2,1,1); $2=(c=="0"?"1":"0") substr($2,2)} {print}' "$1"; } |
| 208 | flipsig "$C/msgs/$M1" > "$T/fs.msg" |
| 209 | check "$(post "$T/fs.msg"):$(head -c 26 "$T/body")" "403:ipcc1 refused signature" "a result with one signature byte changed is refused" |
| 210 | check "$(post "$C/msgs/$M1"):$(head -c 26 "$T/body")" "409:ipcc1 refused duplicate" "the same signed result sent again is refused as a duplicate" |
| 211 | run m1 "$T/signer" mall < "$C/msgs/$M1" > "$T/mall.msg" |
| 212 | osslverify "$T/mall.msg" "$PUB1" && ! cmp -s "$T/mall.msg" "$C/msgs/$M1" && ok "control: the malleated copy (s replaced by n - s) differs and is a valid signature (OpenSSL)" || bad "malleated copy not valid or not different" |
| 213 | check "$(post "$T/mall.msg"):$(head -c 26 "$T/body")" "409:ipcc1 refused duplicate" "the malleated copy is refused as a replay (the replay key is the signed bytes)" |
| 214 | cnt() { awk -v k="$1" '$2=="result" && $3==k && $6=="counted"' "$C/ledger" | wc -l; } |
| 215 | P1=$(awk -v k="$K1" '$2=="result" && $3==k {print $5}' "$C/ledger" | head -1) |
| 216 | check "$(cnt "$K1"):$(ls "$C/parts/$P1/k" 2>/dev/null | grep -c "$K1")" "1:1" "machine 1 is counted once for the part" |
| 217 | # a fresh signed job for machine 2, then results that change the revision or the compiler |
| 218 | signed() { run "$1" "$T/signer" sign; } |
| 219 | nextjob() { # nextjob MACHINE KEY -> job lines in $T/job |
| 220 | printf 'ipcc1 next\nkey %s\ntime %s\nnonce %s\n' "$2" "$(date +%s)" "$(od -An -tx1 -N16 /dev/urandom | tr -d ' \n')" | signed "$1" > "$T/n.msg" |
| 221 | post "$T/n.msg" > /dev/null; cp "$T/body" "$T/job" |
| 222 | } |
| 223 | result() { # result MACHINE KEY JOB PART COMP BIN OUT EXIT |
| 224 | printf 'ipcc1 result\nkey %s\njob %s\npart %s\ncompiler %s\nbinary %s\nstdout %s\nexit %s\ntime %s\n' "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$(date +%s)" | signed "$1" |
| 225 | } |
| 226 | nextjob m2 "$K2"; J=$(awk '$1=="job"{print $2}' "$T/job"); JP=$(awk '$1=="part"{print $2}' "$T/job") |
| 227 | [ -n "$J" ] && ok "machine 2 got job $J for part $(echo "$JP" | cut -c1-16)" || bad "machine 2 got no job: $(cat "$T/job")" |
| 228 | Z=0000000000000000000000000000000000000000000000000000000000000000 |
| 229 | OTHER=$( [ "$JP" = "$PH" ] && echo "$PP" || echo "$PH" ) |
| 230 | result m2 "$K2" "$J" "$OTHER" "$HPIN" "$Z" "$Z" 0 > "$T/rv.msg" |
| 231 | check "$(post "$T/rv.msg"):$(head -c 25 "$T/body")" "403:ipcc1 refused mismatch" "a result for a different revision than the job named is refused" |
| 232 | result m2 "$K2" "$J" "$JP" "$RPIN" "$Z" "$Z" 0 > "$T/rc.msg" |
| 233 | check "$(post "$T/rc.msg"):$(head -c 25 "$T/body")" "403:ipcc1 refused mismatch" "a result naming a different compiler is refused" |
| 234 | result m2 "$K2" 0123456789abcdef0123456789abcdef "$JP" "$HPIN" "$Z" "$Z" 0 > "$T/rj.msg" |
| 235 | check "$(post "$T/rj.msg"):$(head -c 20 "$T/body")" "403:ipcc1 refused job" "a result for a job never issued to this key is refused" |
| 236 | printf '%s %s %s %s\n' "$K2" "$JP" "$HPIN" "$(($(date +%s) - 3700))" > "$C/jobs/$J" |
| 237 | result m2 "$K2" "$J" "$JP" "$HPIN" "$Z" "$Z" 0 > "$T/rx.msg" |
| 238 | check "$(post "$T/rx.msg"):$(head -c 20 "$T/body")" "403:ipcc1 refused job" "a result for a job issued more than an hour ago is refused" |
| 239 | check "$(grep -c '' "$C/refused")" "$(grep -c '' "$C/refused")" "refusals are appended to the refused log ($(grep -c '' "$C/refused") lines)" |
| 240 | |
| 241 | # ---- 6. unregistered and deny-listed keys; size; volume alarms |
| 242 | machine mu; run mu "$T/signer" gen > "$T/mu.pub"; KU=$(cut -d' ' -f2 "$T/mu.pub") |
| 243 | nextjob mu "$KU" |
| 244 | check "$(head -c 26 "$T/job")" "ipcc1 refused unregistered" "a key that never registered is refused" |
| 245 | printf 'key %s\n' "$K2" >> "$P/deny" |
| 246 | nextjob m2 "$K2" |
| 247 | check "$(head -c 20 "$T/job")" "ipcc1 refused denied" "a deny-listed key is refused" |
| 248 | result m2 "$K2" "$J" "$JP" "$HPIN" "$Z" "$Z" 0 > "$T/rd.msg" |
| 249 | check "$(post "$T/rd.msg"):$(head -c 20 "$T/body")" "403:ipcc1 refused denied" "a result from a deny-listed key is refused" |
| 250 | : > "$P/deny" |
| 251 | printf 'part %s\n' "$PP" > "$P/deny" |
| 252 | nextjob m2 "$K2" |
| 253 | check "$(awk '$1=="part"{print $2}' "$T/job")" "$PH" "a deny-listed part is never handed out (machine 2 gets the other part)" |
| 254 | J2=$(awk '$1=="job"{print $2}' "$T/job") |
| 255 | : > "$P/deny" |
| 256 | head -c 4097 /dev/zero | tr '\0' 'a' > "$T/big.msg" |
| 257 | check "$(post "$T/big.msg"):$(head -c 21 "$T/body")" "413:ipcc1 refused size" "a body of 4097 bytes is refused" |
| 258 | head -c 4096 /dev/zero | tr '\0' 'a' > "$T/max.msg" |
| 259 | check "$(post "$T/max.msg"):$(head -c 26 "$T/body")" "400:ipcc1 refused malformed" "control: 4096 bytes pass the size check (then fail the form)" |
| 260 | # volume is watched, not refused (decision 2026-11-11): per key 150 accepted messages an hour, all |
| 261 | # keys 3600, refusals 3600 are alarm thresholds; passing one writes one line to alarms naming who |
| 262 | check "$(code "$B/community/alarms")" 404 "control: no alarm yet" |
| 263 | printf '%s 150\n' "$(date +%s)" > "$C/rate/$K2" |
| 264 | nextjob m2 "$K2"; check "$(head -c 12 "$T/job")" "ipcc1 ok job" "the 151st message of the hour from one key is accepted (no volume refusal)" |
| 265 | check "$(grep -c "ALARM signed-messages $K2 passed 150 in the hour: 151" "$C/alarms")" 1 "and one alarm line names the key and the count" |
| 266 | nextjob m2 "$K2"; check "$(grep -c "$K2" "$C/alarms")" 1 "control: the next message adds no second alarm in the same hour" |
| 267 | printf '%s 3600\n' "$(date +%s)" > "$C/rate/all" |
| 268 | nextjob m2 "$K2"; check "$(head -c 12 "$T/job"):$(grep -c 'ALARM signed-messages all passed 3600 in the hour: 3601' "$C/alarms")" "ipcc1 ok job:1" "the 3601st message of the hour in all is accepted and alarmed" |
| 269 | printf '%s 3600\n' "$(date +%s)" > "$C/rate/refused" |
| 270 | post "$T/big.msg" > /dev/null; check "$(grep -c 'ALARM refusals refused passed 3600 in the hour: 3601' "$C/alarms")" 1 "the 3601st refusal of the hour is alarmed" |
| 271 | check "$(code "$B/community/alarms"):$(grep -c ALARM "$T/body")" "200:3" "GET /community/alarms serves the alarm lines" |
| 272 | rm "$C/rate/$K2" "$C/rate/all" "$C/rate/refused" |
| 273 | # a counter that cannot be saved raises no repeated alarm (it alarms only when the count was written) |
| 274 | printf '%s 150\n' "$(date +%s)" > "$C/rate/$K2"; mkdir "$C/rate/$K2.new" |
| 275 | nextjob m2 "$K2"; r1=$(head -c 8 "$T/job"); nextjob m2 "$K2"; r2=$(head -c 8 "$T/job") |
| 276 | check "$r1:$r2:$(grep -c "ALARM signed-messages $K2" "$C/alarms")" "ipcc1 ok:ipcc1 ok:1" "with the counter unsaveable, both messages are answered and no second alarm line is written" |
| 277 | rmdir "$C/rate/$K2.new"; rm -f "$C/rate/$K2" |
| 278 | # the alarm log is set aside at 4 MiB like the others, and the set-aside file is served |
| 279 | head -c 4194304 /dev/zero | tr '\0' 'a' > "$C/alarms"; printf '%s 3600\n' "$(date +%s)" > "$C/rate/refused" |
| 280 | post "$T/big.msg" > /dev/null |
| 281 | aa=$(ls "$C" | grep '^alarms\.[0-9]*$' | head -1) |
| 282 | check "$( [ -n "$aa" ] && wc -c < "$C/$aa"):$(grep -c 'ALARM refusals' "$C/alarms"):$(code "$B/community/$aa")" "4194304:1:200" "a full alarm log is set aside as $aa, served, and the new alarm starts a new log" |
| 283 | rm -f "$C/rate/refused" |
| 284 | # the volunteer's rate is their own number: no upper bound |
| 285 | rc=0; run m2 "$T/runner" set rate 3601 > "$T/m2.set" 2>&1 || rc=$? |
| 286 | check "$rc:$(run m2 "$T/runner" status | sed -n 's/^setting: at most \([0-9]*\) checks.*/\1/p')" "0:3601" "set rate 3601 is saved and read back (no upper bound)" |
| 287 | run m2 "$T/runner" set rate 30 > /dev/null 2>&1 |
| 288 | printf 'ipcc1 next\nkey %s\ntime %s\nnonce %s\n' "$K2" "$(($(date +%s) - 400))" 00000000000000000000000000000000 | signed m2 > "$T/old.msg" |
| 289 | check "$(post "$T/old.msg"):$(head -c 20 "$T/body")" "403:ipcc1 refused clock" "a message 400 s old is refused" |
| 290 | for reason in signature duplicate mismatch job unregistered denied size clock; do |
| 291 | grep -q " $reason " "$C/refused" || bad "refusal '$reason' not recorded" |
| 292 | done |
| 293 | ok "every refusal reason above is recorded in the refused log" |
| 294 | # refusal log rotation: a log at 4 MiB is set aside as refused.<seconds>, never grown toward forged's |
| 295 | # file-size limit; the API still answers |
| 296 | check "$(ls "$C" | grep -c '^refused\.[0-9]*$')" 0 "control: no set-aside refusal log yet" |
| 297 | head -c 4194304 /dev/zero | tr '\0' 'r' > "$C/refused" |
| 298 | check "$(post "$T/big.msg")" 413 "a refusal after the log reached 4 MiB is still answered" |
| 299 | a=$(ls "$C" | grep '^refused\.[0-9]*$' | head -1) |
| 300 | check "$( [ -n "$a" ] && wc -c < "$C/$a"):$(grep -c '' "$C/refused")" "4194304:1" "the full log was set aside as $a and a new one started" |
| 301 | check "$(code "$B/community/$a"):$(wc -c < "$T/body")" "200:4194304" "GET /community/$a serves the set-aside log" |
| 302 | check "$(code "$B/community/refused.x1"):$(code "$B/community/ledger.")" "404:404" "control: other names are not served" |
| 303 | curl -s "$B/community/" | grep -q "community/$a" && ok "the community page links the set-aside log" || bad "no link to $a" |
| 304 | |
| 305 | # ---- 7. hostile parts are contained by the cell; the mutant cell lets them through |
| 306 | mkdir -p "$T/cell" |
| 307 | cell() { # cell DRIVER NAME STDIN-FILE -> "$T/cell/NAME.<driver>" (the driver's line) and .out (stdout) |
| 308 | d=$T/cell/$2.$1; rm -rf "$d"; mkdir -p "$d"; cp "$H/$2.om" "$d/source.om"; cp "$3" "$d/stdin" |
| 309 | INTERPLANE_RUNNER_HOME=$T/m1/.interplane-runner IPCC_CANARY=volunteer-secret "$T/$1" "$d" > "$d.line" 2>&1 |
| 310 | sed -n 's/^exit \([^ ]*\).*/\1/p' "$d.line" |
| 311 | } |
| 312 | CAN=$T/canary-written; printf '%s\n' "$CAN" > "$T/w.in" |
| 313 | check "$(cell celldrv hello "$T/empty")" 0 "a normal part passes in the cell" |
| 314 | check "$(cell celldrv fork "$T/empty"):$(cat "$T/cell/fork.celldrv/stdout" 2>/dev/null)" "0:forks 00" "fork loop: no process could be started" |
| 315 | o=$(cell celldrv memhog "$T/empty"); case $o in signal*|cell*) ok "memory hog (192 MiB) did not run: $o" ;; *) bad "memory hog ran: $o";; esac |
| 316 | check "$(cell celldrv writer "$T/w.in"):$(test -e "$CAN" && echo written || echo absent)" "0:absent" "file writer: no file created" |
| 317 | check "$(cell celldrv passwd "$T/empty"):$(grep -c root "$T/cell/passwd.celldrv/stdout" 2>/dev/null)" "0:0" "/etc/passwd: not readable" |
| 318 | check "$(cell celldrv env "$T/empty"):$(cat "$T/cell/env.celldrv/stdout" 2>/dev/null)" "0:env 0" "environment: empty (the canary variable is not visible)" |
| 319 | nlog() { cat "$T/hub.stderr" "$T/data/logs/"* 2>/dev/null | grep -c netprobe; } |
| 320 | c0=$(nlog) |
| 321 | check "$(cell celldrv net "$T/net.in"):$(cat "$T/cell/net.celldrv/stdout" 2>/dev/null)" "0:socket -1" "network: no socket" |
| 322 | check "$(nlog)" "$c0" "the test hub saw no request from the probe in the real cell" |
| 323 | check "$(cell celldrv gpu "$T/empty"):$(cat "$T/cell/gpu.celldrv/stdout" 2>/dev/null)" "0:gpu open -1" "GPU device: not opened" |
| 324 | o=$(cell celldrv spin "$T/empty"); case $o in signal*|timeout) ok "endless loop ended by the cell: $o" ;; *) bad "endless loop: $o";; esac |
| 325 | # a cell that cannot start: the compiler is not executable (mode 600), so execpure fails (EACCES 13) |
| 326 | mkdir -p "$T/mc/.interplane-runner/bin"; cp "$HOMC" "$T/mc/.interplane-runner/bin/omc"; chmod 600 "$T/mc/.interplane-runner/bin/omc" |
| 327 | d=$T/cell/cellfail; rm -rf "$d"; mkdir -p "$d"; cp "$H/hello.om" "$d/source.om"; : > "$d/stdin" |
| 328 | check "$(INTERPLANE_RUNNER_HOME=$T/mc/.interplane-runner "$T/celldrv" "$d" | sed -n 's/^exit \([^ ]*\).*/\1/p')" cell13 "a cell that cannot start is reported as cell13 (EACCES), not as a program outcome" |
| 329 | check "$(cell celldrv exit125 "$T/empty"):$(cat "$T/cell/exit125.celldrv/stderr" 2>/dev/null)" "125:not the cell" "control: a part that exits 125 with its own stderr keeps outcome 125" |
| 330 | sleep 0.2; left=$(pgrep -f "$T/cell/" | wc -l); check "$left" 0 "no process of any probe is left" |
| 331 | # the mutant: the same probes through execprog (no Landlock, seccomp or limits) must get out |
| 332 | n=0; out= |
| 333 | [ "$(cell celldrvo fork "$T/empty"; cat "$T/cell/fork.celldrvo/stdout")" != "0forks 00" ] && { n=$((n+1)); out="$out fork"; } |
| 334 | cell celldrvo writer "$T/w.in" > /dev/null; test -e "$CAN" && { n=$((n+1)); out="$out file"; }; rm -f "$CAN" |
| 335 | cell celldrvo passwd "$T/empty" > /dev/null; grep -q root "$T/cell/passwd.celldrvo/stdout" && { n=$((n+1)); out="$out passwd"; } |
| 336 | cell celldrvo net "$T/net.in" > /dev/null; grep -q '^sent' "$T/cell/net.celldrvo/stdout" && { n=$((n+1)); out="$out network"; } |
| 337 | cell celldrvo memhog "$T/empty" > /dev/null; grep -q 'touched MiB 192' "$T/cell/memhog.celldrvo/stdout" && { n=$((n+1)); out="$out memory"; } |
| 338 | check "$n:$out" "5: fork file passwd network memory" "control: the mutant cell (execprog) lets these probes out, and the checks above would fail on them" |
| 339 | sleep 0.3; [ "$(nlog)" -gt "$c0" ] && ok "control: the test hub saw the mutant probe's request" || bad "control: no request from the mutant network probe reached the hub" |
| 340 | cell celldrvo env "$T/empty" > /dev/null |
| 341 | check "$(cat "$T/cell/env.celldrvo/stdout")" "env 0" "note: execprog also starts programs with an empty environment, so this mutant cannot show an environment leak" |
| 342 | pkill -f "$T/cell/fork.celldrvo" 2>/dev/null; true |
| 343 | |
| 344 | # ---- 8. honest runners agree; a third, lying runner disagrees |
| 345 | # earlier steps ran the newest part (probe) on honest machines (0, 1 and the one-line join machine |
| 346 | # when its background job reached the hub before it left); n0 is that count, read from the store |
| 347 | : > "$P/deny" |
| 348 | line() { curl -s "$B/community/part/$1" | grep -o 'Ran again by [^<]*' | head -1 | sed 's/ *$//'; } |
| 349 | first() { grep -o 'Ran again by [0-9]* community runners*: [0-9]* agree[^.]*\.' | head -1; } |
| 350 | n0=$(ls "$C/parts/$PP/k" | wc -l) |
| 351 | run m2 "$T/runner" once > "$T/m2.once.1" 2>&1 |
| 352 | n1=$((n0 + 1)) |
| 353 | check "$(line "$PP")" "Ran again by $n1 community runners: $n1 agree. The agreeing result has the same bytes as Interplane's own check. Keys are free to make, so this is not called verified." \ |
| 354 | "$n1 honest machines on the probe part agree, with the hub's own receipt" |
| 355 | run m3 "$T/liar" once > "$T/m3.once.1" 2>&1 |
| 356 | check "$(line "$PP" | sed 's/reproduced\. .*/reproduced./')" "Ran again by $((n1 + 1)) community runners: $n1 agree, 1 disagree. While results disagree this part is not presented as reproduced." \ |
| 357 | "a lying machine is shown as a disagreement" |
| 358 | # the hello part: machines 1 and 2 (honest) and 3 (lying) |
| 359 | for m in m1 m2; do run $m "$T/runner" once > "$T/$m.once.2" 2>&1; done |
| 360 | run m3 "$T/liar" once > "$T/m3.once.2" 2>&1 |
| 361 | curl -s "$B/community/part/$PH" > "$T/part.html" |
| 362 | grep -o 'Ran again by [^<]*' "$T/part.html" | head -1 > "$T/line.txt" |
| 363 | grep -q 'Ran again by 3 community runners: 2 agree, 1 disagree. While results disagree this part is not presented as reproduced.' "$T/line.txt" \ |
| 364 | && ok "page: $(cut -c1-118 "$T/line.txt")" || bad "page line: $(cat "$T/line.txt") (ledger: $(grep -c counted "$C/ledger") counted)" |
| 365 | grep -q 'same bytes as Interplane' "$T/line.txt" && bad "a disagreeing part is tied to the hub's check" || ok "with a disagreement the page does not tie the result to the hub's own check" |
| 366 | grep -i 'verified' "$T/line.txt" | grep -vq 'not called verified' && bad "the page calls agreement verified" || ok "the page does not call community agreement verified" |
| 367 | grep -qi 'is reproduced\|was reproduced' "$T/part.html" && bad "the page claims reproduced" || ok "no reproduced claim on the page" |
| 368 | n=0; for k in "$K1" "$K2" "$K3"; do grep -q "$k" "$T/part.html" && n=$((n+1)); done |
| 369 | check "$n" 3 "the developer view lists the three keys with time, exit and fingerprints" |
| 370 | curl -s "$B/salvage/$PH" | grep -o 'Ran again by [^<]*' | head -1 > "$T/sline.txt" |
| 371 | check "$(first < "$T/sline.txt")" "Ran again by 3 community runners: 2 agree, 1 disagree." "the part's own page in the yard shows the same record" |
| 372 | run m3 "$T/liar" once > "$T/m3.once.3" 2>&1 |
| 373 | check "$(line "$PH" | first)" "Ran again by 3 community runners: 2 agree, 1 disagree." "control: asking again adds no machine (each key once per revision)" |
| 374 | curl -s "$B/community/" > "$T/index.html" |
| 375 | # the supervisor clears work/ when it starts (and after each worker): an interrupted job's folder |
| 376 | # does not stay; while it runs, `once` and `selftest` are refused instead of racing it |
| 377 | mkdir -p "$T/m1/.interplane-runner/work/stale-job"; : > "$T/m1/.interplane-runner/work/stale-job/part.elf" |
| 378 | run m1 "$T/runner" start > /dev/null 2>&1 |
| 379 | for i in $(seq 50); do [ -e "$T/m1/.interplane-runner/work/stale-job" ] || break; sleep 0.1; done |
| 380 | check "$(test -e "$T/m1/.interplane-runner/work/stale-job" && echo kept || echo removed)" removed "the supervisor removed an interrupted job's folder when it started" |
| 381 | rc=0; run m1 "$T/runner" once > "$T/m1.busy" 2>&1 || rc=$? |
| 382 | check "$rc:$(grep -c 'stop it first' "$T/m1.busy")" "1:1" "once is refused while the background runner works" |
| 383 | run m1 "$T/runner" stop > /dev/null 2>&1 |
| 384 | grep -q 'curl -fsSL https://interplane.io/community/join | sh' "$T/index.html" && grep -q 'not called verified' "$T/index.html" \ |
| 385 | && ok "the community page shows the join line and states the counting rule" || bad "the community page misses the join line or the rule" |
| 386 | |
| 387 | # ---- 8b. every page route by name, and the live store's shape (2026-11-11: /community/key/<id> |
| 388 | # answered 404 on the live hub because "/community/msg/" and "/community/key/" have the same length |
| 389 | # and only the length was checked; /community/part/<id> made the live forged exit 103 because its |
| 390 | # k/ folder listed "." or ".." last, a 24-byte entry that cm_row read at byte 83: or is eager in Omega) |
| 391 | nreg=0; for f in "$C"keys/*; do [ "$(tail -c 2 "$f")" = j ] && nreg=$((nreg + 1)); done |
| 392 | check "$(code "$B/community/"):$(grep -o '[0-9]* runners* registered' "$T/body" | head -1)" "200:$nreg runner$([ "$nreg" = 1 ] || echo s) registered" \ |
| 393 | "the community page counts the registered runners (keys that joined and have not left)" |
| 394 | n=0; for k in "$K1" "$K2" "$K3"; do grep -q "community/key/$k" "$T/body" && n=$((n + 1)); done |
| 395 | check "$n" 3 "the community page lists each registered runner key" |
| 396 | grep -q 'x86-64, most PCs and servers: not covered yet' "$T/body" && grep -q 'Mac: not covered' "$T/body" \ |
| 397 | && ok "the community page says Linux on x86-64 and Mac are not covered" || bad "the community page does not say which computers are not covered" |
| 398 | for k in "$K1" "$K2" "$K3"; do |
| 399 | check "$(code "$B/community/key/$k"):$(cmp -s "$T/body" "$C/keys/$k" && echo same || echo differs)" "200:same" "GET /community/key/<key> is the key record" |
| 400 | done |
| 401 | check "$(code "$B/community/msg/$M1"):$(cmp -s "$T/body" "$C/msgs/$M1" && echo same || echo differs)" "200:same" "GET /community/msg/<id> is the signed message" |
| 402 | check "$(code "$B/community/key/$M1"):$(code "$B/community/msg/$K1"):$(code "$B/community/kez/$K1"):$(code "$B/community/pare/$PH")" "404:404:404:404" \ |
| 403 | "control: a message id under key/, a key id under msg/ and same-length wrong prefixes are 404" |
| 404 | names() { # names K: K 64-hex names this filesystem lists before "." and ".." in a one-block folder |
| 405 | : > "$T/names" |
| 406 | for b in $(seq 400); do |
| 407 | mkdir "$T/names.d" |
| 408 | head -c 1280 /dev/urandom | od -An -v -tx1 | tr -d ' \n' | fold -w 64 | (cd "$T/names.d" && xargs touch) |
| 409 | ls -f "$T/names.d" | awk 'f == 0 && ($0 == "." || $0 == "..") {f = 1} f == 0 {print}' >> "$T/names" |
| 410 | rm -rf "$T/names.d" |
| 411 | [ "$(wc -l < "$T/names")" -ge "$1" ] && { head -n "$1" "$T/names"; return 0; } |
| 412 | done |
| 413 | return 1 |
| 414 | } |
| 415 | sed 's/^note a normal part$/note a normal part, in the short-record shape/' "$H/hello.om" > "$T/shape.om" |
| 416 | kill "$HUBPID"; wait "$HUBPID" 2>/dev/null # the salvage store has one writer: publish with the hub stopped |
| 417 | publish shape "$T/shape.om" "$T/empty" "$T/hello.exp" |
| 418 | PS=$(cut -c1-64 "$T/part.shape") |
| 419 | KS=$(names 1) || bad "no name lists before . and .. on this filesystem: the shape is not made" |
| 420 | bin=$(head -c 129 "$S/receipts/$PS" | tail -c 64); out=$(head -c 193 "$S/receipts/$PS" | tail -c 64) |
| 421 | v="$bin $out 0"; h=$(printf '%s\n' "$v" | sha256sum | cut -c1-64) |
| 422 | mkdir -p "$C/parts/$PS/k" "$C/parts/$PS/g/$h" |
| 423 | printf '%s\n' "$v" > "$C/parts/$PS/g/$h.v"; : > "$C/parts/$PS/g/$h/$KS" |
| 424 | printf '%s %s 0 1794414226 %s\n' "$bin" "$out" "$M1" > "$C/parts/$PS/k/$KS" |
| 425 | check "$(ls -f "$C/parts/$PS/k" | tail -n 1 | tr -d .)" "" "the fixture part's k/ ends with . or .. (the live store's shape)" |
| 426 | startHub |
| 427 | check "$(code "$B/community/part/$PS"):$(grep -o 'Ran again by 1 community runner: 1 agree' "$T/body" | head -1)" "200:Ran again by 1 community runner: 1 agree" \ |
| 428 | "GET /community/part/<id> whose k/ ends with a short entry" |
| 429 | bad2=0; for i in $(seq 100); do [ "$(code "$B/community/part/$PS")" = 200 ] || bad2=$((bad2 + 1)); done |
| 430 | check "$bad2:$(kill -0 "$HUBPID" 2>/dev/null && echo up || echo gone)" "0:up" "100 more requests of that page: all 200, the hub still up" |
| 431 | # mutant: the eager read put back in cm_row must be caught (the hub exits 103, trap 3, on that page) |
| 432 | sed '0,/^if lt rl 84$/s//if or lt rl 84 ne get d 83 0/' "$T/hub.om" > "$T/hub-eager.om" |
| 433 | check "$(grep -c '^if or lt rl 84 ne get d 83 0$' "$T/hub-eager.om")" 1 "eager-read mutant made (cm_row only)" |
| 434 | taskset -c "$CORES" nice -n 10 "$HOMC" < "$T/hub-eager.om" > "$T/hub-eager" 2> "$T/hub-eager.err" && chmod +x "$T/hub-eager" \ |
| 435 | || bad "build eager-read mutant: $(cat "$T/hub-eager.err")" |
| 436 | kill "$HUBPID"; wait "$HUBPID" 2>/dev/null; startHub "$T/hub-eager" |
| 437 | c=$(code "$B/community/part/$PS") |
| 438 | for i in $(seq 50); do kill -0 "$HUBPID" 2>/dev/null || break; sleep 0.1; done |
| 439 | if kill -0 "$HUBPID" 2>/dev/null; then |
| 440 | kill "$HUBPID"; wait "$HUBPID" 2>/dev/null; bad "eager-read mutant not caught: status $c and the hub is still up" |
| 441 | else |
| 442 | rc=0; wait "$HUBPID" || rc=$? |
| 443 | check "$c:$rc" "000:103" "eager-read mutant caught: no answer and exit 103 (trap 3)" |
| 444 | fi |
| 445 | startHub |
| 446 | |
| 447 | # ---- 9. alarms (standing rule 2026-11-11): measured against a stated threshold. An ALARM line asks a |
| 448 | # person to look; it does not fail the gate. |
| 449 | alarm() { if [ "$2" -gt "$3" ]; then echo "ALARM $1: $2 $4, over the threshold $3 $4"; else echo "MEASURE $1: $2 $4 (alarm above $3 $4)"; fi; } |
| 450 | cp "$T/runner" "$T/m1/.interplane-runner/bin/interplane-runner" |
| 451 | alarm "runner folder of machine 1 after its jobs (promise: under 10 MiB)" "$(du -sk "$T/m1/.interplane-runner" | cut -f1)" 10240 KiB |
| 452 | alarm "hub store after the whole gate" "$(du -sk "$C" | cut -f1)" 102400 KiB |
| 453 | ms() { curl -s -o /dev/null -w '%{time_total}' "$@" | awk '{printf "%d", $1*1000}'; } |
| 454 | alarm "developer view of a part with 3 keys" "$(ms "$B/community/part/$PH")" 1000 ms |
| 455 | bh=$(curl -s "$B/community/part/$PH" | wc -c); kh=$(ls "$C/parts/$PH/k" | wc -l) |
| 456 | bp=$(curl -s "$B/community/part/$PP" | wc -c); kp=$(ls "$C/parts/$PP/k" | wc -l) |
| 457 | row=$(( (bp - bh) / (kp - kh) )) |
| 458 | alarm "developer view: bytes per key row (forged's page buffer is 8 MiB, so about $(( (8388608 - bh) / row )) keys fit before that page answers 500; alarm when under 5000 keys would fit)" "$row" 1600 bytes |
| 459 | alarm "community page" "$(ms "$B/community/")" 1000 ms |
| 460 | alarm "a refused API call (duplicate)" "$(ms --data-binary "@$C/msgs/$M1" "$B/community/api")" 1000 ms |
| 461 | alarm "lines in the refused log" "$(grep -c '' "$C/refused")" 100000 lines |
| 462 | |
| 463 | echo "community gate: $PASS passed, $FAIL failed (scratch $T)" |
| 464 | [ "$FAIL" = 0 ] |