Files
alzeo/tests/test_pi_gen.py
T
Hasan BasbunarandClaude Opus 5.5 bcd8325d8d v1.51: pi offers the Liquid AI LFM2.5 24B-A2B lane the one level it holds, and opencode none
Its chat_template.jinja (at the pinned revision) ends every generation prompt with "<think>" and reads
add_generation_prompt, bos_token, messages, tools and preserve_thinking alone: no enable_thinking, no
reasoning effort, nothing that cuts the reasoning. pi offered every level on it, off first, and started
at off. It now maps every level but high to null, which pi 1.2.0 hides (getSupportedThinkingLevels),
starts at high and sends no effort field (supportsReasoningEffort false: the template reads none); omp
gets high as its one effort and its default, though omp 18.4.9 offers off and auto beside it whatever
its file says. opencode offered no level already: its block has no variants and no "reasoning", which
in opencode 1.19.5 would add low, medium and high on @ai-sdk/openai-compatible. A test holds both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 15:38:53 +01:00

494 lines
28 KiB
Python

#!/usr/bin/env python3
"""pi-gen.py derives the pi and omp agent configs from the generated opencode.json.
pi and omp read no opencode.json (docs/pi.md): their default model, provider
names and limits are plain values in their own files, so the files this
generator writes are where those facts live. These check the derivation against
the artifact: key form, limits, the pi/omp value parity (one build, two
serializations), the omp thinking ladder taken from the artifact's variants,
the compaction sizing, and the quiet paths (no artifact, foreign providers).
The omp YAML is read back by a mini reader for the emitter's exact subset:
pi-gen.py is stdlib-only, this CI step installs no PyYAML, and neither side
of the parity check may import one. The spelling on disk is verified against
omp itself (docs/pi.md); what these tests pin is the pair's values.
"""
import importlib.util
import json
import os
import pathlib
import re
import subprocess
import tempfile
import sys
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
GEN = REPO / "pi-gen.py"
ARTIFACT = {
"provider": {
"qwen38": {
"options": {"baseURL": "http://127.0.0.1:30001/v1", "apiKey": "{file:/keys/api-key}"},
"models": {"qwen3.8-27b": {
"name": "Qwen3.8-27B (local)",
"limit": {"context": 173000, "input": 173000, "output": 64000},
"variants": {"lean": {}, "low": {}, "medium": {}, "xhigh": {}},
"modalities": {"input": ["text", "image"]}}},
},
"someone-elses": {"options": {"baseURL": "https://x.test/v1"}, "models": {"m": {}}},
},
"compaction": {"preserve_recent_tokens": 46000},
"model": "qwen38/qwen3.8-27b",
}
def run(args):
return subprocess.run([sys.executable, str(GEN)] + args, capture_output=True, text=True)
def yload(text):
"""Read what pi-gen.py's own writer emits: quoted strings, bare true/
false/int, two-space indents, '- ' items. Nothing else, on purpose: the
generator promises those shapes and the real omp parses them."""
rows = [(len(l) - len(l.lstrip(" ")), l.strip()) for l in text.splitlines() if l.strip()]
i = 0
def sc(tok):
if tok.startswith('"'):
return json.loads(tok)
if tok in ("true", "false"):
return tok == "true"
if tok in ("{}", "[]"):
return {} if tok == "{}" else []
return int(tok)
def block(ind):
nonlocal i
if i < len(rows) and rows[i][1].startswith("-"):
out = []
while i < len(rows) and rows[i][0] == ind and rows[i][1].startswith("-"):
body = rows[i][1][1:].strip()
if body.startswith('"') or ":" not in body:
i += 1
out.append(sc(body))
else: # '- id: x': a mapping item, first key inlined
rows[i] = (ind + 2, body)
out.append(block(ind + 2))
return out
out = {}
while i < len(rows) and rows[i][0] == ind and not rows[i][1].startswith("-"):
key, _, val = rows[i][1].partition(":")
val = val.strip()
i += 1
if val:
out[key] = sc(val) # quoted strings keep any ':' inside
else:
out[key] = block(ind + 2) if i < len(rows) and rows[i][0] >= ind + 2 else {}
return out
return block(0)
class PiGen(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.art = os.path.join(self.tmp.name, "opencode.json")
with open(self.art, "w") as f:
f.write(json.dumps(ARTIFACT))
self.out = os.path.join(self.tmp.name, "out")
def tearDown(self):
self.tmp.cleanup()
def gen(self, *extra):
r = run(["--config", self.art, "--out", self.out] + list(extra))
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
return r
def read_pi(self):
with open(os.path.join(self.out, "pi", "models.json")) as f:
models = json.loads(f.read())
with open(os.path.join(self.out, "pi", "settings.json")) as f:
settings = json.loads(f.read())
return models, settings
def read_omp(self):
with open(os.path.join(self.out, "omp", "models.yml")) as f:
models = yload(f.read())
with open(os.path.join(self.out, "omp", "config.yml")) as f:
cfg = yload(f.read())
return models, cfg
def test_generation(self):
self.gen()
models, settings = self.read_pi()
prov = models["providers"]["qwen38"]
self.assertNotIn("someone-elses", models["providers"])
self.assertEqual(prov["apiKey"], "!cat /keys/api-key")
entry = prov["models"][0]
self.assertEqual((entry["contextWindow"], entry["maxTokens"]), (173000, 64000))
self.assertEqual(entry["input"], ["text", "image"])
self.assertEqual(settings["defaultProvider"], "qwen38")
self.assertEqual(settings["defaultModel"], "qwen3.8-27b")
self.assertEqual(settings["compaction"]["keepRecentTokens"], 46000)
self.assertEqual(settings["compaction"]["modelOverrides"]["qwen38/qwen3.8-27b"], {"reserveTokens": 64000})
self.assertEqual(settings["modelThinkingLevels"], {"qwen38/qwen3.8-27b": "off"})
# its system prompt goes out as "system": as "developer" the served template refused
# every request (400 "Unexpected message role.", pi 0.99.2, 2026-10-01)
self.assertEqual(entry["compat"], {"supportsDeveloperRole": False})
def test_omp_parity_and_thinking(self):
self.gen()
models, _ = self.read_pi()
omp_models, omp_cfg = self.read_omp()
pi_entry = dict(models["providers"]["qwen38"]["models"][0])
omp_entry = dict(omp_models["providers"]["qwen38"]["models"][0])
pi_entry.pop("inputLimits")
pi_entry.pop("compat")
thinking = omp_entry.pop("thinking")
compat = omp_entry.pop("compat")
self.assertEqual(omp_entry, pi_entry) # one build, two serializations
# the template's lean rides on minimal through reasoningEffortMap, and
# qwenTemplateReasoningEffort is what routes the mapped pick onto
# chat_template_kwargs.reasoning_effort. Without that flag the picker
# moved and no effort field was sent (captured against omp 18.4.6,
# 2026-10-01): it is the one field the ladder needs.
self.assertEqual(thinking, {"mode": "effort", "efforts": ["minimal", "low", "medium", "xhigh"],
"defaultLevel": "minimal"})
# and rides chat_template_kwargs alone: omp's default dialect also sent a top-level
# reasoning_effort, which SGLang refuses as "lean" (a 400 on every request at the
# default level, omp 18.4.9, 2026-10-01)
self.assertEqual(compat, {"thinkingFormat": "qwen-chat-template", "qwenTemplateReasoningEffort": True,
"reasoningEffortMap": {"minimal": "lean"}})
self.assertEqual(omp_cfg["modelRoles"]["default"], "qwen38/qwen3.8-27b")
def test_kolibri_is_sent_its_effort_and_starts_at_high(self):
# Kolibri reasons at high with no effort field: pi's "off" sent nothing, so a pi user saw
# thinking off while every request reasoned at high (found in review, 2026-10-14)
art = json.loads(json.dumps(ARTIFACT))
art["provider"]["kolibri"] = {
"options": {"baseURL": "http://127.0.0.1:30001/v1", "apiKey": "{file:/keys/api-key}"},
"models": {"kolibri-1": {"name": "Kolibri-1 FP8 official (local, 262K)",
"limit": {"context": 173000, "input": 173000, "output": 64000},
"variants": {"none": {}, "low": {}, "medium": {}, "high": {}},
"modalities": {"input": ["text"], "output": ["text"]}}}}
art["model"] = "kolibri/kolibri-1"
with open(self.art, "w") as f:
f.write(json.dumps(art))
self.gen()
models, settings = self.read_pi()
entry = models["providers"]["kolibri"]["models"][0]
self.assertEqual(entry["compat"], {"supportsDeveloperRole": False, "supportsReasoningEffort": True})
self.assertEqual(entry["thinkingLevelMap"], {"off": "none", "minimal": "low", "xhigh": "high"})
self.assertEqual(settings["modelThinkingLevels"]["kolibri/kolibri-1"], "high")
self.assertEqual(settings["modelThinkingLevels"]["qwen38/qwen3.8-27b"], "off", "the Qwen lanes as before")
self.assertNotIn("thinkingLevelMap", models["providers"]["qwen38"]["models"][0])
omp_models, _ = self.read_omp()
omp_entry = dict(omp_models["providers"]["kolibri"]["models"][0])
self.assertEqual(omp_entry.pop("thinking"), {"mode": "effort", "efforts": ["minimal", "low", "medium", "high"],
"defaultLevel": "high"})
self.assertEqual(omp_entry.pop("compat"), {"thinkingFormat": "qwen-chat-template",
"qwenTemplateReasoningEffort": True,
"reasoningEffortMap": {"minimal": "none"}})
pi_entry = {k: v for k, v in entry.items() if k not in ("compat", "thinkingLevelMap")}
self.assertEqual(omp_entry, pi_entry, "one build, two serializations; omp has no thinkingLevelMap")
def test_omp_starts_a_lane_at_its_installed_templates_default(self):
# omp sends its default level on every request, and took lean for every patched Qwen template:
# a box installed with LEAN_DEFAULT=0, whose templates keep Qwen's xhigh, got lean in omp alone
# (found in review, 2026-10-20). The default is the installed template's, read beside the configs.
os.makedirs(self.out, exist_ok=True)
def level(default):
if default is None:
p = pathlib.Path(self.out, "chat-template-sglang.jinja")
if p.exists():
p.unlink()
else:
pathlib.Path(self.out, "chat-template-sglang.jinja").write_text(
"{%- set reasoning_effort = reasoning_effort|default('" + default + "') %}\n")
self.gen()
omp_models, _ = self.read_omp()
return omp_models["providers"]["qwen38"]["models"][0]["thinking"]["defaultLevel"]
self.assertEqual(level("xhigh"), "xhigh")
self.assertEqual(level("lean"), "minimal")
self.assertEqual(level(None), "minimal") # no template there: the patched default
def test_the_flash_local_lane_starts_in_omp_at_the_level_its_installer_chose(self):
# the lane's default is lean since v1.46.4, as on the other Qwen lanes, or Qwen's xhigh where its installer
# keeps FLASH_LOCAL_EFFORT=xhigh beside these configs. omp took "lean" in its tiers for the patched template's
# default and started an xhigh lane at minimal, sent as lean (found in review, 2026-10-20); and it read the
# lane's template, which an update writes after these configs, so it stayed at the xhigh of v1.46.3's (found
# in review of v1.46.4): the installer's kept choice decides
import importlib.util
spec = importlib.util.spec_from_file_location("oc_flash_local", REPO / "oc-flash-local.py")
ocf = importlib.util.module_from_spec(spec)
spec.loader.exec_module(ocf)
os.makedirs(self.out, exist_ok=True)
# the box's layout: the key, the lane's template and the choice its installer keeps, side by side
template = pathlib.Path(self.out, "chat-template-flash-local.jinja")
choice = pathlib.Path(self.out, "flash-local-effort")
def omp(default, kept, listed=None):
"""omp's thinking block for the lane, with the template's default (None: no template there yet), the choice
its installer kept (None: none), and the artifact's levels in another order (listed)."""
for path, body in ((template, default and "{%- set e = reasoning_effort|default('" + default + "') %}\n"),
(choice, kept and kept + "\n")):
if body:
path.write_text(body)
elif path.exists():
path.unlink()
art = json.loads(json.dumps(ARTIFACT))
art["provider"]["flash-local"] = ocf.provider("http://127.0.0.1:30001/v1", os.path.join(self.out, "api-key"),
205000, 32000, "Qwen3.8-Flash-Next FP4-Local (local, 262K)")
model = art["provider"]["flash-local"]["models"]["qwen3.8-flash-next-fp4"]
if listed:
model["variants"] = {lvl: model["variants"][lvl] for lvl in listed}
art["model"] = "flash-local/qwen3.8-flash-next-fp4"
with open(self.art, "w") as f:
f.write(json.dumps(art))
self.gen()
_, settings = self.read_pi()
# pi sends no effort, so the template's own default, whichever it is
self.assertEqual(settings["modelThinkingLevels"]["flash-local/qwen3.8-flash-next-fp4"], "off")
omp_models, _ = self.read_omp()
entry = omp_models["providers"]["flash-local"]["models"][0]
self.assertEqual(entry["compat"]["reasoningEffortMap"], {"minimal": "lean"})
self.assertEqual(omp_models["providers"]["qwen38"]["models"][0]["thinking"]["defaultLevel"], "minimal",
"the patched template's default, lean, for the lanes that keep it")
return entry["thinking"]
listed = ["xhigh", "minimal", "low", "medium"] # the provider's order, xhigh first as since v1.37.0
self.assertEqual(omp("lean", None), {"mode": "effort", "efforts": listed, "defaultLevel": "minimal"})
self.assertEqual(omp("xhigh", "xhigh"), {"mode": "effort", "efforts": listed, "defaultLevel": "xhigh"})
# the installer's choice decides, not the template: an update runs this before the lane's installer writes the
# template again (still at the xhigh of v1.46.3), and a choice made is in the template at its next write only
self.assertEqual(omp("xhigh", None)["defaultLevel"], "minimal")
self.assertEqual(omp("lean", "xhigh")["defaultLevel"], "xhigh")
# nor the order of the artifact's levels
self.assertEqual(omp("lean", None, listed=["lean", "low", "medium", "xhigh"])["defaultLevel"], "minimal")
self.assertEqual(omp(None, "xhigh", listed=["lean", "low", "medium", "xhigh"])["defaultLevel"], "xhigh")
# installed and never loaded, no template yet
self.assertEqual(omp(None, None), {"mode": "effort", "efforts": listed, "defaultLevel": "minimal"})
self.assertEqual(omp(None, "xhigh"), {"mode": "effort", "efforts": listed, "defaultLevel": "xhigh"})
def test_nemotron_is_sent_its_effort_starts_at_high_and_takes_images(self):
# Bolt reasons at its full depth unasked, as Kolibri does at high; the proxy turns the effort
# field into the template's words (keepalive-proxy.py, nemotron_effort), and Bolt reads images
art = json.loads(json.dumps(ARTIFACT))
art["provider"]["nemotron"] = {
"options": {"baseURL": "http://127.0.0.1:30001/v1", "apiKey": "{file:/keys/api-key}"},
"models": {"nemotron-3.5-bolt": {"name": "Nemotron 3.5 Bolt (local, 262K)",
"limit": {"context": 205000, "input": 205000, "output": 32000},
"variants": {"none": {}, "low": {}, "medium": {}, "high": {}},
"attachment": True,
"modalities": {"input": ["text", "image"], "output": ["text"]}}}}
art["model"] = "nemotron/nemotron-3.5-bolt"
with open(self.art, "w") as f:
f.write(json.dumps(art))
self.gen()
models, settings = self.read_pi()
entry = models["providers"]["nemotron"]["models"][0]
self.assertEqual(entry["compat"], {"supportsDeveloperRole": False, "supportsReasoningEffort": True})
self.assertEqual(entry["thinkingLevelMap"], {"off": "none", "minimal": "low", "xhigh": "high"})
self.assertEqual(entry["input"], ["text", "image"])
self.assertEqual(settings["modelThinkingLevels"]["nemotron/nemotron-3.5-bolt"], "high")
self.assertEqual(settings["modelThinkingLevels"]["qwen38/qwen3.8-27b"], "off", "the Qwen lanes as before")
def test_the_unsloth_lane_starts_in_omp_at_its_templates_default_and_takes_text(self):
# the Qwen3.8 Flash-Next Unsloth GGUF lane's template is its GGUF's, patched with the Qwen fixes (v1.48): its
# default read beside these configs, as the 27B's is; and it loads no vision projector, so text alone
import importlib.util
spec = importlib.util.spec_from_file_location("oc_flash_unsloth", REPO / "oc-flash-unsloth.py")
ocu = importlib.util.module_from_spec(spec)
spec.loader.exec_module(ocu)
os.makedirs(self.out, exist_ok=True)
art = json.loads(json.dumps(ARTIFACT))
art["provider"]["flash-unsloth"] = ocu.provider("http://127.0.0.1:30001/v1", os.path.join(self.out, "api-key"),
205000, 32000, "Qwen3.8-Flash-Next Unsloth (local, 262K)")
art["model"] = "flash-unsloth/qwen3.8-flash-next-unsloth"
with open(self.art, "w") as f:
f.write(json.dumps(art))
template = pathlib.Path(self.out, "chat-template-flash-unsloth.jinja")
for default, level in (("lean", "minimal"), ("xhigh", "xhigh")):
with self.subTest(default=default):
template.write_text("{%- set e = reasoning_effort|default('" + default + "') %}\n")
self.gen()
models, settings = self.read_pi()
self.assertEqual(settings["modelThinkingLevels"]["flash-unsloth/qwen3.8-flash-next-unsloth"], "off")
entry = models["providers"]["flash-unsloth"]["models"][0]
self.assertEqual(entry["input"], ["text"])
self.assertNotIn("inputLimits", entry)
omp_models, _ = self.read_omp()
omp_entry = omp_models["providers"]["flash-unsloth"]["models"][0]
self.assertEqual(omp_entry["thinking"], {"mode": "effort", "efforts": ["minimal", "low", "medium", "xhigh"],
"defaultLevel": level})
self.assertEqual(omp_entry["compat"]["reasoningEffortMap"], {"minimal": "lean"})
def test_ornith_is_sent_its_levels_as_they_are_starts_at_high_and_takes_images(self):
# Ornith's template reads enable_thinking alone: the proxy turns none and minimal off and every
# other level on (keepalive-proxy.py, ornith_effort), so pi sends its levels as they are, its off
# as none; Kolibri's map sent its minimal as low, which the proxy kept whole (found in review,
# 2026-10-22)
art = json.loads(json.dumps(ARTIFACT))
art["provider"]["ornith-122b"] = {
"options": {"baseURL": "http://127.0.0.1:30001/v1", "apiKey": "{file:/keys/api-key}"},
"models": {"ornith-1.5-122b": {"name": "Ornith 1.5 122B NVFP4 + MTP (local, 1M)",
"limit": {"context": 990000, "input": 990000, "output": 32000},
"variants": {"high": {}, "none": {}},
"attachment": True,
"modalities": {"input": ["text", "image"], "output": ["text"]}}}}
art["model"] = "ornith-122b/ornith-1.5-122b"
with open(self.art, "w") as f:
f.write(json.dumps(art))
self.gen()
models, settings = self.read_pi()
entry = models["providers"]["ornith-122b"]["models"][0]
self.assertEqual(entry["compat"], {"supportsDeveloperRole": False, "supportsReasoningEffort": True})
self.assertEqual(entry["thinkingLevelMap"], {"off": "none"})
self.assertEqual(entry["input"], ["text", "image"])
self.assertEqual(settings["modelThinkingLevels"]["ornith-122b/ornith-1.5-122b"], "high")
def test_lfm25_offers_the_one_level_its_template_holds_and_sends_none(self):
"""The Liquid AI LFM2.5 24B-A2B lane's template reasons on every request and reads no level and no switch (its
chat_template.jinja at the pinned revision): pi offered all its levels on it, off first, and started there."""
prov = json.loads(subprocess.run([sys.executable, str(REPO / "oc-lfm25.py"), "http://127.0.0.1:30001/v1",
"/keys/api-key", "74000", "32000", "LFM2.5 (local, 131K)"],
capture_output=True, text=True, check=True).stdout)
art = json.loads(json.dumps(ARTIFACT))
art["provider"].update(prov["provider"])
art["model"] = "lfm25/lfm2.5-24b-a2b"
with open(self.art, "w") as f:
f.write(json.dumps(art))
self.gen()
models, settings = self.read_pi()
entry = models["providers"]["lfm25"]["models"][0]
self.assertTrue(entry["reasoning"])
# pi 1.2.0's getSupportedThinkingLevels, ported: a level mapped to null is hidden, xhigh and max need a mapping
levels = ["off", "minimal", "low", "medium", "high", "xhigh", "max"]
tlm = entry.get("thinkingLevelMap") or {}
shown = [lvl for lvl in levels if not (lvl in tlm and tlm[lvl] is None)
and (lvl not in ("xhigh", "max") or lvl in tlm)]
self.assertEqual(shown, ["high"])
self.assertEqual(settings["modelThinkingLevels"]["lfm25/lfm2.5-24b-a2b"], "high")
# no field sent: pi's OpenAI dialect sends reasoning_effort only with supportsReasoningEffort, which it
# otherwise detects as true for a provider it does not know
self.assertIs(entry["compat"]["supportsReasoningEffort"], False)
# the other lanes as before
self.assertEqual(settings["modelThinkingLevels"]["qwen38/qwen3.8-27b"], "off")
self.assertNotIn("thinkingLevelMap", models["providers"]["qwen38"]["models"][0])
omp_models, _ = self.read_omp()
omp_entry = omp_models["providers"]["lfm25"]["models"][0]
self.assertEqual(omp_entry["thinking"], {"mode": "effort", "efforts": ["high"], "defaultLevel": "high"})
self.assertNotIn("qwenTemplateReasoningEffort", omp_entry["compat"])
self.assertNotIn("thinkingLevelMap", omp_entry)
def test_idempotent(self):
self.gen()
again = self.gen()
self.assertNotIn("wrote", again.stdout)
def test_the_documented_command_runs(self):
"""The README and docs/pi.md run it as ./pi-gen.py, which a file committed without
its execute bit answered with Permission denied (found on the reference box, 2026-10-06)."""
self.assertTrue(os.access(GEN, os.X_OK), "pi-gen.py is not executable")
def test_no_artifact_is_quiet_success(self):
r = run(["--config", os.path.join(self.tmp.name, "none.json"), "--out", self.out])
self.assertEqual(r.returncode, 0)
self.assertFalse(os.path.exists(self.out))
def test_foreign_artifact_writes_nothing(self):
art = os.path.join(self.tmp.name, "foreign.json")
with open(art, "w") as f:
f.write('{"provider": {"other": {}}, "model": "other/x"}')
r = run(["--config", art, "--out", self.out])
self.assertEqual(r.returncode, 0)
self.assertNotIn("wrote", r.stdout)
def test_a_model_without_tiers_still_speaks_the_sglang_dialect(self):
art = json.loads(json.dumps(ARTIFACT))
del art["provider"]["qwen38"]["models"]["qwen3.8-27b"]["variants"]
with open(self.art, "w") as f:
f.write(json.dumps(art))
self.gen()
omp_models, _ = self.read_omp()
entry = omp_models["providers"]["qwen38"]["models"][0]
self.assertNotIn("thinking", entry)
self.assertEqual(entry["compat"], {"thinkingFormat": "qwen-chat-template"})
def test_a_key_path_with_a_space_is_quoted_for_the_shell(self):
# both agents run the !command in a shell
art = json.loads(json.dumps(ARTIFACT))
art["provider"]["qwen38"]["options"]["apiKey"] = "{file:/home/my user/api-key}"
with open(self.art, "w") as f:
f.write(json.dumps(art))
self.gen()
models, _ = self.read_pi()
self.assertEqual(models["providers"]["qwen38"]["apiKey"], "!cat '/home/my user/api-key'")
with open(os.path.join(self.out, "omp", "models.yml")) as f:
self.assertIn('apiKey: "!cat \'/home/my user/api-key\'"', f.read())
def test_key_line_is_quoted(self):
# A plain scalar may not start with '!': unquoted, the !cat key is a
# YAML tag, not a string, and omp would misread the provider. The
# reader above would shrug at that; the byte on disk cannot.
self.gen()
with open(os.path.join(self.out, "omp", "models.yml")) as f:
self.assertIn('apiKey: "!cat /keys/api-key"', f.read())
def load(name, path):
spec = importlib.util.spec_from_file_location(name, path)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod
class TheDocSaysWhatEachLaneIsSent(unittest.TestCase):
"""docs/pi.md has a line for each lane pi sends its effort field to (EFFORT_FIELD), under its family's name
(Kolibri, Nemotron, Ornith), with the levels pi-gen.py maps and the one pi starts at: Ornith 1.5 122B had its
table in pi-gen.py and no line in the page (found 2026-11-10)."""
def test_every_lane_of_effort_field(self):
gen = load("pi_gen_for_its_doc", GEN)
reg = load("lane_registry_for_pi_doc", REPO / "lane_registry.py")
page = (REPO / "docs" / "pi.md").read_text()
section = page[page.index("## Reasoning effort"):]
section = section[:section.index("\n## ", 1)]
bullets = re.findall(r"^- \*\*([^*]+)\*\*(.*)$", section, re.M)
self.assertGreaterEqual(len(bullets), 3, section)
for prov, (level_map, start) in gen.EFFORT_FIELD.items():
with self.subTest(prov):
title = next(f["title"] for f in reg.LANES.values() if f["provider"] == prov)
family = re.sub(r"-\d+$", "", title.split()[0])
said = [rest for name, rest in bullets if name.startswith(family)]
self.assertEqual(len(said), 1, f"docs/pi.md has {len(said)} lines for {family} ({prov}), one expected")
for frm, to in level_map.items():
self.assertIn(f"`{frm}` to `{to}`", said[0])
# pi's: omp's start, in the same line, is said "starts at" alone
self.assertIn(f"its level starts at `{start}`", said[0])
class AnUpdateRegeneratesThemToo(unittest.TestCase):
"""install.sh regenerates pi's and omp's files as switch-model.sh does after a switch (block
4f): v1.30.0's update changed Kolibri's pair in opencode.json and left pi's models.json at the
old one until the next switch (found 2026-10-14)."""
BLOCK = ('if [ -d "$CONFIG_DIR/pi" ] || [ -d "$CONFIG_DIR/omp" ]; then\n'
' python3 "$REPO_DIR/pi-gen.py" --config "$CONFIG_DIR/opencode.json" --out "$CONFIG_DIR" \\\n')
def test_install_and_the_switch_run_it_the_same_way(self):
for script in ("install.sh", "switch-model.sh"):
with self.subTest(script):
self.assertEqual((REPO / script).read_text().count(self.BLOCK), 1)
def test_install_runs_it_once_opencode_json_is_written(self):
text = (REPO / "install.sh").read_text()
at = text.index(self.BLOCK)
self.assertLess(text.rindex('python3 "$REPO_DIR/oc-point-default.py" "$CONFIG_DIR/opencode.json"'), at,
"after the last write of the artifact it reads")
self.assertLess(at, text.index('echo "opencode-web.service restarted so it reads the new limits"'))
if __name__ == "__main__":
unittest.main()