A plain install is unchanged: LAN-only, dashboard behind the API key. `llmhost install-newt` is the upgrade path. It installs a pinned, sha256-checked newt as a third user service and switches the dashboard to an OIDC authorization-code + PKCE sign-in limited to allowed groups or users. The API still takes the key. Secrets live in 0600 files, never in config.json, a service file or argv. `llmhost remove-newt` undoes it; setup/update keep it; `logs --newt` shows the tunnel (and `logs -f` now follows the service it was asked for). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.9 KiB
Python
76 lines
2.9 KiB
Python
"""Shared bits for the suites: repo-relative imports, a sandbox, and a check() counter.
|
|
|
|
Each suite is a plain script: run it directly, or run them all with `python3 tests/run.py`.
|
|
Stdlib only, like the rest of llm-host.
|
|
|
|
Every suite sandboxes LLMHOST_HOME / LLMHOST_CONFIG / XDG_* before importing llmhost, so
|
|
nothing touches a real install. setup() asserts that, because a suite that forgot
|
|
LLMHOST_HOME once deleted a live install's data directory.
|
|
"""
|
|
import json
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
REPO = Path(__file__).resolve().parents[1]
|
|
FIXTURES = Path(__file__).resolve().parent / "fixtures"
|
|
|
|
|
|
def setup():
|
|
"""Point every path llmhost writes to at a fresh temp dir. Returns its root."""
|
|
root = tempfile.mkdtemp(prefix="llmhost-test-")
|
|
os.environ["LLMHOST_HOME"] = root + "/.local/share/llm-host"
|
|
os.environ["LLMHOST_CONFIG"] = root + "/.config/llm-host"
|
|
os.environ["XDG_CONFIG_HOME"] = root + "/.config"
|
|
os.environ["XDG_DATA_HOME"] = root + "/.local/share"
|
|
sys.path.insert(0, str(REPO))
|
|
return root
|
|
|
|
|
|
def guard(paths, root):
|
|
"""Move the paths no env var covers into the sandbox, then abort unless everything
|
|
llmhost could write or delete is inside it.
|
|
|
|
LLMHOST_HOME and LLMHOST_CONFIG redirect most of it, but BIN_DIR/SHIM come off
|
|
Path.home() with no override, so they are repointed here -- once, for every suite,
|
|
rather than per test. The assertion is the real safety net: a suite that forgot
|
|
LLMHOST_HOME once deleted a live install's data directory."""
|
|
paths.BIN_DIR = Path(root) / ".local/bin"
|
|
paths.SHIM = paths.BIN_DIR / "llmhost"
|
|
paths.LOG_DIR = Path(root) / "logs"
|
|
for name in ("DATA", "CONFIG_DIR", "CONFIG_FILE", "KEY_FILE", "OIDC_SECRET_FILE", "NEWT_SECRET_FILE", "NEWT_DIR", "BIN_DIR", "SHIM", "LOG_DIR"):
|
|
value = str(getattr(paths, name))
|
|
if not value.startswith(root):
|
|
sys.exit(f"ABORT: paths.{name} = {value} is outside the sandbox {root}")
|
|
|
|
|
|
def config():
|
|
"""The planned-models fixture: a real `llmhost setup` result, machine bits pinned."""
|
|
return json.loads((FIXTURES / "config.json").read_text())
|
|
|
|
|
|
class Checks:
|
|
def __init__(self):
|
|
self.failed = []
|
|
self.passed = 0
|
|
|
|
def __call__(self, label, cond, extra=""):
|
|
if cond:
|
|
self.passed += 1
|
|
print(" ok " + label)
|
|
else:
|
|
self.failed.append(label)
|
|
print(" FAIL " + label + ((" <- " + str(extra)) if extra else ""))
|
|
return bool(cond)
|
|
|
|
def section(self, title):
|
|
print("\n" + title)
|
|
|
|
def done(self, root=None):
|
|
if root:
|
|
shutil.rmtree(root, ignore_errors=True)
|
|
print("\n" + (f"ALL PASS ({self.passed} checks)" if not self.failed
|
|
else f"{len(self.failed)} FAILURES of {self.passed + len(self.failed)}: {self.failed}"))
|
|
sys.exit(1 if self.failed else 0)
|