interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / collab / tests / title.sh
| 1 | #!/bin/bash |
| 2 | # ORACLE: host test driver (bash + curl + rad), not product code. |
| 3 | # collab/tests/title.sh: a patch whose title is longer than the 256-byte page title must not end forged. |
| 4 | # copttl (collab/co4pat.om) and coittl (collab/co5iss.om) copied the title with `for k ulong n bound 256`; |
| 5 | # a count past the bound is trap 4 and the server exits 104. Seen on the public patch |
| 6 | # aien-architecture-mv 44dffbaa (title over 256 bytes) on 2026-11-09. |
| 7 | # A test forged on PORT (default 18498) with a private data dir reads the real store and allow-list |
| 8 | # (read-only). Negative control: the same build with the cap removed from copttl must exit 104 on the |
| 9 | # same request. No public repository has an issue: coittl, and the UTF-8 cut (cottlcut), are covered by |
| 10 | # collab/tests/issue-title.sh on a private Radicle profile. |
| 11 | # Usage: collab/tests/title.sh (CORES default 14; TITLE_PORT; KEEP=1 keeps the temp dir) |
| 12 | set -u |
| 13 | H=$(cd "$(dirname "$0")" && pwd) |
| 14 | export PORT=${TITLE_PORT:-18498} CORES=${CORES:-14} |
| 15 | T=$(mktemp -d /tmp/cptitle.XXXXXX) |
| 16 | PASS=0; FAIL=0 |
| 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 | PID= |
| 21 | trap '[ -n "$PID" ] && kill $PID 2>/dev/null; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT |
| 22 | if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi |
| 23 | RID=z37zcFYooiuCCZsf5L74eeFJYiwWM # aien-architecture-mv |
| 24 | PATCH=44dffbaa6c6ea2bb5464ca93014b945104924b10 |
| 25 | P=/drakestapleton/aien-architecture-mv/patches/$PATCH |
| 26 | # the oracle for the title length is rad, not forged |
| 27 | TL=$(rad patch show "$PATCH" --repo "rad:$RID" 2> /dev/null | sed -n 's/^│ Title *//p' | head -1 | sed 's/ *$//' | wc -c) |
| 28 | if [ "$TL" -le 257 ]; then echo "NOT_RUN: patch $PATCH is not readable here or its title is $TL bytes (need over 256)"; exit 3; fi |
| 29 | ok "fixture: rad shows a title of $((TL - 1)) bytes, over the 256-byte page title" |
| 30 | start() { # start OUT [SEDX]: build and start a test forged; PID set |
| 31 | mkdir -p "$T/data" |
| 32 | DATA=$T/data/ SEDX=${2:-} "$H/tbuild.sh" "$1" || return 1 |
| 33 | FORGE_SOCIAL_DIR=$T/data/ taskset -c "$CORES" nice -n 10 "$1" 2>> "$1.log" & |
| 34 | PID=$! |
| 35 | for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && return 0; sleep 0.1; done |
| 36 | return 1 |
| 37 | } |
| 38 | stop() { kill $PID 2> /dev/null; wait $PID 2> /dev/null; PID=; sleep 0.3; } |
| 39 | start "$T/forged" || { bad "test forged did not start"; exit 1; } |
| 40 | for b in / /forge/; do |
| 41 | c=$(curl -s -o "$T/page" -w '%{http_code}' -H "X-Forge-Base: $b" "http://127.0.0.1:$PORT$P") |
| 42 | check "$c" 200 "[$b] patch page with the long title" |
| 43 | t=$(grep -o '<title>[^<]*</title>' "$T/page" | head -1) |
| 44 | n=$(printf '%s' "$t" | wc -c) |
| 45 | if [ "$n" -gt 15 ] && [ "$n" -le 1551 ]; then ok "[$b] title element present and bounded ($n bytes with tags and escapes)"; else bad "[$b] title element: $n bytes"; fi |
| 46 | done |
| 47 | c=$(curl -s -o /dev/null -w '%{http_code}' -H 'Accept: application/json' "http://127.0.0.1:$PORT$P") |
| 48 | check "$c" 200 "patch page as JSON" |
| 49 | c=$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PORT/explore") |
| 50 | check "$c" 200 "server still answers after the long title" |
| 51 | if kill -0 $PID 2> /dev/null; then ok "server process still running"; else bad "server process is gone"; fi |
| 52 | stop |
| 53 | # negative control: remove the cap from copttl only (the first of the two capped loops in unit order) |
| 54 | start "$T/mut" '0,/^for k ulong hmin n 256 bound 256$/s//for k ulong n bound 256/' || { bad "mutant did not start"; exit 1; } |
| 55 | 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") |
| 56 | [ "$b" = "$((a - 1))" ] && ok "mutant: cap removed from one loop ($a capped loops, then $b)" || bad "mutant: capped loops $a, then $b (want one fewer)" |
| 57 | curl -s -o /dev/null --max-time 5 "http://127.0.0.1:$PORT$P" |
| 58 | wait $PID 2> /dev/null; rc=$?; PID= |
| 59 | check "$rc" 104 "NEG mutant without the cap exits on the same request (trap 4)" |
| 60 | echo "collab title: $PASS passed, $FAIL failed" |
| 61 | [ "$FAIL" = 0 ] |