Files
alzeo/tests/test_oc_point_default.py
Hasan BasbunarandClaude Opus 5.5 8124380330 v1.48.1: what the independent review found: --clients sets the limits alone, the steps say what restarts
- switch-model.sh <flash-local|flash-unsloth> --clients sets the lane's limits and the name of its entry
  for the window its unit starts with (oc-point-default.py --name-only, new), and no longer opencode's
  default model nor its compaction: the boot stays on another lane, and so do they, where a reboot came
  back on the boot lane with opencode pointed at the other one.
- The Load's two clients steps and the action's explanation said "Nothing restarts.": switch-model.sh
  restarts opencode-web when the config it reads changed, which cuts a reply it is writing; they say so,
  in fit_opencode's words.
- The banner gives a clone with a tracked file modified its own installer too: get.sh refuses it
  ("modified tracked files").
- The vLLM units and their test say what the stop's mark does not cover: a stop during ExecStartPre
  still ends failed, and systemd runs no ExecStop after a main process that failed.
- docs/cockpit.md and both lanes' pages name --clients.
Tests that fail on the code before: test_switch_clients_only (the default model and the compaction
kept), test_oc_point_default (--name-only, exit 2 before), test_cockpit_version (an edited clone).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 00:12:29 +01:00

160 lines
6.4 KiB
Python
Executable File

#!/usr/bin/env python3
"""oc-point-default.py: the default model and the served entry's picker name
follow the installed lane, in any opencode.json-shaped file.
This edits the file opencode really reads, so every case asserts on the file
on disk afterwards: default model, small model, shown name, and everything
else byte-identical. A lane change that leaves the previous lane's default in
place strands every agent session on a model nothing serves (reference box,
stock install over an fp8/flash era config)."""
import json
import os
import subprocess
import sys
import tempfile
REPO_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SCRIPT = os.path.join(REPO_DIR, "oc-point-default.py")
def run(*args):
r = subprocess.run([sys.executable, SCRIPT, *args],
capture_output=True, text=True)
return r.returncode, (r.stdout + r.stderr).strip()
def write(tmp, doc):
p = os.path.join(tmp, "oc.json")
with open(p, "w") as f:
json.dump(doc, f, indent=2)
f.write("\n")
return p
def read(p):
with open(p) as f:
return json.load(f)
def stale_fp8_config():
return {
"provider": {
"qwen38": {"models": {"qwen3.8-27b": {
"name": "Qwen3.8-27B FP8 official + DFlash2 (local, 1M)",
"limit": {"context": 700000, "input": 700000, "output": 200000}}}},
"flashnext": {"models": {"qwen3.8-flash-next": {
"name": "Qwen3.8-Flash-Next NVFP4 + MTP (local, 262K)",
"limit": {"context": 175000, "input": 175000, "output": 64000}}}},
},
"model": "flashnext/qwen3.8-flash-next",
"small_model": "flashnext/qwen3.8-flash-next",
}
def main() -> None:
tmp = tempfile.mkdtemp()
# 1. The reported bug: stock 1M installed over an fp8/flash era config.
# Default flips lanes, the served entry is renamed, the other lane keeps
# its entry, limits untouched.
p = write(tmp, stale_fp8_config())
rc, out = run(p, "27b", "stock", "1010000")
assert rc == 0, out
assert "opencode default model -> qwen38/qwen3.8-27b" in out, out
cfg = read(p)
assert cfg["model"] == "qwen38/qwen3.8-27b", cfg["model"]
assert cfg["small_model"] == "qwen38/qwen3.8-27b"
assert cfg["provider"]["qwen38"]["models"]["qwen3.8-27b"]["name"] == \
"Qwen3.8-27B NVFP4 + DFlash2 (local, 1M)"
assert cfg["provider"]["flashnext"]["models"]["qwen3.8-flash-next"]["name"] == \
"Qwen3.8-Flash-Next NVFP4 + MTP (local, 262K)"
assert cfg["provider"]["qwen38"]["models"]["qwen3.8-27b"]["limit"]["context"] == 700000
# 2. Window suffixes: 1M, explicit K, unknown.
p = write(tmp, stale_fp8_config())
rc, _ = run(p, "flash", "flash-uncensored", "262144")
assert rc == 0
cfg = read(p)
assert cfg["model"] == "flashnext/qwen3.8-flash-next"
assert cfg["provider"]["flashnext"]["models"]["qwen3.8-flash-next"]["name"] == \
"Qwen3.8-Flash-Next NVFP4 abliterated + MTP (local, 262K)"
# 2b. The flash lane over a 27B-era config: both defaults follow it, and nothing else in
# the file moves. small_model was never checked on this side, so a small model left on
# the 27B passed (found in review, 2026-09-24).
doc = stale_fp8_config()
doc["model"] = doc["small_model"] = "qwen38/qwen3.8-27b"
p = write(tmp, doc)
rc, out = run(p, "flash", "flash", "262144")
assert rc == 0, out
cfg = read(p)
assert (cfg["model"], cfg["small_model"]) == ("flashnext/qwen3.8-flash-next",) * 2, cfg
for d in (cfg, doc):
del d["model"], d["small_model"], d["provider"]["flashnext"]["models"]["qwen3.8-flash-next"]["name"]
assert cfg == doc, "something else in the file moved"
p = write(tmp, stale_fp8_config())
rc, _ = run(p, "27b", "fp8", "")
assert rc == 0
assert read(p)["provider"]["qwen38"]["models"]["qwen3.8-27b"]["name"] == \
"Qwen3.8-27B FP8 official + DFlash2 (local)"
# 3. Unknown choice still flips the default (the lane is what matters),
# but renames nothing it cannot name.
p = write(tmp, stale_fp8_config())
rc, out = run(p, "27b", "future-thing", "262144")
assert rc == 0, out
cfg = read(p)
assert cfg["model"] == "qwen38/qwen3.8-27b"
assert cfg["provider"]["qwen38"]["models"]["qwen3.8-27b"]["name"] == \
"Qwen3.8-27B FP8 official + DFlash2 (local, 1M)"
# 4. A config predating the lane's provider: untouched, NOTE, exit 0.
p = write(tmp, {"provider": {"qwen38": {"models": {}}}, "model": "qwen38/qwen3.8-27b"})
before = open(p, "rb").read()
rc, out = run(p, "flash", "flash", "262144")
assert rc == 0, out
assert "NOTE" in out and "flashnext" in out, out
assert open(p, "rb").read() == before
# 5. Not JSON: exit 3, file untouched.
p = os.path.join(tmp, "broken.json")
with open(p, "w") as f:
f.write("{not json")
rc, _ = run(p, "27b", "stock", "1010000")
assert rc == 3, rc
assert open(p).read() == "{not json"
# 6. Idempotent: pointing twice changes nothing the second time.
p = write(tmp, stale_fp8_config())
run(p, "27b", "stock", "1010000")
once = open(p, "rb").read()
rc, _ = run(p, "27b", "stock", "1010000")
assert rc == 0
assert open(p, "rb").read() == once
# 7. Usage: exit 2, no traceback.
r = subprocess.run([sys.executable, SCRIPT], capture_output=True, text=True)
assert r.returncode == 2, r.returncode
assert "Traceback" not in r.stderr, r.stderr
# 8. --name-only (switch-model.sh --clients, v1.48.1): the served entry's name follows the window, and nothing
# else moves: the default and small models stay on the lane the boot names, every other byte as it was.
doc = stale_fp8_config()
p = write(tmp, doc)
rc, out = run("--name-only", p, "flash", "flash", "1048576")
assert rc == 0, out
after = read(p)
assert after["provider"]["flashnext"]["models"]["qwen3.8-flash-next"]["name"].endswith("(local, 1M)"), after
after["provider"]["flashnext"]["models"]["qwen3.8-flash-next"]["name"] = \
doc["provider"]["flashnext"]["models"]["qwen3.8-flash-next"]["name"]
assert after == doc, after
p = write(tmp, doc)
rc, out = run("--name-only", p, "27b", "stock", "1010000")
assert rc == 0, out
assert (read(p)["model"], read(p)["small_model"]) == (doc["model"], doc["small_model"]), read(p)
print("test_oc_point_default: OK")
if __name__ == "__main__":
main()