Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/infra/test/sandbox-patch.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / infra / test / sandbox-patch.sh` 162 lines ยท 10808 bytes Raw Blame History 1 #!/bin/bash 2 # The git patch intake inside the bubblewrap sandbox (infra/spark/forged-sandbox.sh, SANDBOX-NEEDS.md 3 # "Git patch intake"). HOST test on the Spark with scratch folders only: patch/tests/lib.sh makes 4 # the fixture repository, throwaway keys and the sign-in and upload helpers; this script builds a 5 # second test copy whose home paths name a scratch home (as infra/test/sandbox.sh does), with the 6 # listener helper, the socket filter and the public reader beside it, and starts it through the 7 # wrapper as the service does (FORGED_SANDBOX=on, FORGED_NETNS=on: no network, socket filter on, 8 # listener made outside by forged-listen). Nothing of the live forge, ~/git, ~/forge-data or 9 # ~/forge-public is read or written. 10 # Steps: 11 # 1. the public export and the repository mounts: the listed git store is mounted read-only at 12 # /git/fixrepo.git; a listed name without a git store and an unlisted git store are not 13 # 2. a signed upload is accepted by the sandboxed forged (git init, git am with the store's 14 # objects borrowed through alternates, rev-list, diff; ssh-keygen -Y verify) and reads back 15 # 3. mails in ISO-8859-1 and KOI8-R (git mailinfo converts them to UTF-8 through glibc iconv, 16 # whose converters live in the gconv folder the wrapper mounts) are accepted 17 # 4. an upload to the listed repository without a git store is refused 404 and keeps nothing 18 # 5. controls: the wrapper and public library of CONTROL (default `2dc1deda`, before the git store 19 # mounts) refuse an upload 404 "no git store"; this wrapper without its gconv mount refuses 20 # an ISO-8859-1 mail 422 (git am: "cannot convert from ISO-8859-1 to UTF-8") 21 # Usage: PATCH_TEST_PORT=18488 PATCH_TEST_CORES=18 bash infra/test/sandbox-patch.sh [CONTROL] 22 # KEEP=1 keeps the temp folder. Exit 0 only when every step held. 23 CONTROL=${1:-`2dc1deda63fe50cbd7665495b51706f0814e79d4`} 24 . "$(dirname "$0")/../../patch/tests/lib.sh" 25 REPOF=$OWNER/fixrepo 26 H=$T/sbhome 27 S=$T/sbx 28 DATA=$T/data 29 30 echo "== build: the sandbox test copy, home paths at $H" 31 mkdir -p "$H/handoffs/radicle" "$H/handoffs/hive/manager/reviews" "$H/handoffs/hive/forge/receipts" \ 32 "$H/.local/state/aien-factory" "$H/.radicle/storage" "$H/git" "$S" "$DATA/logs" 33 printf 'private direct-launch fixture\n' > "$DATA/forged-supervisor.pid" 34 cp "$T/RIDS.md" "$H/handoffs/radicle/RIDS.md" 35 git clone -q --bare "$T/src" "$H/.radicle/storage/$RID1" || buildfail "storage fixture" 36 mkdir -p "$H/.radicle/storage/$RID2" 37 git clone -q --bare "$T/src" "$H/git/fixrepo.git" || buildfail "git store fixture" 38 git clone -q --bare "$T/src" "$H/git/unlisted.git" || buildfail "unlisted git store fixture" 39 { printf 'om2\n'; cat $(cat "$T/units.txt"); } | sed -e "s|/home/drakestapleton/|$H/|g" \ 40 -e "s|^text tforg1 \".*\"|text tforg1 \"http://127.0.0.1:$PORT\"|" -e "s/18480/$PORT/g" > "$T/sb.om" || buildfail "compose" 41 for t in tfdata tfstore tfrids tpgroot; do 42 grep -q "^text $t \"$H/" "$T/sb.om" || buildfail "the sandbox copy does not name the scratch home in $t" 43 done 44 compile "$T/sb.om" "$S/forged" || buildfail "$(cat "$T/omc.err")" 45 compile infra/spark/forged-listen.om "$S/forged-listen" || buildfail "forged-listen: $(cat "$T/omc.err")" 46 compile infra/spark/public-read.om "$S/public-read" || buildfail "public-read: $(cat "$T/omc.err")" 47 compile infra/spark/forged-seccomp.om "$S/forged-seccomp" || buildfail "forged-seccomp: $(cat "$T/omc.err")" 48 "$S/forged-seccomp" > "$S/forged-seccomp.bpf" || buildfail "forged-seccomp did not write the filter" 49 echo "built $(sha256sum < "$S/forged" | cut -c1-16) forged, filter $(sha256sum < "$S/forged-seccomp.bpf" | cut -c1-16), wrapper $(sha256sum < infra/spark/forged-sandbox.sh | cut -c1-16)" 50 51 export FORGED_READ_HOME=$H FORGED_PATH_HOME=$H FORGE_DATA=$DATA FORGED_PUBLIC_READER=$S/public-read \ 52 FORGED_PUBLIC_DIR=$T/forge-public FORGED_SANDBOX=on FORGED_NETNS=on 53 unset FORGED_SECCOMP FORGED_SALVAGE FORGED_COMMUNITY_PUB 54 55 stop() { [ -n "$PID" ] && kill -- -"$PID" 2>/dev/null; wait "$PID" 2>/dev/null; PID=; } 56 port_free() { for i in $(seq 100); do [ -z "$(ss -ltnH "sport = :$PORT")" ] && return 0; sleep 0.1; done; return 1; } 57 # sbstart DIR: start the sandboxed forged through DIR/forged-sandbox.sh with DIR/forged-public.sh 58 sbstart() { 59 port_free || { echo "port $PORT is taken"; exit 1; } 60 FORGED_PUBLIC_LIB=$1/forged-public.sh FORGED_LISTEN_PORT=$PORT setsid bash "$1/forged-sandbox.sh" "$S/forged" \ 61 >> "$T/sandbox.err" 2>&1 < /dev/null & 62 PID=$! 63 for i in $(seq 100); do curl -s -o /dev/null "$B/" && return 0; kill -0 "$PID" 2>/dev/null || break; sleep 0.1; done 64 echo "sandboxed server did not start"; tail -5 "$T/sandbox.err"; exit 1 65 } 66 # the sandboxed forged: the /app/forged process below this run's bwrap (PID is bwrap after the 67 # wrapper's execs; bwrap's pid-1 child starts prlimit, which execs forged) 68 inner() { 69 local p=$PID q i 70 for i in 1 2 3 4; do 71 q=$(pgrep -P "$p" | head -1); [ -n "$q" ] || return 1; p=$q 72 case "$(tr '\0' ' ' < "/proc/$p/cmdline")" in /app/forged*) echo "$p"; return 0;; esac 73 done 74 return 1 75 } 76 77 echo "== 1. public export and repository mounts" 78 mkdir -p "$T/new"; cp infra/spark/forged-sandbox.sh infra/spark/forged-public.sh "$T/new/" 79 ( 80 DATA=$DATA BIN=$S/forged; . "$T/new/forged-public.sh" 81 public_init && public_sync && public_repos | cut -f1,2 | tr '\t' ' ' 82 ) > "$T/repos.txt" 2>&1 83 printf 'rad %s\ngit fixrepo\nrad %s\n' "$RID1" "$RID2" > "$T/repos.want" 84 cmp -s "$T/repos.txt" "$T/repos.want" && ok "public_repos: $(tr '\n' ',' < "$T/repos.txt") (no git row for nostore, nothing for unlisted)" \ 85 || bad "public_repos: $(tr '\n' '|' < "$T/repos.txt")" 86 sbstart "$T/new" 87 grep -q '^forged-sandbox: on; .*no network' "$T/sandbox.err" && ok "wrapper: $(grep '^forged-sandbox: on' "$T/sandbox.err" | tail -1 | cut -c1-120)" \ 88 || bad "wrapper did not report sandbox on with no network: $(tail -3 "$T/sandbox.err" | tr '\n' '|')" 89 FP=$(inner) 90 if [ -n "$FP" ] && awk '{print $5}' "/proc/$FP/mountinfo" > "$T/mounts.txt" 2>/dev/null; then 91 grep "^$H/git" "$T/mounts.txt" > "$T/gitmounts.txt" 92 [ "$(cat "$T/gitmounts.txt")" = "$H/git/fixrepo.git" ] && grep -qx "$H/.radicle/storage/$RID1" "$T/mounts.txt" \ 93 && ok "mounts of pid $FP under $H/git: exactly $H/git/fixrepo.git (no nostore.git, no unlisted.git)" \ 94 || bad "mounts under $H/git: $(tr '\n' '|' < "$T/gitmounts.txt")" 95 awk -v p="$H/git/fixrepo.git" '$5 == p { split($6, o, ","); if (o[1] == "ro") f = 1 } END { exit !f }' "/proc/$FP/mountinfo" \ 96 && ok "the git store mount is read-only" || bad "the git store mount is not read-only: $(grep " $H/git/" "/proc/$FP/mountinfo")" 97 else bad "could not read the mount table of the sandboxed forged (pid '$FP')"; fi 98 99 echo "== 2. a signed upload inside the sandbox" 100 newkey k1 101 signin k1 10.4.0.1 || { echo "SANDBOX: pass=$PASS fail=$FAIL"; exit 1; } 102 ok "signed in inside the sandbox (ssh-keygen -Y verify)" 103 newclone w; commitf "$T/w" "notes/sandbox.txt" "sandbox line" "sandbox: one note"; mkmbox "$T/w" origin/main 104 TITLE="Sandbox note"; DESC="Written by infra/test/sandbox-patch.sh."; sigmake 105 KEPT=$(kept); C=$(upload); accepted "$C" "upload to the sandboxed forged (git am with alternates into the read-only store)" 106 c=$(code GET "$R/patches/$ID.diff") 107 git -C "$T/w" diff --full-index -M "$BASE" HEAD > "$T/want.diff" 108 [ "$c" = 200 ] && cmp -s "$T/body" "$T/want.diff" && ok "raw .diff of $ID: 200, byte-equal to git diff --full-index -M base HEAD" \ 109 || bad "raw .diff of $ID: $c" 110 c=$(code GET "$R/patches/$ID") 111 [ "$c" = 200 ] && grep -qF 'Sandbox note' "$T/body" && ok "patch page of $ID: 200 with the title" || bad "patch page of $ID: $c" 112 [ -z "$(ls -A "$H/git/fixrepo.git/objects/info" 2>/dev/null | grep -v '^packs$')" ] && [ "$(git -C "$H/git/fixrepo.git" rev-parse main)" = "$BASE" ] \ 113 && ok "the git store is unchanged (main at the base, no alternates of its own)" || bad "the git store changed" 114 115 echo "== 3. mails in other charsets (git mailinfo converts them to UTF-8 through iconv)" 116 # mailcs CHARSET BYTES: a commit whose file and message hold BYTES in CHARSET, as a mail in CHARSET 117 mailcs() { 118 newclone "cs$1"; git -C "$T/cs$1" config i18n.commitEncoding "$1" 119 printf "$2\\n" > "$T/cs$1/text-$1.txt" 120 G -C "$T/cs$1" add -A && GIT_AUTHOR_DATE=2026-11-10T10:00:00Z GIT_COMMITTER_DATE=2026-11-10T10:00:00Z \ 121 git -C "$T/cs$1" -c user.name=fixture -c user.email=fixture@example.org commit -q -F <(printf "text: $2\\n") 122 mkmbox "$T/cs$1" origin/main 123 grep -qix "Content-Type: text/plain; charset=$1" "$MBOX" || bad "the fixture mail is not $1: $(grep -i '^Content-Type' "$MBOX")" 124 TITLE="Mail in $1"; DESC="git mailinfo converts it to UTF-8."; sigmake 125 KEPT=$(kept); C=$(upload) 126 } 127 mailcs ISO-8859-1 'caf\351 au lait' 128 accepted "$C" "ISO-8859-1 mail (git mailinfo converts it with glibc's gconv modules)" 129 mailcs KOI8-R '\320\322\311\327\305\324' 130 accepted "$C" "KOI8-R mail (git mailinfo converts it with glibc's gconv modules)" 131 132 echo "== 4. a listed repository without a git store" 133 newclone w2; commitf "$T/w2" "notes/nostore.txt" "nostore line" "nostore: one note"; mkmbox "$T/w2" origin/main 134 TITLE="No store"; DESC="nostore is listed and has no git store."; REPOF=$OWNER/nostore; UPATH=/$OWNER/nostore/patches/new; sigmake 135 KEPT=$(kept); C=$(upload); refused "$C" 404 "this repository has no git store on this forge" "listed repository without a git store" 136 REPOF=$OWNER/fixrepo; UPATH= 137 stop 138 139 echo "== 5. control: the wrapper of $CONTROL" 140 mkdir -p "$T/old" 141 git show "$CONTROL:infra/spark/forged-sandbox.sh" > "$T/old/forged-sandbox.sh" && git show "$CONTROL:infra/spark/forged-public.sh" > "$T/old/forged-public.sh" \ 142 || { bad "control files of $CONTROL"; echo "SANDBOX: pass=$PASS fail=$FAIL"; exit 1; } 143 sbstart "$T/old" 144 signin k1 10.4.0.1 || { echo "SANDBOX: pass=$PASS fail=$FAIL"; exit 1; } 145 newclone w3; commitf "$T/w3" "notes/control.txt" "control line" "control: one note"; mkmbox "$T/w3" origin/main 146 TITLE="Control"; DESC="No git store mount in this wrapper."; sigmake 147 KEPT=$(kept); C=$(upload); refused "$C" 404 "this repository has no git store on this forge" "control wrapper $CONTROL (no git store mount)" 148 stop 149 150 echo "== 5b. control: this wrapper without the gconv mount" 151 mkdir -p "$T/nogconv"; cp "$T/new/forged-public.sh" "$T/nogconv/" 152 sed '/^args+=(--ro-bind "\$gconv" "\$gconv")$/d' "$T/new/forged-sandbox.sh" > "$T/nogconv/forged-sandbox.sh" 153 if cmp -s "$T/new/forged-sandbox.sh" "$T/nogconv/forged-sandbox.sh"; then bad "the gconv mutant changed nothing"; else 154 sbstart "$T/nogconv" 155 signin k1 10.4.0.1 || { echo "SANDBOX: pass=$PASS fail=$FAIL"; exit 1; } 156 mailcs ISO-8859-1 'na\357ve' 157 refused "$C" 422 "the mbox does not apply cleanly on base" "ISO-8859-1 mail without the gconv mount" 158 stop 159 fi 160 echo "== forged-sandbox stderr"; grep -v '^$' "$T/sandbox.err" | cut -c1-200 | sort | uniq -c 161 echo "SANDBOX: pass=$PASS fail=$FAIL" 162 [ "$FAIL" = 0 ]