Files
alzeo/tests/test_install_bind.py
Hasan BasbunarandClaude Opus 5.5 f0f69a4be0 install: a new box's install cut before its own unit is no flash box to the next run
A 27B install puts the flash lane's unit in at its step 6, beside it and never loaded, and its own unit at step 8. Cut
between the two (Ctrl-C during opencode's download, a closed terminal, a power cut), the box held the flash unit alone,
and the next run took it for its lane: "Keeping the installed target model: flash", 230 GiB of free disk asked, which
stopped a box that had room for the 27B, or 152 GB fetched. A flash unit nothing enables, with no 27B unit, is the box's
lane when the text-lane record says it had the boot, or when it can serve (its image, launcher and checkpoint here).

Three fixtures named a flash box without either: they give it its record, and the one whose systemctl never answered
is-enabled --quiet does now.

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

292 lines
16 KiB
Python
Executable File

#!/usr/bin/env python3
"""Which interface the engine and the proxy answer on, and who decides it.
Both listened on every interface until v1.17. The engine does not any more, and that is a
changed default rather than a knob: seven days of journal on the reference box put
581,479 engine requests at 100% from 127.0.0.1, while the machine was reached from a
laptop and a phone on the cockpit port alone. An open port nobody uses would be an
ordinary waste; this one is the port SGLang dies on rather than refuses (sglang#40076 and
sglang#31597, both unfixed upstream, both refused at the proxy since v1.15.0), so leaving
it open leaves a door beside the one with the lock.
Nothing is lost by closing it, which is the only reason a default may move: the proxy on
PORT+1 is a full pass-through, every route and both dialects, plus the guards. A client
that pointed at :30000 from another machine points at :30001 and gets more, not less. The
proxy's own default does not move, because it is the door clients are told to use.
Four things are held here. The engine closes and the proxy stays open on a fresh install.
`ENGINE_BIND=0.0.0.0` brings the old behaviour back for a box that wants it. A bad value
is refused by name rather than written into a unit that fails to start minutes later. And
an installed choice wins over the default IN BOTH DIRECTIONS: a box that had chosen to
keep its engine on the network must not lose it to an update nobody read about, which is
the same promise that protects a box hardened before v1.17.
But 0.0.0.0 was also what every install got before v1.17.0, and a unit cannot say which it
is: kept as a choice, the old default stayed open for good. Since v1.36.0 (decided
2026-10-16) it moves to 127.0.0.1 unless installed.json records it as a choice, or the box
is younger than v1.17.0 (the mtime of its API key) or of an age nobody can tell.
Every run stops at a later refusal on purpose, past the bind resolution and long before
the preflight downloads anything.
"""
import os
import pathlib
import subprocess
import sys
import tempfile
import unittest
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import installer_wall as wall # noqa: E402
REPO = pathlib.Path(__file__).resolve().parents[1]
INSTALL = str(REPO / "install.sh")
# Contradictory cockpit flags: the first refusal BELOW the bind resolution, so the
# resolution has run and whatever it decided is already on stdout.
STOP = ["--no-cockpit", "--with-cockpit"]
STOCK = {"MODEL_CHOICE": "stock"}
def run(args=(), script=None, home=None, **env_extra):
"""A walled copy of install.sh (a fresh box unless `script` is another one), with the
commands that act on the box fenced: the refusal these runs stop at is checked to
have fired, instead of trusted to."""
env, record = wall.fenced_env(home=home or tempfile.mkdtemp(prefix="bind-home-"), **env_extra)
r = subprocess.run([script or fresh_box(), *args], capture_output=True, text=True,
env=env, cwd=wall.cwd(), timeout=60)
out = r.stdout + r.stderr
assert wall.WALL not in out, f"the run went past its refusal:\n{out[-800:]}"
assert not wall.reached(record), wall.reached(record)
return r.returncode, out
def box_with_units(engine_host="127.0.0.1", proxy_bind=None):
"""A copy of install.sh on a box holding the units this test wrote, so the convergence
block reads a bind this box does not actually have."""
units = {"qwen38-sglang.service":
"[Service]\nExecStart=/bin/true --model-path RadixArk/Qwen3.8-27B-NVFP4 "
f"--host {engine_host} --port 30000 --context-length 1010000\n"}
if proxy_bind is not None:
units["qwen38-keepalive.service"] = f"[Service]\nEnvironment=PROXY_BIND={proxy_bind}\n"
return wall.walled(units=wall.units_dir(units))
def flash_box(engine_host):
"""A flash box: its unit only points at the launcher, where the engine flags live, so
the bind to keep is read from launch-flash.sh. Returns (install.sh copy, HOME); no lane
is enabled on it, whatever the host running the test has."""
home = pathlib.Path(tempfile.mkdtemp(prefix="bind-flash-"))
cfg = home / ".config/qwen38"
cfg.mkdir(parents=True)
(cfg / "text-lane").write_text("qwen38-flash.service\n") # its lane has had the boot
(cfg / "launch-flash.sh").write_text(
"#!/bin/bash\nexec docker run --rm --name qwen38-flash lmsysorg/sglang@sha256:" + "a" * 64 +
" python3 -m sglang.launch_server --model-path RadixArk/Qwen3.8-Flash-Next-NVFP4 \\\n"
f" --host {engine_host} --port 30000\n")
units = wall.units_dir({"qwen38-flash.service": f"[Service]\nExecStart=/bin/bash {cfg}/launch-flash.sh\n"})
return wall.walled(units=units), str(home)
def fresh_box():
"""No units anywhere: the default is what answers."""
return wall.walled(units=wall.units_dir())
# Where the binds stand once everything that decides them has run: the line just above the
# refusal these runs stop at. The tests read the messages, so an ENGINE_BIND=0.0.0.0 set
# after the convergence opened the engine at every install with all of them green (found
# in review, 2026-09-24).
BINDS_AT = 'if [ "$NO_COCKPIT" -eq 1 ] && [ "$WITH_COCKPIT" -eq 1 ]; then\n'
def probed(script):
"""The walled copy, printing the binds it resolved just before the refusal it stops at."""
path = pathlib.Path(script)
text = path.read_text()
assert text.count(BINDS_AT) == 1, "install.sh no longer has the cockpit refusal the probe goes before"
path.write_text(text.replace(BINDS_AT, 'echo "BINDS engine=$ENGINE_BIND proxy=$PROXY_BIND ctx=$CONTEXT_MODE lane=$LANE"\n' + BINDS_AT))
return str(path)
def binds(out):
line = next((ln for ln in out.splitlines() if ln.startswith("BINDS ")), None)
assert line, f"the probe never printed:\n{out[-800:]}"
return dict(kv.split("=", 1) for kv in line.split()[1:])
KEPT_ENGINE = "Keeping the installed engine bind:"
KEPT_PROXY = "Keeping the installed proxy bind:"
MOVED_ENGINE = "Moving the engine bind from 0.0.0.0 to 127.0.0.1, the default since v1.17.0"
# a box installed two days before v1.17.0 moved the default, and one three days after
BEFORE_V117, AFTER_V117 = "2026-09-20T10:00:00+02:00", "2026-09-25T10:00:00+02:00"
class TheDefaults(unittest.TestCase):
def test_a_fresh_install_closes_the_engine_and_leaves_the_proxy_open(self):
"""The changed default of v1.17, asserted where it is decided. The engine is the
port SGLang dies on rather than refuses and the one nothing remote was using; the
proxy is the door clients are told to use and the one that refuses what the engine
cannot, so only the first moves."""
code, out = run(STOP, script=fresh_box(), **STOCK)
self.assertNotIn(KEPT_ENGINE, out, "a fresh box has no unit to converge from")
self.assertNotIn(KEPT_PROXY, out)
# the resolution itself, read from the script rather than from a rendered unit,
# because this run stops before anything is written
text = (REPO / "install.sh").read_text()
self.assertIn('ENGINE_BIND="${ENGINE_BIND:-127.0.0.1}"', text)
self.assertIn('PROXY_BIND="${PROXY_BIND:-0.0.0.0}"', text)
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("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."""
# 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(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("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)
self.assertNotIn("take an IPv4 address", out)
class AnInstalledChoiceWins(unittest.TestCase):
def test_the_proxy_bind_is_kept_the_same_way(self):
_, out = run(STOP, script=box_with_units(engine_host="0.0.0.0", proxy_bind="127.0.0.1"),
**STOCK)
self.assertIn(KEPT_PROXY + " 127.0.0.1", out)
def test_the_operator_still_overrides_what_is_installed(self):
"""Convergence keeps a choice; it does not take the choice away."""
_, out = run(STOP, script=box_with_units(engine_host="127.0.0.1"),
ENGINE_BIND="0.0.0.0", **STOCK)
self.assertNotIn(KEPT_ENGINE, out)
def test_an_open_engine_on_a_box_of_unknown_age_stays_open(self):
"""No installed.json and no API key to date the box: what cannot be classed is not
moved, so a box that had chosen 0.0.0.0 keeps it, as every update did before v1.36.0."""
_, out = run(STOP, script=box_with_units(engine_host="0.0.0.0"), **STOCK)
self.assertIn(KEPT_ENGINE + " 0.0.0.0", out)
self.assertNotIn("Moving the engine bind", out)
def test_an_open_engine_from_before_v1_17_is_closed_and_said(self):
"""0.0.0.0 on a box installed before v1.17.0, with nothing recording it as a choice:
the default it was installed with. It moves, and the line says how to keep it."""
home = wall.box_home(key_at=BEFORE_V117)
_, out = run(STOP, script=probed(box_with_units(engine_host="0.0.0.0")), home=home, **STOCK)
self.assertNotIn(KEPT_ENGINE, out)
self.assertIn(MOVED_ENGINE, out)
self.assertIn("To keep it: ENGINE_BIND=0.0.0.0 ./install.sh", out)
self.assertEqual(binds(out)["engine"], "127.0.0.1")
def test_an_open_engine_recorded_as_a_choice_stays_open(self):
"""installed.json records it (ENGINE_BIND=0.0.0.0 passed once since v1.36.0): the age
of the box no longer matters."""
home = wall.box_home(key_at=BEFORE_V117, record={"ENGINE_BIND": "0.0.0.0"})
_, out = run(STOP, script=probed(box_with_units(engine_host="0.0.0.0")), home=home, **STOCK)
self.assertIn(KEPT_ENGINE + " 0.0.0.0", out)
self.assertEqual(binds(out)["engine"], "0.0.0.0")
def test_an_open_engine_on_a_box_younger_than_v1_17_stays_open(self):
"""Installed after the default moved, 0.0.0.0 was typed by somebody: kept (and recorded
as that choice when the run ends, tests/test_conformity_classify.py)."""
home = wall.box_home(key_at=AFTER_V117)
_, out = run(STOP, script=probed(box_with_units(engine_host="0.0.0.0")), home=home, **STOCK)
self.assertIn(KEPT_ENGINE + " 0.0.0.0", out)
self.assertEqual(binds(out)["engine"], "0.0.0.0")
def test_once_installed_json_exists_an_unrecorded_open_engine_moves(self):
"""Every run records a choice since v1.36.0: 0.0.0.0 that no entry names is the old
default, however young the box."""
home = wall.box_home(key_at=AFTER_V117, record={})
_, out = run(STOP, script=probed(box_with_units(engine_host="0.0.0.0")), home=home, **STOCK)
self.assertIn(MOVED_ENGINE, out)
self.assertEqual(binds(out)["engine"], "127.0.0.1")
def test_a_conformity_that_cannot_answer_keeps_the_bind_and_the_run_goes_on(self):
"""Never a failure mode: what conformity.py cannot answer is kept, as before v1.36.0."""
script = pathlib.Path(probed(box_with_units(engine_host="0.0.0.0")))
(script.parent / "conformity.py").write_text("raise SystemExit('broken on purpose')\n")
code, out = run(STOP, script=str(script), home=wall.box_home(key_at=BEFORE_V117), **STOCK)
self.assertIn(KEPT_ENGINE + " 0.0.0.0", out)
self.assertEqual(binds(out)["engine"], "0.0.0.0")
self.assertIn("contradict each other", out, "the run did not reach the refusal it stops at")
self.assertEqual(code, 1)
def test_a_box_already_closed_says_nothing_because_nothing_changed(self):
_, out = run(STOP, script=box_with_units(engine_host="127.0.0.1"), **STOCK)
self.assertNotIn(KEPT_ENGINE, out)
def test_a_flash_box_keeps_its_engine_bind_too(self):
"""On flash the bind is in launch-flash.sh, and the convergence read $UNIT_PATH,
which only the 27B branch sets: every plain re-run printed "UNIT_PATH: unbound
variable", carried on, and rendered the launcher with 127.0.0.1 over the box's
0.0.0.0 (found in review, 2026-09-24)."""
script, home = flash_box("0.0.0.0")
_, out = run(STOP, script=script, home=home)
self.assertNotIn("unbound variable", out)
self.assertIn("Keeping the installed target model: flash", out, "the fixture is a flash box")
self.assertIn(KEPT_ENGINE + " 0.0.0.0", out)
script, home = flash_box("127.0.0.1")
_, out = run(STOP, script=script, home=home)
self.assertNotIn("unbound variable", out)
self.assertNotIn(KEPT_ENGINE, out)
class TheResolvedBinds(unittest.TestCase):
"""What the installer goes on with, read from the run itself rather than its messages."""
def test_each_box_ends_with_the_bind_it_should(self):
cases = (("fresh box", fresh_box(), {}, {"engine": "127.0.0.1", "proxy": "0.0.0.0"}),
("closed box", box_with_units(engine_host="127.0.0.1"), {}, {"engine": "127.0.0.1"}),
("open box", box_with_units(engine_host="0.0.0.0"), {}, {"engine": "0.0.0.0"}),
("operator opens it", box_with_units(engine_host="127.0.0.1"), {"ENGINE_BIND": "0.0.0.0"},
{"engine": "0.0.0.0"}),
("operator closes it", box_with_units(engine_host="0.0.0.0"), {"ENGINE_BIND": "127.0.0.1"},
{"engine": "127.0.0.1"}),
("proxy kept", box_with_units(proxy_bind="127.0.0.1"), {}, {"proxy": "127.0.0.1"}))
for name, script, env, want in cases:
with self.subTest(box=name):
_, out = run(STOP, script=probed(script), **STOCK, **env)
got = binds(out)
self.assertEqual({k: got[k] for k in want}, want)
def test_a_flash_box_ends_with_its_own(self):
for host in ("0.0.0.0", "127.0.0.1"):
script, home = flash_box(host)
_, out = run(STOP, script=probed(script), home=home)
self.assertEqual(binds(out)["engine"], host)
class TheTemplatesCarryIt(unittest.TestCase):
def test_every_engine_template_takes_the_bind_from_the_installer(self):
"""A template that hardcodes the host makes the knob a lie on that lane."""
for name in ("qwen38-sglang.service.template", "qwen38-sglang-1m.service.template",
"qwen38-flash-launch.sh.template"):
text = (REPO / name).read_text()
self.assertIn("--host __ENGINE_BIND__", text, name)
self.assertNotIn("--host 0.0.0.0", text, name)
def test_the_keepalive_unit_passes_the_bind_to_the_proxy(self):
text = (REPO / "qwen38-keepalive.service.template").read_text()
self.assertIn("Environment=PROXY_BIND=__PROXY_BIND__", text)
def test_the_proxy_reads_that_variable_and_defaults_to_every_interface(self):
text = (REPO / "keepalive-proxy.py").read_text()
self.assertIn('os.environ.get("PROXY_BIND", "0.0.0.0")', text)
self.assertIn("Server((BIND, port), H)", text)
if __name__ == "__main__":
unittest.main(verbosity=2)