Files
alzeo/tests/installer_wall.py
T
Hasan BasbunarandClaude Opus 5.5 b784057251 tests: a walled run reads a 128 GB box's memory, and no test loses or takes an exported class
install.sh reads the box's class and its GiB from QWEN38_MEMINFO (/proc/meminfo by default), and
the walled copies read the machine running the tests: on a 64 GB one, 10 of the context mode's 19
tests failed. fenced_env now gives every walled run the reference box's MemTotal unless the test
gives its own, as the fresh machine's 31 and 57.6 GiB cases now do. The in-process tests read
os.environ: with QWEN38_MEMORY_CLASS=64 exported, the proof campaign's own tool, test_boxmem lost
a test and test_conformity_recommended two (both fail so on the old code), and test_boxmem's
cleanup popped the variable for the tests after it, which hid the second. They now set the
class they test and put the environment back as it was (found in review, 2026-10-23).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 21:58:27 +02:00

180 lines
8.7 KiB
Python

"""Installer runs that end where the test says they end, on whatever machine runs the suite.
Six test files run install.sh or get.sh whole and count on one refusal to stop the run early.
Past it, step 1 asks nvidia-smi and docker about the machine and sudo for a ticket, step 2
pulls, step 6 writes the checkpoint configs in the HF cache, and get.sh fetches and resets
the checkout it is started from. Nothing checked that the refusal held: a refusal that moved
down would have run the rest for real on the box the suite ran on, get.sh was started from
the real checkout, and the tests read the box's own units in /etc (found in review,
2026-09-24).
walled() is a copy of the script that ends at a wall: a line that prints WALL and exits
before the part that acts on the machine, so a refusal that does not fire shows up as the
wall and nothing past it can run. The copy reads its units from a directory the test owns,
never /etc/systemd/system. fence() is a PATH entry that answers for the commands that act on
the box: each one records its call and fails, except `systemctl is-enabled`, which answers
from the units the test says are enabled.
"""
import atexit
import datetime
import json
import os
import pathlib
import shutil
import stat
import tempfile
REPO = pathlib.Path(__file__).resolve().parents[1]
WALL = "WALL: the run went past the refusal under test"
UNITS = "/etc/systemd/system/"
REAL_UNITS = "the box's own units"
# Where each script's run stops. install.sh: the first line of step 1, which is the first
# thing that probes the machine; or, for the one test that means to run step 1, the line
# that ends it. get.sh: the first line after its root refusal.
BEFORE_STEP_1 = 'step "1/10 Preflight checks"\n'
AFTER_STEP_1 = 'echo "OK (aarch64, ${TOTAL_GIB} GiB of memory: a ${MEM_CLASS} GB box, ${FREE_DISK_GB} GiB free)"\n'
GET_PAST_ROOT = ' REPO_URL="https://github.com/hasso5703/dgx-spark-qwen38"\n'
# Every directory this makes lives under one root, removed when the process ends: the suite
# runs on the box it tests, and /tmp there held 7,200 directories other tests left behind.
_ROOT = []
def _tmp(prefix):
if not _ROOT:
_ROOT.append(tempfile.mkdtemp(prefix="installer-wall-"))
atexit.register(shutil.rmtree, _ROOT[0], True)
return pathlib.Path(tempfile.mkdtemp(prefix=prefix, dir=_ROOT[0]))
# Every command the installers use to act on the machine or reach the network.
FENCED = ("docker", "sudo", "nvidia-smi", "systemctl", "journalctl", "curl", "wget", "git",
"pip", "pip3", "hf", "huggingface-cli", "tailscale", "opencode", "loginctl")
def walled(script="install.sh", at=None, after=False, units=None):
"""Path of a copy of `script` (a repo file) that exits at the wall.
at: the line the wall goes before (or after, with after=True); the default for
install.sh is the first line of step 1, for get.sh the line after the root refusal.
units: the directory standing in for /etc/systemd/system (a fresh empty one by
default); every mention of that path in the copy is pointed at it. The box's own units
are read only with units=REAL_UNITS, by the one test that is about the box it runs on."""
text = (REPO / script).read_text()
at = at or (BEFORE_STEP_1 if script == "install.sh" else GET_PAST_ROOT)
if text.count(at) != 1:
raise AssertionError(f"{script} no longer has the line the wall goes at: {at!r}")
wall = f'echo "{WALL}"; exit 97\n'
text = text.replace(at, at + wall if after else wall + at, 1)
if units != REAL_UNITS:
units = pathlib.Path(units or _tmp("units-"))
text = text.replace(UNITS, f"{units}/")
if "/etc/systemd" in text[:text.index(wall)]:
raise AssertionError(f"{script} reads units under a path this copy does not redirect")
d = _tmp("walled-")
copy = d / pathlib.Path(script).name
copy.write_text(text)
copy.chmod(0o755)
# the library the installers source from their own directory (since v1.30), its units
# pointed where the copy's are
lanes = (REPO / "lanes.sh").read_text()
if units != REAL_UNITS:
lanes = lanes.replace("/etc/systemd/system", str(units))
(d / "lanes.sh").write_text(lanes)
# and the fetch they run (since v1.31), which they check is there before mounting it
(d / "ckpt-fetch.py").write_text((REPO / "ckpt-fetch.py").read_text())
# and conformity.py (since v1.36.0), which the convergence asks whether an installed value
# is a default of an older release or a choice
(d / "conformity.py").write_text((REPO / "conformity.py").read_text())
# and boxmem.py (since the 64 GB DGX Spark), which says the box's memory class
(d / "boxmem.py").write_text((REPO / "boxmem.py").read_text())
# and the side lanes' installers, whose defaults it recommends (since v1.36.0): read only,
# so written without the execute bit, and a run that reached one would stop on it
for side in ("install-kolibri.sh", "install-image.sh", "install-video.sh"):
(d / side).write_text((REPO / side).read_text())
# and the head of the CHANGELOG, whose first heading names the release the list before
# step 1 compares the box with (since v1.36.0)
(d / "CHANGELOG.md").write_text("".join((REPO / "CHANGELOG.md").read_text().splitlines(keepends=True)[:3]))
return str(copy)
def units_dir(units=None):
"""A directory standing in for /etc/systemd/system, holding `units` ({name: text})."""
d = _tmp("units-")
for name, text in (units or {}).items():
(d / name).write_text(text)
return str(d)
def fence(enabled=()):
"""(PATH entry, record file). Put the entry first on PATH: each command in FENCED
appends its argv to the record and exits 97; `systemctl is-enabled [--quiet] UNIT`
answers 0 for the units in `enabled`, 1 for the others, and records nothing."""
d = _tmp("fence-")
record = d / "calls"
record.touch()
for name in FENCED:
body = f'#!/bin/sh\necho "{name} $*" >> "{record}"\nexit 97\n'
if name == "systemctl":
cases = "".join(f' *" {u}") exit 0 ;;\n' for u in enabled)
body = ('#!/bin/sh\ncase "$1" in\n is-enabled)\n case " $*" in\n' + cases +
' esac\n exit 1 ;;\nesac\n' + body.split("\n", 1)[1])
(d / name).write_text(body)
(d / name).chmod((d / name).stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
return str(d), record
def meminfo_128():
"""A /proc/meminfo of the reference box, a 128 GB DGX Spark (121.6 GiB of MemTotal)."""
path = _tmp("meminfo-") / "meminfo"
path.write_text("MemTotal: 127533104 kB\nMemAvailable: 121000000 kB\n")
return path
def fenced_env(home=None, enabled=(), first=None, **extra):
"""(env, record): a minimal environment whose PATH starts with the fence (after
`first`, a directory of the test's own stubs, when given) and a throwaway HOME.
install.sh reads the box's class and its GiB from QWEN38_MEMINFO (/proc/meminfo by
default): a walled run reads a 128 GB box's unless the test gives its own, so it does not
depend on the machine the tests run on (on a 64 GB one, 10 of the context mode's tests
failed, found in review, 2026-10-23)."""
entry, record = fence(enabled)
path = ":".join(p for p in (first, entry, "/usr/local/bin:/usr/bin:/bin") if p)
env = {"PATH": path, "HOME": str(home or _tmp("home-"))}
env.update({k: str(v) for k, v in extra.items()})
env.setdefault("QWEN38_MEMINFO", str(meminfo_128()))
return env, record
def reached(record):
"""What the run asked the fenced commands for, one line per call."""
return pathlib.Path(record).read_text().splitlines()
def box_home(key_at=None, record=None):
"""A HOME whose ~/.config/qwen38 holds an API key last written at `key_at` (an ISO instant;
none when None), the age conformity.py gives a box with no installed.json, and that file
when `record` ({setting: value} of recorded choices) is given."""
home = _tmp("home-")
cfg = home / ".config/qwen38"
cfg.mkdir(parents=True)
if key_at:
(cfg / "api-key").write_text("not-a-key\n")
t = datetime.datetime.fromisoformat(key_at).timestamp()
os.utime(cfg / "api-key", (t, t))
if record is not None:
(cfg / "installed.json").write_text(json.dumps({
"schema": 1, "release": "v1.36.0", "commit": "0" * 40, "path": "full",
"box_since": "2026-09-05T09:00:00+00:00", "box_since_from": "api-key",
"choices": {k: {"value": v, "since": "2026-10-20T08:00:00+00:00", "how": "env"}
for k, v in record.items()}}))
return str(home)
def cwd():
"""A directory that is not a clone of this repo: get.sh uses the checkout it is started
from, and the real one is the last place a test should start it."""
return str(_tmp("cwd-"))