okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221rc1 merge tui-update (3165c2e8a)a1cc285fa

main
8.1 KiB133 linesraw
1#!/usr/bin/env bash
2# Settings > Engine, from the BUILT packages (not the checkout), with two REAL engine versions, in a throwaway HOME.
3#
4#   bash tests/terminal/engine_flow.sh            # run from a checkout of the branch; Linux x86_64 with NVIDIA tools or --backend cuda; needs internet
5#
6# 1. builds the Terminal/Control package from this checkout (packaging/package_terminal.py) and extracts it: everything below runs from that package;
7# 2. downloads the real, signed 0.2.8 (engine 0.1.54) and 0.2.9 (engine 0.1.55) Linux x86_64 CUDA 13 engine packages and their feeds from the public
8#    release page (read only) and serves each feed from 127.0.0.1;
9# 3. `strata update` twice: the old engine must be KEPT; then list, switch back, switch forward, an update that downloads nothing because the
10#    newest engine is already installed, delete, refusals, and a fresh process after each step (a restart).
11# Nothing here touches the real HOME: HOME, XDG_* and the settings file are inside the work folder, which is removed at the end.
12set -uo pipefail
13REPO="$(cd "$(dirname "$0")/../.." && pwd)"
14W="${ENGINE_FLOW_DIR:-$HOME/engine-flow-$$}"
15FAIL=0
16say() { printf '\n=== %s\n' "$*"; }
17ok() { printf 'PASS  %s\n' "$*"; }
18bad() { printf 'FAIL  %s\n' "$*"; FAIL=1; }
19check() { if eval "$2"; then ok "$1"; else bad "$1  [$2]"; fi; }
20PIDS=()
21cleanup() { for p in "${PIDS[@]:-}"; do [ -n "$p" ] && kill "$p" 2>/dev/null; done; [ -n "${W:-}" ] && [ -d "$W" ] && [ "${KEEP:-0}" != 1 ] && rm -rf "$W"; }
22trap cleanup EXIT
23
24mkdir -p "$W"/{rel28,rel29,pkg,term,home}
25BASE=https://github.com/Niko1221/Strata/releases/download
26ENG54=strata-engine-0.1.54-linux-x86_64-cuda-cuda13.tar.gz
27ENG55=strata-engine-0.1.55-linux-x86_64-cuda-cuda13.tar.gz
28
29say "build the Terminal/Control package from this checkout"
30if [ -n "${TERMINAL_ARCHIVE:-}" ]; then
31  ARCHIVE="$TERMINAL_ARCHIVE"          # built elsewhere from the same checkout (a box without PyPI access): the flow below runs from that archive
32  echo "using the archive built beforehand: $ARCHIVE"
33else
34  export STRATA_COMMIT="${STRATA_COMMIT:-$(git -C "$REPO" rev-parse HEAD 2>/dev/null)}"   # a checkout copied without .git: pass STRATA_COMMIT
35  ( cd "$REPO" && python3 packaging/package_terminal.py --out "$W/pkg" --target linux-x86_64 ) > "$W/build.log" 2>&1 || { tail -20 "$W/build.log"; bad "package build"; exit 1; }
36  ARCHIVE="$(ls "$W"/pkg/*.tar.gz | head -1)"
37fi
38tar -xzf "$ARCHIVE" -C "$W/term"
39S="$(find "$W/term" -maxdepth 3 -path '*/bin/strata' | head -1)"
40check "the package has its launcher" "[ -x '$S' ]"
41BRANCH_VERSION="$(cat "$REPO/VERSION" 2>/dev/null)"
42echo "package: $(basename "$ARCHIVE")  launcher: $S"
43
44say "real releases (read only): feeds and the two engine packages"
45for pair in "v0.2.8:rel28:$ENG54" "v0.2.9:rel29:$ENG55"; do
46  IFS=: read -r tag dir eng <<< "$pair"
47  for f in strata-feed.json strata-feed.json.sig "$eng"; do
48    if [ -n "${RELEASE_FILES:-}" ] && [ -f "$RELEASE_FILES/$dir/$f" ]; then
49      cp "$RELEASE_FILES/$dir/$f" "$W/$dir/$f"          # the same files, fetched beforehand (a box without internet)
50    else
51      curl -fsSL --retry 3 -o "$W/$dir/$f" "$BASE/$tag/$f" || { bad "download $tag/$f"; exit 1; }
52    fi
53  done
54done
55ls -l "$W/rel28" "$W/rel29"
56
57# an isolated user: HOME, XDG and the settings file are inside $W
58export HOME="$W/home" XDG_DATA_HOME="$W/home/.local/share" XDG_CONFIG_HOME="$W/home/.config" XDG_STATE_HOME="$W/home/.local/state" XDG_CACHE_HOME="$W/home/.cache"
59export STRATA_SETTINGS_FILE="$W/home/app-settings.json"
60unset STRATA_NO_ACQUIRE STRATA_COMPONENTS_DIR STRATA_API_KEY STRATA_UPDATE_FEED STRATA_ENGINE_BACKEND STRATA_INSTALL_DIR STRATA_HOME
61mkdir -p "$HOME"
62COMP="$XDG_DATA_HOME/strata/components"
63
64serve() {          # serve DIR on a free port, log the requests; sets PORT and SERVER_PID (not run in a subshell, so the pid survives)
65  local dir="$1" log="$2" port
66  port=$(python3 -c 'import socket;s=socket.socket();s.bind(("127.0.0.1",0));print(s.getsockname()[1])')
67  python3 -m http.server "$port" --bind 127.0.0.1 --directory "$dir" > "$log" 2>&1 &
68  SERVER_PID=$!; PIDS+=("$SERVER_PID")
69  for _ in $(seq 1 50); do curl -fs -o /dev/null "http://127.0.0.1:$port/strata-feed.json" && break; sleep 0.2; done
70  PORT="$port"
71}
72json() { python3 -c "import json,sys; d=json.load(sys.stdin); print($1)"; }
73engines_json() { "$S" components engines --output json; }
74active_version() { "$S" components engine --output json --backend cuda | json "(d.get('engine') or {}).get('version')"; }
75folders() { ls "$COMP/engine" 2>/dev/null | grep -v '^\.' | sort | tr '\n' ' '; }
76engine_gets() { grep -c "GET /$1" "$2" || true; }
77
78say "step 1: 0.2.8 feed -> engine 0.1.54"
79serve "$W/rel28" "$W/server28.log"; P28=$PORT; PID28=$SERVER_PID
80"$S" update --feed "http://127.0.0.1:$P28/strata-feed.json" --no-control --backend cuda 2>&1 | tail -8
81check "0.1.54 is the engine in use" "[ \"\$(active_version)\" = 0.1.54 ]"
82kill "$PID28"; wait "$PID28" 2>/dev/null
83
84say "step 2: 0.2.9 feed -> engine 0.1.55; the old engine is KEPT"
85serve "$W/rel29" "$W/server29.log"; P29=$PORT; PID29=$SERVER_PID
86"$S" update --feed "http://127.0.0.1:$P29/strata-feed.json" --no-control --backend cuda 2>&1 | tail -8
87check "0.1.55 is the engine in use" "[ \"\$(active_version)\" = 0.1.55 ]"
88echo "folders: $(folders)"
89check "both engine folders are installed" "[ \$(folders | wc -w) -eq 2 ] && folders | grep -q 0.1.54 && folders | grep -q 0.1.55"
90"$S" components engines
91check "the list names both, 0.1.55 in use and newest, with sizes" "engines_json | json \"[ (e['version'],e['active'],e['newest'],e['bytes']>1e8) for f in d['families'] for e in f['engines']]\" | grep -q \"('0.1.55', True, True, True)\" && engines_json | json \"[ (e['version'],e['active']) for f in d['families'] for e in f['engines']]\" | grep -q \"('0.1.54', False)\""
92
93say "step 3: switch back to 0.1.54, then restart (a fresh process)"
94"$S" components use 0.1.54 2>&1 | tail -4
95check "0.1.54 is in use" "[ \"\$(active_version)\" = 0.1.54 ]"
96check "the engine program of 0.1.54 runs and says so" "env -i \"\$(ls -d $COMP/engine/0.1.54-*)/strata\" --version | grep -q 0.1.54"
97check "the pin is written" "grep -q '\"pinned\"' '$COMP/.updates/state.json'"
98check "after a restart: still 0.1.54 (new process)" "[ \"\$(bash -c \"'$S' components engine --output json --backend cuda\" | json \"d['engine']['version']\")\" = 0.1.54 ]"
99
100say "step 4: the engine in use cannot be deleted"
101"$S" components remove 0.1.54; RC=$?
102check "remove of the engine in use is refused (exit 2)" "[ $RC -eq 2 ]"
103check "its folder is still there" "ls -d $COMP/engine/0.1.54-* >/dev/null"
104
105say "step 5: switch forward to the newest (follows updates again)"
106"$S" components use newest 2>&1 | tail -4
107check "0.1.55 is in use" "[ \"\$(active_version)\" = 0.1.55 ]"
108check "no pin" "! grep -q '\"pinned\"' '$COMP/.updates/state.json'"
109
110say "step 6: back to 0.1.54, then an update with the newest already installed downloads nothing and makes it the engine in use"
111"$S" components use 0.1.54 2>&1 | tail -2
112B=$(engine_gets "$ENG55" "$W/server29.log")
113"$S" update --check --feed "http://127.0.0.1:$P29/strata-feed.json" --no-control --backend cuda 2>&1 | tail -6
114"$S" update --feed "http://127.0.0.1:$P29/strata-feed.json" --no-control --backend cuda 2>&1 | tail -6
115A=$(engine_gets "$ENG55" "$W/server29.log")
116check "the engine archive was not requested again" "[ '$A' = '$B' ]"
117check "0.1.55 is the engine in use, pin cleared" "[ \"\$(active_version)\" = 0.1.55 ] && ! grep -q '\"pinned\"' '$COMP/.updates/state.json'"
118check "both engines are still installed" "[ \$(folders | wc -w) -eq 2 ]"
119
120say "step 7: delete 0.1.54; the engine in use stays"
121"$S" components remove 0.1.54 2>&1 | tail -3
122check "0.1.54 is gone" "! ls -d $COMP/engine/0.1.54-* >/dev/null 2>&1"
123check "0.1.55 still runs" "env -i \"\$(ls -d $COMP/engine/0.1.55-*)/strata\" --version | grep -q 0.1.55"
124"$S" components remove 0.1.55; RC=$?
125check "the last engine, in use, is refused" "[ $RC -eq 2 ]"
126"$S" components rollback; RC=$?
127check "rollback with nothing older says so (exit 2)" "[ $RC -eq 2 ]"
128check "a start finds the engine after all of it (new process)" "[ \"\$(active_version)\" = 0.1.55 ]"
129"$S" components engines
130
131say "result"
132[ "$FAIL" = 0 ] && echo "ALL PASSED" || echo "SOME FAILED"
133exit "$FAIL"