Files
alzeo/tests/test_switch_room.py
T
Hasan Basbunar 2dcbee7598 video lane pass three: what the reviews claimed, what the box answered
Every finding from the branch's security, concurrency and front-end reviews
went to its own verification agent before it was believed (the standing rule
after the QA pass's own two self-inflicted bugs), and everything below is
what survived that; the CHANGELOG's pass-three paragraph carries the full
ledger, the memory the verdicts per finding.

- silence is not death (real, the only true half of S1): run() swallows a
  systemctl slower than five seconds as "", and ("","") differs from every
  baseline - the poll cut a live request with a confident "the lane was
  stopped" and gave the lock back beside a job still generating. Silence now
  reads as LIFE_UNKNOWN and waits; deactivating stays terminal because this
  runtime cancels its tasks at stop (seven logged stops, all under a second),
  which is also what makes the Cancel modal's ~12 min honest and the
  template's TimeoutStopSec comment - and the docs' stop bullet - wrong:
  both rewritten around the ceiling they describe. M5, which promised a
  stop that waits the hour out, verified false against that journal.
- the admission guard had no slack (real): the largest accepted estimate,
  15 s at 720P on 57 steps, lands the lock's deadline on the lane's expected
  finish; the refusal now keeps a tenth, on both sides, and the parity test
  parses the margin out of app.js and cockpit.py and answers through the
  server for every tab combination.
- the numbers were the journal's, not the docs' (F3 real, no regeneration
  needed): 23:21:01 to 23:30:54 is 592 s, 9:52, over the 50-step default;
  the 10:52 and 49-step figures were typos that 197a3b1 had spread to the
  page four times, the changelog, the docs and the tests. k keeps its 3.05
  (592/(50x4) = 2.96 rounded up), the 720P pins 7.65 against a measured
  7.43.
- one cap per route (real): a shared max() had made the video route's cap
  the image lane's 40 MiB; a prompt plus two keyframes now answers 413 over
  its own 10 MiB at the socket, pinned by a test.
- the keyframes' whole story (three findings): an ENOSPC while staging died
  outside the error paths with no answer on the socket and a half-written
  PNG behind (now 503 with the reason, and whatever got named gets unlinked);
  the 504 hand-off unlinked frames a queued job had not read yet - the
  runtime localizes file:// URIs when the job starts, not when the POST
  arrives - so the watcher owns them now and unlinks when the lane is done;
  a cockpit killed mid-call left them forever, a fresh one sweeps them; and
  the parked video's link, which only lived in one page run, rebuilds itself
  from /api/video's progress after an F5.
- a non-numeric seed rode out as seed:null, which the filter drops in
  silence - a random video under a number in the box: vidProblem says what a
  seed may be before the wire.
- the switch grew the room check its text branch had learned (real on a
  fresh box: 145 GB behind a button over 90 free), reading the need from
  install-video.sh so the two drift together, its dl_free_gb defined once
  before every branch; and the rollback guard now really disables the
  competing units at a switch, llama.cpp's included - the uninstall test
  excludes that one by name and reason: the switch mentions it to stop a
  collision, it writes no such unit, and the file's own doctrine says an
  operator's unit is nobody's business.

Sixteen tests added (ten dashboard, three switch, one socket), five source
pins rewritten to the new shapes; the dashboard suite is 694, ci-local 45
ok 0 skipped, the typography gate holds, ruff F,E9 clean.

Signed-off-by: Hasan Basbunar <basbunarhasan@gmail.com>
2026-09-28 23:53:35 +02:00

109 lines
4.7 KiB
Python

#!/usr/bin/env python3
"""A switch checks for room before it downloads, and the cockpit gives it the time to.
switch-model.sh can download a whole checkpoint (22 to 126 GB), and a cockpit button can
start it: it checked no free space, blamed HF_TOKEN for any failed download, and the
cockpit's switch job timed out at 30 min, when a flash download alone takes about 23 at
the reference box's 89 MB/s (found in review, 2026-09-24). The switch's own lines run
here against a fake cache and a df stub.
"""
import pathlib
import re
import subprocess
import tempfile
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
TEXT = (REPO / "switch-model.sh").read_text()
START = TEXT.index('DL_REPO_CACHE="$HF_CACHE/hub/models--${TARGET_REPO//\\//--}"')
BLOCK = TEXT[START:TEXT.index("DL_TOKEN_ARGS=()", START)]
# the room checks read free space through one function, defined once before every
# branch runs; every replay carries it in front of the block it exercises
_lines = TEXT.splitlines(keepends=True)
_at = next(i for i, ln in enumerate(_lines) if ln.startswith("dl_free_gb(){"))
DLFREE = "".join(_lines[_at:_at + 2])
def run(lane, free_gb, cached_gib=0.0):
d = pathlib.Path(tempfile.mkdtemp(prefix="sw-room-"))
blobs = d / "hf/hub/models--org--target/blobs"
blobs.mkdir(parents=True)
if cached_gib:
with open(blobs / "b", "wb") as f:
f.truncate(int(cached_gib * 1024 ** 3))
(d / "df").write_text(f"#!/bin/sh\necho Avail; echo {free_gb}G\n")
(d / "df").chmod(0o755)
script = ('set -euo pipefail\ndie(){ echo "DIE: $*"; exit 1; }\n'
f'HF_CACHE="{d}/hf"; TARGET_REPO=org/target; TARGET_LANE={lane}\n'
+ DLFREE + BLOCK + "echo ROOM-OK\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
class ASwitchChecksForRoom(unittest.TestCase):
def test_a_flash_switch_without_room_stops_before_anything(self):
out = run("flash", free_gb=50)
self.assertIn("DIE: not enough room", out)
self.assertNotIn("ROOM-OK", out)
def test_what_is_cached_comes_off_the_need(self):
self.assertIn("ROOM-OK", run("flash", free_gb=60, cached_gib=126))
def test_a_27b_switch_with_room_goes_on(self):
self.assertIn("ROOM-OK", run("27b", free_gb=100))
VID_START = TEXT.index('VID_WANT_GB="$(grep')
VID_END = TEXT.index('(nothing was changed). Free some space first, or point HF_HOME at a bigger disk."', VID_START)
VID_BLOCK = TEXT[VID_START:TEXT.index("\n", VID_END) + 1]
def run_video(free_gb, cached_gib=0.0):
d = pathlib.Path(tempfile.mkdtemp(prefix="sw-room-"))
blobs = d / "hf/hub/models--MiniMaxAI--MiniMax-H3/blobs"
blobs.mkdir(parents=True)
if cached_gib:
with open(blobs / "b", "wb") as f:
f.truncate(int(cached_gib * 1024 ** 3))
(d / "df").write_text(f"#!/bin/sh\necho Avail; echo {free_gb}G\n")
(d / "df").chmod(0o755)
script = ('set -euo pipefail\ndie(){ echo "DIE: $*"; exit 1; }\n'
f'REPO_DIR="{REPO}"; HF_CACHE="{d}/hf"; VID_MODEL=MiniMaxAI/MiniMax-H3; '
f'VID_MODEL_DIR="{d}/hf/hub/models--MiniMaxAI--MiniMax-H3"\n'
+ DLFREE + VID_BLOCK + "echo ROOM-OK\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
class TheVideoSwitchChecksForRoomToo(unittest.TestCase):
"""145 GB of fl2va weights behind a button, under a serving engine: the video
branch skipped the room check the text branch had learned (reviews, 2026-09-28).
The need is read from install-video.sh, so the two files drift together."""
def test_a_video_switch_without_room_stops_before_anything(self):
# this box's real numbers of 2026-09-28: 90 GB free, empty cache, 145 needed
out = run_video(free_gb=90)
self.assertIn("DIE: not enough room", out)
self.assertNotIn("ROOM-OK", out)
def test_the_complete_cache_of_a_real_box_answers_without_a_die(self):
self.assertIn("ROOM-OK", run_video(free_gb=90, cached_gib=135))
def test_a_video_switch_with_room_goes_on(self):
self.assertIn("ROOM-OK", run_video(free_gb=200))
class TheCockpitGivesItTheTime(unittest.TestCase):
def test_the_switch_job_outlives_a_flash_download(self):
cockpit = (REPO / "dashboard/cockpit.py").read_text()
block = cockpit[cockpit.index('"switch": {'):]
timeout = int(re.search(r'"timeout":\s*(\d+)', block).group(1))
self.assertGreaterEqual(timeout, 2 * 3600, "124 GB at 89 MB/s is 23 min, at 20 MB/s 1 h 45")
if __name__ == "__main__":
unittest.main(verbosity=2)