interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / server / tests / favicon.sh

121 lines · 7182 bytes Raw Blame History
1#!/usr/bin/env bash
2# Site icon: every forge HTML page names <base>assets/favicon.svg, and forged serves it.
3# Finding BOARD 2026-11-10T15:08:43Z: pages had no icon link, so browsers asked /favicon.ico (404 and
4# a console error). Entirely private: own port, own storage fixture, no radicle-node, never 18480.
5# bash server/tests/favicon.sh (spark; FORGED_CPUS default 4,5; FORGE_ICON_PORT default 18562)
6# Negative control: FORGE_ICON_BASE (default 8f6b4a29, the head before the fix) built the same way
7# must NOT name the icon and must answer 404 for assets/favicon.svg.
8set -euo pipefail
9cd "$(dirname "$0")/../.."
10OMC=$HOME/work/flux/omega-mv/seed/out/omc
11PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
12PORT=${FORGE_ICON_PORT:-18562}
13BASEREV=${FORGE_ICON_BASE:-8f6b4a29f261665f83df81fbebf9b4955b85df5f}
14case "$PORT" in 185[5-9][0-9]) ;; *) echo 'REFUSED: use a private port in 18550..18599'; exit 2;; esac
15[ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo 'FAIL compiler pin'; exit 1; }
16if ss -ltnH "sport = :$PORT" | grep -q .; then echo "NOT_RUN: private port $PORT busy"; exit 3; fi
17T=$(mktemp -d)
18pid=
19pass=0
20ok() { pass=$((pass+1)); echo "PASS $*"; }
21die() { echo "FAIL $*"; exit 1; }
22cleanup() {
23 if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; fi
24 git worktree remove --force "$T/basewt" 2>/dev/null || true
25 if [ "${KEEP_TEST_TMP:-0}" = 1 ]; then echo "Evidence: $T"; else rm -rf "$T"; fi
26}
27trap cleanup EXIT
28run() { taskset -c "${FORGED_CPUS:-4,5}" nice -n 10 "$@"; }
29RID=z631r2JJiVT8it4tST7RK24hpowi
30mkdir -p "$T/repo" "$T/storage" "$T/data/logs" "$T/ng" "$T/bin"
31cp server/tests/fake/rad server/tests/fake/getent "$T/bin/"
32chmod 755 "$T/bin/rad" "$T/bin/getent"
33: > "$T/ng/dl.log"; : > "$T/ng/access.log"
34printf 'icon fixture\n' > "$T/repo/README.md"
35git -C "$T/repo" init -q -b main
36git -C "$T/repo" add .
37git -C "$T/repo" -c user.name=Fixture -c user.email=fixture@example.invalid commit -qm 'icon fixture'
38git clone -q --bare "$T/repo" "$T/storage/$RID"
39printf '| repo | RID | default branch |\n|---|---|---|\n| iconfixture | rad:%s | main |\n' "$RID" > "$T/RIDS.md"
40
41# build SRCDIR NAME: compose SRCDIR's units with every live target moved into $T, compile to $T/NAME.bin
42build() {
43 local src=$1 name=$2
44 ( cd "$src" && { printf 'om2\n'; for u in $(./run.sh units); do cat "$u"; done; } ) > "$T/$name.base.om"
45 sed -e "s|2130706433 18480|2130706433 $PORT|" \
46 -e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|g" \
47 -e "s|/home/drakestapleton/.radicle/storage/|$T/storage/|g" \
48 -e "s|/home/drakestapleton/forge-data/|$T/data/|g" \
49 -e "s|^text tfzp0 \".*\"|text tfzp0 \"$T/ng/dl.log\"|" \
50 -e "s|^text tfzp1 \".*\"|text tfzp1 \"$T/ng/access.log\"|" \
51 -e "s|^text tfzwal \".*\"|text tfzwal \"$T/ng/wal\"|" \
52 -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \
53 -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|" \
54 -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" "$T/$name.base.om" > "$T/$name.om"
55 for marker in "2130706433 $PORT" "$T/RIDS.md" "$T/storage/" "$T/data/"; do grep -qF "$marker" "$T/$name.om"; done
56 if grep -qE '2130706433 18480|/home/drakestapleton/(forge-data|\.radicle|handoffs/radicle)' "$T/$name.om"; then
57 die "live target remains in $name"
58 fi
59 run "$OMC" < "$T/$name.om" > "$T/$name.bin" 2> "$T/$name.err" || { cat "$T/$name.err"; die "compile $name"; }
60 chmod 755 "$T/$name.bin"
61}
62start() {
63 FORGE_SOCIAL_DIR="$T/data/" taskset -c "${FORGED_CPUS:-4,5}" nice -n 10 "$T/$1.bin" > "$T/$1.log" 2>&1 &
64 pid=$!
65 for _ in $(seq 50); do
66 kill -0 "$pid" 2>/dev/null || die "$1 server exited during startup"
67 curl --max-time 1 -fsS -o /dev/null "http://127.0.0.1:$PORT/explore" && return 0
68 sleep 0.1
69 done
70 die "$1 server not ready"
71}
72stop() { kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; pid=; }
73# get PATH BASE [curl args]: status on stdout; body $T/body, headers $T/hdr
74get() {
75 local p=$1 b=$2; shift 2
76 curl --max-time 10 -sS -o "$T/body" -D "$T/hdr" -H "X-Forge-Base: $b" "$@" "http://127.0.0.1:$PORT/$p" -w '%{http_code}'
77}
78hdr() { grep -i "^$1:" "$T/hdr" | head -1 | tr -d '\r' | cut -d' ' -f2-; }
79WANT_SVG='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" rx="12" fill="#2563eb"/><g stroke="#ffffff" stroke-width="5"><path d="M32 10v44M10 32h44M16 16l32 32M16 48l32-32"/></g></svg>'
80
81build . new
82start new
83for base in / /forge/; do
84 link="<link rel=\"icon\" type=\"image/svg+xml\" href=\"${base}assets/favicon.svg\">"
85 for page in explore drakestapleton/iconfixture search?q=icon login no-such-page-xyz; do
86 code=$(get "$page" "$base")
87 case "$page" in no-such-page-xyz) [ "$code" = 404 ] || die "$base$page HTTP $code, expected 404";;
88 *) [ "$code" = 200 ] || die "$base$page HTTP $code";; esac
89 [ "$(grep -cF "$link" "$T/body")" = 1 ] || die "$base$page: icon link missing or repeated"
90 grep -qF "${base}assets/forge.css\"><link rel=\"icon\"" "$T/body" || die "$base$page: stylesheet link changed"
91 done
92 ok "base $base: explore, project, search, login and a 404 page each name ${base}assets/favicon.svg once"
93 code=$(get assets/favicon.svg "$base")
94 [ "$code" = 200 ] || die "${base}assets/favicon.svg HTTP $code"
95 [ "$(hdr content-type)" = "image/svg+xml" ] || die "content-type $(hdr content-type)"
96 [ "$(hdr cache-control)" = "public, max-age=300" ] || die "cache-control $(hdr cache-control)"
97 printf '%s\n' "$WANT_SVG" | cmp -s - "$T/body" || die "icon body differs"
98 [ "$(hdr content-length)" = "$(wc -c < "$T/body")" ] || die "content-length $(hdr content-length) vs body"
99 ok "base $base: assets/favicon.svg 200, image/svg+xml, public max-age=300, exact drawing, length matches"
100done
101code=$(get assets/favicon.svg / -X POST -H 'Origin: https://interplane.io' --data x)
102[ "$code" = 405 ] || die "POST favicon HTTP $code, expected 405"
103ok "POST assets/favicon.svg answers 405, as assets/forge.css does ($(get assets/forge.css / -X POST -H 'Origin: https://interplane.io' --data x))"
104code=$(get favicon.ico /); [ "$code" = 404 ] || die "favicon.ico HTTP $code"
105ok "favicon.ico is still not served (pages name the svg, so browsers do not ask for it)"
106code=$(get assets/forge.css /); [ "$code" = 200 ] || die "forge.css HTTP $code"
107ok "assets/forge.css still 200"
108kill -0 "$pid" || die "server died"
109stop
110
111# Negative control: the head before the fix.
112git worktree add -q --detach "$T/basewt" "$BASEREV"
113build "$T/basewt" old
114start old
115code=$(get explore /); [ "$code" = 200 ] || die "control explore HTTP $code"
116if grep -qF 'rel="icon"' "$T/body"; then die "control: base $BASEREV already names an icon, test does not discriminate"; fi
117code=$(get assets/favicon.svg /); [ "$code" = 404 ] || die "control: favicon HTTP $code, expected 404"
118ok "negative control at ${BASEREV:0:8}: no icon link, assets/favicon.svg 404"
119stop
120sha256sum "$OMC" "$T/new.om" "$T/new.bin" "$T/old.om" "$T/old.bin"
121echo "favicon.sh: PASS $pass"