Files
alzeo/tests/test_switch_running_check.py
Hasan BasbunarandClaude Opus 5.5 7658102efc install, switch: a lane is stopped then started, never restarted beside another one (#76)
systemd refuses to restart a unit while one it conflicts with, ordered after it both ways, is active: "Transaction
order is cyclic". Measured on throwaway units of the user manager (systemd 255): a start, which stops the other
first, goes through, and so does a restart of the unit that is itself active. job_compare (src/core/job.c) counts a
restart as a stop, and the stop Conflicts= asks of the other lane then has to come both before and after it.

install.sh's step 9 restarted the text lane whatever was active: MODEL_CHOICE=<text target> or --recommended on a box
where a side lane serves died there, the text lane enabled at boot and the side lane still serving. It stops it, then
starts it, as a Load does. The switch's last words advised a restart of a target that does not serve, which is refused
beside a lane that still loads: it says start. README says when each one applies.

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

54 lines
2.9 KiB
Python

#!/usr/bin/env python3
"""The text switch says which lane it stops, read from every lane's unit.
./switch-model.sh <text target> ends on the command that makes the switch effective: "stop <the lane
that serves> && start <the target>". It found the lane that serves among the units it names one by
one, and the Qwen3.8 Flash-Next FP4-Local lane was not among them: with that lane serving, a switch to the flash
lane printed "restart qwen38-flash.service", naming the wrong lane and hiding that the one serving
would stop (found in review, 2026-10-20). Every side lane's unit name the script declares must be
among those it checks. Read from the script as written."""
import pathlib
import re
import subprocess
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
TEXT = (REPO / "switch-model.sh").read_text()
class TheRunningCheck(unittest.TestCase):
def test_it_names_every_side_lanes_unit(self):
start = TEXT.index('RUNNING=""\nsystemctl is-active --quiet "$OTHER_UNIT_NAME"')
block = TEXT[start:TEXT.index("Switch queued", start)]
checked = set(re.findall(r'systemctl is-active --quiet "\$(\w+)"', block))
declared = {n for n in re.findall(r'^(\w+_UNIT_NAME)="qwen38-[\w-]+\.service"', TEXT, re.M)
if n not in ("SGL_UNIT_NAME", "FLASH_UNIT_NAME")} # the text targets: OTHER_UNIT_NAME
self.assertTrue(declared)
self.assertEqual(declared - checked, set())
class WhatMakesItEffective(unittest.TestCase):
"""Its last words, run as written. A lane that still loads is not in RUNNING (is-active does not see it), and beside
it systemd refuses a restart of the target ("Transaction order is cyclic", issue 76, 2026-11-30): a target that
does not serve is started, which stops that lane first."""
def said(self, running="", target_active=False):
start = TEXT.index('if [ -n "$RUNNING" ]; then\n echo "Effective after: sudo systemctl stop $RUNNING')
block = TEXT[start:TEXT.index("\nfi\n", start) + 4]
return subprocess.run(["bash", "-euo", "pipefail", "-c",
f"systemctl(){{ return {0 if target_active else 3}; }}\n"
f'RUNNING="{running}"; TARGET_UNIT_NAME=qwen38-sglang.service\n' + block],
capture_output=True, text=True, timeout=30).stdout
def test_the_lane_that_serves_is_stopped_first(self):
self.assertIn("sudo systemctl stop qwen38-flash.service && sudo systemctl start qwen38-sglang.service",
self.said(running="qwen38-flash.service"))
def test_the_target_is_restarted_when_it_serves_and_started_when_it_does_not(self):
self.assertIn("sudo systemctl restart qwen38-sglang.service", self.said(target_active=True))
self.assertIn("sudo systemctl start qwen38-sglang.service", self.said())
if __name__ == "__main__":
unittest.main(verbosity=2)