mirror of
https://github.com/hasso5703/alzeo.git
synced 2026-12-05 12:24:28 +01:00
The branch was cut before v1.59.1. Its proxy roles take the next two version numbers, its installer's disk figures add its 5 GB to v1.59.1's, its card keeps the Lanes view's order and the lanes' boot button with its own systemd verbs, and its tests of an empty chunked body send the chunk the proxy reads since v6.63. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
329 lines
18 KiB
Python
329 lines
18 KiB
Python
#!/usr/bin/env python3
|
|
"""Smaller installer defects found in review (2026-09-24), each against install.sh's own lines."""
|
|
import pathlib
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
REPO = pathlib.Path(__file__).resolve().parents[1]
|
|
TEXT = (REPO / "install.sh").read_text()
|
|
|
|
|
|
def line(prefix):
|
|
return next(ln for ln in TEXT.splitlines() if ln.startswith(prefix))
|
|
|
|
|
|
class ADfThatFailsSaysSo(unittest.TestCase):
|
|
"""A df that fails under pipefail ended the install at its own line, and the
|
|
"found unknown GiB" message written for exactly that case never showed."""
|
|
|
|
def run_lines(self, *lines):
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="df-fail-"))
|
|
(d / "df").write_text("#!/bin/sh\necho 'df: cannot reach it' >&2\nexit 1\n")
|
|
(d / "df").chmod(0o755)
|
|
script = ("set -euo pipefail\ndie(){ echo \"DIE: $*\"; exit 1; }\n"
|
|
f'HF_CACHE="{d}"; NEED_GB=45; DOCKER_ROOT="{d}"; DOCKER_NEED_GB=40; IMG_LABEL=img\n'
|
|
+ "\n".join(lines) + "\n")
|
|
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
|
|
env={"PATH": f"{d}:/usr/bin:/bin"})
|
|
return r.stdout + r.stderr
|
|
|
|
def test_the_hf_cache_disk(self):
|
|
out = self.run_lines(line("FREE_DISK_GB="), line('[ -n "$FREE_DISK_GB" ]'))
|
|
self.assertIn("DIE: Need ~45 GiB free", out)
|
|
self.assertIn("found unknown GiB", out)
|
|
|
|
def test_the_docker_disk(self):
|
|
out = self.run_lines(line("DOCKER_FREE_GB="), line('[ "${DOCKER_FREE_GB:-0}"'))
|
|
self.assertIn("DIE: Need ~40 GiB free on", out)
|
|
|
|
|
|
class TheDownloadHintNamesTheDraftPin(unittest.TestCase):
|
|
def test_it_is_draft2(self):
|
|
i = TEXT.index("Checkpoint download failed.")
|
|
hint = TEXT[i:TEXT.index("\n", i)]
|
|
self.assertIn("DRAFT2_REV=main", hint)
|
|
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("\nfor _p in \"$HF_CACHE\"", START)]
|
|
|
|
def check(self, home="/home/u", hf="/home/u/.cache/huggingface", ple="/home/u/flashnext-ple", repo="/home/u/dgx-spark-qwen38",
|
|
cockpit=1):
|
|
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, "REPO_DIR": repo,
|
|
"COCKPIT": str(cockpit)})
|
|
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"))
|
|
|
|
def test_the_clone_too_which_the_cockpits_unit_runs_from(self):
|
|
for bad in ("/home/u/my clones/alzeo", "/home/u/a'b", '/home/u/a"b', "/home/u/$x", "/home/u/100%", "/home/u/a:b", "/home/u/a|b",
|
|
"/home/u/a&b", "/home/u/a\\b", "/home/u/a\tb"):
|
|
self.assertIn("DIE: this clone's path", self.check(repo=bad), bad)
|
|
self.assertIn("FINE", self.check(repo=bad, cockpit=0), "no cockpit, or one cut: nothing runs from it")
|
|
# what v1.59.0 took, and systemd takes (found in review, 2026-11-30)
|
|
for good in ("/home/u/Téléchargements/alzeo", "/home/u/a,b", "/home/u/a=b", "/home/u/a#b", "/home/u/a[1]", "/home/u/a~b"):
|
|
self.assertIn("FINE", self.check(repo=good), good)
|
|
|
|
|
|
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 [ -z "$SECONDARY" ] && [ "$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, secondary=""):
|
|
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; SECONDARY={secondary}; 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)
|
|
|
|
def test_a_run_for_the_other_text_lane_leaves_the_ports_to_its_parent(self):
|
|
# it shares them with the lane its parent serves, which holds them by design
|
|
out = self.run_block(8080, 30001, secondary="flash")
|
|
self.assertIn("PASSED", out)
|
|
self.assertNotIn("DIE", 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')
|
|
(d / "lanes.sh").write_text((REPO / "lanes.sh").read_text()) # sourced by the scripts since v1.30
|
|
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 TheSummarySaysWhatBecameOfEachOtherLane(unittest.TestCase):
|
|
"""The closing lines, one per lane the run did not serve. A lane left out and still on
|
|
the box is "not updated", not "not installed" (it read "not installed" until the review
|
|
of 2026-09-24), and a lane that did not install says how to try again."""
|
|
START = TEXT.index(" lane_line(){")
|
|
FUNC = TEXT[START:TEXT.index("\n }\n", START) + 7]
|
|
|
|
def line(self, state, on_the_box, cockpit=1):
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="lane-line-"))
|
|
unit = d / "qwen38-image.service"
|
|
if on_the_box:
|
|
unit.write_text("[Unit]\n")
|
|
script = (f"set -euo pipefail\nCOCKPIT={cockpit}\n" + self.FUNC +
|
|
f'\nlane_line "Images " {state} image image "40 GB" "{unit}"\n')
|
|
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
|
|
env={"PATH": "/usr/bin:/bin"})
|
|
self.assertEqual(r.returncode, 0, r.stderr)
|
|
return r.stdout
|
|
|
|
def test_a_lane_no_switch_drives_is_told_its_own_commands_without_a_cockpit(self):
|
|
# the embeddings lane ("-", no switch target): with the cockpit off, its line sent the
|
|
# person to "the cockpit's Lanes view" and nowhere else (the review of v1.60.0)
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="lane-line-"))
|
|
unit = d / "qwen38-embed.service"
|
|
unit.write_text("[Unit]\n")
|
|
for state in ("units", "installed", "proved"):
|
|
with self.subTest(state):
|
|
script = ("set -euo pipefail\nCOCKPIT=0\n" + self.FUNC +
|
|
f'\nlane_line "Embeddings " {state} embeddings - "3 GB" "{unit}"\n')
|
|
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
|
|
env={"PATH": "/usr/bin:/bin"})
|
|
self.assertEqual(r.returncode, 0, r.stderr)
|
|
self.assertIn("sudo systemctl enable --now qwen38-embed.service", r.stdout)
|
|
self.assertNotIn("switch-model.sh", r.stdout)
|
|
if state == "units":
|
|
self.assertIn("./prepare-lane.sh embeddings", r.stdout)
|
|
self.assertNotIn("cockpit", r.stdout)
|
|
|
|
def test_left_out_but_still_on_the_box(self):
|
|
out = self.line("off", True)
|
|
self.assertIn("left out by --no-image on this run, so not updated", out)
|
|
self.assertIn("a run without it updates it", out)
|
|
|
|
def test_left_out_and_absent(self):
|
|
out = self.line("off", False)
|
|
self.assertIn("a run without it adds it, ready to load (40 GB)", out)
|
|
|
|
def test_proved_installed_and_failed(self):
|
|
self.assertIn("installed and proved it serves", self.line("proved", True))
|
|
self.assertIn("installed and up to date", self.line("installed", True))
|
|
self.assertIn("./install.sh --with-image installs it whole", self.line("failed", False))
|
|
|
|
def test_a_lane_installed_whose_proof_failed_is_told_how_to_prove_it(self):
|
|
# its unit is on the box, so the next plain run finds it not new, updates it and proves
|
|
# nothing: the line promised a retry that never came (found in review, 2026-10-14)
|
|
out = self.line("unproved", True)
|
|
self.assertIn("./install.sh --with-image proves it again", out)
|
|
self.assertNotIn("tries again", out)
|
|
|
|
def test_a_lane_that_did_not_install_is_not_said_to_have_failed_its_proof(self):
|
|
# its room or a download stopped it; with its unit there (installed on demand) it read
|
|
# "installed but did not prove it serves", and a plain run gives such a lane its units
|
|
# only, trying nothing again (found in review, 2026-10-15)
|
|
out = self.line("failed", True)
|
|
self.assertIn("it did not install", out)
|
|
self.assertIn("(it did not install): ./install.sh --with-image installs it whole", out)
|
|
self.assertNotIn("prove", out)
|
|
# a lane named with --with-<lane> that died before its runtime (its room, a download) is
|
|
# given its units only by a plain run: "a plain ./install.sh tries the same again" was
|
|
# not so (found in review, 2026-10-15)
|
|
self.assertNotIn("a plain ./install.sh", out)
|
|
|
|
def test_with_no_cockpit_a_lane_on_demand_is_told_its_terminal_commands(self):
|
|
self.assertIn("its first Load from the cockpit's Lanes view builds it", self.line("units", True))
|
|
out = self.line("units", True, cockpit=0)
|
|
self.assertIn("./prepare-lane.sh image builds it, then ./switch-model.sh image switches to it", out)
|
|
self.assertNotIn("cockpit", out)
|
|
|
|
|
|
class OneDiskForBoth(unittest.TestCase):
|
|
"""HF_CACHE and Docker's root on one disk, as on a stock box: the needs add up there."""
|
|
START = TEXT.index('HF_DEV="$(stat -L -c %d "$HF_CACHE"')
|
|
BLOCK = TEXT[START:TEXT.index("\nfi\n", START) + 4]
|
|
|
|
def run_block(self, same_disk, free):
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="one-disk-"))
|
|
(d / "hf").mkdir()
|
|
other = pathlib.Path("/dev/shm") if not same_disk else d / "docker"
|
|
other.mkdir(exist_ok=True)
|
|
script = ("set -euo pipefail\ndie(){ echo \"DIE: $*\"; exit 1; }\n"
|
|
f'HF_CACHE="{d}/hf"; DOCKER_ROOT="{other}"; NEED_GB=45; DOCKER_NEED_GB=40; IMG_LABEL=img; '
|
|
f"FREE_DISK_GB={free}\n" + self.BLOCK + "\necho FITS\n")
|
|
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30)
|
|
return r.stdout
|
|
|
|
def test_the_sum_is_asked_on_one_disk(self):
|
|
self.assertIn("DIE: Need ~85 GiB free on the disk that holds both", self.run_block(True, 60))
|
|
self.assertIn("FITS", self.run_block(True, 90))
|
|
|
|
def test_two_disks_are_left_to_their_own_checks(self):
|
|
self.assertIn("FITS", self.run_block(False, 60))
|
|
|
|
def test_a_cache_linked_to_another_disk_is_on_that_disk(self):
|
|
# ~/.cache/huggingface a symlink to an SSD, Docker on the home disk (the reference box
|
|
# since 2026-10-13): the link's own device is the home disk's, and the two needs were
|
|
# summed against the SSD's free space (found in review, 2026-10-14)
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="one-disk-link-"))
|
|
ssd = pathlib.Path(tempfile.mkdtemp(dir="/dev/shm", prefix="ssd-"))
|
|
self.addCleanup(__import__("shutil").rmtree, ssd, True)
|
|
(d / "docker").mkdir()
|
|
(d / "hf").symlink_to(ssd)
|
|
script = ("set -euo pipefail\ndie(){ echo \"DIE: $*\"; exit 1; }\n"
|
|
f'HF_CACHE="{d}/hf"; DOCKER_ROOT="{d}/docker"; NEED_GB=45; DOCKER_NEED_GB=40; IMG_LABEL=img; '
|
|
"FREE_DISK_GB=60\n" + self.BLOCK + "\necho FITS\n")
|
|
out = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30).stdout
|
|
self.assertIn("FITS", out)
|
|
|
|
|
|
|
|
class ABadFlashKnobIsRefusedByName(unittest.TestCase):
|
|
"""A FLASH_REPLAYSSM_SPEC that is neither 0 nor 1 is refused with its own message: the
|
|
refusal returned 1 at a top-level call, so the ERR trap's "Install failed at line ..."
|
|
came after it. This runs install.sh up to that call, in a throwaway HOME; the lines
|
|
before it only assign and define."""
|
|
|
|
def run_prefix(self, **env):
|
|
lines = TEXT.splitlines()
|
|
stop = next(i for i, ln in enumerate(lines) if ln == "resolve_flash_tier_args")
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix="knob-"))
|
|
self.addCleanup(__import__("shutil").rmtree, d, True)
|
|
(d / "prefix.sh").write_text("\n".join(lines[:stop + 1]) + '\necho "REACHED $FLASH_TIER_ARGS"\n')
|
|
return subprocess.run(["bash", str(d / "prefix.sh")], capture_output=True, text=True, timeout=30,
|
|
env={"PATH": "/usr/bin:/bin", "HOME": str(d), **env})
|
|
|
|
def test_a_bad_value_is_refused_without_the_trap(self):
|
|
r = self.run_prefix(FLASH_REPLAYSSM_SPEC="2")
|
|
self.assertEqual(r.returncode, 1, r.stdout + r.stderr)
|
|
self.assertIn("FLASH_REPLAYSSM_SPEC must be 0 or 1 (got: 2)", r.stderr)
|
|
self.assertNotIn("Install failed at line", r.stderr)
|
|
self.assertNotIn("REACHED", r.stdout)
|
|
|
|
def test_the_good_values_pass(self):
|
|
for value, flag in (("0", False), ("1", True)):
|
|
r = self.run_prefix(FLASH_REPLAYSSM_SPEC=value)
|
|
self.assertEqual(r.returncode, 0, r.stderr)
|
|
self.assertEqual("--enable-linear-replayssm-spec" in r.stdout, flag, value)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|