#!/usr/bin/env bash # next/tests/bootstrap_start.sh — Step 4f-consolidate test. # # bootstrap:start/3 is the one-call kernel bring-up: starts the # registry gen_server, populates it from the genesis bundle, # and starts the nx_kernel gen_server. Each test inlines the # start call with downstream operations because spawned # processes don't survive across separate erlang-eval-ast calls. # 11 cases. set -uo pipefail cd "$(git rev-parse --show-toplevel)" SX_SERVER="${SX_SERVER:-hosts/ocaml/_build/default/bin/sx_server.exe}" if [ ! -x "$SX_SERVER" ]; then SX_SERVER="/root/rose-ash/hosts/ocaml/_build/default/bin/sx_server.exe" fi if [ ! -x "$SX_SERVER" ]; then echo "ERROR: sx_server.exe not found." >&2 exit 1 fi VERBOSE="${1:-}" PASS=0; FAIL=0; ERRORS="" TMPFILE=$(mktemp); trap "rm -f $TMPFILE" EXIT PRELUDE='KM = <<1,2,3,4>>, KS = [{key_id,k1},{algorithm,ed25519},{value,KM}], AS = [{public_keys,[[{id,k1},{created,0},{value,KM}]]}], bootstrap:start(alice, KS, AS),' cat > "$TMPFILE" < length(registry:list(K)) end, registry:kinds()), lists:foldl(fun (X, A) -> X + A end, 0, L)\")") ;; nx_kernel fresh log_tip = 0 (epoch 25) (eval "(erlang-eval-ast \"${PRELUDE} nx_kernel:log_tip()\")") ;; nx_kernel publish advances log_tip (epoch 26) (eval "(erlang-eval-ast \"${PRELUDE} nx_kernel:publish([{type, create}, {object, nil}]), nx_kernel:log_tip()\")") ;; nx_kernel state carries the supplied actor_id (epoch 27) (eval "(get (erlang-eval-ast \"${PRELUDE} nx_kernel:actor_id(nx_kernel:query()) =:= alice\") :name)") ;; Registry lookup works after start (canonical entry: Create) (epoch 28) (eval "(get (erlang-eval-ast \"${PRELUDE} case registry:lookup(activity_types, <<99,114,101,97,116,101>>) of {ok, _} -> ok; _ -> bad end\") :name)") EPOCHS OUTPUT=$(timeout 300 "$SX_SERVER" < "$TMPFILE" 2>/dev/null) check() { local epoch="$1" desc="$2" expected="$3" local actual actual=$(echo "$OUTPUT" | awk -v e="$epoch" ' $0 ~ "^\\(ok-len " e " " { getline; print; exit } $0 ~ "^\\(ok " e " " { print; exit } $0 ~ "^\\(error " e " " { print; exit } ') [ -z "$actual" ] && actual="" if echo "$actual" | grep -qF -- "$expected"; then PASS=$((PASS+1)) [ "$VERBOSE" = "-v" ] && echo " ok $desc" else FAIL=$((FAIL+1)) ERRORS+=" FAIL [$desc] (epoch $epoch) expected: $expected | actual: $actual " fi } check 10 "bootstrap module loaded" "bootstrap" check 20 "whereis(nx_kernel) is Pid" "true" check 21 "activity_types count = 3" "3" check 22 "object_types count = 10" "10" check 23 "projections count = 7" "7" check 24 "total entries = 31" "31" check 25 "fresh log_tip = 0" "0" check 26 "publish advances tip to 1" "1" check 27 "actor_id = alice" "true" check 28 "registry has create" "ok" TOTAL=$((PASS+FAIL)) if [ $FAIL -eq 0 ]; then echo "ok $PASS/$TOTAL next/tests/bootstrap_start.sh passed" else echo "FAIL $PASS/$TOTAL passed, $FAIL failed:" echo "$ERRORS" fi [ $FAIL -eq 0 ]