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/social/tests/units-check.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 / social / tests / units-check.sh` 158 lines ยท 8432 bytes Raw Blame History 1 #!/bin/sh 2 # Alarm: the social test binary is built from run.sh's own unit list, never from a typed copy. 3 # Run from anywhere: sh social/tests/units-check.sh (lib.sh runs it before every social build) 4 # Checks, on this tree and on a scratch copy of run.sh, social/ and the units run.sh lists (with 5 # FORGE_STORE exported, as lib.sh does for STORE_VARIANT=1, on the store-reading build's lists): 6 # 1 the list is `./run.sh seams` with the one server/nosocial.om line replaced by the byte-sorted 7 # social/*.om; the units that are no slice's seam come in the same order as in `./run.sh units`; 8 # 2 `./run.sh seams` ignores FORGE_TRY; 9 # 3 no social/tests script but this one types a unit path; 10 # 4 two units swapped in run.sh, and one unit added to run.sh, reach the list while lib.sh and 11 # units.sh stay byte-identical (the edit is made on whichever run.sh lines name those units, so 12 # this check is not a copy of run.sh's text); 13 # negative controls: typed lists in lib.sh, a run.sh that lists the social seam 0 or 2 times or 14 # fails, a missing listed unit and an empty social folder must each be caught. 15 # Needs .build/chrome.om (./run.sh chrome) unless FORGE_SITE_* asks for a rebuild. 16 set -u 17 cd "$(dirname "$0")/../.." 18 export LC_ALL=C 19 . social/tests/units.sh 20 PASS=0; FAIL=0 21 ok() { PASS=$((PASS+1)); echo "PASS $*"; } 22 bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } 23 W=$(mktemp -d /tmp/forge-social-units.XXXXXX) 24 trap 'rm -rf "$W"' EXIT 25 trap 'exit 130' HUP INT TERM 26 27 # 1 the derived list against run.sh's own lists 28 seams=$(./run.sh seams) || { echo "FAIL ./run.sh seams"; exit 1; } 29 list=$(social_units social) || { echo "FAIL social_units social"; exit 1; } 30 want=$(printf '%s\n' "$seams" | while IFS= read -r u; do 31 if [ "$u" = server/nosocial.om ]; then ls social/*.om; else printf '%s\n' "$u"; fi 32 done) 33 [ "$list" = "$want" ] && ok "list is ./run.sh seams with social/*.om in place of server/nosocial.om ($(printf '%s\n' "$list" | wc -l) units)" \ 34 || bad "list differs from ./run.sh seams with social/*.om substituted" 35 [ "$(printf '%s\n' "$list" | grep -c '^social/')" = "$(ls social/*.om | wc -l)" ] && ok "every social/*.om is listed" || bad "social units missing" 36 printf '%s\n' "$seams" | grep -vx 'server/no[a-z]*\.om' > "$W/core" 37 units=$(./run.sh units) || { echo "FAIL ./run.sh units"; exit 1; } 38 [ "$(printf '%s\n' "$units" | awk 'NR == FNR { k[$0] = 1; next } $0 in k' "$W/core" -)" = "$(cat "$W/core")" ] \ 39 && ok "the $(wc -l < "$W/core") units that are no seam come in ./run.sh units' order (ending $(tail -1 "$W/core"))" \ 40 || bad "./run.sh seams and ./run.sh units disagree on the order of the units that are no seam" 41 42 # 2 seams is a command, not an environment value 43 [ "$(FORGE_TRY='browse dl collab social quiet growth salvage community open research door' ./run.sh seams)" = "$seams" ] \ 44 && ok "FORGE_TRY does not change ./run.sh seams" || bad "FORGE_TRY changes ./run.sh seams" 45 46 # 3 no typed unit list 47 for f in social/tests/*.sh; do 48 [ "$f" = social/tests/units-check.sh ] && continue 49 t=$(typed_units "$f") 50 [ -z "$t" ] && ok "$f types no unit path" || bad "$f types unit paths: $t" 51 done 52 53 # scratch copy: run.sh, social/, a stand-in chrome, every relative unit run.sh lists and the table 54 # run.sh makes its generated agents unit from 55 copy() { 56 rm -rf "$W/t"; mkdir -p "$W/t/.build" 57 cp run.sh "$W/t/"; cp -R social "$W/t/" 58 mkdir -p "$W/t/server"; cp server/agents.tsv "$W/t/server/" 59 echo "text tchrsite \"0\"" > "$W/t/.build/chrome.om" 60 printf '%s\n' "$seams" | while IFS= read -r u; do 61 case $u in /*) ;; *) mkdir -p "$W/t/$(dirname "$u")"; cp "$u" "$W/t/$u" ;; esac 62 done 63 } 64 # derive DIR [SRC]: the list in scratch tree DIR; exit status of social_units 65 derive() { (cd "$1" && unset FORGE_SITE_REF FORGE_SITE_SRC && social_units "${2:-social}") > "$W/out" 2> "$W/err"; } 66 same() { cmp -s social/tests/lib.sh "$W/t/social/tests/lib.sh" && cmp -s social/tests/units.sh "$W/t/social/tests/units.sh"; } 67 # here: the list with this tree's root replaced by the scratch tree's (the chrome is named by its path) 68 here() { awk -v p="$(pwd)/" -v q="$W/t/" 'index($0, p) == 1 { $0 = q substr($0, length(p) + 1) } { print }'; } 69 # line_of UNIT: the number of the one run.sh line that names UNIT and no other .om path; empty when 70 # no line or several lines name it 71 line_of() { 72 awk -v t="$1" '{ s = $0; hit = 0 73 while ((i = index(s, t)) > 0) { 74 b = i > 1 ? substr(s, i - 1, 1) : ""; a = substr(s, i + length(t), 1) 75 if (b !~ /[A-Za-z0-9_.\/$-]/ && a !~ /[A-Za-z0-9_.\/-]/) hit = 1 76 s = substr(s, i + length(t)) 77 } 78 if (hit) { hits++; ln = NR; c = gsub(/\.om/, "&") } } 79 END { if (hits == 1 && c == 1) print ln }' run.sh 80 } 81 # wrap FILTER: the scratch run.sh becomes the real one with its output through FILTER 82 wrap() { 83 mv "$W/t/run.sh" "$W/t/run.real.sh" 84 printf '#!/bin/sh\n"$(dirname "$0")/run.real.sh" "$@" | %s\n' "$1" > "$W/t/run.sh" 85 chmod +x "$W/t/run.sh" 86 } 87 88 # 4a swap the first two adjacent units (no seam, relative path) that each have a run.sh line of their own 89 pa=; pb=; prev= 90 for u in $(printf '%s\n' "$seams"); do 91 case $u in /* | server/no*.om) prev=; continue ;; esac 92 if [ -z "$pa" ] && [ -n "$prev" ]; then 93 la=$(line_of "$prev"); lb=$(line_of "$u") 94 if [ -n "$la" ] && [ -n "$lb" ] && [ "$la" -lt "$lb" ]; then pa=$prev; pb=$u; na=$la; nb=$lb; fi 95 fi 96 prev=$u 97 done 98 if [ -z "$pa" ]; then bad "reorder: no two adjacent units of ./run.sh seams have a run.sh line of their own" 99 else 100 copy 101 awk -v a="$na" -v b="$nb" 'NR == FNR { l[FNR] = $0; next } FNR == a { print l[b]; next } FNR == b { print l[a]; next } { print }' \ 102 run.sh run.sh > "$W/t/run.sh" 103 if ! derive "$W/t"; then bad "reorder: $(cat "$W/err")" 104 else 105 exp=$(printf '%s\n' "$list" | awk -v a="$pa" -v b="$pb" '$0 == a { held = $0; next } { print } held && $0 == b { print held; held = "" }' | here) 106 [ "$(cat "$W/out")" = "$exp" ] && [ "$exp" != "$(printf '%s\n' "$list" | here)" ] && same \ 107 && ok "run.sh lines $na and $nb swapped: $pb now before $pa in the list, lib.sh and units.sh unedited" \ 108 || bad "run.sh lines $na and $nb swapped, but the list did not follow" 109 fi 110 fi 111 # 4b one more unit before run.sh's last, on a copy of the line that names the last 112 last=$(printf '%s\n' "$seams" | tail -1) 113 nl=$(line_of "$last") 114 if [ -z "$nl" ]; then bad "added unit: $last has no run.sh line of its own" 115 else 116 copy 117 awk -v n="$nl" -v t="$last" -v r=server/zz-added.om 'NR == n { i = index($0, t); print substr($0, 1, i - 1) r substr($0, i + length(t)) } { print }' \ 118 run.sh > "$W/t/run.sh" 119 echo "fn zzadded to int" > "$W/t/server/zz-added.om" 120 if ! derive "$W/t"; then bad "added unit: $(cat "$W/err")" 121 else 122 [ "$(cat "$W/out")" = "$(printf '%s\n' "$list" | sed '$d' | here; echo server/zz-added.om; echo "$last")" ] && same \ 123 && ok "a unit added on run.sh line $nl reaches the list before $last, lib.sh and units.sh unedited" \ 124 || bad "a unit added on run.sh line $nl did not reach the list" 125 fi 126 fi 127 128 # negative controls: typed lists 129 for typed in 'U="server/util.om server/repos.om nodes/head.om server/main.om server/tr.om"' \ 130 'U="./server/util.om ./nodes/head.om"' 'U="$PWD/server/util.om"' 'U="server/{util,repos}.om"' \ 131 'for u in util repos; do U="$U server/$u.om"; done'; do 132 copy 133 printf '%s\n' "$typed" >> "$W/t/social/tests/lib.sh" 134 [ -n "$(typed_units "$W/t/social/tests/lib.sh")" ] && ok "NEG typed in lib.sh is caught: $typed" || bad "NEG typed list not caught: $typed" 135 done 136 # negative controls: run.sh's list 137 for neg in "grep -vx server/nosocial.om|0 times" "awk '{ print } \$0 == \"server/nosocial.om\" { print }'|2 times" \ 138 "cat; exit 3|./run.sh seams failed"; do 139 copy 140 wrap "${neg%|*}" 141 if derive "$W/t"; then bad "NEG run.sh | ${neg%|*} gave a list" 142 else grep -qF "${neg#*|}" "$W/err" && ok "NEG run.sh | ${neg%|*} fails ($(cat "$W/err"))" || bad "NEG run.sh | ${neg%|*}: $(cat "$W/err")" 143 fi 144 done 145 copy 146 gone=$(printf '%s\n' "$seams" | grep -v '^/' | grep -vx 'server/no[a-z]*\.om' | head -1) 147 rm "$W/t/$gone" 148 if derive "$W/t"; then bad "NEG a missing unit gave a list" 149 else grep -qF "$gone does not exist" "$W/err" && ok "NEG a missing listed unit ($gone) fails" || bad "NEG missing unit: $(cat "$W/err")" 150 fi 151 copy 152 mkdir "$W/t/empty" 153 if derive "$W/t" empty; then bad "NEG an empty social folder gave a list" 154 else grep -q 'no .om file' "$W/err" && ok "NEG an empty social folder fails" || bad "NEG empty folder: $(cat "$W/err")" 155 fi 156 157 echo "---- $PASS passed, $FAIL failed" 158 [ "$FAIL" = 0 ]