Files
alzeo/dashboard/tests/test_cockpit_opencode_config.py
T
Hasan Basbunar e2f1f324b6 cockpit redesign: the one-page front, its tests, and the one-click load
The monolithic app.js and the tab <select> become a rail of views:
index.html plus css/cockpit.css and nine scripts sharing one scope
(base, now, lanes, ops, agent, decide, image, video, boot). Every
regression the swap left behind is fixed here, not papered over.

The one-click lane change (the point of the redesign): the page walks
switch, stop, start as one journey, one job per step, stopping at the
first gate that refuses. In dry run the state never moves, so the wait
for the engine to go down was a 90 s stall against a wall; dry run now
skips that wait and the sheet says up front that a later gate can
refuse because the box still reads as it was.

Tests that read app.js read the page the browser loads instead:
pagejs concatenates the nine scripts in the order index.html asks for
them, and the CI target step reads LANE_TARGETS from base.js, the one
list the UI actually keeps. No assertion was weakened or deleted to
get here; the app.js readers were moved to the new markup, and the
video journal gained an end-to-end class over the real 12-minute
journal captured 2026-09-29.

House style reached the new files before they were tracked: five en
dashes in ops.js became the ellipsis the rest of the page already
uses for no-data cells.

Held by: ci-local 40 ok 0 fail (5 skip = missing packages on this
runner), ruff F/E9 clean, page tests 4/4, mobile-check 184/184 on four
iPhone viewports against this front, monkey 58/58, lifecycle mutation
93.4% over the 91% floor.
2026-09-30 12:00:59 +02:00

70 lines
2.7 KiB
Python

"""The Settings tab reads opencode's config the way opencode does.
collect_opencode() read it with json.loads: a config with a comment or a trailing comma,
which opencode reads (jsonc-parser), came out unreadable, and an unreadable one showed as
empty ("none", "not declared") on the page (found in review, 2026-09-24). This loads the
real cockpit with COCKPIT_DRY_RUN=1, a throwaway config dir and a throwaway HOME."""
import importlib.util
import os
import shutil
import sys
import tempfile
import unittest
from pathlib import Path
HERE = Path(__file__).resolve()
DASH = HERE.parents[1]
REPO = HERE.parents[2]
COMMENTED = """{
// the lane the installer points at
"model": "qwen38/qwen3.8-27b",
"provider": {
"qwen38": {"models": {"qwen3.8-27b": {"limit": {"context": 559000, "output": 186000},},},},
},
}
"""
class TheConfigAsOpencodeReadsIt(unittest.TestCase):
@classmethod
def setUpClass(cls):
env, path = dict(os.environ), list(sys.path)
cls.addClassCleanup(lambda: (os.environ.clear(), os.environ.update(env), sys.path.__setitem__(slice(None), path)))
cls.tmp = Path(tempfile.mkdtemp(prefix="cockpit-oc-"))
cls.addClassCleanup(shutil.rmtree, cls.tmp, True)
(cls.tmp / "cfg").mkdir()
(cls.tmp / "cfg" / "api-key").write_text("k\n")
os.environ.update(HOME=str(cls.tmp), COCKPIT_DRY_RUN="1", COCKPIT_CONFIG_DIR=str(cls.tmp / "cfg"),
COCKPIT_REPO_DIR=str(REPO), COCKPIT_PORT="0", COCKPIT_AGENT_PORT="0", COCKPIT_AUTOHEAL="0")
sys.path.insert(0, str(DASH))
spec = importlib.util.spec_from_file_location("cockpit_oc_config_under_test", DASH / "cockpit.py")
cls.cp = importlib.util.module_from_spec(spec)
spec.loader.exec_module(cls.cp)
cls.real = cls.tmp / ".config" / "opencode" / "opencode.json"
cls.real.parent.mkdir(parents=True)
def collect(self, text):
self.real.write_text(text)
out = self.cp.collect_opencode()
return out.get("data", out)["real"]
def test_comments_and_trailing_commas_are_read(self):
real = self.collect(COMMENTED)
self.assertNotIn("error", real)
self.assertEqual(real["default"], "qwen38/qwen3.8-27b")
self.assertEqual(real["limits"]["qwen38/qwen3.8-27b"], {"context": 559000, "output": 186000})
def test_a_config_that_does_not_parse_says_so(self):
real = self.collect('{"model": ')
self.assertIn("error", real)
self.assertIsNone(real["default"])
def test_a_config_that_is_not_an_object_says_so(self):
real = self.collect("[1, 2]")
self.assertIn("not a JSON object", real["error"])
if __name__ == "__main__":
unittest.main(verbosity=2)