interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / open / tests / run.sh
| 1 | #!/usr/bin/env bash |
| 2 | # open/tests/run.sh: the gate for Open Humanity's shelf of open builds. |
| 3 | # Part 1 open/intake.om, the program outside the sandbox, against a stand-in rad (a shell script |
| 4 | # in a throwaway HOME: it logs its arguments, "seeds" by making the storage folder and |
| 5 | # prints a payload). No network, no real Radicle node, no real key. |
| 6 | # Part 2 open/route.om inside a test copy of forged (private port, private data folder), with a |
| 7 | # throwaway ed25519 key signed in the way social/tests does it. |
| 8 | # Each part ends with mutants: the same checks must FAIL on a copy with one guard removed. |
| 9 | # Heavy enough to want a pool lock: |
| 10 | # flock -o ~/handoffs/hive/queen/pool-18.lock env FORGED_CPUS=18 sh open/tests/run.sh |
| 11 | set -u |
| 12 | cd "$(dirname "$0")/../.." |
| 13 | OMV=$HOME/work/flux/omega-mv |
| 14 | OMC=$OMV/seed/out/omc |
| 15 | PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194 |
| 16 | [ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo "omc is not the pin"; exit 1; } |
| 17 | PORT=${OPEN_TEST_PORT:-18493} |
| 18 | CORES=${FORGED_CPUS:-2} |
| 19 | T=$(mktemp -d /tmp/openbuilds.XXXXXX) |
| 20 | PASS=0; FAIL=0 |
| 21 | ok() { PASS=$((PASS+1)); echo "PASS $*"; } |
| 22 | bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } |
| 23 | check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want '$2', got '$1'"; fi; } |
| 24 | PID= |
| 25 | stop() { [ -n "$PID" ] && { kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null; }; PID=; } |
| 26 | trap 'stop; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT |
| 27 | omc() { taskset -c "$CORES" nice -n 10 "$OMC"; } |
| 28 | TAB=$(printf '\t') |
| 29 | |
| 30 | # ------------------------------------------------------------------ part 1: the intake |
| 31 | { printf 'om2\n'; cat "$OMV/om/tls/sha2.om" open/intake.om; } | omc > "$T/intake" 2> "$T/omc.err" || { echo "BUILD FAILED open/intake.om: $(cat "$T/omc.err")"; exit 1; } |
| 32 | chmod 700 "$T/intake" |
| 33 | rid() { printf 'z2abcdefghijkmnopqrstuvw%s' "$1"; } |
| 34 | D1=did:key:z6MkTestKeyNumberOne111111111111111111111111111 |
| 35 | D2=did:key:z6MkTestKeyNumberTwo222222222222222222222222222 |
| 36 | D3=did:key:z6MkTestKeyNumberThree3333333333333333333333333 |
| 37 | # world NAME: a fresh throwaway HOME, storage, open folder, work folder and state file under $T/NAME |
| 38 | world() { |
| 39 | W=$T/$1; rm -rf "$W" |
| 40 | mkdir -p -m 700 "$W/home/.local/bin" "$W/home/stub" "$W/home/store" "$W/open" "$W/work" |
| 41 | cat > "$W/home/.local/bin/rad" <<'EOF' |
| 42 | #!/bin/sh |
| 43 | # stand-in for rad: log the arguments; seed copies stub/template.git (a real bare repository) when |
| 44 | # it exists; seed without a rid prints stub/policy (the policy list) or |
| 45 | # fails when stub/policyfail exists; a rid in stub/late fails and its folder appears 2 s later (the |
| 46 | # node finishing a fetch after rad stopped); seed makes the storage folder unless the rid is listed in |
| 47 | # stub/notfound (52 MiB of it when listed in stub/big); inspect prints stub/payload |
| 48 | S=$HOME/stub |
| 49 | echo "$*" >> "$S/rad.log" |
| 50 | r=${2#rad:} |
| 51 | case $1 in |
| 52 | seed) |
| 53 | [ -n "${2:-}" ] || { [ -e "$S/policyfail" ] && exit 1; cat "$S/policy" 2>/dev/null; exit 0; } |
| 54 | grep -qx "$r" "$S/late" 2>/dev/null && { ( sleep 2; mkdir -p "$HOME/store/$r"; echo part > "$HOME/store/$r/partial" ) > /dev/null 2>&1 & exit 1; } |
| 55 | grep -qx "$r" "$S/notfound" 2>/dev/null && exit 1 |
| 56 | if [ -d "$S/template.git" ]; then cp -r "$S/template.git" "$HOME/store/$r"; else mkdir -p "$HOME/store/$r" && echo ref > "$HOME/store/$r/HEAD"; fi |
| 57 | grep -qx "$r" "$S/big" 2>/dev/null && head -c 54525952 /dev/zero > "$HOME/store/$r/pack" |
| 58 | exit 0 ;; |
| 59 | unseed) exit 0 ;; |
| 60 | inspect) [ "${3:-}" = --visibility ] && { cat "$S/visibility" 2>/dev/null || echo private; exit 0; } |
| 61 | [ "${3:-}" = --delegates ] && { [ -e "$S/delfail" ] && exit 1 |
| 62 | [ -e "$S/delegates" ] && { cat "$S/delegates"; exit 0; } |
| 63 | echo 'did:key:z6MkTestKeyNumberOne111111111111111111111111111 (one)'; exit 0; } |
| 64 | cat "$S/payload"; exit 0 ;; |
| 65 | esac |
| 66 | exit 2 |
| 67 | EOF |
| 68 | chmod 700 "$W/home/.local/bin/rad" |
| 69 | printf '%s\n' '{"xyz.radicle.project":{"defaultBranch":"main","description":"A demo that stops half way","name":"demo-project"}}' > "$W/home/stub/payload" |
| 70 | : > "$W/home/stub/rad.log" |
| 71 | # the reserves are the only refusal for room; this gate sets them to one byte, so the machine's |
| 72 | # own free space never decides an outcome here (open/tests/up.sh tests them) |
| 73 | printf 'OPEN_RESERVE_STORAGE_BYTES=1\nOPEN_RESERVE_DATA_BYTES=1\n' > "$W/work/reserve" |
| 74 | } |
| 75 | # alarm NAME: "value/threshold|key|volume>=VOL" of a firing alarm in <work>alarms.txt |
| 76 | alarm() { awk -F'\t' -v n="$1" -v v="${2:-0}" '$1==n {print $2"/"$3"|"$5"|"($6>=v)}' "$W/work/alarms.txt" 2>/dev/null; } |
| 77 | intake() { "${BIN:-$T/intake}" "$W/open/" "$W/state" "$W/work/" "$W/home/store/" "$W/home" once; } |
| 78 | q() { printf '%s\n' "$1" >> "$W/open/queue"; } |
| 79 | row() { awk -F'\t' -v r="$1" '$1==r' "$W/open/list.tsv" 2>/dev/null; } |
| 80 | st() { row "$1" | cut -f2; } |
| 81 | calls() { grep -c -- "$1" "$W/home/stub/rad.log"; } |
| 82 | |
| 83 | world w1 |
| 84 | # 1. no allow file: nobody may bring |
| 85 | q "B${TAB}$(rid A1)${TAB}$D1${TAB}first try"; intake |
| 86 | case "$(st "$(rid A1)")" in "refused: intake is open to invited keys"*) ok "no allow file: the bring is refused";; *) bad "no allow file: state '$(st "$(rid A1)")'";; esac |
| 87 | check "$(calls "^seed rad:")" 0 "no allow file: rad was not called (the alarm pass asks for the bare rad seed list only)" |
| 88 | [ ! -e "$W/home/store/$(rid A1)" ] && ok "no allow file: nothing in storage" || bad "storage folder made without permission" |
| 89 | # 2. an allowed key brings a project |
| 90 | echo "$D1" > "$W/work/allow" |
| 91 | q "B${TAB}$(rid A2)${TAB}$D1${TAB}needs a parser & tests"; intake |
| 92 | check "$(st "$(rid A2)")" open "allowed key: the project is open" |
| 93 | check "$(row "$(rid A2)" | cut -f3)" "$D1" "the row names the key that brought it" |
| 94 | row "$(rid A2)" | cut -f4 | grep -qE '^20[0-9]{2}-[0-9]{2}-[0-9]{2}$' && ok "the row has a date" || bad "date '$(row "$(rid A2)" | cut -f4)'" |
| 95 | [ "$(row "$(rid A2)" | cut -f5)" -gt 0 ] 2>/dev/null && ok "the row has a size in KiB" || bad "size '$(row "$(rid A2)" | cut -f5)'" |
| 96 | check "$(row "$(rid A2)" | cut -f6)" demo-project "name from the identity document" |
| 97 | check "$(row "$(rid A2)" | cut -f7)" "A demo that stops half way" "description from the identity document" |
| 98 | check "$(row "$(rid A2)" | cut -f8)" "needs a parser & tests" "the note is kept" |
| 99 | check "$(grep -c -x "seed rad:$(rid A2) --scope all --fetch" "$W/home/stub/rad.log")" 1 "rad seed was called once with the rid, scope all, fetch" |
| 100 | # 3. the same bring again changes nothing |
| 101 | q "B${TAB}$(rid A2)${TAB}$D1${TAB}again"; intake |
| 102 | check "$(calls "seed rad:$(rid A2)")" 1 "a second bring of an open project does not seed again" |
| 103 | check "$(row "$(rid A2)" | cut -f8)" "needs a parser & tests" "a second bring does not rewrite the row" |
| 104 | # 4. a key that is not on the list; then the * line |
| 105 | q "B${TAB}$(rid A3)${TAB}$D2${TAB}other key"; intake |
| 106 | case "$(st "$(rid A3)")" in refused:*invited*) ok "a key not on the list is refused";; *) bad "unlisted key: '$(st "$(rid A3)")'";; esac |
| 107 | echo '*' >> "$W/work/allow" |
| 108 | q "B${TAB}$(rid A3)${TAB}$D2${TAB}other key"; intake |
| 109 | check "$(st "$(rid A3)")" open "a * line admits every key" |
| 110 | # 5. a repository this node already holds, and that is not public, is never touched or listed |
| 111 | mkdir "$W/home/store/$(rid A4)"; echo keep > "$W/home/store/$(rid A4)/marker" |
| 112 | q "B${TAB}$(rid A4)${TAB}$D1${TAB}already here"; intake |
| 113 | case "$(st "$(rid A4)")" in "refused: this project's storage is already on this node") ok "storage already present: refused";; *) bad "present storage: '$(st "$(rid A4)")'";; esac |
| 114 | check "$(calls "seed rad:$(rid A4)")" 0 "storage already present: no seed" |
| 115 | q "W${TAB}$(rid A4)${TAB}$D1"; intake |
| 116 | [ -f "$W/home/store/$(rid A4)/marker" ] && ok "withdraw of a refused row leaves the storage alone" || bad "a repository the intake did not bring was removed" |
| 117 | check "$(calls "unseed rad:$(rid A4)")" 0 "withdraw of a refused row does not unseed" |
| 118 | # 5b. the published copy is not an authority: a row planted there cannot make the intake remove anything |
| 119 | mkdir "$W/home/store/$(rid A9)"; echo keep > "$W/home/store/$(rid A9)/marker" |
| 120 | printf '%s\topen\t%s\t2026-11-10\t1\tplanted\t\t\n' "$(rid A9)" "$D1" >> "$W/open/list.tsv" |
| 121 | q "W${TAB}$(rid A9)${TAB}$D1"; intake |
| 122 | [ -f "$W/home/store/$(rid A9)/marker" ] && ok "a row planted in the published list does not get a repository removed" || bad "planted row: repository removed" |
| 123 | check "$(calls "unseed rad:$(rid A9)")" 0 "a planted row does not unseed" |
| 124 | # 6. not found on the network |
| 125 | echo "$(rid A5)" > "$W/home/stub/notfound" |
| 126 | q "B${TAB}$(rid A5)${TAB}$D1${TAB}nowhere"; intake |
| 127 | case "$(st "$(rid A5)")" in "refused: not found"*) ok "not found: refused";; *) bad "not found: '$(st "$(rid A5)")'";; esac |
| 128 | check "$(calls "unseed rad:$(rid A5)")" 1 "not found: the seeding policy is removed again" |
| 129 | check "$(grep -c planted "$W/open/list.tsv")" 0 "the publish after it drops the planted row" |
| 130 | # 7. over the former size limit (50 MiB): listed and kept; the largest_project_kib alarm names the key |
| 131 | # and the volume |
| 132 | echo "$(rid A6)" > "$W/home/stub/big" |
| 133 | q "B${TAB}$(rid A6)${TAB}$D1${TAB}too big"; intake |
| 134 | check "$(st "$(rid A6)")" open "over the former 50 MiB: listed" |
| 135 | [ -e "$W/home/store/$(rid A6)/pack" ] && ok "over the former 50 MiB: the copy is kept" || bad "big copy removed" |
| 136 | check "$(calls "unseed rad:$(rid A6)")" 0 "over the former 50 MiB: not unseeded" |
| 137 | check "$(alarm largest_project_kib 52428800 | cut -d'|' -f2,3)" "$D1|1" "the largest_project_kib alarm names the key and a volume over 50 MiB" |
| 138 | # 8. withdraw: only the key that brought it |
| 139 | q "W${TAB}$(rid A2)${TAB}$D2"; intake |
| 140 | check "$(st "$(rid A2)")" open "another key cannot withdraw the project" |
| 141 | [ -d "$W/home/store/$(rid A2)" ] && ok "another key's withdraw leaves the storage" || bad "storage removed by another key" |
| 142 | q "W${TAB}$(rid A2)${TAB}$D1"; intake |
| 143 | check "$(st "$(rid A2)")" withdrawn "the owner withdraws the project" |
| 144 | [ ! -e "$W/home/store/$(rid A2)" ] && ok "withdraw removes the copy" || bad "copy still there after withdraw" |
| 145 | check "$(calls "unseed rad:$(rid A2)")" 1 "withdraw unseeds" |
| 146 | check "$(row "$(rid A2)" | cut -f6)" demo-project "a withdrawn row keeps the name" |
| 147 | # 9. hostile queue lines: none may reach rad or the list |
| 148 | before=$(wc -l < "$W/open/list.tsv"); logb=$(grep -vcx seed "$W/home/stub/rad.log") |
| 149 | q "B${TAB}../../../../etc${TAB}$D1${TAB}x" |
| 150 | q "B${TAB}z2abcdefghijkmnopqr/../../x${TAB}$D1${TAB}x" |
| 151 | q "B${TAB}$(rid A7)0OIl${TAB}$D1${TAB}x" |
| 152 | q "B${TAB}z2abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVW${TAB}$D1${TAB}x" |
| 153 | q "B${TAB}$(rid A7)${TAB}did key with spaces${TAB}x" |
| 154 | q "B${TAB}$(rid A7)${TAB}${TAB}x" |
| 155 | q "B${TAB}a2abcdefghijkmnopqrstuvwA7${TAB}$D1${TAB}x" |
| 156 | q "W${TAB}..${TAB}$D1" |
| 157 | q "X${TAB}$(rid A7)${TAB}$D1" |
| 158 | q "B $(rid A7) $D1" |
| 159 | q "" |
| 160 | printf 'B\t\377\376\001\t%s\tx\n' "$D1" >> "$W/open/queue" |
| 161 | intake |
| 162 | check "$(wc -l < "$W/open/list.tsv")" "$before" "12 malformed queue lines add no row" |
| 163 | check "$(grep -vcx seed "$W/home/stub/rad.log")" "$logb" "12 malformed queue lines never reach rad" |
| 164 | check "$(cat "$W/state")" "$(stat -c %s "$W/open/queue")" "the offset passed every line" |
| 165 | # 10. a hostile identity document cannot break the row |
| 166 | printf '%s\n' '{"xyz.radicle.project":{"defaultBranch":"main","description":"line\none \"q\" <b>","name":"a\tb<script>"}}' > "$W/home/stub/payload" |
| 167 | q "B${TAB}$(rid A8)${TAB}$D1${TAB}odd payload"; intake |
| 168 | check "$(row "$(rid A8)" | awk -F'\t' '{print NF}')" 8 "hostile payload: the row still has 8 fields" |
| 169 | check "$(grep -c "^$(rid A8)" "$W/open/list.tsv")" 1 "hostile payload: one line" |
| 170 | check "$(row "$(rid A8)" | cut -f6)" "a b<script>" "hostile payload: the escape became a space, the text is kept as data" |
| 171 | # 11. no number of projects a key: the ninth is fetched, and the key_shelf_rows alarm names the key |
| 172 | world w2; echo "$D3" > "$W/work/allow" |
| 173 | for i in 1 2 3 4 5 6 7 8 9; do q "B${TAB}$(rid B$i)${TAB}$D3${TAB}n$i"; done; intake |
| 174 | check "$(awk -F'\t' '$2=="open"' "$W/open/list.tsv" | wc -l)" 9 "a key brings nine projects" |
| 175 | check "$(calls "seed rad:$(rid B9)")" 1 "the ninth is seeded" |
| 176 | check "$(alarm key_shelf_rows | cut -d'|' -f1,2)" "9/8|$D3" "the key_shelf_rows alarm fires at 9 of the former 8 and names the key" |
| 177 | # 12. no budget and no count: 800 uninvited brings with 200-byte notes take the list past the former |
| 178 | # 262,143-byte read buffer; every refusal row stays, and so does the open project |
| 179 | B58=123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz |
| 180 | fill() { # N KEY: N bring lines from KEY, each a new rid, each with a 200-byte note |
| 181 | awk -v n="$1" -v d="$2" -v a="$B58" 'BEGIN { s = sprintf("%200s", ""); gsub(/ /, "n", s) |
| 182 | for (i = 0; i < n; i++) printf "B\tz2abcdefghijkmnopqrstuvwxyzRef%s%s\t%s\t%s\n", substr(a, int(i / 58) % 58 + 1, 1), substr(a, i % 58 + 1, 1), d, s }' >> "$W/open/queue" |
| 183 | } |
| 184 | world w3; echo "$D1" > "$W/work/allow" |
| 185 | fill 800 "$D2"; intake |
| 186 | q "B${TAB}$(rid V1)${TAB}$D1${TAB}victim"; intake |
| 187 | fill 1 "$D3"; intake |
| 188 | check "$(st "$(rid V1)")" open "800 uninvited refusals do not push an open project out of the list" |
| 189 | check "$(awk -F'\t' -v d="$D2" '$3==d' "$W/work/list.tsv" | wc -l)|$(awk -F'\t' -v d="$D3" '$3==d' "$W/work/list.tsv" | wc -l)" "799|1" "all refusal rows are kept, nothing drops the oldest (the last request names the first rid again and replaces only its row)" |
| 190 | [ "$(stat -c %s "$W/work/list.tsv")" -gt 262143 ] && ok "the private list holds them past the former 262,143-byte read buffer ($(stat -c %s "$W/work/list.tsv") bytes)" || bad "private list $(stat -c %s "$W/work/list.tsv") bytes" |
| 191 | check "$(awk -F'\t' 'NF != 8' "$W/work/list.tsv" | wc -l)" 0 "every row of the private list keeps its 8 fields" |
| 192 | cmp -s "$W/work/list.tsv" "$W/open/list.tsv" && ok "the published list is the private list, byte for byte" || bad "the published list differs from the private list" |
| 193 | q "W${TAB}$(rid V1)${TAB}$D1"; intake |
| 194 | [ ! -e "$W/home/store/$(rid V1)" ] && ok "after them the owner can still withdraw the project" || bad "the owner's withdraw found no row; the copy stays seeded" |
| 195 | # 12b. a list several times the former 262,143-byte read buffer (1.2 MB of rows of the shapes the |
| 196 | # intake writes, one of them 70,000 bytes long): two refusals, a withdrawal and a new bring through |
| 197 | # it. Every other row is kept byte for byte, in order; the four changed rows go last, in order. |
| 198 | # bigplant FILE BYTES LONG D1 D2 D3: open and held rows of D1 (open: a 400-byte description and a |
| 199 | # 200-byte note), refusals of D2 (200-byte note), withdrawn rows of D3, until FILE holds at least |
| 200 | # BYTES; row 400 (open) has a LONG-byte description. Prints: rows, rows on the shelf, the last |
| 201 | # open rid, the last refused rid, the long row's rid |
| 202 | bigplant() { |
| 203 | python3 -I - "$@" <<'EOF' |
| 204 | import sys |
| 205 | f, want, long_, d1, d2, d3 = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), sys.argv[4], sys.argv[5], sys.argv[6] |
| 206 | A = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' |
| 207 | rows = []; total = 0; i = 0; pub = 0; lastopen = lastref = longrid = '' |
| 208 | while total < want: |
| 209 | rid = 'z2Big%s%s%sabcdefghijkmnopqrstuvwxyz' % (A[i // 3364 % 58], A[i // 58 % 58], A[i % 58]) |
| 210 | k = i % 4 |
| 211 | if k == 0: |
| 212 | r = [rid, 'open', d1, '2026-11-%02d' % (1 + i % 28), str(1 + i % 5000), 'project-%d' % i, |
| 213 | (('A demo of row %d. ' % i) * 30)[:400], (('note %d ' % i) * 40)[:200]] |
| 214 | lastopen = rid; pub += 1 |
| 215 | elif k == 1: |
| 216 | r = [rid, 'refused: intake is open to invited keys for now', d2, '2026-11-11', '0', '', '', (('n%d' % i) * 100)[:200]] |
| 217 | lastref = rid |
| 218 | elif k == 2: |
| 219 | r = [rid, 'withdrawn', d3, '2026-11-10', '0', 'gone-%d' % i, '', ''] |
| 220 | else: |
| 221 | r = [rid, 'held', d1, '2026-11-09', str(i), 'held-%d' % i, 'node project %d' % i, ''] |
| 222 | pub += 1 |
| 223 | if i == 400 and long_: |
| 224 | r[6] = 'L' * long_; longrid = rid |
| 225 | line = '\t'.join(r) + '\n' |
| 226 | rows.append(line); total += len(line); i += 1 |
| 227 | open(f, 'w').write(''.join(rows)) |
| 228 | print(len(rows), pub, lastopen, lastref, longrid) |
| 229 | EOF |
| 230 | } |
| 231 | # keepck BEFORE AFTER RID...: AFTER is BEFORE without the rows of RID..., byte for byte and in order, |
| 232 | # then one row for each RID, in that order. Prints the number of rows kept. |
| 233 | keepck() { |
| 234 | python3 -I - "$@" <<'EOF' |
| 235 | import sys |
| 236 | b = open(sys.argv[1], 'rb').read().split(b'\n')[:-1]; a = open(sys.argv[2], 'rb').read().split(b'\n')[:-1] |
| 237 | ch = [r.encode() for r in sys.argv[3:]] |
| 238 | keep = [r for r in b if r.split(b'\t')[0] not in ch] |
| 239 | assert a[:len(keep)] == keep, ('kept rows differ', len(a), len(keep)) |
| 240 | assert [r.split(b'\t')[0] for r in a[len(keep):]] == ch, 'the changed rows are not last in order' |
| 241 | print(len(keep)) |
| 242 | EOF |
| 243 | } |
| 244 | # bigrun: the four requests of 12b against a planted 1.2 MB list (BIN may name a mutant) |
| 245 | bigrun() { |
| 246 | set -- $(bigplant "$W/work/list.tsv" 1200000 70000 "$D1" "$D2" "$D3") |
| 247 | BROWS=$1 BPUB=$2 BOPEN=$3 BREF=$4 BLONG=$5 |
| 248 | cp "$W/work/list.tsv" "$T/big.before"; mkdir -p "$W/home/store/$BOPEN"; echo keep > "$W/home/store/$BOPEN/marker" |
| 249 | q "B${TAB}$(rid X1)${TAB}$D2${TAB}not invited"; q "B${TAB}$BREF${TAB}$D2${TAB}again" |
| 250 | q "W${TAB}$BOPEN${TAB}$D1"; q "B${TAB}$(rid N1)${TAB}$D1${TAB}new project"; intake |
| 251 | } |
| 252 | world w3b; echo "$D1" > "$W/work/allow" |
| 253 | bigrun |
| 254 | check "$(stat -c %s "$T/big.before" | awk '{print ($1 >= 4 * 262143)}')" 1 "the planted list is at least 4 times the former read buffer ($(stat -c %s "$T/big.before") bytes, $BROWS rows)" |
| 255 | k=$(keepck "$T/big.before" "$W/work/list.tsv" "$(rid X1)" "$BREF" "$BOPEN" "$(rid N1)" 2>&1) && ok "all $k other rows kept byte for byte and in order, the long row too; the four changed rows last" || bad "rows lost or changed: $k" |
| 256 | check "$(st "$(rid X1)")|$(st "$BREF")" "refused: intake is open to invited keys for now|refused: intake is open to invited keys for now" "two refusals in a 1.2 MB list (a new rid, and a row past the former buffer)" |
| 257 | check "$(st "$BOPEN")" withdrawn "the owner withdraws a project whose row is past the former buffer" |
| 258 | [ ! -e "$W/home/store/$BOPEN" ] && ok "the withdrawn project's copy is removed" || bad "withdrawn copy still there" |
| 259 | check "$(st "$(rid N1)")" open "a new bring through a 1.2 MB list" |
| 260 | check "$(wc -l < "$W/work/list.tsv")" "$((BROWS + 2))" "the list has every planted row plus the two new ones" |
| 261 | cmp -s "$W/work/list.tsv" "$W/open/list.tsv" && ok "the published 1.2 MB list is the private list, byte for byte" || bad "the published list differs from the private list" |
| 262 | case "$(alarm list_row_bytes)" in 70[0-9][0-9][0-9]/4096*) ok "alarm list_row_bytes names the 70,000-byte row ($(alarm list_row_bytes | cut -d'|' -f1))";; *) bad "list_row_bytes: '$(alarm list_row_bytes)'";; esac |
| 263 | # 13. the queue is rotated once it has been read past 256 KiB, so forged's 1 MiB cap is never final |
| 264 | world w4; echo "$D1" > "$W/work/allow" |
| 265 | awk 'BEGIN { for (i = 0; i < 4200; i++) printf "X\tz2abcdefghijkmnopqrstuvwxyzABCDEFGHJKLM\tdid:key:z6MkFiller1111111111111111111\n" }' > "$W/open/queue" |
| 266 | q "B${TAB}$(rid R1)${TAB}$D1${TAB}after filler"; intake |
| 267 | check "$(st "$(rid R1)")" open "the line after 256 KiB of queue is handled" |
| 268 | [ ! -e "$W/open/queue" ] && [ ! -e "$W/open/queue.old" ] && ok "a queue read past 256 KiB is rotated away" || bad "queue still there ($(stat -c %s "$W/open/queue" 2>/dev/null) bytes)" |
| 269 | check "$(cat "$W/state")" 0 "the offset starts again at 0" |
| 270 | q "B${TAB}$(rid R2)${TAB}$D1${TAB}new queue"; intake |
| 271 | check "$(st "$(rid R2)")" open "a line in the new queue is handled" |
| 272 | # a line forged appended to the old queue during the rename is still handled; the lines before |
| 273 | # the stored offset are not handled again |
| 274 | printf 'B\t%s\t%s\tdone before\n' "$(rid R3)" "$D1" > "$W/open/queue.old"; stat -c %s "$W/open/queue.old" > "$W/state" |
| 275 | printf 'B\t%s\t%s\tlate line\n' "$(rid R4)" "$D1" >> "$W/open/queue.old"; intake |
| 276 | check "$(st "$(rid R4)")" open "a late line in queue.old is handled" |
| 277 | check "$(row "$(rid R3)" | wc -l)" 0 "a line before the offset in queue.old is not handled again" |
| 278 | [ ! -e "$W/open/queue.old" ] && ok "queue.old is removed" || bad "queue.old left" |
| 279 | # a restart after queue.old was finished (offset 0) only removes it |
| 280 | printf 'B\t%s\t%s\treplayed\n' "$(rid R5)" "$D1" > "$W/open/queue.old"; echo 0 > "$W/state"; intake |
| 281 | check "$(row "$(rid R5)" | wc -l)" 0 "a finished queue.old is not replayed after a restart" |
| 282 | |
| 283 | # 14. a project the node already seeds by policy (not fetched yet) is the owner's: not touched |
| 284 | world w5; echo "$D1" > "$W/work/allow" |
| 285 | printf 'rad:%s some-project allow followed\n' "$(rid P1)" > "$W/home/stub/policy"; echo "$(rid P1)" > "$W/home/stub/notfound" |
| 286 | q "B${TAB}$(rid P1)${TAB}$D1${TAB}seeded by the owner"; intake |
| 287 | check "$(st "$(rid P1)")" "refused: this node already seeds this project" "a rid in the node's policy list is refused" |
| 288 | check "$(calls "seed rad:$(rid P1)")" 0 "its policy is not rewritten and not removed (no seed, no unseed)" |
| 289 | # 15. a node that does not answer the policy question: nothing is seeded |
| 290 | world w6; echo "$D1" > "$W/work/allow"; : > "$W/home/stub/policyfail" |
| 291 | q "B${TAB}$(rid P2)${TAB}$D1${TAB}node down"; intake |
| 292 | check "$(st "$(rid P2)")" "refused: the Radicle node did not answer; try again" "no answer from the node: refused" |
| 293 | check "$(calls "seed rad:$(rid P2)")" 0 "no answer from the node: no seed" |
| 294 | rm "$W/home/stub/policyfail"; q "B${TAB}$(rid P2)${TAB}$D1${TAB}node back"; intake |
| 295 | check "$(st "$(rid P2)")" open "the same project is accepted once the node answers" |
| 296 | # 16. a folder that appears after this program's own failed fetch is its leftover, not a refusal for good |
| 297 | world w7; echo "$D1" > "$W/work/allow"; echo "$(rid L1)" > "$W/home/stub/late" |
| 298 | q "B${TAB}$(rid L1)${TAB}$D1${TAB}slow fetch"; intake |
| 299 | case "$(st "$(rid L1)")" in "refused: not found"*) ok "a fetch that fails is refused as not found";; *) bad "late fetch: '$(st "$(rid L1)")'";; esac |
| 300 | sleep 3; [ -e "$W/home/store/$(rid L1)/partial" ] && ok "the folder appeared after the failure (the stand-in node finished late)" || bad "stand-in did not make the late folder" |
| 301 | : > "$W/home/stub/late"; q "B${TAB}$(rid L1)${TAB}$D1${TAB}second try"; intake |
| 302 | check "$(st "$(rid L1)")" open "the second bring removes the leftover and succeeds" |
| 303 | [ ! -e "$W/home/store/$(rid L1)/partial" ] && ok "the leftover is gone" || bad "leftover file still there" |
| 304 | # 16b. a refusal that is not about a fetch (a key that is not invited, a node that does not answer, |
| 305 | # the storage reserve before the fetch) leaves the failed-fetch row, so the late folder is still |
| 306 | # cleared on the next bring. The reserve world sets a reserve no disk can keep for the refusal and |
| 307 | # sets it back before the retry. |
| 308 | for via in uninvited nodedown reserve; do |
| 309 | world "w7$via"; echo "$D1" > "$W/work/allow"; echo "$(rid L2)" > "$W/home/stub/late" |
| 310 | q "B${TAB}$(rid L2)${TAB}$D1${TAB}slow fetch"; intake; sleep 3; : > "$W/home/stub/late" |
| 311 | case "$via" in |
| 312 | uninvited) q "B${TAB}$(rid L2)${TAB}$D2${TAB}someone else"; intake ;; |
| 313 | nodedown) : > "$W/home/stub/policyfail"; q "B${TAB}$(rid L2)${TAB}$D1${TAB}node down"; intake; rm "$W/home/stub/policyfail" ;; |
| 314 | reserve) printf 'OPEN_RESERVE_STORAGE_BYTES=999999999999999999\n' > "$W/work/reserve" |
| 315 | q "B${TAB}$(rid L2)${TAB}$D1${TAB}full"; intake; printf 'OPEN_RESERVE_STORAGE_BYTES=1\n' > "$W/work/reserve" ;; |
| 316 | esac |
| 317 | case "$(st "$(rid L2)")" in "refused: not found"*) ok "$via: the failed-fetch row stays";; *) bad "$via: row replaced by '$(st "$(rid L2)")'";; esac |
| 318 | q "B${TAB}$(rid L2)${TAB}$D1${TAB}retry"; intake |
| 319 | check "$(st "$(rid L2)")" open "$via in between: the next bring still clears the leftover and succeeds" |
| 320 | done |
| 321 | # 17. text cut inside a character, or not UTF-8 at all, cannot make the list invalid UTF-8 |
| 322 | world w8; echo "$D1" > "$W/work/allow" |
| 323 | printf '{"xyz.radicle.project":{"defaultBranch":"main","description":"bad \377 byte and caf\303\251","name":"%s\360\237\230\200"}}\n' "$(head -c 118 /dev/zero | tr '\0' a)" > "$W/home/stub/payload" |
| 324 | q "B${TAB}$(rid U1)${TAB}$D1${TAB}utf8"; printf 'B\t%s\t%s\tnote \377\376 here\n' "$(rid U2)" "$D1" >> "$W/open/queue"; intake |
| 325 | iconv -f UTF-8 -t UTF-8 "$W/open/list.tsv" > /dev/null 2>&1 && ok "the published list is valid UTF-8" || bad "the published list is not valid UTF-8" |
| 326 | check "$(row "$(rid U1)" | cut -f6 | tail -c 5 | tr -d '\n')" "aa??" "a name cut inside a 4-byte character ends in ?? (120 bytes)" |
| 327 | check "$(row "$(rid U1)" | cut -f7)" "bad ? byte and café" "a stray byte in the description becomes ?, a real character is kept" |
| 328 | check "$(row "$(rid U2)" | cut -f8)" "note ?? here" "stray bytes in a queued note become ?" |
| 329 | # 18. a public project the node already holds and seeds by its own policy is listed as held: no |
| 330 | # fetch, no seed, and a withdraw only takes the row away |
| 331 | world w9; echo "$D1" > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 332 | mkdir "$W/home/store/$(rid K1)"; echo keep > "$W/home/store/$(rid K1)/marker" |
| 333 | printf 'rad:%s own-project allow all\n' "$(rid K1)" > "$W/home/stub/policy" |
| 334 | q "B${TAB}$(rid K1)${TAB}$D1${TAB}our own unfinished project"; intake |
| 335 | check "$(st "$(rid K1)")" held "a public project already on the node is listed as held" |
| 336 | check "$(row "$(rid K1)" | cut -f6)" demo-project "a held row has the project's name" |
| 337 | check "$(calls "^seed rad:")" 0 "a held project is not seeded (no seed with its rid)" |
| 338 | q "W${TAB}$(rid K1)${TAB}$D2"; intake |
| 339 | check "$(st "$(rid K1)")" held "another key cannot withdraw a held row" |
| 340 | q "W${TAB}$(rid K1)${TAB}$D1"; intake |
| 341 | check "$(st "$(rid K1)")" withdrawn "the key that listed it withdraws the row" |
| 342 | [ -f "$W/home/store/$(rid K1)/marker" ] && ok "withdrawing a held row leaves the repository" || bad "held repository removed" |
| 343 | check "$(calls unseed)" 0 "withdrawing a held row does not unseed" |
| 344 | q "B${TAB}$(rid K1)${TAB}$D1${TAB}again"; intake |
| 345 | check "$(st "$(rid K1)")" held "it can be listed again" |
| 346 | # 19. the leftover of the intake's own failed fetch is not the node's project. Newer refusals no |
| 347 | # longer push its row out (there is no budget); when the row is gone all the same (here it is |
| 348 | # deleted by hand), the folder is still refused (the node does not seed it), never listed as held |
| 349 | world w10; echo "$D1" > "$W/work/allow"; echo public > "$W/home/stub/visibility"; echo "$(rid K2)" > "$W/home/stub/late" |
| 350 | q "B${TAB}$(rid K2)${TAB}$D1${TAB}x"; intake; sleep 3; : > "$W/home/stub/late" |
| 351 | fill 260 "$D3"; intake |
| 352 | check "$(row "$(rid K2)" | wc -l)" 1 "260 newer refusals leave the failed-fetch row in the list" |
| 353 | awk -F'\t' -v r="$(rid K2)" '$1!=r' "$W/work/list.tsv" > "$T/w10.list" && cat "$T/w10.list" > "$W/work/list.tsv" |
| 354 | check "$(awk -F'\t' -v r="$(rid K2)" '$1==r' "$W/work/list.tsv" | wc -l)" 0 "the failed-fetch row deleted by hand" |
| 355 | q "B${TAB}$(rid K2)${TAB}$D1${TAB}again"; intake |
| 356 | check "$(st "$(rid K2)")" "refused: this project's storage is already on this node" "a public folder the node does not seed is refused, not held" |
| 357 | # 19b. only a delegate of a held project may list it: the node's own projects cannot be put on the |
| 358 | # shelf under another key, even when the allow file admits every key |
| 359 | world w14; echo '*' > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 360 | for k in D1 D2 D3 D4 D5 D6 D7 D8; do mkdir "$W/home/store/$(rid $k)"; echo keep > "$W/home/store/$(rid $k)/marker"; printf 'rad:%s own-project allow all\n' "$(rid $k)" >> "$W/home/stub/policy"; done |
| 361 | q "B${TAB}$(rid D1)${TAB}$D2${TAB}not mine"; intake |
| 362 | check "$(st "$(rid D1)")" "refused: only a delegate of this project can list it from this node" "a key that is not a delegate cannot list a held project" |
| 363 | check "$(calls "^seed rad:")" 0 "a refused held bring seeds nothing" |
| 364 | [ -f "$W/home/store/$(rid D1)/marker" ] && ok "a refused held bring leaves the repository" || bad "repository touched" |
| 365 | printf '%sX (longer key)\n' "$D2" > "$W/home/stub/delegates" |
| 366 | q "B${TAB}$(rid D2)${TAB}$D2${TAB}prefix"; intake |
| 367 | check "$(st "$(rid D2)")" "refused: only a delegate of this project can list it from this node" "a delegate whose key only starts with the bringer's key does not admit it" |
| 368 | printf 'did:key:z6MkOther (o)\n%s (two)\n' "$D2" > "$W/home/stub/delegates" |
| 369 | q "B${TAB}$(rid D3)${TAB}$D2${TAB}second delegate"; intake |
| 370 | check "$(st "$(rid D3)")" held "a key on any line of the delegates is admitted" |
| 371 | : > "$W/home/stub/delfail" |
| 372 | q "B${TAB}$(rid D4)${TAB}$D2${TAB}node down"; intake |
| 373 | check "$(st "$(rid D4)")" "refused: the Radicle node did not answer; try again" "no answer about the delegates: refused, nothing listed" |
| 374 | rm "$W/home/stub/delfail" |
| 375 | printf 'did:key:z6MkOther (%s)\n' "$D2" > "$W/home/stub/delegates" |
| 376 | q "B${TAB}$(rid D5)${TAB}$D2${TAB}mid-line"; intake |
| 377 | check "$(st "$(rid D5)")" "refused: only a delegate of this project can list it from this node" "the bringer's key in the middle of a delegates line does not admit it" |
| 378 | printf 'x%s (two)\n' "$D2" > "$W/home/stub/delegates" |
| 379 | q "B${TAB}$(rid D6)${TAB}$D2${TAB}suffix"; intake |
| 380 | check "$(st "$(rid D6)")" "refused: only a delegate of this project can list it from this node" "a delegate whose key only ends with the bringer's key does not admit it" |
| 381 | printf '%s' "$D2" > "$W/home/stub/delegates" |
| 382 | q "B${TAB}$(rid D7)${TAB}$D2${TAB}no line end"; intake |
| 383 | check "$(st "$(rid D7)")" held "a delegate on a last line with no line end is admitted" |
| 384 | printf '%s\r\n' "$D2" > "$W/home/stub/delegates" |
| 385 | q "B${TAB}$(rid D8)${TAB}$D2${TAB}crlf"; intake |
| 386 | check "$(st "$(rid D8)")" held "a delegate line that ends in CR LF is admitted" |
| 387 | rm "$W/home/stub/delegates" |
| 388 | # 19d. the policy list names a project only in its first column: a longer rid, or a project name |
| 389 | # that holds the rid's text, is not the node's policy for it (refused, never held) |
| 390 | world w16; echo "$D1" > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 391 | for k in R1 R2 R3; do mkdir "$W/home/store/$(rid $k)"; echo keep > "$W/home/store/$(rid $k)/marker"; done |
| 392 | printf 'rad:%sX longer-rid allow all\n' "$(rid R1)" > "$W/home/stub/policy" |
| 393 | printf 'rad:z2abcdefghijkmnopqrstuvwQQ rad:%s allow all\n' "$(rid R2)" >> "$W/home/stub/policy" |
| 394 | printf '\342\224\202 rad:%s own-project allow all \342\224\202\n' "$(rid R3)" >> "$W/home/stub/policy" |
| 395 | q "B${TAB}$(rid R1)${TAB}$D1${TAB}longer"; q "B${TAB}$(rid R2)${TAB}$D1${TAB}name"; q "B${TAB}$(rid R3)${TAB}$D1${TAB}table"; intake |
| 396 | check "$(st "$(rid R1)")" "refused: this project's storage is already on this node" "a longer rid in the policy list is not this project's policy" |
| 397 | check "$(st "$(rid R2)")" "refused: this project's storage is already on this node" "a project name holding the rid is not this project's policy" |
| 398 | check "$(st "$(rid R3)")" held "a table row of rad seed (left border, one space, rad:rid) is this project's policy" |
| 399 | [ -f "$W/home/store/$(rid R1)/marker" ] && [ -f "$W/home/store/$(rid R2)/marker" ] && ok "refused held brings leave the storage alone" || bad "storage touched" |
| 400 | # 19c. held rows do not count in a key's key_shelf_rows (they cost no fetch and no disk); they do |
| 401 | # count in shelf_rows, which has no limit: the 200th row is listed and the alarm fires |
| 402 | world w15; echo "$D1" > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 403 | # (rid suffixes are base58: no 0, so the tenth is HA) |
| 404 | for i in 1 2 3 4 5 6 7 8 9 A; do mkdir "$W/home/store/$(rid H$i)"; printf 'rad:%s own-project allow all\n' "$(rid H$i)" >> "$W/home/stub/policy"; q "B${TAB}$(rid H$i)${TAB}$D1${TAB}own $i"; done; intake |
| 405 | check "$(awk -F'\t' '$2=="held"' "$W/work/list.tsv" | wc -l | tr -d ' ')" 10 "a delegate lists 10 of the node's own projects as held" |
| 406 | q "B${TAB}$(rid F1)${TAB}$D1${TAB}fetched"; intake |
| 407 | check "$(st "$(rid F1)")" open "10 held rows and a fetched one are all listed" |
| 408 | check "$(alarm key_shelf_rows)" "" "held rows are not counted in key_shelf_rows (one fetched row)" |
| 409 | awk -v d="$D3" 'BEGIN { for (i = 0; i < 189; i++) printf "z2abcdefghijkmnopqrstuvwS%03d\topen\t%s\t2026-11-10\t1\tplanted\t\t\n", i, d }' >> "$W/work/list.tsv" |
| 410 | mkdir "$W/home/store/$(rid H11)"; printf 'rad:%s own-project allow all\n' "$(rid H11)" >> "$W/home/stub/policy" |
| 411 | q "B${TAB}$(rid H11)${TAB}$D1${TAB}one more"; intake |
| 412 | check "$(st "$(rid H11)")" held "the 200th row on the shelf is listed" |
| 413 | check "$(alarm shelf_rows | cut -d'|' -f1)" 201/200 "the shelf_rows alarm fires past the former 200, held rows counted" |
| 414 | |
| 415 | # 20. the page snapshot: head, last commits, top-level files and README of the project, as data |
| 416 | world w11; echo "$D1" > "$W/work/allow" |
| 417 | G=$W/src; git init -q -b main "$G" |
| 418 | ( cd "$G" && git config user.name 'Ada & Co' && git config user.email a@example.invalid && git config commit.gpgsign false |
| 419 | { printf '# Demo\n\nHalf done. <script>alert(1)</script>\n\ttabbed line\n'; printf 'ctl\001x \377 end\n'; head -c 900 /dev/zero | tr '\0' a; printf '\n'; } > README.md |
| 420 | mkdir src && echo x > src/a.txt && echo y > 'we<ird>&name.txt' && git add -A && git commit -q -m 'first <i>commit</i>' && echo z >> src/a.txt && git commit -q -am 'second commit' ) |
| 421 | git clone -q --bare "$G" "$W/home/stub/template.git" |
| 422 | q "B${TAB}$(rid S1)${TAB}$D1${TAB}snapshot"; intake |
| 423 | P=$W/open/p/$(rid S1).txt |
| 424 | check "$(st "$(rid S1)")" open "a real repository is brought" |
| 425 | check "$(grep '^H' "$P" | cut -f2)" "$(git -C "$G" rev-parse HEAD)" "snapshot: the head is the project's HEAD" |
| 426 | check "$(grep -c '^C' "$P")" 2 "snapshot: both commits" |
| 427 | check "$(grep '^C' "$P" | head -1 | cut -f4-)" "Ada & Co${TAB}second commit" "snapshot: newest commit first, with its author" |
| 428 | check "$(grep '^C' "$P" | sed -n 2p | cut -f5)" "first <i>commit</i>" "snapshot: a subject is kept as data" |
| 429 | check "$(grep '^T' "$P" | cut -f2- | tr '\n' '|')" "b${TAB}README.md|t${TAB}src|b${TAB}we<ird>&name.txt|" "snapshot: the top-level files with their type" |
| 430 | check "$(grep '^R' "$P" | sed -n 1p)" "R${TAB}# Demo" "snapshot: the README, first line" |
| 431 | check "$(grep '^R' "$P" | sed -n 4p)" "R${TAB} tabbed line" "snapshot: a tab in the README becomes a space" |
| 432 | check "$(grep '^R' "$P" | sed -n 5p)" "R${TAB}ctl x ? end" "snapshot: a control byte becomes a space, a stray byte ?" |
| 433 | check "$(grep '^R' "$P" | sed -n '6,8p' | awk '{print length($0) - 2}' | tr '\n' ' ')" "400 400 100 " "snapshot: a 900-byte line is cut into lines of at most 400" |
| 434 | iconv -f UTF-8 -t UTF-8 "$P" > /dev/null 2>&1 && ok "snapshot: valid UTF-8" || bad "snapshot is not valid UTF-8" |
| 435 | check "$(tr -d '\t\n' < "$P" | LC_ALL=C grep -c '[[:cntrl:]]')" 0 "snapshot: no control byte but tab and line feed" |
| 436 | # a second bring by the lister refreshes it; 12 commits and 205 files meet the caps |
| 437 | ( cd "$G" && for i in $(seq 1 10); do echo "$i" > "n$i.txt"; git add -A; git commit -q -m "more $i"; done; for i in $(seq 1 205); do : > "f$i"; done; git add -A; git commit -q -m 'many files' |
| 438 | git push -q "$W/home/store/$(rid S1)" main ) |
| 439 | q "B${TAB}$(rid S1)${TAB}$D2${TAB}someone else"; intake |
| 440 | check "$(grep -c '^C' "$P")" 2 "another key's bring does not refresh the snapshot" |
| 441 | q "B${TAB}$(rid S1)${TAB}$D1${TAB}again"; intake |
| 442 | check "$(grep '^H' "$P" | cut -f2)" "$(git -C "$G" rev-parse HEAD)" "the lister's second bring refreshes the head" |
| 443 | check "$(grep -c '^C' "$P")" 10 "at most 10 commits" |
| 444 | check "$(grep -c '^T' "$P")" 200 "at most 200 top-level entries" |
| 445 | check "$(calls "seed rad:$(rid S1)")" 1 "a refresh does not seed again" |
| 446 | q "W${TAB}$(rid S1)${TAB}$D1"; intake |
| 447 | [ ! -e "$P" ] && ok "withdraw removes the snapshot" || bad "snapshot left after withdraw" |
| 448 | |
| 449 | # the operator's remove file: a project or a key named there comes off the shelf and stays off |
| 450 | world w12; echo '*' > "$W/work/allow" |
| 451 | q "B${TAB}$(rid R1)${TAB}$D1${TAB}one"; q "B${TAB}$(rid R2)${TAB}$D2${TAB}two"; q "B${TAB}$(rid R4)${TAB}$D3${TAB}four"; intake |
| 452 | check "$(st "$(rid R1)")$(st "$(rid R2)")$(st "$(rid R4)")" openopenopen "three keys bring three projects" |
| 453 | printf '*\n\nrad:%s\n' "$(rid R1)" > "$W/work/remove"; intake |
| 454 | check "$(st "$(rid R1)")" "refused: removed by the operator" "remove file: the named project is off the shelf, with no request from its bringer" |
| 455 | [ ! -e "$W/home/store/$(rid R1)" ] && ok "remove file: its copy is deleted" || bad "copy left after the removal" |
| 456 | check "$(calls "unseed rad:$(rid R1)")" 1 "remove file: it is unseeded" |
| 457 | check "$(row "$(rid R1)" | cut -f3)" "$D1" "remove file: the row stays under the key that brought it" |
| 458 | check "$(row "$(rid R1)" | cut -f7,8)" "$TAB" "remove file: description and note are cleared" |
| 459 | check "$(st "$(rid R2)")$(st "$(rid R4)")" openopen "remove file: other projects stay; a * line and an empty line name nothing" |
| 460 | q "B${TAB}$(rid R1)${TAB}$D1${TAB}again"; intake |
| 461 | check "$(st "$(rid R1)")" "refused: removed by the operator" "a removed project cannot be brought again" |
| 462 | check "$(calls "^seed rad:$(rid R1)")" 1 "and the refused bring fetches nothing" |
| 463 | echo "$D2" >> "$W/work/remove"; intake |
| 464 | check "$(st "$(rid R2)")" "refused: removed by the operator" "remove file: the projects of a named key come off the shelf" |
| 465 | q "B${TAB}$(rid R3)${TAB}$D2${TAB}three"; intake |
| 466 | check "$(st "$(rid R3)")" "refused: removed by the operator" "a named key cannot bring" |
| 467 | check "$(calls "^seed rad:$(rid R3)")" 0 "and nothing is fetched for it" |
| 468 | check "$(st "$(rid R4)")" open "a key and a project that are not named are untouched" |
| 469 | echo "$D2" > "$W/work/remove"; q "B${TAB}$(rid R1)${TAB}$D1${TAB}back"; intake |
| 470 | check "$(st "$(rid R1)")" open "with its line taken out of the file the project can be brought again" |
| 471 | world w13; echo "$D1" > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 472 | mkdir "$W/home/store/$(rid K7)"; echo keep > "$W/home/store/$(rid K7)/marker" |
| 473 | printf 'rad:%s own-project allow all\n' "$(rid K7)" > "$W/home/stub/policy" |
| 474 | q "B${TAB}$(rid K7)${TAB}$D1${TAB}held"; intake |
| 475 | check "$(st "$(rid K7)")" held "a project the node seeds is held" |
| 476 | echo "$(rid K7)" > "$W/work/remove"; intake |
| 477 | check "$(st "$(rid K7)")" "refused: removed by the operator" "remove file: a held project comes off the shelf (rid without rad:)" |
| 478 | [ -e "$W/home/store/$(rid K7)/marker" ] && ok "remove file: a held project's storage is left alone" || bad "held storage deleted by the removal" |
| 479 | check "$(calls unseed)" 0 "remove file: a held project is not unseeded" |
| 480 | # a did of 96 bytes (the queue's cap): the remove line names it whole; its 95-byte prefix names nothing |
| 481 | world w14; echo '*' > "$W/work/allow" |
| 482 | D96=did:key:z6Mk$(printf 'L%.0s' $(seq 84)); D95=${D96%?} |
| 483 | q "B${TAB}$(rid K8)${TAB}$D96${TAB}long key"; intake |
| 484 | check "$(st "$(rid K8)")" open "a 96-byte key brings a project" |
| 485 | echo "$D95" > "$W/work/remove"; intake |
| 486 | check "$(st "$(rid K8)")" open "remove file: a line that is only a prefix of the key takes nothing down" |
| 487 | echo "$D96" > "$W/work/remove"; intake |
| 488 | check "$(st "$(rid K8)")" "refused: removed by the operator" "remove file: a named 96-byte key's project comes off the shelf" |
| 489 | |
| 490 | # A failed read must not become an empty/prefix list and advance the queue. A directory opens |
| 491 | # read-only but pread fails with EISDIR, exercising the failed-read rather than missing-file path. |
| 492 | world readfail; echo "$D1" > "$W/work/allow"; mkdir "$W/work/list.tsv" |
| 493 | q "B${TAB}$(rid RF1)${TAB}$D1${TAB}retry me"; intake 2> "$T/readfail.err" |
| 494 | check "$(calls '^seed rad:')" 0 'list read failed: no fetch decision made' |
| 495 | check "$(cat "$W/state" 2>/dev/null || echo 0)" 0 'list read failed: queue offset not advanced' |
| 496 | grep -q 'list.tsv read failed' "$T/readfail.err" && ok 'list read failed: stderr explicitly says the request is retried' || bad 'list read error was silent' |
| 497 | rmdir "$W/work/list.tsv"; intake |
| 498 | check "$(st "$(rid RF1)")" open 'after repairing the list, the same queue request is retried' |
| 499 | # mutants of the intake: each removes one guard; the guarded outcome must change |
| 500 | mut() { # NAME PYTHON-EDIT |
| 501 | python3 -I - "$T/mut-$1.om" "$2" <<'EOF' |
| 502 | import sys |
| 503 | s = open('open/intake.om').read() |
| 504 | old, new = sys.argv[2].split('=>') |
| 505 | old = old.replace('|', '\n'); new = new.replace('|', '\n') |
| 506 | assert s.count(old) == 1, (old, s.count(old)) |
| 507 | open(sys.argv[1], 'w').write(s.replace(old, new)) |
| 508 | EOF |
| 509 | { printf 'om2\n'; cat "$OMV/om/tls/sha2.om" "$T/mut-$1.om"; } | omc > "$T/mut-$1" 2>> "$T/omc.err" && chmod 700 "$T/mut-$1" |
| 510 | } |
| 511 | mut noallow 'if not allowed|rsave kr0 fl|ret|end|=>' && { world m1; BIN=$T/mut-noallow |
| 512 | q "B${TAB}$(rid C1)${TAB}$D1${TAB}x"; intake |
| 513 | [ "$(st "$(rid C1)")" = open ] && ok "MUTANT without the allow check admits the key (the check is what refuses)" || bad "mutant noallow still refused: '$(st "$(rid C1)")'"; BIN=; } || bad "mutant noallow did not build" |
| 514 | mut heldrm 'if not held|dounseed|dorm|end|if snpath false=>dounseed|dorm|if snpath false' && { world m2; BIN=$T/mut-heldrm; echo '*' > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 515 | printf 'rad:%s own-project allow all\n' "$(rid C2)" > "$W/home/stub/policy" |
| 516 | mkdir "$W/home/store/$(rid C2)"; echo keep > "$W/home/store/$(rid C2)/marker" |
| 517 | q "B${TAB}$(rid C2)${TAB}$D1${TAB}x"; q "W${TAB}$(rid C2)${TAB}$D1"; intake |
| 518 | [ ! -e "$W/home/store/$(rid C2)/marker" ] && ok "MUTANT that treats a held row as fetched removes the node's own repository" || bad "mutant heldrm kept the marker"; BIN=; } || bad "mutant heldrm did not build" |
| 519 | mut novis 'if not dovis|save kr1|ret|end|=>' && { world m2b; BIN=$T/mut-novis; echo '*' > "$W/work/allow" |
| 520 | mkdir "$W/home/store/$(rid C5)"; printf 'rad:%s own-project allow all\n' "$(rid C5)" > "$W/home/stub/policy" |
| 521 | q "B${TAB}$(rid C5)${TAB}$D1${TAB}x"; intake |
| 522 | [ "$(st "$(rid C5)")" = held ] && ok "MUTANT without the visibility check lists a private repository" || bad "mutant novis: '$(st "$(rid C5)")'"; BIN=; } || bad "mutant novis did not build" |
| 523 | mut heldpol 'hp = policy|if eq hp 2|save kr6|ret|end|if eq hp 0|save kr1|ret|end|=>' && { world m2c; BIN=$T/mut-heldpol; echo "$D1" > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 524 | echo "$(rid C6)" > "$W/home/stub/late"; q "B${TAB}$(rid C6)${TAB}$D1${TAB}x"; intake; sleep 3; : > "$W/home/stub/late" |
| 525 | awk -F'\t' -v r="$(rid C6)" '$1!=r' "$W/work/list.tsv" > "$T/m2c.list" && cat "$T/m2c.list" > "$W/work/list.tsv"; q "B${TAB}$(rid C6)${TAB}$D1${TAB}z"; intake |
| 526 | [ "$(st "$(rid C6)")" = held ] && ok "MUTANT without the held policy check lists the leftover of a failed fetch" || bad "mutant heldpol: '$(st "$(rid C6)")'"; BIN=; } || bad "mutant heldpol did not build" |
| 527 | mut pubauth 'fn lopen sl ulong to void|lclose sl|wpath klist|=>fn lopen sl ulong to void|lclose sl|pok = pinopen|rname klist|' && { world m4; BIN=$T/mut-pubauth; echo '*' > "$W/work/allow" |
| 528 | mkdir "$W/home/store/$(rid C4)"; echo keep > "$W/home/store/$(rid C4)/marker" |
| 529 | printf '%s\topen\t%s\t2026-11-10\t1\tplanted\t\t\n' "$(rid C4)" "$D1" > "$W/open/list.tsv" |
| 530 | q "W${TAB}$(rid C4)${TAB}$D1"; intake |
| 531 | [ ! -e "$W/home/store/$(rid C4)/marker" ] && ok "MUTANT that trusts the published list removes a planted repository" || bad "mutant pubauth kept the marker"; BIN=; } || bad "mutant pubauth did not build" |
| 532 | mut anywith 'end|end|if not lisdid s e|ret|end|blank=>end|end|blank' && { world m3; BIN=$T/mut-anywith; echo '*' > "$W/work/allow" |
| 533 | q "B${TAB}$(rid C3)${TAB}$D1${TAB}x"; q "W${TAB}$(rid C3)${TAB}$D2"; intake |
| 534 | [ "$(st "$(rid C3)")" = withdrawn ] && ok "MUTANT without the owner check lets another key withdraw" || bad "mutant anywith: '$(st "$(rid C3)")'"; BIN=; } || bad "mutant anywith did not build" |
| 535 | mut nopolicy 'p = policy|if eq p 1|save kr7|ret|end|if eq p 2|rsave kr6 fl|ret|end|=>' && { world m7; BIN=$T/mut-nopolicy; echo "$D1" > "$W/work/allow" |
| 536 | printf 'rad:%s some-project allow followed\n' "$(rid P1)" > "$W/home/stub/policy"; echo "$(rid P1)" > "$W/home/stub/notfound" |
| 537 | q "B${TAB}$(rid P1)${TAB}$D1${TAB}x"; intake |
| 538 | [ "$(calls "unseed rad:$(rid P1)")" = 1 ] && ok "MUTANT without the policy check unseeds a project the owner seeds" || bad "mutant nopolicy did not unseed"; BIN=; } || bad "mutant nopolicy did not build" |
| 539 | mut noleft 'left = fl|=>' && { world m8; BIN=$T/mut-noleft; echo "$D1" > "$W/work/allow"; echo "$(rid L1)" > "$W/home/stub/late" |
| 540 | q "B${TAB}$(rid L1)${TAB}$D1${TAB}x"; intake; sleep 3; : > "$W/home/stub/late"; q "B${TAB}$(rid L1)${TAB}$D1${TAB}y"; intake |
| 541 | case "$(st "$(rid L1)")" in *"already on this node") ok "MUTANT without the leftover rule refuses the project for good";; *) bad "mutant noleft: '$(st "$(rid L1)")'";; esac; BIN=; } || bad "mutant noleft did not build" |
| 542 | mut norsave 'fn rsave t view uchar * fl bool to void|if not fl|save t|end|end|=>fn rsave t view uchar * fl bool to void|save t|end|' && { world m10; BIN=$T/mut-norsave; echo "$D1" > "$W/work/allow"; echo "$(rid L2)" > "$W/home/stub/late" |
| 543 | q "B${TAB}$(rid L2)${TAB}$D1${TAB}x"; intake; sleep 3; : > "$W/home/stub/late"; q "B${TAB}$(rid L2)${TAB}$D2${TAB}y"; intake; q "B${TAB}$(rid L2)${TAB}$D1${TAB}z"; intake |
| 544 | case "$(st "$(rid L2)")" in *"already on this node") ok "MUTANT whose refusals replace the failed-fetch row refuses the project for good";; *) bad "mutant norsave: '$(st "$(rid L2)")'";; esac; BIN=; } || bad "mutant norsave did not build" |
| 545 | mut noutf8 'put dsl 0 jget kdesc 1 400|usnm|usds|=>put dsl 0 jget kdesc 1 400|' && { world m9; BIN=$T/mut-noutf8; echo "$D1" > "$W/work/allow" |
| 546 | printf '{"xyz.radicle.project":{"defaultBranch":"main","description":"bad \377 byte","name":"n"}}\n' > "$W/home/stub/payload" |
| 547 | q "B${TAB}$(rid U1)${TAB}$D1${TAB}x"; intake |
| 548 | iconv -f UTF-8 -t UTF-8 "$W/open/list.tsv" > /dev/null 2>&1 && bad "mutant noutf8 still wrote valid UTF-8" || ok "MUTANT without the UTF-8 pass publishes an invalid list"; BIN=; } || bad "mutant noutf8 did not build" |
| 549 | mut snapraw 'if or lt c 32 eq c 127|if not and tabs eq c 9|c = uchar 32|end|end|put ub i c=>put ub i c' && { world m11; BIN=$T/mut-snapraw; echo "$D1" > "$W/work/allow" |
| 550 | G=$W/src; git init -q -b main "$G"; ( cd "$G" && git config user.name a && git config user.email a@example.invalid && git config commit.gpgsign false && printf 'ctl\001x\n' > README.md && git add -A && git commit -q -m one ) |
| 551 | git clone -q --bare "$G" "$W/home/stub/template.git"; q "B${TAB}$(rid S2)${TAB}$D1${TAB}x"; intake |
| 552 | [ "$(tr -d '\t\n' < "$W/open/p/$(rid S2).txt" | LC_ALL=C grep -c '[[:cntrl:]]')" != 0 ] && ok "MUTANT without the control-byte pass writes a control byte into the snapshot" || bad "mutant snapraw wrote a clean snapshot"; BIN=; } || bad "mutant snapraw did not build" |
| 553 | mut snapkeep 'if snpath false|r = unlink pth 0 get pthl 0|unpin|end|=>' && { world m12; BIN=$T/mut-snapkeep; echo "$D1" > "$W/work/allow" |
| 554 | q "B${TAB}$(rid S3)${TAB}$D1${TAB}x"; q "W${TAB}$(rid S3)${TAB}$D1"; intake |
| 555 | [ -e "$W/open/p/$(rid S3).txt" ] && ok "MUTANT that keeps the snapshot leaves the page data of a withdrawn project" || bad "mutant snapkeep removed the snapshot"; BIN=; } || bad "mutant snapkeep did not build" |
| 556 | mut oldread 'k = pread int sub get lst o 1 lcb mul sl 65536 65536 long pos=>w = ulong 0|if lt pos 262143|w = sub 262143 pos|end|if gt w 65536|w = ulong 65536|end|k = long 0|if gt w 0|k = pread int sub get lst o 1 lcb mul sl 65536 w long pos|end' && { world m5; BIN=$T/mut-oldread; echo "$D1" > "$W/work/allow" |
| 557 | bigrun; k=$(keepck "$T/big.before" "$W/work/list.tsv" "$(rid X1)" "$BREF" "$BOPEN" "$(rid N1)" 2>&1) |
| 558 | [ $? != 0 ] && ok "MUTANT that reads only the former 262,143 bytes of the list cuts it ($(wc -l < "$W/work/list.tsv") of $((BROWS + 2)) rows left)" || bad "mutant oldread kept every row"; BIN=; } || bad "mutant oldread did not build" |
| 559 | mut norotate 'if not qrotate|ret false|end|z = sleepns 1000000000|ret true|=>ret false|' && { world m6; BIN=$T/mut-norotate; echo "$D1" > "$W/work/allow" |
| 560 | awk 'BEGIN { for (i = 0; i < 4200; i++) printf "X\tz2abcdefghijkmnopqrstuvwxyzABCDEFGHJKLM\tdid:key:z6MkFiller1111111111111111111\n" }' > "$W/open/queue"; intake |
| 561 | [ -e "$W/open/queue" ] && ok "MUTANT without the rotation keeps the queue growing toward the cap" || bad "mutant norotate removed the queue"; BIN=; } || bad "mutant norotate did not build" |
| 562 | |
| 563 | mut nosweep 'did2 = sweep|=>did2 = false|' && { world m13; BIN=$T/mut-nosweep; echo '*' > "$W/work/allow" |
| 564 | q "B${TAB}$(rid C7)${TAB}$D1${TAB}x"; intake; echo "rad:$(rid C7)" > "$W/work/remove"; intake |
| 565 | [ "$(st "$(rid C7)")" = open ] && ok "MUTANT without the sweep leaves a removed project on the shelf" || bad "mutant nosweep: '$(st "$(rid C7)")'"; BIN=; } || bad "mutant nosweep did not build" |
| 566 | mut nodeny 'if denied|rsave kr8 fl|ret|end|=>' && { world m14; BIN=$T/mut-nodeny; echo '*' > "$W/work/allow" |
| 567 | q "B${TAB}$(rid C8)${TAB}$D1${TAB}x"; intake; echo "rad:$(rid C8)" > "$W/work/remove"; intake; q "B${TAB}$(rid C8)${TAB}$D1${TAB}again"; intake |
| 568 | [ "$(calls "^seed rad:$(rid C8)")" = 2 ] && ok "MUTANT without the bring check fetches a removed project again" || bad "mutant nodeny: $(calls "^seed rad:$(rid C8)") fetches"; BIN=; } || bad "mutant nodeny did not build" |
| 569 | mut rmheld 'if fetched|dounseed|dorm|end|=>dounseed|dorm|' && { world m15; BIN=$T/mut-rmheld; echo "$D1" > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 570 | mkdir "$W/home/store/$(rid C9)"; echo keep > "$W/home/store/$(rid C9)/marker"; printf 'rad:%s own-project allow all\n' "$(rid C9)" > "$W/home/stub/policy" |
| 571 | q "B${TAB}$(rid C9)${TAB}$D1${TAB}x"; intake; echo "$(rid C9)" > "$W/work/remove"; intake |
| 572 | [ ! -e "$W/home/store/$(rid C9)" ] && ok "MUTANT that treats a held project as fetched deletes its storage on removal" || bad "mutant rmheld kept the storage"; BIN=; } || bad "mutant rmheld did not build" |
| 573 | mut nodel 'dg = dodel|if eq dg 2|save kr6|ret|end|if eq dg 0|save kr9|ret|end|=>' && { world m16; BIN=$T/mut-nodel; echo '*' > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 574 | mkdir "$W/home/store/$(rid E1)"; printf 'rad:%s own-project allow all\n' "$(rid E1)" > "$W/home/stub/policy" |
| 575 | q "B${TAB}$(rid E1)${TAB}$D2${TAB}not mine"; intake |
| 576 | [ "$(st "$(rid E1)")" = held ] && ok "MUTANT without the delegate check lets any key list the node's own project" || bad "mutant nodel: '$(st "$(rid E1)")'"; BIN=; } || bad "mutant nodel did not build" |
| 577 | mut delprefix 'ret eq c 13=>ret true' && { world m17; BIN=$T/mut-delprefix; echo '*' > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 578 | mkdir "$W/home/store/$(rid E2)"; printf 'rad:%s own-project allow all\n' "$(rid E2)" > "$W/home/stub/policy"; printf '%sX (longer key)\n' "$D2" > "$W/home/stub/delegates" |
| 579 | q "B${TAB}$(rid E2)${TAB}$D2${TAB}prefix"; intake |
| 580 | [ "$(st "$(rid E2)")" = held ] && ok "MUTANT without the end-of-key check admits a key that is only a prefix of a delegate" || bad "mutant delprefix: '$(st "$(rid E2)")'"; BIN=; } || bad "mutant delprefix did not build" |
| 581 | mut oldcap 'end|if held|if not dovis=>end|if ge lcount true 8|rsave kr0 fl|ret|end|if held|if not dovis' && { world m18; BIN=$T/mut-oldcap; echo "$D1" > "$W/work/allow" |
| 582 | for i in 1 2 3 4 5 6 7 8 9; do q "B${TAB}$(rid G$i)${TAB}$D1${TAB}n$i"; done; intake |
| 583 | [ "$(st "$(rid G9)")" != open ] && ok "MUTANT with the old 8-a-key cap refuses the ninth fetched project ($(st "$(rid G9)"))" || bad "mutant oldcap listed the ninth"; BIN=; } || bad "mutant oldcap did not build" |
| 584 | mut delstart 'if gt i 0|if ne get cb sub i 1 10|ret false|end|end=>' && { world m19; BIN=$T/mut-delstart; echo '*' > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 585 | mkdir "$W/home/store/$(rid E3)"; printf 'rad:%s own-project allow all\n' "$(rid E3)" > "$W/home/stub/policy"; printf 'x%s (two)\n' "$D2" > "$W/home/stub/delegates" |
| 586 | q "B${TAB}$(rid E3)${TAB}$D2${TAB}mid-line"; intake |
| 587 | [ "$(st "$(rid E3)")" = held ] && ok "MUTANT without the start-of-line check admits a key named in the middle of a delegates line" || bad "mutant delstart: '$(st "$(rid E3)")'"; BIN=; } || bad "mutant delstart did not build" |
| 588 | mut rmstart 'if not st|ret false|end|for k ulong n bound 44=>for k ulong n bound 44' && { world m20; BIN=$T/mut-rmstart; echo "$D1" > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 589 | mkdir "$W/home/store/$(rid E4)"; printf 'rad:z2abcdefghijkmnopqrstuvwQQ rad:%s allow all\n' "$(rid E4)" > "$W/home/stub/policy" |
| 590 | q "B${TAB}$(rid E4)${TAB}$D1${TAB}name"; intake |
| 591 | [ "$(st "$(rid E4)")" = held ] && ok "MUTANT without the first-column check takes a project name for the node's policy" || bad "mutant rmstart: '$(st "$(rid E4)")'"; BIN=; } || bad "mutant rmstart did not build" |
| 592 | mut rmend 'e = add i n|if ge e lim|ret true|end|c = get cb e|if eq c 32|ret true|end|if eq c 9|ret true|end|if eq c 13|ret true|end|ret eq c 10=>ret true' && { world m21; BIN=$T/mut-rmend; echo "$D1" > "$W/work/allow"; echo public > "$W/home/stub/visibility" |
| 593 | mkdir "$W/home/store/$(rid E5)"; printf 'rad:%sX longer-rid allow all\n' "$(rid E5)" > "$W/home/stub/policy" |
| 594 | q "B${TAB}$(rid E5)${TAB}$D1${TAB}longer"; intake |
| 595 | [ "$(st "$(rid E5)")" = held ] && ok "MUTANT without the end-of-rid check takes a longer rid for the node's policy" || bad "mutant rmend: '$(st "$(rid E5)")'"; BIN=; } || bad "mutant rmend did not build" |
| 596 | # ------------------------------------------------------------------ part 2: the shelf inside forged |
| 597 | mkdir -p "$T/data" "$T/social"; mkdir -m 700 "$T/slwork" |
| 598 | build() { # OUT [sed expression on the composed source] |
| 599 | { printf 'om2\n'; cat $(FORGE_TRY="salvage open" ./run.sh units); } \ |
| 600 | | sed -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" -e "s/18480/$PORT/g" ${2:+-e "$2"} | omc > "$1" 2>> "$T/omc.err" && chmod 700 "$1" |
| 601 | } |
| 602 | build "$T/forged" || { echo "BUILD FAILED forged: $(tail -2 "$T/omc.err")"; exit 1; } |
| 603 | start() { |
| 604 | FORGE_SOCIAL_DIR="$T/social/" INTERPLANE_SALVAGE_DIR="$T/salvage/" taskset -c "$CORES" nice -n 10 "$1" 2>> "$T/forged.err" & |
| 605 | PID=$! |
| 606 | for i in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PORT/" && return 0; sleep 0.1; done |
| 607 | echo "server did not start"; cat "$T/forged.err"; exit 1 |
| 608 | } |
| 609 | B="http://127.0.0.1:$PORT" |
| 610 | # code: forged adds translation hints while it sends a page (server/tr.om: translate="no" attributes and |
| 611 | # <span translate="no"> around hashes and ids); the content checks read the page without them |
| 612 | # (server/tests/translate.sh gates the hints themselves) |
| 613 | code() { m=$1; p=$2; shift 2; c=$(curl -s -o "$T/body" -D "$T/hdr" -X "$m" "$@" "$B$p" -w '%{http_code}'); grep -qi '^content-type: text/html' "$T/hdr" && sed -i 's/<span translate="no">\([^<]*\)<\/span>/\1/g; s/ translate="no"//g' "$T/body"; printf %s "$c"; } |
| 614 | hdr() { grep -i "^$1:" "$T/hdr" | head -1 | cut -d' ' -f2- | tr -d '\r'; } |
| 615 | field() { grep -o "name=\"$1\" value=\"[^\"]*\"" "$T/body" | head -1 | sed 's/.*value="//; s/"$//'; } |
| 616 | ssh-keygen -q -t ed25519 -N '' -C t1 -f "$T/k1" |
| 617 | did() { python3 -I - "$1" <<'EOF' |
| 618 | import sys, base64 |
| 619 | blob = base64.b64decode(open(sys.argv[1]).read().split()[1]) |
| 620 | raw = b'\xed\x01' + blob[-32:] |
| 621 | A = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' |
| 622 | n = int.from_bytes(raw, 'big'); s = '' |
| 623 | while n: n, r = divmod(n, 58); s = A[r] + s |
| 624 | print('did:key:z' + s) |
| 625 | EOF |
| 626 | } |
| 627 | K1=$(did "$T/k1.pub") |
| 628 | signin() { # [KEYFILE DID], default the first throwaway key |
| 629 | code GET /login >/dev/null |
| 630 | PREN=$(hdr set-cookie | sed -n 's/^\([A-Za-z_-]*forge_pre\)=.*/\1/p') |
| 631 | PRE=$(hdr set-cookie | sed -n 's/^[A-Za-z_-]*forge_pre=\([0-9a-f]*\);.*/\1/p') |
| 632 | CSRF=$(field csrf); NONCE=$(field nonce); TS=$(field ts) |
| 633 | printf '%s' "interplane-forge-login:$NONCE:$TS" | ssh-keygen -Y sign -f "${1:-$T/k1}" -n interplane-forge > "$T/sig" 2>/dev/null |
| 634 | c=$(code POST /login -H "Cookie: $PREN=$PRE" --data-urlencode "csrf=$CSRF" --data-urlencode "nonce=$NONCE" --data-urlencode "ts=$TS" --data-urlencode "did=${2:-$K1}" --data-urlencode "sig@$T/sig") |
| 635 | SES=$(hdr set-cookie | sed -n 's/^__Host-forge_session=\([0-9a-f]*\);.*/\1/p') |
| 636 | CK="Cookie: __Host-forge_session=$SES" |
| 637 | } |
| 638 | Q=$T/data/open/queue |
| 639 | qn() { [ -f "$Q" ] && wc -l < "$Q" || echo 0; } |
| 640 | start "$T/forged" |
| 641 | R1=$(rid H1) |
| 642 | c=$(code GET /open); check "$c" 301 "GET /open redirects"; check "$(hdr location)" /open/ "to /open/" |
| 643 | c=$(code GET /open/); check "$c" 200 "GET /open/ signed out" |
| 644 | grep -q "Open builds" "$T/body" && grep -q "Sign in with your key" "$T/body" && ok "signed out: the page asks for a sign-in" || bad "signed-out page text" |
| 645 | grep -q 'name="rid"' "$T/body" && bad "signed out: the form is shown" || ok "signed out: no bring form" |
| 646 | grep -q "waiting for its first project" "$T/body" && ok "an empty shelf says so" || bad "empty shelf text" |
| 647 | c=$(code POST /open/ --data-urlencode "action=bring" --data-urlencode "rid=rad:$R1" --data-urlencode "consent=yes"); [ "$c" != 200 ] && [ "$(qn)" = 0 ] && ok "NEG a POST without a session writes nothing ($c)" || bad "unsigned POST: $c, queue $(qn)" |
| 648 | signin; check "${#SES}" 64 "signed in with a throwaway key" |
| 649 | c=$(code GET /open/ -H "$CK"); check "$c" 200 "GET /open/ signed in" |
| 650 | TOK=$(field csrf); check "${#TOK}" 32 "the bring form carries a CSRF token" |
| 651 | grep -q 'name="rid"' "$T/body" && ok "signed in: the bring form is shown" || bad "no bring form when signed in" |
| 652 | post() { code POST /open/ -H "$CK" --data-urlencode "csrf=$TOK" "$@"; } |
| 653 | c=$(code POST /open/ -H "$CK" --data-urlencode "action=bring" --data-urlencode "rid=rad:$R1" --data-urlencode "consent=yes"); [ "$c" != 303 ] && [ "$(qn)" = 0 ] && ok "NEG no CSRF token: refused ($c)" || bad "POST without csrf: $c" |
| 654 | c=$(code POST /open/ -H "$CK" --data-urlencode "csrf=${TOK%?}x" --data-urlencode "action=bring" --data-urlencode "rid=rad:$R1" --data-urlencode "consent=yes"); [ "$c" != 303 ] && [ "$(qn)" = 0 ] && ok "NEG wrong CSRF token: refused ($c)" || bad "POST with wrong csrf: $c" |
| 655 | c=$(post --data-urlencode "action=bring" --data-urlencode "rid=rad:../../../etc/passwd" --data-urlencode "consent=yes" --data-urlencode "note="); check "$c" 400 "NEG a path as the rid" |
| 656 | c=$(post --data-urlencode "action=bring" --data-urlencode "rid=rad:z2abc" --data-urlencode "consent=yes" --data-urlencode "note="); check "$c" 400 "NEG a rid that is too short" |
| 657 | c=$(post --data-urlencode "action=bring" --data-urlencode "rid=rad:${R1}0" --data-urlencode "consent=yes" --data-urlencode "note="); check "$c" 400 "NEG a rid with a character outside base58" |
| 658 | c=$(post --data-urlencode "action=bring" --data-urlencode "rid=rad:$R1" --data-urlencode "note="); check "$c" 400 "NEG no permission tick" |
| 659 | c=$(post --data-urlencode "action=bring" --data-urlencode "rid=rad:$R1" --data-urlencode "consent=yes" --data-urlencode "note=$(head -c 201 /dev/zero | tr '\0' n)"); check "$c" 400 "NEG a note over 200 bytes" |
| 660 | c=$(post --data-urlencode "action=erase" --data-urlencode "rid=rad:$R1" --data-urlencode "consent=yes" --data-urlencode "note="); check "$c" 400 "NEG an unknown action" |
| 661 | check "$(qn)" 0 "nine refused posts wrote nothing" |
| 662 | c=$(post --data-urlencode "action=bring" --data-urlencode "rid=rad:$R1" --data-urlencode "consent=yes" --data-urlencode "note=needs a parser & tests"); check "$c" 303 "bring" |
| 663 | check "$(hdr location)" /open/ "bring returns to the shelf" |
| 664 | check "$(sed -n 1p "$Q")" "B${TAB}$R1${TAB}$K1${TAB}needs a parser & tests" "the queue line: kind, rid, the signed-in key, the note" |
| 665 | c=$(post --data-urlencode "action=bring" --data-urlencode "rid=$(rid H2)" --data-urlencode "consent=yes" --data-urlencode "note=$(printf 'two\r\nlines\there')"); check "$c" 303 "bring without the rad: prefix, note with a line break and a tab" |
| 666 | check "$(qn)" 2 "a line break in the note does not add a queue line" |
| 667 | check "$(sed -n 2p "$Q" | awk -F'\t' '{print NF}')" 4 "a tab in the note does not add a field" |
| 668 | c=$(post --data-urlencode "action=bring" --data-urlencode "rid=rad:$R1" --data-urlencode "consent=yes" --data-urlencode "note=" --data-urlencode "did=did:key:z6MkSomebodyElse"); check "$c" 303 "bring with an empty note"; check "$(sed -n 3p "$Q" | cut -f3)" "$K1" "a did field in the form is ignored; the session decides" |
| 669 | c=$(post --data-urlencode "action=withdraw" --data-urlencode "rid=rad:$R1"); check "$c" 303 "withdraw" |
| 670 | check "$(sed -n 4p "$Q")" "W${TAB}$R1${TAB}$K1" "the withdraw line" |
| 671 | c=$(code POST /open/ -H "$CK" -H "Origin: https://evil.example" --data-urlencode "csrf=$TOK" --data-urlencode "action=withdraw" --data-urlencode "rid=rad:$R1"); [ "$c" != 303 ] && [ "$(qn)" = 4 ] && ok "NEG a POST from another origin writes nothing ($c)" || bad "cross-origin POST: $c, queue $(qn)" |
| 672 | c=$(code PUT /open/ -H "$CK"); check "$c" 405 "NEG PUT" |
| 673 | # the list, written here as the intake would write it, with hostile text in every free field |
| 674 | H='<script>alert(1)</script>"&' |
| 675 | { |
| 676 | printf '%s\topen\t%s\t2026-11-10\t412\t%s\t%s\t%s\n' "$R1" "$K1" "$H" "desc $H" "note $H" |
| 677 | printf '%s\topen\t%s\t2026-11-09\t77\tother-project\tsecond one\twants a reviewer\n' "$(rid H3)" "$D2" |
| 678 | printf '%s\trefused: larger than 50 MiB\t%s\t2026-11-10\t0\t\t\tmine\n' "$(rid H4)" "$K1" |
| 679 | printf '%s\trefused: not found\t%s\t2026-11-10\t0\t\t\ttheirs\n' "$(rid H5)" "$D2" |
| 680 | printf '%s\twithdrawn\t%s\t2026-11-10\t0\tgone-project\t\t\n' "$(rid H6)" "$D2" |
| 681 | printf '../../etc\topen\t%s\t2026-11-10\t1\tbad-rid\tx\tx\n' "$D2" |
| 682 | printf '%s\topen\t%s\n' "$(rid H7)" "$D2" |
| 683 | printf '%s\theld\t%s\t2026-11-10\t900\tnode-project\talready on the node\tours\n' "$(rid H8)" "$D2" |
| 684 | } > "$T/data/open/list.tsv" |
| 685 | mkdir -p "$T/data/open/p" |
| 686 | { |
| 687 | printf 'H\tabc123def4567890abc123def4567890abc123de\t2026-11-10\n' |
| 688 | printf 'C\t1a2b3c4\t2026-11-10\tAda <b>\tfix <script>alert(2)</script>\n' |
| 689 | printf 'T\tb\tREADME.md\nT\tt\tsrc\nT\tb\twe<ird>&name.txt\n' |
| 690 | printf 'R\t# Demo\nR\t\nR\t<img src=x onerror=alert(3)>\n' |
| 691 | printf 'X\tunknown kind\njunk without a tab\n' |
| 692 | } > "$T/data/open/p/$R1.txt" |
| 693 | cp "$T/data/open/p/$R1.txt" "$T/data/open/p/$(rid H4).txt" |
| 694 | c=$(code GET /open/); check "$c" 200 "the shelf with rows" |
| 695 | grep -q '<script' "$T/body" && bad "the page carries a script tag from a row" || ok "hostile row text is escaped (no <script in the page)" |
| 696 | grep -q '<script>alert(1)</script>"&' "$T/body" && ok "the hostile text is shown as text" || bad "escaped text not found" |
| 697 | check "$(grep -o 'href="/open/z[0-9A-Za-z]*"' "$T/body" | sort | tr '\n' ' ')" "href=\"/open/$R1\" href=\"/open/$(rid H3)\" href=\"/open/$(rid H8)\" " "exactly the two well-formed open rows and the held row are listed" |
| 698 | check "$(grep -o 'Not verified' "$T/body" | wc -l)" 3 "each listed project says Not verified" |
| 699 | grep -q -e "bad-rid" -e "gone-project" -e "larger than 50 MiB" -e "not found" "$T/body" && bad "a refused, withdrawn or malformed row is public" || ok "refused, withdrawn and malformed rows are not public" |
| 700 | grep -q 'value="withdraw"' "$T/body" && bad "signed out: a withdraw button" || ok "signed out: no withdraw button" |
| 701 | c=$(code GET /open/ -H "$CK") |
| 702 | check "$(grep -o 'value="withdraw"' "$T/body" | wc -l)" 1 "signed in: one withdraw button, on the project this key brought" |
| 703 | grep -q "larger than 50 MiB" "$T/body" && ok "signed in: this key sees its own refusal" || bad "own refusal not shown" |
| 704 | grep -q "not found" "$T/body" && bad "signed in: another key's refusal is shown" || ok "signed in: another key's refusal stays private" |
| 705 | c=$(code GET /open/ -H 'Accept: application/json'); check "$c" 200 "the JSON form" |
| 706 | python3 -I - "$T/body" "$R1" "$H" "$K1" <<'EOF' && ok "JSON: parses, 3 projects, hostile text round-trips, verified is false" || bad "JSON form" |
| 707 | import json, sys |
| 708 | d = json.load(open(sys.argv[1], encoding='utf-8')) |
| 709 | p = d['projects'] |
| 710 | assert d['schema'] == 'interplane/open-builds/1' and len(p) == 3, d |
| 711 | a = p[0] |
| 712 | assert a['rid'] == sys.argv[2] and a['name'] == sys.argv[3] and a['unfinished'] == 'note ' + sys.argv[3], a |
| 713 | assert a['brought_by'] == sys.argv[4] and a['kib'] == 412 and a['date'] == '2026-11-10', a |
| 714 | assert all(x['verified'] is False for x in p) |
| 715 | EOF |
| 716 | # the project page |
| 717 | c=$(code GET /open/); grep -q "href=\"/open/$R1\"" "$T/body" && ok "the shelf links each project to its page" || bad "no link to the project page" |
| 718 | c=$(code GET "/open/$R1"); check "$c" 200 "GET /open/<rid> of a listed project" |
| 719 | grep -q -e '<script' -e '<img' "$T/body" && bad "the project page carries a tag from the snapshot" || ok "snapshot text is escaped on the project page" |
| 720 | grep -q 'fix <script>alert(2)</script>' "$T/body" && grep -q '<img src=x onerror=alert(3)>' "$T/body" && ok "the hostile commit subject and README line are shown as text" || bad "escaped snapshot text not found" |
| 721 | grep -q 'Latest commits' "$T/body" && grep -q '<li>src/</li>' "$T/body" && grep -q '<li>we<ird>&name.txt</li>' "$T/body" && grep -q 'abc123def4567890abc123def4567890abc123de 2026-11-10' "$T/body" && grep -q 'No public Git URL yet: Interplane does not serve Git clones yet.' "$T/body" && grep -q 'Not verified' "$T/body" && ok "the page shows head, commits, files (a folder with a slash), no-clone-URL line, Not verified" || bad "project page content" |
| 722 | grep -q -e 'unknown kind' -e 'junk without' "$T/body" && bad "an unknown snapshot line is shown" || ok "snapshot lines of an unknown kind are not shown" |
| 723 | c=$(code GET "/open/$(rid H8)"); check "$c" 200 "a held project has a page"; grep -q 'No snapshot of this project yet' "$T/body" && ok "without a snapshot the page says so" || bad "no-snapshot text" |
| 724 | c=$(code GET "/open/$(rid H4)"); check "$c" 404 "NEG a refused project has no page, even with a snapshot file there" |
| 725 | c=$(code GET "/open/$(rid H6)"); check "$c" 404 "NEG a withdrawn project has no page" |
| 726 | c=$(code GET "/open/$(rid ZZ)"); check "$c" 404 "NEG a rid that is not on the shelf" |
| 727 | c=$(code GET "/open/zshort"); check "$c" 404 "NEG a rid that is too short" |
| 728 | c=$(code GET "/open/${R1}0"); check "$c" 404 "NEG a rid with a character outside base58" |
| 729 | c=$(curl -s -o /dev/null --path-as-is -w '%{http_code}' "$B/open/../open/p/$R1.txt"); [ "$c" != 200 ] && ok "NEG the snapshot file is not served as a path ($c)" || bad "snapshot file served directly" |
| 730 | c=$(code POST "/open/$R1" -H "$CK" --data-urlencode "csrf=$TOK"); [ "$c" != 200 ] && [ "$c" != 303 ] && ok "NEG POST to a project page is refused ($c)" || bad "POST to a project page: $c" |
| 731 | c=$(code GET "/open/$R1" -H 'Accept: application/json'); check "$c" 200 "the project page as JSON" |
| 732 | python3 -I - "$T/body" "$R1" "$K1" <<'EOF' && ok "project JSON: parses; head, commits, files and README round-trip as data" || bad "project JSON" |
| 733 | import json, sys |
| 734 | d = json.load(open(sys.argv[1], encoding='utf-8')) |
| 735 | assert d['schema'] == 'interplane/open-build/1' and d['rid'] == sys.argv[2] and d['brought_by'] == sys.argv[3], d |
| 736 | assert d['verified'] is False and d['kib'] == 412 |
| 737 | assert d['head'] == 'abc123def4567890abc123def4567890abc123de 2026-11-10', d['head'] |
| 738 | assert d['commits'] == ['1a2b3c4 2026-11-10 Ada <b> fix <script>alert(2)</script>'], d['commits'] |
| 739 | assert d['files'] == ['README.md', 'src/', 'we<ird>&name.txt'], d['files'] |
| 740 | assert d['readme'] == '# Demo\n\n<img src=x onerror=alert(3)>\n', d['readme'] |
| 741 | assert d['parts'] == [], d['parts'] |
| 742 | EOF |
| 743 | # parts taken from the project: the salvage store is on in this test server. A second throwaway |
| 744 | # key submits (its own write budget), the real collector verifies the derived part. |
| 745 | c=$(code GET "/open/$R1"); grep -q 'Parts taken from this project' "$T/body" && grep -q 'None yet' "$T/body" && ok "a project with no submission says so and points to Bring your build" || bad "empty parts section" |
| 746 | { printf 'om2\n'; cat "$OMV/om/tls/sha2.om" salvage/00core.om salvage/10verify.om salvage/collector.om; } | omc > "$T/collector" 2>> "$T/omc.err" && chmod 700 "$T/collector" || bad "collector did not build" |
| 747 | ssh-keygen -q -t ed25519 -N '' -C t2 -f "$T/k2"; K2=$(did "$T/k2.pub"); CK1=$CK; signin "$T/k2" "$K2"; CK2=$CK; CK=$CK1 |
| 748 | code GET /salvage/new -H "$CK2" >/dev/null; STOK=$(field csrf) |
| 749 | spost() { p=$1; shift; code POST "$p" -H "$CK2" --data-urlencode "csrf=$STOK" "$@"; } |
| 750 | src() { spost /salvage/ --data-urlencode action=source --data-urlencode consent=yes --data-urlencode "title=$1" --data-urlencode "origin=$2" --data-urlencode license=MIT --data-urlencode "description=half a parser" --data-urlencode "source=a sketch $1" --data-urlencode credit=tester --data-urlencode "language=Plain text"; } |
| 751 | c=$(src 'Parser <b>sketch</b>' "rad:$R1"); check "$c" 303 "a source is submitted with this project as its origin"; SID=$(hdr location | sed 's|.*/||') |
| 752 | c=$(src 'Other project source' "rad:$(rid H3)"); SID2=$(hdr location | sed 's|.*/||') |
| 753 | c=$(src 'Near miss origin' "see rad:$R1"); SID3=$(hdr location | sed 's|.*/||') |
| 754 | check "${#SID}${#SID2}${#SID3}" 646464 "three sources saved" |
| 755 | c=$(code GET "/open/$R1") |
| 756 | grep -q "href=\"/salvage/$SID\">Parser <b>sketch</b></a> (source, not verified)" "$T/body" && ok "the project page lists the source taken from it, title escaped, as not verified" || bad "source not listed" |
| 757 | grep -q -e "$SID2" -e "$SID3" "$T/body" && bad "a source of another origin is listed" || ok "a source of another project, or with the rid only inside its origin text, is not listed" |
| 758 | printf 'om2\ntext msg "hello\\n"\nfn main to int\nr = write 1 msg 0 len msg\nret 0\nend\n' > "$T/part.om"; printf 'hello\n' > "$T/expected" |
| 759 | derive() { spost "/salvage/$SID" --data-urlencode action=derive --data-urlencode consent=yes --data-urlencode "title=$1" --data-urlencode "description=one small part" --data-urlencode "source@$T/part.om" --data-urlencode "input=" --data-urlencode "expected@$T/expected"; } |
| 760 | c=$(derive 'Greeting part'); check "$c" 303 "an Omega part is derived from that source"; PRT=$(hdr location | sed 's|.*/||') |
| 761 | c=$(code GET "/open/$R1"); grep -q "$PRT" "$T/body" && bad "an unverified draft part is listed" || ok "a derived part that is not verified and published is not listed" |
| 762 | c=$(spost "/salvage/$PRT" --data-urlencode action=verify); check "$c" 303 "verification is queued" |
| 763 | env -i INTERPLANE_SALVAGE_DIR="$T/salvage/" INTERPLANE_SALVAGE_WORK="$T/slwork/" OMEGA_COMPILER="$OMC" taskset -c "$CORES" "$T/collector" once > "$T/collector.out" 2>&1; check "$?" 1 "the real collector ran the declared example and wrote a receipt (exit 1 = a receipt was written)" |
| 764 | c=$(spost "/salvage/$PRT" --data-urlencode action=publish); check "$c" 303 "the verified part is published" |
| 765 | c=$(derive 'Draft part, never verified'); DRAFT=$(hdr location | sed 's|.*/||') |
| 766 | c=$(code GET "/open/$R1") |
| 767 | grep -q "href=\"/salvage/$PRT\">Greeting part</a> (Omega part, verified)" "$T/body" && ok "the project page lists the verified part with a link to its page and receipt" || bad "verified part not listed" |
| 768 | grep -q "$DRAFT" "$T/body" && bad "a second, unverified draft is listed" || ok "a later unverified draft is still not listed" |
| 769 | grep -q 'Not verified. Brought by' "$T/body" && ok "the project itself stays Not verified" || bad "project line changed" |
| 770 | c=$(code GET "/open/$(rid H3)"); grep -q "$SID2" "$T/body" && ! grep -q -e "$SID\"" -e "$PRT" "$T/body" && ok "the other project lists only its own source" || bad "parts of the other project" |
| 771 | code GET "/open/$R1" -H 'Accept: application/json' >/dev/null |
| 772 | python3 -I - "$T/body" "$SID" "$PRT" <<'EOF' && ok "project JSON: parts holds the verified part and the source, newest first" || bad "project JSON parts" |
| 773 | import json, sys |
| 774 | p = json.load(open(sys.argv[1], encoding='utf-8'))['parts'] |
| 775 | assert p == [{'id': sys.argv[3], 'title': 'Greeting part', 'kind': 'omega-part', 'verified': True}, |
| 776 | {'id': sys.argv[2], 'title': 'Parser <b>sketch</b>', 'kind': 'source', 'verified': False}], p |
| 777 | EOF |
| 778 | # names of their own for the JSON, the forge row entries, the line for agents |
| 779 | c=$(code GET /open.json); check "$c" 200 "GET /open.json" |
| 780 | python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["schema"]=="interplane/open-builds/1" and len(d["projects"])==3' "$T/body" && ok "/open.json is the shelf JSON without an Accept header" || bad "/open.json" |
| 781 | c=$(code GET "/open/$R1.json"); check "$c" 200 "GET /open/<rid>.json" |
| 782 | python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["schema"]=="interplane/open-build/1" and d["rid"]==sys.argv[2] and len(d["commits"])==1' "$T/body" "$R1" && ok "/open/<rid>.json is the project JSON without an Accept header" || bad "/open/<rid>.json" |
| 783 | c=$(code GET "/open/$(rid H4).json"); check "$c" 404 "NEG the .json name of a refused project" |
| 784 | c=$(code GET "/open/${R1}.jsonx"); check "$c" 404 "NEG a near-miss suffix is not a rid" |
| 785 | c=$(code POST /open.json -H "$CK" --data-urlencode "csrf=$TOK"); [ "$c" != 200 ] && [ "$c" != 303 ] && ok "NEG POST to /open.json is refused ($c)" || bad "POST /open.json: $c" |
| 786 | c=$(code GET /open/) |
| 787 | grep -q '<a href="/open/">Open builds</a>' "$T/body" && ok "the forge row carries Open builds" || bad "no Open builds entry in the forge row" |
| 788 | grep -q '<a href="/salvage/">Bring your build</a>' "$T/body" && ok "the forge row carries Bring your build while the store is on" || bad "no Bring your build entry" |
| 789 | grep -q 'open.json</code>' "$T/body" && ok "the shelf tells agents where its JSON is" || bad "no line for agents" |
| 790 | # no queue cap: a queue past the former 1 MiB still takes a line (queue_bytes alarms; the data |
| 791 | # reserve, through <data>open/space, is what refuses) |
| 792 | head -c 1048577 /dev/zero > "$Q" |
| 793 | c=$(post --data-urlencode "action=bring" --data-urlencode "rid=rad:$R1" --data-urlencode "consent=yes" --data-urlencode "note="); check "$c" 303 "a queue past the former 1 MiB still takes a line" |
| 794 | [ "$(stat -c %s "$Q")" -gt 1048577 ] && ok "and the line is written" || bad "queue not written" |
| 795 | stop |
| 796 | # the shelf past the former 262,143-byte list buffer: forged reads <data>open/list.tsv a row at a |
| 797 | # time; every row on the shelf of a 1.2 MB list (one of them 70,000 bytes) is in /open.json, in |
| 798 | # order, and on /open/; project pages past the former buffer answer |
| 799 | cp "$T/data/open/list.tsv" "$T/list.small" |
| 800 | set -- $(bigplant "$T/data/open/list.tsv" 1200000 70000 "$D1" "$D2" "$D3"); BPUB=$2 BOPEN=$3 BLONG=$5 |
| 801 | # shelfck LIST JSON: the rids of /open.json are the shelf rows of LIST, in order |
| 802 | shelfck() { |
| 803 | python3 -I - "$1" "$2" <<'EOF' |
| 804 | import json, sys |
| 805 | want = [l.split('\t')[0] for l in open(sys.argv[1], encoding='utf-8') if l.split('\t')[1] in ('open', 'held', 'stored')] |
| 806 | got = [p['rid'] for p in json.load(open(sys.argv[2], encoding='utf-8'))['projects']] |
| 807 | assert got == want, (len(got), len(want)) |
| 808 | print(len(got)) |
| 809 | EOF |
| 810 | } |
| 811 | start "$T/forged" |
| 812 | c=$(code GET /open.json); check "$c" 200 "GET /open.json with a 1.2 MB list" |
| 813 | n=$(shelfck "$T/data/open/list.tsv" "$T/body" 2>&1) && ok "/open.json lists all $n shelf rows of the 1.2 MB list, in order" || bad "/open.json: $n" |
| 814 | check "$n" "$BPUB" "and that is every open and held row planted" |
| 815 | c=$(code GET /open/); [ "$c" = 200 ] && grep -q "$BOPEN" "$T/body" && grep -q "$BLONG" "$T/body" && ok "/open/ shows the last open row and the 70,000-byte row" || bad "/open/ with a 1.2 MB list: $c" |
| 816 | c=$(code GET "/open/$BOPEN"); check "$c" 200 "the project page of the last row answers" |
| 817 | c=$(code GET "/open/$BLONG.json"); [ "$c" = 200 ] && python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d["rid"]==sys.argv[2] and len(d["description"])==400' "$T/body" "$BLONG" && ok "the 70,000-byte row has a page; its description is cut at the page's 400 as every row's is" || bad "long row page: $c $(head -c 200 "$T/body")" |
| 818 | stop |
| 819 | if build "$T/forged-mtr" '/^fn ohlfill /,/^fn ohlnext /s/^k = pread int sub get gost 0 1 goc 0 65536 long pos$/w = ulong 0\nif lt pos 262143\nw = sub 262143 pos\nend\nif gt w 65536\nw = ulong 65536\nend\nk = long 0\nif gt w 0\nk = pread int sub get gost 0 1 goc 0 w long pos\nend/'; then |
| 820 | start "$T/forged-mtr"; c=$(code GET /open.json) |
| 821 | n=$(shelfck "$T/data/open/list.tsv" "$T/body" 2>&1 | tail -1) && case "$n" in AssertionError*) false;; esac && bad "mutant oldread (forged) listed every row" || ok "MUTANT of forged that reads only the former 262,143 bytes of the list loses rows ($c: $n)"; stop |
| 822 | else bad "mutant oldread (forged) did not build"; fi |
| 823 | # Far past fob in BOTH representations. Quotes double in JSON and ampersands/quotes expand |
| 824 | # five/sixfold in HTML. Assert complete ordered rows, not only the last rid or a successful code. |
| 825 | python3 -I - "$T/data/open/list.tsv" "$D1" <<'EOF' |
| 826 | import sys |
| 827 | A = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' |
| 828 | with open(sys.argv[1], 'w') as f: |
| 829 | for i in range(10000): |
| 830 | r = 'z2Huge%s%s%sabcdefghijkmnopqrstuvwxyz' % (A[i // 3364 % 58], A[i // 58 % 58], A[i % 58]) |
| 831 | f.write('\t'.join([r, 'open', sys.argv[2], '2026-11-11', '1', '&' * 120, '"' * 400, '&' * 200]) + '\n') |
| 832 | EOF |
| 833 | htmlshelfck() { |
| 834 | python3 -I - "$1" "$2" <<'EOF' |
| 835 | import sys |
| 836 | from html.parser import HTMLParser |
| 837 | class Cards(HTMLParser): |
| 838 | def __init__(self): super().__init__(); self.rids=[]; self.card=False |
| 839 | def handle_starttag(self, tag, attrs): |
| 840 | d=dict(attrs) |
| 841 | if tag=='article' and 'sl-card' in d.get('class','').split(): self.card=True |
| 842 | if self.card and tag=='a' and '/open/' in d.get('href',''): self.rids.append(d['href'].rsplit('/',1)[-1]) |
| 843 | def handle_endtag(self, tag): |
| 844 | if tag=='article': self.card=False |
| 845 | p=Cards(); data=open(sys.argv[2]).read(); p.feed(data) |
| 846 | want=[l.split('\t')[0] for l in open(sys.argv[1])] |
| 847 | assert len(data.encode()) > 8388608, len(data.encode()) |
| 848 | assert p.rids == want, (len(p.rids), len(want)) |
| 849 | print(len(p.rids)) |
| 850 | EOF |
| 851 | } |
| 852 | start "$T/forged" |
| 853 | c=$(code GET /open.json); n=$(shelfck "$T/data/open/list.tsv" "$T/body" 2>&1); rc=$? |
| 854 | [ "$c" = 200 ] && [ "$rc" = 0 ] && [ "$(stat -c %s "$T/body")" -gt 8388608 ] && grep -qi 'Transfer-Encoding: chunked' "$T/hdr" && ok "streamed /open.json exceeds 8 MiB ($(stat -c %s "$T/body") bytes), 200, all $n rows in order" || bad "huge JSON: $c $n $(stat -c %s "$T/body")" |
| 855 | c=$(code GET /open/); n=$(htmlshelfck "$T/data/open/list.tsv" "$T/body" 2>&1); rc=$? |
| 856 | [ "$c" = 200 ] && [ "$rc" = 0 ] && grep -qi 'Transfer-Encoding: chunked' "$T/hdr" && ok "streamed /open/ exceeds 8 MiB after escaping ($(stat -c %s "$T/body") bytes), 200, all $n cards in order" || bad "huge HTML: $c $n" |
| 857 | c=$(code GET '/open/?format=text'); [ "$c" = 200 ] && grep -q 'z2Huge' "$T/body" && ok 'streamed shelf still supports format=text' || bad "streamed plain text: $c" |
| 858 | stop |
| 859 | if build "$T/forged-fobmut" 's/^if ge get fobl 0 1048576$/if false/'; then |
| 860 | start "$T/forged-fobmut"; c=$(code GET /open.json) |
| 861 | shelfck "$T/data/open/list.tsv" "$T/body" >/dev/null 2>&1 && bad 'mutant fob-again JSON kept every row' || ok 'MUTANT building shelf in fob again fails the >8 MiB complete JSON check' |
| 862 | c=$(code GET /open/); htmlshelfck "$T/data/open/list.tsv" "$T/body" >/dev/null 2>&1 && bad 'mutant fob-again HTML kept every row' || ok 'MUTANT building shelf in fob again fails the >8 MiB complete HTML check' |
| 863 | stop |
| 864 | else bad 'mutant fob-again did not build'; fi |
| 865 | cp "$T/list.small" "$T/data/open/list.tsv" |
| 866 | # mutant of the shelf: no HTML escaping in the row output |
| 867 | if build "$T/forged-m" '/^fn ohesc /,/^fn ohjs /s/^fescc c$/fputc c/'; then |
| 868 | start "$T/forged-m"; code GET /open/ >/dev/null |
| 869 | grep -q '<script>alert(1)</script>' "$T/body" && ok "MUTANT without the escape emits the script tag (the check above sees it)" || bad "mutant noescape: no script tag" |
| 870 | stop |
| 871 | else bad "mutant noescape did not build"; fi |
| 872 | |
| 873 | if build "$T/forged-m2" '/^fn ohpesc /,/^fn ohpjs /s/^fescc c$/fputc c/'; then |
| 874 | start "$T/forged-m2"; code GET "/open/$R1" >/dev/null |
| 875 | grep -q '<img src=x onerror=alert(3)>' "$T/body" && ok "MUTANT without the snapshot escape emits the tag on the project page" || bad "mutant nopesc: no tag" |
| 876 | stop |
| 877 | else bad "mutant nopesc did not build"; fi |
| 878 | if build "$T/forged-m3" '/^fn ohprow /,/^fn ohpload /s/^if ohpub s e$/if ohrow s e/'; then |
| 879 | start "$T/forged-m3"; c=$(code GET "/open/$(rid H4)") |
| 880 | [ "$c" = 200 ] && ok "MUTANT without the shelf check gives a refused project a page" || bad "mutant nopub: $c" |
| 881 | stop |
| 882 | else bad "mutant nopub did not build"; fi |
| 883 | |
| 884 | if build "$T/forged-m4" '/^fn ohmatch /,/^fn ohtjs /s/^if ohorig$/if slhex id/'; then |
| 885 | start "$T/forged-m4"; code GET "/open/$R1" >/dev/null |
| 886 | grep -q "$SID2" "$T/body" && ok "MUTANT without the origin check lists another project's source" || bad "mutant noorig: other source not listed" |
| 887 | stop |
| 888 | else bad "mutant noorig did not build"; fi |
| 889 | if build "$T/forged-m5" '/^fn ohmatch /,/^fn ohtjs /s/^if not slpublic id$/if not slload id/'; then |
| 890 | start "$T/forged-m5"; code GET "/open/$R1" >/dev/null |
| 891 | grep -q "$DRAFT\">Draft part, never verified</a> (Omega part, verified)" "$T/body" && ok "MUTANT without the public check calls an unverified draft a verified part" || bad "mutant nopublic: draft not listed" |
| 892 | stop |
| 893 | else bad "mutant nopublic did not build"; fi |
| 894 | |
| 895 | if build "$T/forged-m6" '/^fn ohwj /,/^fn ohpage /s/^if ne get gojs 0 0$/if ne get gojs 0 1/'; then |
| 896 | start "$T/forged-m6"; code GET /open.json >/dev/null |
| 897 | head -c 15 "$T/body" | grep -q '<!doctype html>' && ok "MUTANT that ignores the .json name answers HTML at /open.json" || bad "mutant nojsonname: not HTML" |
| 898 | stop |
| 899 | else bad "mutant nojsonname did not build"; fi |
| 900 | |
| 901 | echo "RESULT pass=$PASS fail=$FAIL" |
| 902 | [ "$FAIL" = 0 ] |