CF_ORCH_URL makes sense internally but isn't self-explanatory for a local-first user setting up their own GPU rig. Follows the GPU_SERVER_URL convention Kiwi already established (app/core/config.py there). - app/config.py: resolves GPU_SERVER_URL -> CF_ORCH_URL (back-compat alias) -> https://orch.circuitforge.tech default when CF_LICENSE_KEY is present (Paid+ tiers). Written back to os.environ["CF_ORCH_URL"] so existing callers (get_llm_config, app/api/chat.py) needed zero changes. - .env.example / .env.cloud.example: document GPU_SERVER_URL as the primary name, CF_ORCH_URL noted as a still-honoured legacy alias. - compose.cloud.yml: the hardcoded coordinator URL now sets GPU_SERVER_URL instead of CF_ORCH_URL directly (relies on the same config.py normalization). - docs/reference/environment-variables.md updated. - 6 new tests covering the resolution priority chain and the write-back behavior legacy callers depend on. Closes: #10
86 lines
2.4 KiB
Python
86 lines
2.4 KiB
Python
# tests/test_config.py
|
|
"""Unit tests for the GPU_SERVER_URL / CF_ORCH_URL resolution in app/config.py.
|
|
|
|
app/config.py resolves GPU_SERVER_URL at *module import time* (module-level
|
|
code, not a function), so each test reloads the module after adjusting env
|
|
vars via monkeypatch, then reloads it again afterward with the real
|
|
environment restored so later tests see normal module state.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
|
|
import pytest
|
|
|
|
import app.config as config
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _restore_config_module():
|
|
yield
|
|
importlib.reload(config)
|
|
|
|
|
|
def _clear_orch_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.delenv("GPU_SERVER_URL", raising=False)
|
|
monkeypatch.delenv("CF_ORCH_URL", raising=False)
|
|
monkeypatch.delenv("CF_LICENSE_KEY", raising=False)
|
|
|
|
|
|
def test_gpu_server_url_prefers_explicit_env_var(monkeypatch):
|
|
_clear_orch_env(monkeypatch)
|
|
monkeypatch.setenv("GPU_SERVER_URL", "http://my-rig:7700")
|
|
monkeypatch.setenv("CF_ORCH_URL", "http://should-be-ignored:7700")
|
|
|
|
importlib.reload(config)
|
|
|
|
assert config.GPU_SERVER_URL == "http://my-rig:7700"
|
|
|
|
|
|
def test_gpu_server_url_falls_back_to_cf_orch_url_legacy_alias(monkeypatch):
|
|
_clear_orch_env(monkeypatch)
|
|
monkeypatch.setenv("CF_ORCH_URL", "http://legacy-coordinator:7700")
|
|
|
|
importlib.reload(config)
|
|
|
|
assert config.GPU_SERVER_URL == "http://legacy-coordinator:7700"
|
|
|
|
|
|
def test_gpu_server_url_defaults_when_license_key_present(monkeypatch):
|
|
_clear_orch_env(monkeypatch)
|
|
monkeypatch.setenv("CF_LICENSE_KEY", "test-key-123")
|
|
|
|
importlib.reload(config)
|
|
|
|
assert config.GPU_SERVER_URL == "https://orch.circuitforge.tech"
|
|
|
|
|
|
def test_gpu_server_url_none_when_nothing_set(monkeypatch):
|
|
_clear_orch_env(monkeypatch)
|
|
|
|
importlib.reload(config)
|
|
|
|
assert config.GPU_SERVER_URL is None
|
|
|
|
|
|
def test_gpu_server_url_writes_back_to_cf_orch_url_for_legacy_callers(monkeypatch):
|
|
"""get_llm_config() and app/api/chat.py read os.environ["CF_ORCH_URL"] directly —
|
|
the write-back must happen so they keep working without code changes."""
|
|
import os
|
|
|
|
_clear_orch_env(monkeypatch)
|
|
monkeypatch.setenv("GPU_SERVER_URL", "http://my-rig:7700")
|
|
|
|
importlib.reload(config)
|
|
|
|
assert os.environ.get("CF_ORCH_URL") == "http://my-rig:7700"
|
|
|
|
|
|
def test_gpu_server_url_unset_does_not_write_back(monkeypatch):
|
|
import os
|
|
|
|
_clear_orch_env(monkeypatch)
|
|
|
|
importlib.reload(config)
|
|
|
|
assert "CF_ORCH_URL" not in os.environ
|