Files
alzeo/tests/test_image_lane_install_paths.py
T
Hasan BasbunarandClaude Opus 5.5 81f5012150 A checkpoint already whole asks for no room: install.sh, the Loads and the diffusion lanes' runtimes
A text checkpoint whole in the cache was still asked 10 GiB of its disk by install.sh, by a switch and by a first Load,
and so were the video and MiniMax-H3-Image switches: on a cache disk full of whole checkpoints (2 GiB left on the
reference box, 2026-11-30) no update and no Load of those lanes passed, with nothing to fetch. The caches those 10 GiB
were for are in ~/.config/qwen38. Whole asks 1 now, for what the patches write, and 10 while the 27B's draft is to come.

The image, video and MiniMax-H3-Image installers asked the 11 to 14 GiB of a runtime build at every update, its venv
whole at the pinned wheel and commit: 1 then (lanes.sh, runtime_room_gb).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 08:58:57 +01:00

258 lines
14 KiB
Python

#!/usr/bin/env python3
"""install-image.sh finds the cache it serves from, measures space where things land, and
does not leave a box without an engine when it removes the lane that booted.
Found in review, 2026-09-24:
- HF_CACHE came from the environment or the default, never from the installed unit
(Environment=HF_HOME=), so an update re-downloaded 31 GB into ~/.cache and rewrote
HF_HOME on a box whose lane lived on another disk;
- free space was measured under $HOME, not where the checkpoint and the runtime go, and
"cached" meant the folder existed, which huggingface_hub creates before the first byte;
- --uninstall on a box whose boot lane was the image left no engine enabled at all.
The script's own lines run here with its /etc paths moved to a temporary directory.
"""
import pathlib
import subprocess
import sys
import tempfile
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
import text_lane_fixture as fixture # noqa: E402
REPO = pathlib.Path(__file__).resolve().parents[1]
TEXT = (REPO / "install-image.sh").read_text()
def block(start, end, inclusive=True):
i = TEXT.index(start)
j = TEXT.index(end, i)
return TEXT[i:TEXT.index("\n", j) + 1] if inclusive else TEXT[i:j]
def bash(script, env, path_dirs=()):
path = ":".join([*map(str, path_dirs), "/usr/bin", "/bin"])
r = subprocess.run(["bash", "-c", script], capture_output=True, text=True, timeout=30,
env={"PATH": path, **env})
return r.returncode, r.stdout + r.stderr
class TheCacheItServesFrom(unittest.TestCase):
CACHE = block('installed_env(){', 'HF_CACHE="${HF_CACHE:-$HOME/.cache/huggingface}"')
def run_cache(self, image_unit=None, text_unit=None, env_cache=None):
d = pathlib.Path(tempfile.mkdtemp(prefix="img-cache-"))
(d / "image.service").write_text(image_unit or "")
(d / "text.service").write_text(text_unit or "")
env = {"HOME": str(d)}
if env_cache:
env["HF_CACHE"] = env_cache
# lanes.sh, which the installer sources: the unit's cache is read through it (unit_hf_cache)
script = (f'set -euo pipefail\nINSTALLED="{d}/image.service"; CONFIG_DIR="{d}"; TEXT_UNITS="{d}/text.service"\n'
+ f'LANES_UNIT_DIR="{d}"; . "{REPO}/lanes.sh"\n' + self.CACHE + 'echo "CACHE=$HF_CACHE"\n')
rc, out = bash(script, env)
return next(ln[6:] for ln in out.splitlines() if ln.startswith("CACHE="))
def test_the_installed_unit_wins_over_the_default(self):
self.assertEqual(self.run_cache(image_unit="[Service]\nEnvironment=PYTHONUNBUFFERED=1\n"
"Environment=HF_HOME=/data/hf\n"), "/data/hf")
def test_a_first_install_follows_the_text_lane(self):
self.assertEqual(self.run_cache(text_unit="ExecStart=docker run -v /mnt/hf:/root/.cache/huggingface x\n"),
"/mnt/hf")
def test_the_environment_still_wins(self):
self.assertEqual(self.run_cache(image_unit="Environment=HF_HOME=/data/hf\n", env_cache="/elsewhere"),
"/elsewhere")
class TheSpaceWhereItLands(unittest.TestCase):
# from lanes.sh's existing, which the block uses (the installer sources lanes.sh), to the line it says
SPACE = block("# existing: lanes.sh's", 'echo "OK: $(uname -m), key present, checkpoint')
def run_space(self, have_gib, free_w, free_r=None, mode="full"):
d = pathlib.Path(tempfile.mkdtemp(prefix="img-space-"))
blobs = d / "hf/hub/models--Qwen--Qwen-Image-2.1/blobs"
blobs.mkdir(parents=True)
with open(blobs / "b", "wb") as f:
f.truncate(int(have_gib * 1024 ** 3))
stub = d / "bin"
stub.mkdir()
two = free_r is not None
(stub / "df").write_text("#!/bin/sh\ncase \"$*\" in *lane*) echo Avail; echo %sG;; *) echo Avail; echo %sG;; esac\n"
% (free_r if two else free_w, free_w))
(stub / "stat").write_text("#!/bin/sh\ncase \"$*\" in *lane*) echo %s;; *) echo 1;; esac\n" % (2 if two else 1))
for f in stub.iterdir():
f.chmod(0o755)
(d / "lane").mkdir()
script = ('set -euo pipefail\ndie(){ echo "DIE: $*"; exit 1; }\n'
f'HF_CACHE="{d}/hf"; LANE_DIR="{d}/lane"; MODEL=Qwen/Qwen-Image-2.1; WEIGHTS_GB=31; RUNTIME_GB=11; MODE={mode}\n'
'step(){ echo "STEP $*"; }\ninstall_service(){ echo SERVICE; }\n'
+ f'. "{REPO}/lanes.sh"\n' + self.SPACE)
return bash(script, {"HOME": str(d)}, [stub])
def test_a_download_that_just_started_needs_the_whole_checkpoint(self):
rc, out = self.run_space(have_gib=0.000001, free_w=20)
self.assertEqual(rc, 1, out)
self.assertIn("DIE:", out)
def test_a_whole_checkpoint_needs_the_runtime_only(self):
rc, out = self.run_space(have_gib=30.86, free_w=20)
self.assertEqual(rc, 0, out)
self.assertIn("already cached", out)
def test_a_runtime_already_built_asks_no_room_to_build_it(self):
# runtime_room_gb (lanes.sh), which the three diffusion lanes' installers ask: 11 to 14 GiB were asked at every
# update of a lane whose venv was whole (2026-11-30)
d = pathlib.Path(tempfile.mkdtemp(prefix="img-space-"))
(d / "venv/bin").mkdir(parents=True)
(d / "venv/bin/python").write_text("#!/bin/sh\n")
(d / "venv/bin/python").chmod(0o755)
(d / "git").mkdir()
(d / "git/git").write_text("#!/bin/sh\necho commit1\n")
(d / "git/git").chmod(0o755)
def ask(wheel, pin):
rc, out = bash(f'set -euo pipefail\n. "{REPO}/lanes.sh"\nruntime_room_gb "{d}" {wheel} {pin} 11', {"HOME": str(d)}, [d / "git"])
self.assertEqual(rc, 0, out)
return int(out)
self.assertEqual(ask("0.5.21", "commit1"), 11, "no note: a build cut short")
(d / "sglang-wheel").write_text("0.5.21\n")
self.assertEqual(ask("0.5.21", "commit1"), 1)
self.assertEqual(ask("0.5.22", "commit1"), 11, "its wheel moved")
self.assertEqual(ask("0.5.21", "commit2"), 11, "its source moved")
for lane in ("image", "video", "image-h3"):
text = (REPO / f"install-{lane}.sh").read_text()
at = text.index('RUNTIME_GB="$(runtime_room_gb "$LANE_DIR" "$WHEEL" "$PIN" "$RUNTIME_GB")"')
self.assertLess(at, text.index("free_gb(){"), f"install-{lane}.sh measures after it")
def test_a_prepare_needs_room_for_the_runtime_only(self):
# the checkpoint is the Load's switch's to fetch, and to measure (on demand, 2026-10-14)
rc, out = self.run_space(have_gib=0.0, free_w=20, mode="prepare")
self.assertEqual(rc, 0, out)
rc, out = self.run_space(have_gib=0.0, free_w=5, mode="prepare")
self.assertEqual(rc, 1, out)
def test_units_only_measures_nothing_and_installs_the_unit(self):
rc, out = self.run_space(have_gib=0.0, free_w=0, mode="units")
self.assertEqual(rc, 0, out)
self.assertIn("SERVICE", out)
self.assertNotIn("DIE:", out)
def test_each_disk_is_measured_for_its_own_part(self):
rc, out = self.run_space(have_gib=0.0, free_w=500, free_r=5)
self.assertEqual(rc, 1, out)
self.assertIn("runtime", out)
class RemovingTheLaneThatBooted(unittest.TestCase):
UNINSTALL = block('if [ "$ACTION" = uninstall ]; then', ' exit 0')
def run_uninstall(self, image_enabled, text_enabled, before="qwen38-sglang.service", cached=(), note=None):
d = pathlib.Path(tempfile.mkdtemp(prefix="img-uninst-"))
if note:
(d / "image-model-before-turbo").write_text(note + "\n")
for repo in cached:
(d / "hf/hub" / ("models--" + repo.replace("/", "--"))).mkdir(parents=True)
units = d / "etc"
units.mkdir()
(units / "qwen38-image.service").write_text("[Service]\n")
# a 27B lane that can start, as a box's is once loaded: since v1.37.7 the boot goes back only to
# one whose image and checkpoint are on the box (lanes.sh text_unit_ready, text_lane_fixture)
fixture.put_ready(units, d, d / "hf-text", ["27b"])
(d / "lane-before-image").write_text(before + "\n")
stub = d / "bin"
stub.mkdir()
enabled = []
if image_enabled:
enabled.append("qwen38-image.service")
if text_enabled:
enabled.append("qwen38-sglang.service")
(stub / "systemctl").write_text(
"#!/bin/sh\ncase \"$1\" in is-enabled) for u in %s; do [ \"$3\" = \"$u\" ] && exit 0; done; exit 1;; esac\n"
"echo \"systemctl $*\" >> \"%s/calls\"\n" % (" ".join(enabled) or "none", d))
(stub / "sudo").write_text("#!/bin/sh\n\"$@\"\n")
(stub / "docker").write_text("#!/bin/bash\n" + fixture.DOCKER_HAS_IT + "exit 1\n")
for f in stub.iterdir():
f.chmod(0o755)
text = self.UNINSTALL.replace("/etc/systemd/system", str(units))
script = ('set -euo pipefail\nstep(){ :; }\nACTION=uninstall; UNIT=qwen38-image.service\n'
f'LANES_UNIT_DIR="{units}"; . "{REPO}/lanes.sh"\n' # the library the script sources
f'INSTALLED="{units}/qwen38-image.service"; CONFIG_DIR="{d}"; LANE_DIR="{d}/lane"; '
f'VENV="{d}/lane/venv"; SRC="{d}/lane/sglang"; HF_CACHE="{d}/hf"; MODEL=Qwen/Qwen-Image-2.1\n'
'IMAGE_MODEL_PIN=Qwen/Qwen-Image-2.1; IMAGE_TURBO_PIN=Qwen/Qwen-Image-2.1-Turbo\n'
+ text + "\nfi\n")
rc, out = bash(script, {"HOME": str(d)}, [stub])
calls = (d / "calls").read_text() if (d / "calls").exists() else ""
self.dir = d
return rc, out, calls
def test_the_lane_before_images_is_enabled_again(self):
rc, out, calls = self.run_uninstall(image_enabled=True, text_enabled=False)
self.assertEqual(rc, 0, out)
self.assertIn("systemctl enable qwen38-sglang.service", calls)
self.assertIn("sudo systemctl start qwen38-sglang.service", out)
def test_a_box_whose_text_lane_is_enabled_is_left_as_it_is(self):
rc, out, calls = self.run_uninstall(image_enabled=True, text_enabled=True)
self.assertNotIn("systemctl enable qwen38-sglang.service", calls)
def test_an_image_lane_that_was_not_the_boot_lane_changes_nothing_else(self):
rc, out, calls = self.run_uninstall(image_enabled=False, text_enabled=True)
self.assertNotIn("systemctl enable", calls)
def test_every_checkpoint_of_the_lane_in_the_cache_is_named(self):
"""A box that tried the Turbo holds both; the message named the unit's alone."""
rc, out, calls = self.run_uninstall(image_enabled=False, text_enabled=True,
cached=("Qwen/Qwen-Image-2.1", "Qwen/Qwen-Image-2.1-Turbo"))
self.assertEqual(rc, 0, out)
self.assertIn(f"rm -rf {self.dir}/hf/hub/models--Qwen--Qwen-Image-2.1\n", out)
self.assertIn(f"rm -rf {self.dir}/hf/hub/models--Qwen--Qwen-Image-2.1-Turbo\n", out)
self.assertEqual(out.count("rm -rf "), 2, out)
def test_the_checkpoint_the_switch_note_names_is_named_too(self):
"""A unit installed with IMAGE_MODEL= and switched to the Turbo: the note names the
checkpoint of the unit's own, 31 GB in the cache the message must not forget."""
rc, out, calls = self.run_uninstall(image_enabled=False, text_enabled=True, note="someone/finetune",
cached=("Qwen/Qwen-Image-2.1-Turbo", "someone/finetune"))
self.assertEqual(rc, 0, out)
self.assertIn(f"rm -rf {self.dir}/hf/hub/models--someone--finetune\n", out)
self.assertIn(f"rm -rf {self.dir}/hf/hub/models--Qwen--Qwen-Image-2.1-Turbo\n", out)
def test_nothing_in_the_cache_nothing_to_name_and_the_switch_note_goes(self):
rc, out, calls = self.run_uninstall(image_enabled=False, text_enabled=True, note="someone/finetune")
self.assertEqual(rc, 0, out)
self.assertNotIn("rm -rf", out)
self.assertFalse((self.dir / "image-model-before-turbo").exists(), "the switch note outlived the lane")
class TheSwitchNoteAndAnInstall(unittest.TestCase):
"""./switch-model.sh image-turbo writes down the checkpoint of the unit's own it leaves,
for `image` to bring back. An install that points the unit at another checkpoint makes
that note a stale one: `image` would then bring back a checkpoint from before it."""
BLOCK = block("# A unit installed for another checkpoint", ' fi\n UNIT_PUT="$(unit_put "$RENDER" "$INSTALLED")"')
def run_block(self, installed_model, model):
d = pathlib.Path(tempfile.mkdtemp(prefix="img-note-"))
(d / "unit").write_text(f"ExecStart=/x/sglang serve --model-path {installed_model} \\\n --port 30020\n")
(d / "image-model-before-turbo").write_text("someone/finetune\n")
unit_flag = next(ln for ln in TEXT.splitlines() if ln.startswith("unit_flag(){"))
script = (f'set -euo pipefail\nINSTALLED="{d}/unit"; CONFIG_DIR="{d}"; MODEL="{model}"\n'
+ unit_flag + "\n" + self.BLOCK)
rc, out = bash(script, {"HOME": str(d)})
return rc, out, (d / "image-model-before-turbo").exists()
def test_another_checkpoint_drops_the_note(self):
rc, out, kept = self.run_block("Qwen/Qwen-Image-2.1-Turbo", "Qwen/Qwen-Image-2.1")
self.assertEqual(rc, 0, out)
self.assertFalse(kept)
def test_an_update_of_the_same_checkpoint_keeps_it(self):
rc, out, kept = self.run_block("Qwen/Qwen-Image-2.1-Turbo", "Qwen/Qwen-Image-2.1-Turbo")
self.assertEqual(rc, 0, out)
self.assertTrue(kept)
if __name__ == "__main__":
unittest.main(verbosity=2)