Homepage (TDD slice 3): the real services.json + schema tests
Red tests first (the old services.json was an object, not the new list schema). - tests/homepage_config.bats: the config is a JSON list; every entry has name/category/probe; category is user|admin; method is tcp|http; a showLink entry has a url and a status-only entry does not. - shared/homepage/services.json: the real fleet. User: SearXNG, ComfyUI, OpenWebUI, Gitea, Calibre-Web, RomM, Copyparty, Plex, Jellyfin. Admin: Hermes, Grafana, Prometheus, Loki, node-exporter, alloy, Caddy, dnsmasq, Gluetun (wip - a tunnel has no simple local port), the two LLMs, mariadb, valkey, Postgres. Ports confirmed from the repo config (compose/quadlet). docs fields are empty for now (the /docs/ workstream fills them as each service goes active).
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bats
|
||||
# Seam: shared/homepage/services.json — the service config the checker reads
|
||||
# and the pages render. It must be a JSON list; every entry carries name,
|
||||
# category, and a host:port probe. category is user or admin. method, when
|
||||
# present, is tcp or http.
|
||||
|
||||
load helpers
|
||||
|
||||
@test "services.json: valid schema" {
|
||||
python3 - "$REPO_ROOT/shared/homepage/services.json" <<'PY'
|
||||
import json, sys
|
||||
path = sys.argv[1]
|
||||
try:
|
||||
data = json.load(open(path))
|
||||
except FileNotFoundError:
|
||||
sys.exit("services.json not found")
|
||||
assert isinstance(data, list), "top level must be a list"
|
||||
assert data, "the list must not be empty"
|
||||
for svc in data:
|
||||
for field in ("name", "category", "probe"):
|
||||
assert field in svc, f"{svc.get('name', '?')} is missing {field}"
|
||||
assert svc["category"] in ("user", "admin"), svc["category"]
|
||||
if "method" in svc:
|
||||
assert svc["method"] in ("tcp", "http"), svc["method"]
|
||||
host, _, port = svc["probe"].rpartition(":")
|
||||
assert host and port.isdigit(), f"bad probe {svc['probe']}"
|
||||
PY
|
||||
}
|
||||
|
||||
@test "services.json: every user service has an Open link, status-only backends do not" {
|
||||
python3 - "$REPO_ROOT/shared/homepage/services.json" <<'PY'
|
||||
import json, sys
|
||||
data = json.load(open(sys.argv[1]))
|
||||
for svc in data:
|
||||
show = svc.get("showLink", True)
|
||||
if show:
|
||||
assert svc.get("url"), f"{svc['name']} shows a link but has no url"
|
||||
else:
|
||||
assert not svc.get("url"), f"{svc['name']} is status-only but has a url"
|
||||
PY
|
||||
}
|
||||
Reference in New Issue
Block a user