Files
alzeo/tests/test_switch_clients_only.py
Hasan Basbunar 7aae54f4db tests: the switch sandboxes copy oc-permissions.py, the merger's sibling
e449833e made oc-merge-limits.py load oc-permissions.py at import time
(one server matcher shared with the relay, review 7), and
oc-point-default.py imports the merger, so every switch path that points
opencode at the new lane or renames an entry now needs that sibling beside
the helpers. The three switch sandboxes (test_lfm25_lane, test_lfm3_lane,
test_switch_clients_only) copied the helpers without it: both crashed with
FileNotFoundError, the NOTE lines went by, and cfg["model"] stayed on
qwen38 after an lfm25/lfm3 switch while the flash-unsloth entry kept its
placeholder name. On a box every helper runs from the repo root, where the
sibling is present, so the behavior the tests protect is unchanged in
production; the sandboxes now mirror the repo, as test_install_agent_v2.py
already does. No assertion changed. Proof of the culprit: git archive of
e449833e and of its parent, same invocation, the three files green before
and red from e449833e on; with the sibling copied, all three pass on this
branch (Ran 19 OK, Ran 21 OK skipped=1, Ran 3 OK).

Generated by Mistral Vibe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 11:29:54 +01:00

116 lines
7.1 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
# oc-permissions.py too: the merger loads its sibling, the server matcher (e449833e, review 7)
for f in ("oc-limits.sh", "oc-merge-limits.py", "oc-permissions.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()