Files
alzeo/tests/test_install_small_fixes.py
T
Hasan BasbunarandClaude Opus 5.5 8d7b750e8a lanes.sh: one record of the text lane the box comes back to
Until v1.29 every switch to a side lane (image, video, Kolibri) wrote a link to the lane it took
the boot from, install.sh followed those links with six order-dependent lines, and three
uninstalls followed them their own ways: a round trip between side lanes made two links name
each other (close_lane_loop closed that in v1.29), a side lane removed left another's link
naming a unit that was gone (the image and video uninstalls then left no lane at boot), and
every new lane meant editing all of it (found in review, 2026-10-14). One record now,
text-lane, the SGLang text unit the box had at boot last: switch-model.sh notes it when it
leaves a text lane or switches to a text target, install.sh when it makes its lane the boot
lane, and install.sh's resolution and every uninstall read it from lanes.sh, which they all
source. With no chain there is no loop to close. A box switched before keeps its answer: the
links are read once, while the side lane is still the one at boot, and become the record. An
uninstall whose noted lane is gone gives the boot to whichever text lane is installed, the 27B
first, where a link that led nowhere left the box with nothing.

Tests: every sequence of switches up to six lanes long (1,364) through switch-model.sh's own
notes, install.sh's own resolution and the uninstalls' give-back resolves the last text lane
served; the library itself; the migration from the links (the reference box's three, one of
them stale); the harnesses that copy the scripts carry the library. test_lane_before_loops.py
tested the links and goes with them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 14:13:41 +02:00

280 lines
14 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 GB" 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 GB free", out)
self.assertIn("found unknown GB", 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 GB 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("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 [ -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):
d = pathlib.Path(tempfile.mkdtemp(prefix="lane-line-"))
unit = d / "qwen38-image.service"
if on_the_box:
unit.write_text("[Unit]\n")
script = ("set -euo pipefail\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_left_out_but_still_on_the_box(self):
out = self.line("off", True)
self.assertIn("left out by --no-image, so not updated", out)
self.assertIn("./install.sh --with-image brings it back", out)
def test_left_out_and_absent(self):
out = self.line("off", False)
self.assertIn("./install.sh --with-image adds it (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("a plain ./install.sh tries again", 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("failed", True)
self.assertIn("./install.sh --with-image proves it again", out)
self.assertNotIn("a plain ./install.sh tries again", 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 GB 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)