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/collab/tests/issue-title.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 / collab / tests / issue-title.sh` 88 lines ยท 6684 bytes Raw Blame History 1 #!/bin/bash 2 # ORACLE: host test driver (bash + curl + rad + iconv), not product code. 3 # collab/tests/issue-title.sh: an issue whose title is longer than the 256-byte page title must not end 4 # forged (coittl, collab/co5iss.om), and the cut title must stay valid UTF-8 (cottlcut, collab/co4pat.om). 5 # Everything is private to a temp dir: a throwaway Radicle profile (RAD_HOME) with one private repo and 6 # one issue whose 401-byte title has 3-byte characters across byte 256, and a test forged on PORT 7 # (default 18499) whose store and allow-list point at that profile. Nothing touches ~/.radicle. 8 # A patch with the same title covers copttl the same way (added after the second review of `486f1cd8`). 9 # Negative controls: without cottlcut the title element is not valid UTF-8; without the cap in coittl 10 # the same request exits 104 (trap 4). 11 # Usage: collab/tests/issue-title.sh (CORES default 14; ISSUE_TITLE_PORT; KEEP=1 keeps the temp dir) 12 set -u 13 H=$(cd "$(dirname "$0")" && pwd) 14 export PORT=${ISSUE_TITLE_PORT:-18499} CORES=${CORES:-14} 15 T=$(mktemp -d /tmp/cpititle.XXXXXX); W=$T/w 16 PASS=0; FAIL=0; PID= 17 ok() { PASS=$((PASS+1)); echo "PASS $*"; } 18 bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } 19 check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; } 20 trap '[ -n "$PID" ] && kill $PID 2>/dev/null; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT 21 if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi 22 export RAD_HOME=$T/rad RAD_PASSPHRASE= 23 rad auth --alias cptitle < /dev/null > /dev/null 2>&1 || { echo "rad auth failed"; exit 1; } 24 git init -q -b main "$W" && cd "$W" && echo hi > a.txt && git add a.txt \ 25 && git -c user.name=t -c user.email=t@t.invalid commit -qm init \ 26 && rad init --private --name cpititle --description "issue title test" --default-branch main --no-confirm --no-seed > /dev/null 2>&1 \ 27 || { echo "rad init failed"; exit 1; } 28 RID=$(rad . | sed 's/^rad://') 29 # 254 ASCII bytes, then 49 euro signs (e2 82 ac): byte 256 is inside the first one; 401 bytes in all 30 TITLE="$(printf 'x%.0s' $(seq 254))$(printf '\xe2\x82\xac%.0s' $(seq 49))" 31 check "$(printf '%s' "$TITLE" | LC_ALL=C wc -c)" 401 "fixture: title bytes" 32 rad issue open --repo "rad:$RID" --title "$TITLE" --description body --no-announce > "$T/open.out" 2>&1 \ 33 || { echo "rad issue open failed: $(cat "$T/open.out")"; exit 1; } 34 ISS=$(git -C "$RAD_HOME/storage/$RID" for-each-ref --format='%(refname)' 'refs/namespaces/*/refs/cobs/xyz.radicle.issue/*' | head -1 | sed 's|.*/||') 35 [ -n "$ISS" ] || { echo "issue id not found in $RAD_HOME/storage/$RID"; exit 1; } 36 # the patch: pushed with a short message, then given the title, because git quotes a push option 37 # that holds bytes outside ASCII and the remote helper does not read the quoted form 38 git checkout -q -b f1 && echo b > b.txt && git add b.txt && git -c user.name=t -c user.email=t@t.invalid commit -qm second \ 39 && git push -o patch.message=short rad HEAD:refs/patches > "$T/push.out" 2>&1 || { echo "patch push failed: $(cat "$T/push.out")"; exit 1; } 40 PAT=$(git -C "$RAD_HOME/storage/$RID" for-each-ref --format='%(refname)' 'refs/namespaces/*/refs/cobs/xyz.radicle.patch/*' | head -1 | sed 's|.*/||') 41 [ -n "$PAT" ] || { echo "patch id not found in $RAD_HOME/storage/$RID"; exit 1; } 42 rad patch edit "$PAT" --repo "rad:$RID" --no-announce --message "$TITLE" --message body > "$T/edit.out" 2>&1 \ 43 || { echo "rad patch edit failed: $(cat "$T/edit.out")"; exit 1; } 44 PP=/drakestapleton/cpititle/patches/$PAT 45 printf '# test allow-list\n\n| repo | RID | default branch |\n|---|---|---|\n| cpititle | rad:%s | main |\n' "$RID" > "$T/rids.md" 46 mkdir -p "$T/data" "$T/social" 47 start() { # start OUT [SEDX]: build and start a test forged; PID set 48 DATA=$T/data/ STORE=$RAD_HOME/storage/ RIDS=$T/rids.md SEDX=${2:-} "$H/tbuild.sh" "$1" || return 1 49 FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$1" 2>> "$1.log" & 50 PID=$! 51 for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && return 0; sleep 0.1; done 52 return 1 53 } 54 stop() { kill $PID 2> /dev/null; wait $PID 2> /dev/null; PID=; sleep 0.3; } 55 # title BODY -> the bytes inside ... 56 title() { tr '\n' ' ' < "$1" | LC_ALL=C sed -n 's|.*\([^<]*\).*|\1|p'; } 57 utf8() { title "$1" | iconv -f UTF-8 -t UTF-8 > /dev/null 2>&1 && echo valid || echo invalid; } 58 P=/drakestapleton/cpititle/issues/$ISS 59 start "$T/forged" || { bad "test forged did not start"; exit 1; } 60 for b in / /forge/; do 61 c=$(curl -s -o "$T/page" -w '%{http_code}' -H "X-Forge-Base: $b" "http://127.0.0.1:$PORT$P") 62 check "$c" 200 "[$b] issue page with the 401-byte title" 63 check "$(utf8 "$T/page")" valid "[$b] title element is valid UTF-8" 64 check "$(title "$T/page" | LC_ALL=C grep -o x | wc -l)" 254 "[$b] title keeps the 254 ASCII bytes before the cut character" 65 c=$(curl -s -o "$T/page" -w '%{http_code}' -H "X-Forge-Base: $b" "http://127.0.0.1:$PORT$PP") 66 check "$c" 200 "[$b] patch page with the 401-byte title" 67 check "$(utf8 "$T/page")" valid "[$b] patch title element is valid UTF-8" 68 check "$(title "$T/page" | LC_ALL=C grep -o x | wc -l)" 254 "[$b] patch title keeps the 254 ASCII bytes before the cut character" 69 done 70 kill -0 $PID 2> /dev/null && ok "server process still running" || bad "server process is gone" 71 stop 72 # negative control 1: without cottlcut the cut falls inside the character 73 start "$T/nocut" '/^if gt n 256$/,/^end$/s/^cottlcut o$/x = ulong 0/' || { bad "no-cut mutant did not start"; exit 1; } 74 check "$(grep -c '^cottlcut o$' "$T/nocut.om")" 0 "no-cut mutant: both cottlcut calls removed" 75 curl -s -o "$T/page" -H 'X-Forge-Base: /' "http://127.0.0.1:$PORT$P" 76 check "$(utf8 "$T/page")" invalid "NEG without cottlcut the title element is not valid UTF-8" 77 curl -s -o "$T/page" -H 'X-Forge-Base: /' "http://127.0.0.1:$PORT$PP" 78 check "$(utf8 "$T/page")" invalid "NEG without cottlcut the patch title element is not valid UTF-8" 79 stop 80 # negative control 2: the cap removed from coittl only 81 start "$T/mut" '/^fn coittl to void$/,/^end$/s/^for k ulong hmin n 256 bound 256$/for k ulong n bound 256/' || { bad "mutant did not start"; exit 1; } 82 a=$(grep -c '^for k ulong hmin n 256 bound 256$' "$T/forged.om"); b=$(grep -c '^for k ulong hmin n 256 bound 256$' "$T/mut.om") 83 [ "$b" = "$((a - 1))" ] && ok "mutant: cap removed from coittl only ($a capped loops, then $b)" || bad "mutant: capped loops $a, then $b (want one fewer)" 84 curl -s -o /dev/null --max-time 5 -H 'X-Forge-Base: /' "http://127.0.0.1:$PORT$P" 85 wait $PID 2> /dev/null; rc=$?; PID= 86 check "$rc" 104 "NEG coittl without the cap exits on the same request (trap 4)" 87 echo "collab issue title: $PASS passed, $FAIL failed" 88 [ "$FAIL" = 0 ]