mirror of
https://github.com/hasso5703/alzeo.git
synced 2026-12-06 12:54:19 +01:00
Hasan's ask on 2026-09-30: the one-liner installs everything, for everyone, by default: both text lanes, the image lane, the video lane and the decision endpoint (already in the proxy). The text lane MODEL_CHOICE names serves, the 27B by default. The other text lane is installed beside it by this same script, started again for that lane (QWEN38_SECONDARY): it converges on that lane's own unit, installs it without enabling it, starts nothing, and leaves the proxy, the boot lane, opencode, the cockpit and the side lanes to its parent, which passes it the shared settings and none of its own lane's (a MODEL_CHOICE or MODEL_REV for the served lane must not pick the other one's). It runs before step 7, so opencode lists both lanes from the first run. The image and video lanes are prepared while the served lane serves. Every lane a run installs for the first time (or names with --with-<lane>) then proves it serves: the served lane stops once, each new lane boots, answers and stops, and the served lane comes back and proves itself again (prove_text_lane: the step-9 wait and smoke, returning instead of dying) before the proxy and opencode follow the new pool. A routine update proves nothing twice and keeps the served lane serving. A lane that does not install, a disk too small for it included, is said and the rest goes on; the summary names what became of each lane. --no-image, --no-video, --no-flash and --no-27b leave a lane out and are remembered in marker files like --no-cockpit; --with-<lane> brings it back. install-video.sh counted its checkpoint as 145 GiB against 134.2 cached and told a complete cache "10 GB to download". New tests run each piece as written against stubs: the markers, the flags, the secondary run's convergence on the reference box's layout, the parent's hand-off, the proofs' order and failures, and the proof of a text lane; 19 deliberate mutations, 19 killed. 15 tests that pinned the opt-in lanes now pin the defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
257 lines
13 KiB
Python
257 lines
13 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')
|
|
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))
|
|
|
|
|
|
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 -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))
|
|
|
|
|
|
|
|
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)
|