Files
alzeo/tests/test_switch_clients_only.py
T
Hasan BasbunarandClaude Opus 5.5 c3437a68cd v1.49.0: the Unsloth GGUF lane's second target, UD-IQ3_XXS, four requests of 262,144 tokens each
flash-unsloth-iq3 serves Unsloth's UD-IQ3_XXS of the same repository at the same revision, under
the same served name, as the Kolibri lane serves two checkpoints (decisions 1359, 1366 and 1374).
Its four parts are pinned by their sha256 and size, read from the box's cache, which gguf-fetch.py
had checked as they came (the fourth is UD-Q4_K_XL's own file); its first Load fetches them, and
its chat template comes from its own first part. Its native form is four windows of 262,144 tokens
in q8_0 (-c 1048576 -np 4: eight let the box's guard stop the engine under GSM8K's eight requests,
2026-11-14), its 1M mode the lane's one request; FLASH_UNSLOTH_IQ3_SLOTS and FLASH_UNSLOTH_IQ3_KV
hold the form, which a measure under load may still move.

The lane's default target is one line of install-flash-unsloth.sh, FLASH_UNSLOTH_DEFAULT, still
flash-unsloth: a new install serves it, an update keeps the target its unit serves, and
--recommended brings the default back. The switch hands the installer its target
(FLASH_UNSLOTH_TARGET) for its fetch and its stage; opencode's entry, from the switch and from
install.sh, names the target the unit serves (lanes.sh, flash_unsloth_target); the cockpit reads
it from the unit, the engine panel from the GGUF the engine loaded (/props model_path), and the
Library counts each target's own parts, where the shared snapshot read either whole. check-pins.sh
asks the Hub for the four pointers too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 02:55:56 +01:00

115 lines
7.0 KiB
Python

#!/usr/bin/env python3
"""switch-model.sh <flash-local|flash-unsloth|flash-unsloth-iq3> --clients: the clients of a lane whose clients follow its
unit's window (opencode, and through its config pi and claude-local) set for the window its installed unit starts with,
and nothing else: no fetch, no unit rewritten, no boot moved, no engine touched, no record written.
A window chosen with FLASH_LOCAL_CONTEXT or FLASH_UNSLOTH_CONTEXT and --units-only reaches the unit and not the clients,
which switch-model.sh alone sets. The Load of such a lane that serves without being the boot lane, with that update
owed to it, restarted its unit alone: a switch would have pointed the boot at it, which no update asks for (2026-10-17),
and back from 1M the clients kept 840,000 tokens where the proxy refuses a prompt past 250,000. Its Load now runs this
before the restart (base.js, laneJourneySteps).
The script runs as written on a copy whose unit paths point at this test's files (test_switch_fetch_only.Box), with a
fake docker and a systemctl and a sudo that record every call and answer nothing.
"""
import json
import pathlib
import shutil
import subprocess
import sys
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO / "tests"))
from test_switch_fetch_only import Box # noqa: E402
LANES = {
# target: (its unit's engine flags at the 1M window, the generator of its provider, its served model, the 1M pair)
"flash-local": ("vllm serve m --max-model-len 1048576 --max-num-seqs 8", "oc-flash-local.py",
"qwen3.8-flash-next-fp4", 840000),
"flash-unsloth": ("-m /x.gguf -c 1048576 -np 1", "oc-flash-unsloth.py", "qwen3.8-flash-next-unsloth", 830000),
}
class ClientsOnly(unittest.TestCase):
def box(self, target):
box = Box()
self.addCleanup(shutil.rmtree, box.t, True)
cfg = box.home / ".config" / "qwen38"
(cfg / "api-key").write_text("k\n")
flags, gen, model, _ = LANES[target]
unit = box.flocal_unit if target == "flash-local" else box.unsloth_unit
unit.write_text(f"[Service]\nExecStart=/bin/bash -c '/usr/bin/docker run --rm --name qwen38-{target} x \\\n"
f" {flags} --port 30000'\n")
# the clients as the lane's 262,144-token window left them
out = subprocess.run([sys.executable, str(REPO / gen), "http://127.0.0.1:30001/v1", str(cfg / "api-key"),
"205000", "32000", "a name (local, 262K)"], capture_output=True, text=True, check=True)
base = {"model": "qwen38/qwen3.8-27b", "compaction": {"preserve_recent_tokens": 46000, "prune": False},
"provider": {"qwen38": {"models": {"qwen3.8-27b": {
"name": "x", "limit": {"context": 547000, "input": 547000, "output": 182000}}}},
**json.loads(out.stdout)["provider"]}}
(box.home / ".config" / "opencode").mkdir(parents=True)
box.configs = (cfg / "opencode.json", box.home / ".config" / "opencode" / "opencode.json")
for c in box.configs:
c.write_text(json.dumps(base, indent=2) + "\n")
# what the script runs beside it in this mode
for f in ("oc-limits.sh", "oc-merge-limits.py", "oc-point-default.py", gen, "pi-gen.py", "boxmem.py"):
(box.script.parent / f).write_text((REPO / f).read_text())
(box.script.parent / "oc-limits.sh").chmod(0o755)
box.target_unit = unit
return box
def test_the_clients_take_the_pair_of_the_units_window_and_nothing_else_changes(self):
for target, (_, _, model, ctx) in LANES.items():
with self.subTest(target=target):
box = self.box(target)
base_model, base_compaction = "qwen38/qwen3.8-27b", {"preserve_recent_tokens": 46000, "prune": False}
units = {p: p.read_bytes() for p in box.target_unit.parent.iterdir()}
rc, out, runs, calls = box.run(target, "--clients")
self.assertEqual(rc, 0, out)
for c in box.configs:
entry = json.loads(c.read_text())["provider"][target]["models"][model]
self.assertEqual(entry["limit"], {"context": ctx, "input": ctx, "output": 32000}, c)
self.assertTrue(entry["name"].endswith("(local, 1M)"), entry["name"])
# the boot stays on another lane: so do opencode's default model and its compaction, sized for it
doc = json.loads(c.read_text())
self.assertEqual((doc["model"], doc["compaction"]), (base_model, base_compaction), c)
self.assertEqual(runs, [], "a docker run: a fetch")
self.assertEqual({p: p.read_bytes() for p in box.target_unit.parent.iterdir()}, units, "a unit changed")
self.assertEqual([c for c in calls if c.startswith("sudo ")
or c.split()[0] in ("enable", "disable", "daemon-reload")], [], "the boot moved")
self.assertFalse((box.home / ".config/qwen38/text-lane").exists(), "--clients wrote the text-lane record")
self.assertNotIn("Switch queued", out)
def test_the_unsloth_lanes_entry_names_the_target_its_unit_serves(self):
# UD-IQ3_XXS (v1.49): its four windows of 262,144 get the native pair, under its own name, whichever of the lane's
# two targets --clients is run for: the unit in place says which one it serves
for target in ("flash-unsloth-iq3", "flash-unsloth"):
with self.subTest(target=target):
box = self.box("flash-unsloth")
box.target_unit.write_text(
"[Service]\nExecStart=/bin/bash -c '/usr/bin/docker run --rm --name qwen38-flash-unsloth x \\\n"
" -m /root/.cache/huggingface/hub/models--unsloth--Qwen3.8-Flash-Next-GGUF/snapshots/x/UD-IQ3_XXS/q.gguf \\\n"
" -c 1048576 -np 4 -ctk q8_0 -ctv q8_0 --port 30000'\n")
rc, out, runs, calls = box.run(target, "--clients")
self.assertEqual(rc, 0, out)
for c in box.configs:
entry = json.loads(c.read_text())["provider"]["flash-unsloth"]["models"]["qwen3.8-flash-next-unsloth"]
self.assertEqual(entry["limit"], {"context": 205000, "input": 205000, "output": 32000}, c)
self.assertEqual(entry["name"], "Qwen3.8-Flash-Next Unsloth UD-IQ3_XXS + DFlash2 (local, 262K)", c)
self.assertEqual(runs, [], "a docker run: a fetch")
self.assertNotIn("Switch queued", out)
def test_another_target_is_refused_and_nothing_changes(self):
box = self.box("flash-local")
before = [c.read_bytes() for c in box.configs]
rc, out, runs, calls = box.run("kolibri", "--clients")
self.assertNotEqual(rc, 0)
self.assertIn("--clients", out)
self.assertEqual([c.read_bytes() for c in box.configs], before)
self.assertEqual((runs, [c for c in calls if c.startswith("sudo ")]), ([], []))
if __name__ == "__main__":
unittest.main()