Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions ods/extensions/services/dashboard-api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,20 @@ def _load_core_service_ids() -> frozenset:
core_ids_path = Path(INSTALL_DIR) / "config" / "core-service-ids.json"
if core_ids_path.exists():
try:
return frozenset(json.loads(core_ids_path.read_text(encoding="utf-8")))
except (json.JSONDecodeError, OSError):
pass
payload = json.loads(core_ids_path.read_text(encoding="utf-8"))
if (
not isinstance(payload, list)
or not payload
or any(not isinstance(item, str) or not item for item in payload)
):
raise ValueError("core service IDs must be a non-empty string list")
return frozenset(payload)
except (json.JSONDecodeError, OSError, ValueError) as exc:
logger.warning(
"Invalid core service ID registry at %s: %s; using defaults",
core_ids_path,
exc,
)
# Fallback to hardcoded list
return frozenset({
"dashboard-api", "dashboard", "llama-server", "model-router", "open-webui",
Expand Down
26 changes: 26 additions & 0 deletions ods/extensions/services/dashboard-api/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ def test_extension_catalog_skips_non_object_entries(monkeypatch, tmp_path):
monkeypatch.setattr(config, "CATALOG_PATH", catalog)

assert config.load_extension_catalog() == [valid]
def test_core_service_ids_load_valid_registry(monkeypatch, tmp_path):
registry = tmp_path / "config" / "core-service-ids.json"
registry.parent.mkdir()
registry.write_text(
json.dumps(["custom-core", "dashboard"]), encoding="utf-8"
)
monkeypatch.setattr(config, "INSTALL_DIR", str(tmp_path))

assert config._load_core_service_ids() == frozenset({
"custom-core", "dashboard",
})


@pytest.mark.parametrize("payload", [{"dashboard": True}, [], [None], "dashboard"])
def test_core_service_ids_fall_back_for_invalid_registry(
monkeypatch, tmp_path, payload
):
registry = tmp_path / "config" / "core-service-ids.json"
registry.parent.mkdir()
registry.write_text(json.dumps(payload), encoding="utf-8")
monkeypatch.setattr(config, "INSTALL_DIR", str(tmp_path))

loaded = config._load_core_service_ids()

assert "dashboard-api" in loaded
assert "llama-server" in loaded


class TestReadManifestFile:
Expand Down
Loading