interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / server / tests / title.sh

119 lines · 6339 bytes Raw Blame History
1#!/usr/bin/env bash
2# L1057: title boundaries and real HTTP long-path requests, entirely private.
3# Carried from fix/forged-rc104 3c3e46b onto the line that keeps 5129fbf's form of the fix
4# (`for i ulong hmin n 120 bound 120` in brti). Two changes for that: the negative control undoes
5# that line, and the count sources of server/counts.om are moved into the temp dir as well.
6# KEEP_TEST_TMP=1 retains sources, binaries and logs for an evidence handoff.
7set -euo pipefail
8cd "$(dirname "$0")/../.."
9OMC=$HOME/work/flux/omega-mv/seed/out/omc
10PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
11PORT=${FORGE_TITLE_PORT:-18557}
12case "$PORT" in 185[5-9][0-9]|1999[0-9]) ;; *) echo 'REFUSED: use a private port in 18550..18599 or 19990..19999'; exit 2;; esac
13[ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo 'FAIL compiler pin'; exit 1; }
14if ss -ltnH "sport = :$PORT" | grep -q .; then echo "NOT_RUN: private port $PORT busy"; exit 3; fi
15T=$(mktemp -d)
16pid=
17cleanup() {
18 if [ -n "$pid" ]; then kill "$pid" 2>/dev/null || true; wait "$pid" 2>/dev/null || true; fi
19 if [ "${KEEP_TEST_TMP:-0}" = 1 ]; then echo "Evidence: $T"; else rm -rf "$T"; fi
20}
21trap cleanup EXIT
22run() { taskset -c "${FORGED_CPUS:-4,5}" nice -n 10 "$@"; }
23compile() {
24 run "$OMC" < "$1" > "$1.bin" 2> "$1.err" || { cat "$1.err"; exit 1; }
25 chmod 755 "$1.bin"
26}
27{ printf 'om2\n'; for u in $(./run.sh units); do cat "$u"; done; } > "$T/base.om"
28sed 's/^fn main to int$/fn fmainx to int/' "$T/base.om" > "$T/unit.om"
29cat browse/tests/title.om >> "$T/unit.om"
30compile "$T/unit.om"
31run "$T/unit.om.bin"
32echo 'PASS title bytes and unchanged lookup path: 0, 1, 119, 120, 121, 4096'
33# Negative control: exactly undo the production fix in the real composed code.
34[ "$(grep -c '^for i ulong hmin n 120 bound 120$' "$T/unit.om")" = 1 ]
35sed 's/^for i ulong hmin n 120 bound 120$/for i ulong n bound 120/' "$T/unit.om" > "$T/old-unit.om"
36compile "$T/old-unit.om"
37rc=0; run "$T/old-unit.om.bin" || rc=$?
38[ "$rc" = 104 ] || { echo "FAIL old title: rc=$rc, expected 104"; exit 1; }
39echo 'PASS negative control: old title code exits 104'
40
41# This storage contains only our fixture. No radicle-node is started.
42RID=z631r2JJiVT8it4tST7RK24hpowi
43mkdir -p "$T/repo" "$T/storage" "$T/data/logs" "$T/ng" "$T/bin"
44cp server/tests/fake/rad server/tests/fake/getent "$T/bin/"
45chmod 755 "$T/bin/rad" "$T/bin/getent"
46: > "$T/ng/dl.log"; : > "$T/ng/access.log"
47p120=$(printf '%120s' '' | tr ' ' a)
48p121=$(printf '%121s' '' | tr ' ' b)
49p240=$(printf '%240s' '' | tr ' ' c)
50dir121=$(printf '%121s' '' | tr ' ' d)
51for path in "$p120" "$p121" "$p240"; do printf 'L1057 fixture\n' > "$T/repo/$path"; done
52mkdir "$T/repo/$dir121"
53printf 'L1057 directory fixture\n' > "$T/repo/$dir121/leaf"
54git -C "$T/repo" init -q -b main
55git -C "$T/repo" add .
56git -C "$T/repo" -c user.name=Fixture -c user.email=fixture@example.invalid commit -qm 'L1057 fixture'
57git clone -q --bare "$T/repo" "$T/storage/$RID"
58printf '| repo | RID | default branch |\n|---|---|---|\n| crashfixture | rad:%s | main |\n' "$RID" > "$T/RIDS.md"
59# STORE_VARIANT=1 (with IPL_DIR): the HTTP part on the store-reading build; the fixture made a store and
60# the units composed again for it (the unit part above is the same code in both builds)
61SV=${STORE_VARIANT:-0}
62if [ "$SV" = 1 ]; then
63 FIXSTORE_FROM=/nonexistent bash store/tests/fixstore.sh "$T/RIDS.md" "$T/storage" "$T/store"
64 export FORGE_STORE=$T/store
65 { printf 'om2\n'; for u in $(./run.sh units); do cat "$u"; done; } > "$T/base.om"
66 echo "STORE_VARIANT: store-reading build, store $T/store"
67fi
68sed -e "s|2130706433 18480|2130706433 $PORT|" \
69 -e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|g" \
70 -e "s|/home/drakestapleton/.radicle/storage/|$T/storage/|g" \
71 -e "s|/home/drakestapleton/forge-data/|$T/data/|g" \
72 -e "s|^text tfzp0 \".*\"|text tfzp0 \"$T/ng/dl.log\"|" \
73 -e "s|^text tfzp1 \".*\"|text tfzp1 \"$T/ng/access.log\"|" \
74 -e "s|^text tfzwal \".*\"|text tfzwal \"$T/ng/wal\"|" \
75 -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \
76 -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|" \
77 -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" "$T/base.om" > "$T/http.om"
78marks=("2130706433 $PORT" "$T/RIDS.md" "$T/storage/" "$T/data/")
79[ "$SV" = 1 ] && marks=("2130706433 $PORT" "$T/store/" "$T/data/")
80for marker in "${marks[@]}"; do grep -qF "$marker" "$T/http.om"; done
81if grep -qE '2130706433 18480|/home/drakestapleton/(forge-data|\.radicle|handoffs/radicle)' "$T/http.om"; then
82 echo 'FAIL live target remains'; exit 1
83fi
84compile "$T/http.om"
85# Launch directly, so the saved PID is the private server, not a shell wrapper.
86FORGE_SOCIAL_DIR="$T/data/" taskset -c "${FORGED_CPUS:-4,5}" nice -n 10 "$T/http.om.bin" > "$T/http.log" 2>&1 &
87pid=$!
88ready=0
89for _ in $(seq 50); do
90 kill -0 "$pid" 2>/dev/null || { echo 'FAIL private server exited during startup'; exit 1; }
91 if curl --max-time 1 -fsS -o /dev/null "http://127.0.0.1:$PORT/explore"; then ready=1; break; fi
92 sleep 0.1
93done
94[ "$ready" = 1 ] || { echo 'FAIL private server not ready'; exit 1; }
95get() {
96 local code
97 code=$(curl --max-time 10 -sS -o "$T/body" -H "X-Forge-Base: $2" "http://127.0.0.1:$PORT/$1" -w '%{http_code}')
98 [ "$code" = 200 ] || { echo "FAIL $1 HTTP $code"; exit 1; }
99 kill -0 "$pid" || { echo 'FAIL server died after request'; exit 1; }
100}
101for base in / /forge/; do
102 for path in "$p120" "$p121" "$p240"; do
103 get "drakestapleton/crashfixture/blob/main/$path" "$base"
104 grep -q 'L1057 fixture' "$T/body"
105 grep -qF "${base}drakestapleton/crashfixture/raw/main/$path" "$T/body"
106 get "drakestapleton/crashfixture/raw/main/$path" "$base"
107 cmp "$T/body" "$T/repo/$path"
108 get "drakestapleton/crashfixture/blame/main/$path" "$base"
109 grep -q 'L1057 fixture' "$T/body"
110 get "drakestapleton/crashfixture/commits/main/$path" "$base"
111 grep -q 'L1057 fixture' "$T/body"
112 done
113 get "drakestapleton/crashfixture/tree/main/$dir121" "$base"
114 grep -q 'leaf' "$T/body"
115 get explore "$base"
116 echo "PASS HTTP $base: blob/raw/blame/commits at 120, 121, 240; long tree; subsequent explore"
117done
118sha256sum "$OMC" "$T/unit.om" "$T/unit.om.bin" "$T/http.om" "$T/http.om.bin"
119echo 'title.sh: PASS'