AtlatestRepositoryfolio
1
#!/usr/bin/env bash2
# Concurrent startup on a fresh root.3
#4
# Every session starts its own folio process against the same root, and the5
# root's directories are created check-then-create. Processes starting6
# together on a root without archive/ collided and one exited with7
# "make-directory: File exists" before answering initialize: 20 of 4808
# starts on 0.2.11 native, 9 of 240 on the dev build.9
#10
# The race needs processes that really start at the same moment, which a11
# sigil test's sequential process-spawn cannot produce, so this is a shell12
# test. Trials and width are sized so that the unfixed build fails almost13
# surely: at 4% per start, 20 trials of 8 leave about a 0.2% chance of a14
# false pass.15
#16
# Exit 0 on pass, 1 on any failed start, 2 if the binary could not be found.17
set -u19
FOLIO=${FOLIO:-$(dirname "$0")/../build/release/bin/folio}20
if [ ! -x "$FOLIO" ]; then21
FOLIO=$(dirname "$0")/../build/dev/bin/folio22
fi23
if [ ! -x "$FOLIO" ]; then24
echo "ERROR: no folio binary at build/release/bin/folio or build/dev/bin/folio" >&225
exit 226
fi28
TRIALS=${TRIALS:-20}29
WIDTH=${WIDTH:-8}30
WORK=$(mktemp -d -t folio-startup.XXXXXX)31
trap 'rm -rf "$WORK"' EXIT32
INIT='{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{}}}'34
dead=035
for trial in $(seq 1 "$TRIALS"); do36
root="$WORK/root-$trial"37
mkdir -p "$root/notes" "$root/projects"38
: > "$root/inbox.md"39
for i in $(seq 1 "$WIDTH"); do40
(echo "$INIT" | FOLIO_ROOT="$root" "$FOLIO" serve > "$WORK/out-$trial-$i" 2>&1) &41
done42
wait43
for i in $(seq 1 "$WIDTH"); do44
if ! grep -q protocolVersion "$WORK/out-$trial-$i"; then45
dead=$((dead + 1))46
echo " FAIL trial $trial process $i: $(tail -c 200 "$WORK/out-$trial-$i" | tr '\n' ' ')"47
fi48
done49
done51
total=$((TRIALS * WIDTH))52
if [ "$dead" -eq 0 ]; then53
echo " PASS $total concurrent starts on fresh roots, all answered initialize"54
exit 055
fi56
echo " FAIL $dead of $total concurrent starts died"57
exit 1