mirror of
https://github.com/hasso5703/alzeo.git
synced 2026-12-06 12:54:19 +01:00
install.sh: paths and binds the units can carry, flash knobs kept, and five smaller defects
HOME, HF_CACHE and PLE_DIR go into the units as they are: a space, a colon, a quote, a $ or a % is refused before step 1 instead of breaking the unit it lands in. ENGINE_BIND and PROXY_BIND take 127.0.0.1 or 0.0.0.0 only, checked again once read back from the units: the box reaches both ports itself on loopback, and 300.1.1.1 passed. A busy PROXY_PORT is ours only when the running proxy's unit names that port. SPEC_TOKEN_MAP_SIZE=0 and FLASH_REPLAYSSM_SPEC=0 are read back from the flash launcher like its tier (a launcher older than the knob keeps the default). A bad FLASH_REPLAYSSM_SPEC exits instead of tripping the ERR trap, --with-image with --no-image is refused, the image lane kept by --no-image is not called missing, oc_fetch_pinned fails when the binary could not be placed, --help's fp8 line gives the measured pools, and two dead variables go. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
fe9be46165
commit
6a69dea716
4 files changed
+288
-18
No files matched your search
+74
-13
@@ -69,7 +69,7 @@ _ENV_PORT="${PORT:-}"; _ENV_HF_CACHE="${HF_CACHE:-}"
|
||||
_ENV_CONTEXT_MODE="${CONTEXT_MODE:-}"; _ENV_PROXY_PORT="${PROXY_PORT:-}"
|
||||
_ENV_ENGINE_BIND="${ENGINE_BIND:-}"; _ENV_PROXY_BIND="${PROXY_BIND:-}"
|
||||
_ENV_PLE_DIR="${PLE_DIR:-}"; FLASH_TIER_ENV="${FLASH_TIER:-}"
|
||||
_ENV_SERVE_IMAGE="${SERVE_IMAGE:-}"; _ENV_FLASH_SERVE_IMAGE="${FLASH_SERVE_IMAGE:-}"
|
||||
_ENV_SPEC_TOKEN_MAP_SIZE="${SPEC_TOKEN_MAP_SIZE:-}"; _ENV_FLASH_REPLAYSSM_SPEC="${FLASH_REPLAYSSM_SPEC:-}"
|
||||
_ENV_DRAFT2_REPO="${DRAFT2_REPO:-}"; _ENV_DRAFT2_REV="${DRAFT2_REV:-}"
|
||||
_ENV_DRAFT2_QUANT="${DRAFT2_QUANT:-}"; _ENV_DRAFT2_TOKENS="${DRAFT2_TOKENS:-}"
|
||||
|
||||
@@ -272,7 +272,7 @@ resolve_flash_tier_args() {
|
||||
throughput) echo "NOTE: FLASH_REPLAYSSM_SPEC=1 has no speculation to apply to on the throughput tier; ignored" ;;
|
||||
*) FLASH_TIER_ARGS="$FLASH_TIER_ARGS --enable-linear-replayssm-spec" ;;
|
||||
esac ;;
|
||||
*) printf 'ERROR: FLASH_REPLAYSSM_SPEC must be 0 or 1 (got: %s)\n' "$FLASH_REPLAYSSM_SPEC" >&2; return 1 ;;
|
||||
*) printf 'ERROR: FLASH_REPLAYSSM_SPEC must be 0 or 1 (got: %s)\n' "$FLASH_REPLAYSSM_SPEC" >&2; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
resolve_flash_tier_args
|
||||
@@ -477,8 +477,9 @@ Env overrides (defaults are pinned to the versions validated 2026-09-11):
|
||||
calibrated NVFP4 draft at depth 16)
|
||||
MODEL_CHOICE=uncensored serve the huihui-abliterated model
|
||||
(edp1096 NVFP4) instead of the stock base
|
||||
MODEL_CHOICE=fp8 serve Qwen's own FP8 release (30.9 GB, about
|
||||
200k fewer tokens of KV pool, slower decode)
|
||||
MODEL_CHOICE=fp8 serve Qwen's own FP8 release (30.9 GB, slower
|
||||
decode; its 1M pool measured 881,895 tokens
|
||||
against 887,797 for NVFP4, 2026-09-18)
|
||||
MODEL_CHOICE=uncensored-fp8 the huihui abliteration in that same FP8 format
|
||||
MODEL_CHOICE=flash serve Qwen3.8-Flash-Next (176B hybrid MoE,
|
||||
NVFP4, SGLang engine, ~126 GB download; the
|
||||
@@ -562,11 +563,22 @@ done
|
||||
# README has said so since v1.5, and it is the one that refuses what the engine cannot.
|
||||
ENGINE_BIND="${ENGINE_BIND:-127.0.0.1}"
|
||||
PROXY_BIND="${PROXY_BIND:-0.0.0.0}"
|
||||
for _b in "$ENGINE_BIND" "$PROXY_BIND"; do
|
||||
case "$_b" in
|
||||
*[!0-9.]*|"") printf 'ERROR: ENGINE_BIND and PROXY_BIND take an IPv4 address (got: %s)\n' "$_b" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
# Loopback or every interface, nothing between: the box reaches both ports itself on
|
||||
# 127.0.0.1 (the proxy's UPSTREAM, the health checks and the smoke test, opencode's
|
||||
# base_url, the cockpit), so a bind that leaves loopback out breaks all of them. The
|
||||
# old check took any digits and dots, 300.1.1.1 and ... included (found in review,
|
||||
# 2026-09-24). Called again once the installed binds are read back.
|
||||
check_binds() {
|
||||
local b
|
||||
for b in "ENGINE_BIND=$ENGINE_BIND" "PROXY_BIND=$PROXY_BIND"; do
|
||||
case "${b#*=}" in
|
||||
127.0.0.1|0.0.0.0) ;;
|
||||
*) printf 'ERROR: %s=%s: this box reaches that port itself on 127.0.0.1 (the proxy, the health checks, opencode), so it binds 127.0.0.1 (this machine only) or 0.0.0.0 (every interface: narrow it with a firewall)\n' "${b%%=*}" "${b#*=}" >&2
|
||||
exit 1 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
check_binds
|
||||
|
||||
# Which choice is installed? The flash unit wins only when it is the enabled
|
||||
# one; a box can hold both unit files but only one engine serves the port.
|
||||
@@ -655,6 +667,26 @@ if [ "$INSTALLED_CHOICE" = "flash" ]; then
|
||||
done
|
||||
resolve_flash_tier_args
|
||||
fi
|
||||
# The two speculative-path knobs a box can turn off, read back like the tier: set to
|
||||
# 0 on one run, both came back on at the next (found in review, 2026-09-24). A
|
||||
# launcher that does not speculate carries neither whatever they were, and one
|
||||
# rendered before a knob existed says nothing of it: those keep the defaults. The
|
||||
# markers are comments of the template, since v1.8 and since v1.10.2.
|
||||
if grep -q -- '--speculative-algorithm' "$FLASH_LAUNCH"; then
|
||||
if [ -z "$_ENV_SPEC_TOKEN_MAP_SIZE" ] && grep -q 'Engine since v1.8' "$FLASH_LAUNCH"; then
|
||||
CUR_MAP="$(grep -oE -- '--speculative-token-map /out/token-map-[0-9]+\.pt' "$FLASH_LAUNCH" | head -1 | sed -E 's/.*token-map-([0-9]+)\.pt/\1/' || true)"
|
||||
if [ "${CUR_MAP:-0}" != "$SPEC_TOKEN_MAP_SIZE" ]; then
|
||||
SPEC_TOKEN_MAP_SIZE="${CUR_MAP:-0}"; TOKEN_MAP_NAME="token-map-${SPEC_TOKEN_MAP_SIZE}.pt"
|
||||
echo "Keeping the installed reduced draft vocabulary: SPEC_TOKEN_MAP_SIZE=$SPEC_TOKEN_MAP_SIZE. Pass SPEC_TOKEN_MAP_SIZE= to change."
|
||||
fi
|
||||
fi
|
||||
if [ -z "$_ENV_FLASH_REPLAYSSM_SPEC" ] && [ "$FLASH_REPLAYSSM_SPEC" = "1" ] \
|
||||
&& grep -q 'No --allow-auto-truncate' "$FLASH_LAUNCH" \
|
||||
&& ! grep -q -- '--enable-linear-replayssm-spec' "$FLASH_LAUNCH"; then
|
||||
FLASH_REPLAYSSM_SPEC=0; resolve_flash_tier_args
|
||||
echo "Keeping the installed MTP verify state: FLASH_REPLAYSSM_SPEC=0. Pass FLASH_REPLAYSSM_SPEC=1 to change."
|
||||
fi
|
||||
fi
|
||||
if [ -z "${_ENV_PLE_DIR:-}" ] && [ -n "$CUR_PLE" ] && [ "$CUR_PLE" != "$PLE_DIR" ]; then
|
||||
PLE_DIR="$CUR_PLE"
|
||||
echo "Keeping the installed PLE table location: $PLE_DIR. Pass PLE_DIR= to change."
|
||||
@@ -757,6 +789,7 @@ if [ -n "$INSTALLED_CHOICE" ]; then
|
||||
echo "Keeping the installed proxy bind: $PROXY_BIND. Pass PROXY_BIND= to change."
|
||||
fi
|
||||
fi
|
||||
check_binds
|
||||
if [ "$INSTALLED_CHOICE" = "27b" ] && [ "$LANE" != "flash" ] && [ -z "$_ENV_CONTEXT_MODE" ]; then
|
||||
if grep -q -- '--context-length 1010000' "$SGL_UNIT_PATH"; then
|
||||
CONTEXT_MODE=1m
|
||||
@@ -841,6 +874,11 @@ fi
|
||||
if [ "$NO_COCKPIT" -eq 1 ] && [ "$WITH_COCKPIT" -eq 1 ]; then
|
||||
printf -- '--no-cockpit and --with-cockpit contradict each other (drop one flag)\n' >&2; exit 1
|
||||
fi
|
||||
# The same for the image lane: both were taken, and --no-image won silently at the end of
|
||||
# the install (found in review, 2026-09-24).
|
||||
if [ "$NO_IMAGE" -eq 1 ] && [ "$WITH_IMAGE" -eq 1 ]; then
|
||||
printf -- '--no-image and --with-image contradict each other (drop one flag)\n' >&2; exit 1
|
||||
fi
|
||||
|
||||
# --no-start and --no-service both return before the image step, so the flag would be
|
||||
# accepted and silently do nothing. Say so here rather than at the end of a long install.
|
||||
@@ -902,6 +940,17 @@ stale_since(){
|
||||
|
||||
step "1/10 Preflight checks"
|
||||
[ "$(uname -m)" = "aarch64" ] || die "This setup targets GB10 (aarch64). Detected: $(uname -m)."
|
||||
# These paths are written into the units and the flash launcher: inside a quoted
|
||||
# `bash -c` line, in a docker `-v src:dst`, and in systemd's own syntax, where % is a
|
||||
# specifier. A space, a colon, a quote, a $ or a % in one was accepted and broke the
|
||||
# unit it went into, seen only when that failed to start (found in review, 2026-09-24).
|
||||
for _p in "HOME=$HOME" "HF_CACHE=$HF_CACHE" "PLE_DIR=$PLE_DIR"; do
|
||||
case "${_p#*=}" in
|
||||
/*) case "${_p#*=}" in *[!A-Za-z0-9._/+@-]*) die "${_p%%=*}=${_p#*=}: the units this installs cannot carry that path. Use an absolute path of letters, digits and . _ / + @ - only." ;; esac ;;
|
||||
*) die "${_p%%=*}=${_p#*=}: an absolute path is needed (the units carry it as it is)." ;;
|
||||
esac
|
||||
done
|
||||
unset _p
|
||||
command -v nvidia-smi >/dev/null || die "nvidia-smi not found. Is the NVIDIA driver stack installed? (stock on DGX OS)"
|
||||
# nvidia-smi says what is wrong when it cannot reach the driver, and exits non-zero:
|
||||
# inside a bare $(...) under set -e that ended the install with only "Install failed at
|
||||
@@ -1002,7 +1051,11 @@ if ss -tlnH 2>/dev/null | awk '{print $4}' | grep -q ":$PORT\$"; then
|
||||
fi
|
||||
fi
|
||||
if [ "$NO_SERVICE" -eq 0 ] && ss -tlnH 2>/dev/null | awk '{print $4}' | grep -q ":$PROXY_PORT\$"; then
|
||||
if systemctl is-active --quiet qwen38-keepalive 2>/dev/null; then
|
||||
# Ours only if the proxy that runs is the one on that port: a running proxy made ANY
|
||||
# busy PROXY_PORT pass, another program's included, which then kept the new unit from
|
||||
# binding (found in review, 2026-09-24).
|
||||
KA_PORT_NOW="$(grep -oE 'keepalive-proxy\.py [0-9]+' /etc/systemd/system/qwen38-keepalive.service 2>/dev/null | head -1 | tr -dc '0-9' || true)"
|
||||
if [ "$KA_PORT_NOW" = "$PROXY_PORT" ] && systemctl is-active --quiet qwen38-keepalive 2>/dev/null; then
|
||||
echo "Note: the keepalive proxy is already running on :$PROXY_PORT, re-installing over it."
|
||||
else
|
||||
die "Port $PROXY_PORT (keepalive proxy) is already in use by another program. Free it, or install with PROXY_PORT=<other>"
|
||||
@@ -1361,9 +1414,13 @@ oc_fetch_pinned(){ # prints the cause of a failure; the caller says what it le
|
||||
rm -rf "$tmp"; echo "NOTE: the opencode $OPENCODE_VERSION archive did not unpack"; return 1
|
||||
fi
|
||||
mkdir -p "$OC_HOME_DIR"
|
||||
# a new file renamed over the old one: a server still running the old binary keeps it
|
||||
install -m 755 "$tmp/opencode" "$OC_HOME_BIN.new" && mv -f "$OC_HOME_BIN.new" "$OC_HOME_BIN"
|
||||
rm -rf "$tmp"
|
||||
# a new file renamed over the old one: a server still running the old binary keeps it.
|
||||
# Its failure is the function's: the rm after it made every run return 0, and a full
|
||||
# disk read "installed" (found in review, 2026-09-24).
|
||||
local placed=0
|
||||
install -m 755 "$tmp/opencode" "$OC_HOME_BIN.new" && mv -f "$OC_HOME_BIN.new" "$OC_HOME_BIN" && placed=1
|
||||
rm -rf "$tmp" "$OC_HOME_BIN.new"
|
||||
[ "$placed" -eq 1 ] || { echo "NOTE: could not put opencode $OPENCODE_VERSION at $OC_HOME_BIN"; return 1; }
|
||||
}
|
||||
OC_FOUND="$(command -v opencode || true)"
|
||||
OC_ON_PATH="$OC_FOUND" # what a shell of the user's finds, before the fallback below
|
||||
@@ -2266,6 +2323,10 @@ except Exception as e:
|
||||
[ "$COCKPIT" -eq 0 ] && echo " cockpit : off (--no-cockpit); ./install.sh --with-cockpit turns it on"
|
||||
if [ "${IMAGE_READY:-0}" -eq 1 ]; then
|
||||
echo " Images : a third lane; switch to Qwen-Image 2.1 in the cockpit (or ./switch-model.sh image)"
|
||||
elif [ -f /etc/systemd/system/qwen38-image.service ] && [ "${IMAGE_ON:-0}" -eq 0 ]; then
|
||||
# --no-image on a box that has the lane: it is there, only not updated by this run
|
||||
# (it used to read "not installed", found in review, 2026-09-24)
|
||||
echo " Images : installed, not updated by this run (--no-image); ./install-image.sh --uninstall removes it"
|
||||
elif [ "${IMAGE_ON:-0}" -eq 0 ]; then
|
||||
echo " Images : not installed; ./install.sh --with-image adds the Qwen-Image 2.1 lane (38 GB)"
|
||||
fi
|
||||
|
||||
@@ -136,18 +136,21 @@ class TheDefaults(unittest.TestCase):
|
||||
def test_the_old_behaviour_is_one_variable_away(self):
|
||||
"""A box that wants the engine on the network says so, and is not argued with."""
|
||||
_, out = run(STOP, script=fresh_box(), ENGINE_BIND="0.0.0.0", **STOCK)
|
||||
self.assertNotIn("take an IPv4 address", out)
|
||||
self.assertNotIn("this box reaches that port itself", out)
|
||||
|
||||
def test_a_value_that_is_not_an_address_is_refused_by_name(self):
|
||||
"""A bad bind writes a unit that fails to start minutes later, on a box whose
|
||||
engine has just been stopped. It is refused here instead, before anything moves."""
|
||||
for bad in ("localhost", "0.0.0.0:30000", "not-an-ip", "::1"):
|
||||
# 300.1.1.1 and ... passed the old digits-and-dots check, and an address that
|
||||
# leaves loopback out breaks what reaches these ports on 127.0.0.1 (found in
|
||||
# review, 2026-09-24)
|
||||
for bad in ("localhost", "0.0.0.0:30000", "not-an-ip", "::1", "300.1.1.1", "...", "192.168.1.10"):
|
||||
code, out = run(STOP, ENGINE_BIND=bad, **STOCK)
|
||||
self.assertNotEqual(code, 0, bad)
|
||||
self.assertIn("ENGINE_BIND and PROXY_BIND take an IPv4 address", out, bad)
|
||||
code, out = run(STOP, PROXY_BIND="nope", **STOCK)
|
||||
self.assertIn(f"ENGINE_BIND={bad}: this box reaches that port itself on 127.0.0.1", out, bad)
|
||||
code, out = run(STOP, PROXY_BIND="100.64.0.1", **STOCK)
|
||||
self.assertNotEqual(code, 0)
|
||||
self.assertIn("ENGINE_BIND and PROXY_BIND take an IPv4 address", out)
|
||||
self.assertIn("PROXY_BIND=100.64.0.1: this box reaches that port itself", out)
|
||||
|
||||
def test_an_address_is_accepted_and_the_run_continues(self):
|
||||
_, out = run(STOP, ENGINE_BIND="127.0.0.1", PROXY_BIND="127.0.0.1", **STOCK)
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python3
|
||||
"""A flash box that turned off the reduced draft vocabulary or the replayssm verify state
|
||||
keeps it off across plain re-runs, as it keeps its tier.
|
||||
|
||||
SPEC_TOKEN_MAP_SIZE=0 and FLASH_REPLAYSSM_SPEC=0 were undone by the next ./install.sh,
|
||||
which read neither back from the installed launcher (found in review, 2026-09-24). A
|
||||
launcher that does not speculate carries neither, and one rendered before a knob existed
|
||||
says nothing about it: both keep the defaults. This runs install.sh's own lines."""
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
REPO = pathlib.Path(__file__).resolve().parents[1]
|
||||
TEXT = (REPO / "install.sh").read_text()
|
||||
FUNC = TEXT[TEXT.index("resolve_flash_tier_args() {"):TEXT.index("\n}\n", TEXT.index("resolve_flash_tier_args() {")) + 3]
|
||||
DEFAULTS = "\n".join(ln for ln in TEXT.splitlines()
|
||||
if re.match(r'(FLASH_TIER|FLASH_REPLAYSSM_SPEC|SPEC_TOKEN_MAP_SIZE)="\$\{', ln)
|
||||
or ln.startswith("TOKEN_MAP_NAME="))
|
||||
START = TEXT.index(" # The tier lives in the launcher as the concurrency it pins")
|
||||
BLOCK = TEXT[START:TEXT.index(' if [ -z "${_ENV_PLE_DIR:-}" ] && [ -n "$CUR_PLE" ]', START)]
|
||||
|
||||
HEAD = "# Engine since v1.8: the OFFICIAL SGLang image\n"
|
||||
NEW = "# No --allow-auto-truncate. It was here undocumented until 2026-09-13\n"
|
||||
CONTEXT = ("TIER=(--max-running-requests 4 --max-mamba-cache-size 20 --mamba-radix-cache-strategy extra_buffer "
|
||||
"--speculative-algorithm NEXTN --speculative-num-steps 3 --speculative-eagle-topk 1 "
|
||||
"--speculative-num-draft-tokens 4{replay})\n")
|
||||
MAP = "TIER+=(--speculative-token-map /out/token-map-{n}.pt)\n"
|
||||
|
||||
|
||||
def knobs(launcher, **env):
|
||||
d = pathlib.Path(tempfile.mkdtemp(prefix="flash-knobs-"))
|
||||
(d / "launch-flash.sh").write_text(launcher)
|
||||
script = ("set -euo pipefail\n" + DEFAULTS + "\n" + FUNC + "\nresolve_flash_tier_args\n"
|
||||
f'FLASH_TIER_ENV="${{FLASH_TIER:-}}"; _ENV_SPEC_TOKEN_MAP_SIZE="${{SPEC_TOKEN_MAP_SIZE_ENV:-}}"\n'
|
||||
f'_ENV_FLASH_REPLAYSSM_SPEC="${{FLASH_REPLAYSSM_SPEC_ENV:-}}"\nFLASH_LAUNCH="{d}/launch-flash.sh"\n'
|
||||
+ BLOCK + '\necho "KNOBS $SPEC_TOKEN_MAP_SIZE $TOKEN_MAP_NAME $FLASH_REPLAYSSM_SPEC $FLASH_TIER_ARGS"\n')
|
||||
extra = {}
|
||||
for k, v in env.items():
|
||||
extra[k] = v
|
||||
if k in ("SPEC_TOKEN_MAP_SIZE", "FLASH_REPLAYSSM_SPEC"):
|
||||
extra[k + "_ENV"] = v
|
||||
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
|
||||
env={"PATH": "/usr/bin:/bin", **extra})
|
||||
line = [ln for ln in r.stdout.splitlines() if ln.startswith("KNOBS ")]
|
||||
assert line, r.stdout + r.stderr
|
||||
size, name, replay, *args = line[0].split()[1:]
|
||||
return size, name, replay, " ".join(args)
|
||||
|
||||
|
||||
class TheKnobsFollowTheLauncher(unittest.TestCase):
|
||||
def test_both_off_stay_off(self):
|
||||
size, name, replay, args = knobs(HEAD + NEW + CONTEXT.format(replay=""))
|
||||
self.assertEqual((size, name, replay), ("0", "token-map-0.pt", "0"))
|
||||
self.assertNotIn("--enable-linear-replayssm-spec", args)
|
||||
|
||||
def test_a_size_of_its_own_is_kept(self):
|
||||
size, name, _, _ = knobs(HEAD + NEW + CONTEXT.format(replay=" --enable-linear-replayssm-spec")
|
||||
+ MAP.format(n=32768))
|
||||
self.assertEqual((size, name), ("32768", "token-map-32768.pt"))
|
||||
|
||||
def test_the_defaults_stay_on_a_default_launcher(self):
|
||||
size, _, replay, args = knobs(HEAD + NEW + CONTEXT.format(replay=" --enable-linear-replayssm-spec")
|
||||
+ MAP.format(n=65536))
|
||||
self.assertEqual((size, replay), ("65536", "1"))
|
||||
self.assertIn("--enable-linear-replayssm-spec", args)
|
||||
|
||||
def test_a_launcher_older_than_the_knob_gets_the_default(self):
|
||||
size, _, replay, _ = knobs(CONTEXT.format(replay="")) # neither marker: before v1.8
|
||||
self.assertEqual((size, replay), ("65536", "1"))
|
||||
_, _, replay, _ = knobs(HEAD + CONTEXT.format(replay="") + MAP.format(n=65536)) # v1.8 to v1.10.1
|
||||
self.assertEqual(replay, "1")
|
||||
|
||||
def test_a_value_passed_wins(self):
|
||||
size, _, replay, _ = knobs(HEAD + NEW + CONTEXT.format(replay=""), SPEC_TOKEN_MAP_SIZE="65536",
|
||||
FLASH_REPLAYSSM_SPEC="1")
|
||||
self.assertEqual((size, replay), ("65536", "1"))
|
||||
|
||||
def test_a_throughput_launcher_says_nothing_of_either(self):
|
||||
size, _, replay, _ = knobs(HEAD + NEW + "TIER=(--max-running-requests 24 --max-mamba-cache-size 96 "
|
||||
"--mamba-radix-cache-strategy extra_buffer_lazy)\n")
|
||||
self.assertEqual((size, replay), ("65536", "1"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
@@ -46,5 +46,124 @@ class TheDownloadHintNamesTheDraftPin(unittest.TestCase):
|
||||
self.assertNotIn(" DRAFT_REV=main", hint, "the retired DSpark pin")
|
||||
|
||||
|
||||
class PathsTheUnitsCannotCarry(unittest.TestCase):
|
||||
"""HOME, HF_CACHE and PLE_DIR go into the units as they are: inside a quoted bash -c
|
||||
line, in a docker -v src:dst, and in systemd's syntax, where % is a specifier."""
|
||||
START = TEXT.index('for _p in "HOME=$HOME" "HF_CACHE=$HF_CACHE" "PLE_DIR=$PLE_DIR"; do')
|
||||
BLOCK = TEXT[START:TEXT.index("unset _p\n", START)]
|
||||
|
||||
def check(self, home="/home/u", hf="/home/u/.cache/huggingface", ple="/home/u/flashnext-ple"):
|
||||
script = "set -euo pipefail\ndie(){ echo \"DIE: $*\"; exit 1; }\n" + self.BLOCK + "\necho FINE\n"
|
||||
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
|
||||
env={"PATH": "/usr/bin:/bin", "HOME": home, "HF_CACHE": hf, "PLE_DIR": ple})
|
||||
return r.stdout
|
||||
|
||||
def test_ordinary_paths_pass(self):
|
||||
self.assertIn("FINE", self.check())
|
||||
self.assertIn("FINE", self.check(hf="/mnt/data-1/hf_cache+x@2"))
|
||||
|
||||
def test_what_breaks_a_unit_is_refused_by_name(self):
|
||||
for bad in ("/mnt/my disk/hf", "/mnt/a:b", "/mnt/it's", "/mnt/$x", "/mnt/100%", "relative/hf"):
|
||||
out = self.check(hf=bad)
|
||||
self.assertIn("DIE: HF_CACHE=", out, bad)
|
||||
self.assertNotIn("FINE", out, bad)
|
||||
self.assertIn("DIE: HOME=", self.check(home="/home/jean dupont"))
|
||||
self.assertIn("DIE: PLE_DIR=", self.check(ple="/data/ple:x"))
|
||||
|
||||
|
||||
class TheBindsAreCheckedAgainOnceReadBack(unittest.TestCase):
|
||||
def test_a_read_back_bind_is_checked_too(self):
|
||||
first = TEXT.index("\ncheck_binds\n")
|
||||
again = TEXT.index("\n check_binds\n")
|
||||
self.assertLess(TEXT.index("Keeping the installed proxy bind"), again)
|
||||
self.assertLess(first, TEXT.index("Keeping the installed engine bind"))
|
||||
|
||||
|
||||
class ABusyProxyPortIsOursOnlyIfOurProxyHoldsIt(unittest.TestCase):
|
||||
START = TEXT.index('if [ "$NO_SERVICE" -eq 0 ] && ss -tlnH 2>/dev/null | awk \'{print $4}\' | grep -q ":$PROXY_PORT\\$"; then')
|
||||
BLOCK = TEXT[START:TEXT.index("\nfi\n", TEXT.index("keepalive proxy) is already in use", START)) + 4]
|
||||
|
||||
def run_block(self, proxy_port, unit_port):
|
||||
d = pathlib.Path(tempfile.mkdtemp(prefix="ka-port-"))
|
||||
(d / "ss").write_text(f"#!/bin/sh\necho 'LISTEN 0 128 0.0.0.0:{proxy_port} 0.0.0.0:*'\n")
|
||||
(d / "systemctl").write_text("#!/bin/sh\nexit 0\n") # the proxy is active
|
||||
for f in ("ss", "systemctl"):
|
||||
(d / f).chmod(0o755)
|
||||
(d / "ka.service").write_text(f"ExecStart=/usr/bin/python3 /x/keepalive-proxy.py {unit_port}\n")
|
||||
block = self.BLOCK.replace("/etc/systemd/system/qwen38-keepalive.service", str(d / "ka.service"))
|
||||
script = ("set -euo pipefail\ndie(){ echo \"DIE: $*\"; exit 1; }\n"
|
||||
f"NO_SERVICE=0; PROXY_PORT={proxy_port}\n" + block + "\necho PASSED\n")
|
||||
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
|
||||
env={"PATH": f"{d}:/usr/bin:/bin"})
|
||||
return r.stdout
|
||||
|
||||
def test_our_proxy_on_its_port_is_reinstalled_over(self):
|
||||
out = self.run_block(30001, 30001)
|
||||
self.assertIn("already running on :30001", out)
|
||||
self.assertIn("PASSED", out)
|
||||
|
||||
def test_another_program_on_the_asked_port_is_refused(self):
|
||||
out = self.run_block(8080, 30001)
|
||||
self.assertIn("DIE: Port 8080 (keepalive proxy) is already in use by another program", out)
|
||||
|
||||
|
||||
class ContradictoryImageFlags(unittest.TestCase):
|
||||
def test_both_image_flags_are_refused_before_anything(self):
|
||||
cut = TEXT.index('step "1/10 Preflight checks"')
|
||||
d = pathlib.Path(tempfile.mkdtemp(prefix="img-flags-"))
|
||||
(d / "install.sh").write_text(TEXT[:cut] + 'echo "FLAGS OK"; exit 0\n')
|
||||
r = subprocess.run(["bash", str(d / "install.sh"), "--with-image", "--no-image"], capture_output=True,
|
||||
text=True, timeout=60, cwd=str(REPO), env={"PATH": "/usr/bin:/bin", "HOME": str(d)})
|
||||
self.assertNotEqual(r.returncode, 0)
|
||||
self.assertIn("--no-image and --with-image contradict each other", r.stderr)
|
||||
self.assertNotIn("FLAGS OK", r.stdout)
|
||||
|
||||
|
||||
class TheOpencodeDownloadSaysWhenItCouldNotPlaceTheBinary(unittest.TestCase):
|
||||
"""oc_fetch_pinned ended on the rm of its temp dir, so it returned 0 whatever the
|
||||
install and the rename before it did: a full disk read "installed"."""
|
||||
FUNC = TEXT[TEXT.index("oc_fetch_pinned(){"):TEXT.index("\n}\n", TEXT.index("oc_fetch_pinned(){")) + 3]
|
||||
|
||||
def run_fetch(self, install_ok):
|
||||
import hashlib
|
||||
import tarfile
|
||||
d = pathlib.Path(tempfile.mkdtemp(prefix="oc-fetch-"))
|
||||
(d / "src").mkdir()
|
||||
(d / "src" / "opencode").write_text("#!/bin/sh\necho 1.18.32\n")
|
||||
with tarfile.open(d / "oc.tar.gz", "w:gz") as t:
|
||||
t.add(d / "src" / "opencode", arcname="opencode")
|
||||
sha = hashlib.sha256((d / "oc.tar.gz").read_bytes()).hexdigest()
|
||||
(d / "bin").mkdir()
|
||||
(d / "bin" / "curl").write_text(f'#!/bin/sh\nwhile [ "$1" != "-o" ]; do shift; done\ncp "{d}/oc.tar.gz" "$2"\n')
|
||||
(d / "bin" / "install").write_text("#!/bin/sh\nexit 0\n" if install_ok else "#!/bin/sh\necho 'No space left on device' >&2\nexit 1\n")
|
||||
if install_ok:
|
||||
(d / "bin" / "install").write_text('#!/bin/sh\nshift 2\ncp "$1" "$2"\n')
|
||||
for f in ("curl", "install"):
|
||||
(d / "bin" / f).chmod(0o755)
|
||||
script = (f'set -euo pipefail\nOPENCODE_VERSION=1.18.32; OPENCODE_SHA256={sha}\n'
|
||||
f'OC_HOME_DIR="{d}/home"; OC_HOME_BIN="{d}/home/opencode"\n' + self.FUNC
|
||||
+ '\nif oc_fetch_pinned; then echo RC0; else echo RC1; fi\n')
|
||||
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
|
||||
env={"PATH": f"{d}/bin:/usr/bin:/bin"})
|
||||
return r.stdout + r.stderr, d
|
||||
|
||||
def test_a_binary_that_could_not_be_placed_is_a_failure(self):
|
||||
out, _ = self.run_fetch(install_ok=False)
|
||||
self.assertIn("RC1", out)
|
||||
self.assertIn("could not put opencode", out)
|
||||
|
||||
def test_a_binary_placed_is_a_success(self):
|
||||
out, d = self.run_fetch(install_ok=True)
|
||||
self.assertIn("RC0", out)
|
||||
self.assertTrue((d / "home" / "opencode").exists())
|
||||
|
||||
|
||||
class TheImageLaneKeptByNoImageIsNotCalledMissing(unittest.TestCase):
|
||||
def test_the_summary_line(self):
|
||||
i = TEXT.index('elif [ -f /etc/systemd/system/qwen38-image.service ] && [ "${IMAGE_ON:-0}" -eq 0 ]; then')
|
||||
self.assertIn("installed, not updated by this run (--no-image)", TEXT[i:i + 400])
|
||||
self.assertLess(i, TEXT.index('" Images : not installed;'))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
Reference in new issue
Block a user