activity-core/tests/test_review_cli_services.py
tegwick 192942244e
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Build and Publish Container Image / build-and-push (push) Successful in 21s
feat(activity): multi-service config, make help default, install-cli
Bare make lists targets. make install-cli installs the activity tool via uv.
Named activity-core backends live in ~/.config/activity/services.json with
list/add/use/default/which; -s/--service selects one call without changing
the default; --activity-url is a one-shot override.
2026-08-06 17:25:54 +02:00

127 lines
4.1 KiB
Python

"""Tests for multi-service activity-core endpoint config."""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from activity_core.review_cli import services as svc
from activity_core.review_cli.main import main
from activity_core.review_cli.sources import (
activity_core_url,
apply_endpoint_overrides,
clear_endpoint_overrides,
state_hub_url,
)
def test_add_list_use_service(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("ACTIVITY_CONFIG_DIR", str(tmp_path))
path = svc.config_path(tmp_path)
cfg = svc.add_service(
"railiance",
activity_core_url="https://activity.coulomb.social/",
state_hub_url="http://127.0.0.1:18000",
description="prod",
make_default=True,
path=path,
)
assert cfg["default"] == "railiance"
assert cfg["services"]["railiance"]["activity_core_url"] == "https://activity.coulomb.social"
svc.add_service(
"local",
activity_core_url="http://127.0.0.1:8010",
path=path,
)
svc.set_default("local", path)
cfg = svc.load_config(path)
assert cfg["default"] == "local"
ep = svc.resolve_endpoints(config_path_override=path)
assert ep["source"] == "default"
assert ep["service"] == "local"
assert ep["activity_core_url"] == "http://127.0.0.1:8010"
ep2 = svc.resolve_endpoints(service="railiance", config_path_override=path)
assert ep2["source"] == "service"
assert ep2["activity_core_url"] == "https://activity.coulomb.social"
assert ep2["state_hub_url"] == "http://127.0.0.1:18000"
ep3 = svc.resolve_endpoints(
service="railiance",
activity_url="http://override:9",
config_path_override=path,
)
assert ep3["source"] == "flag"
assert ep3["activity_core_url"] == "http://override:9"
def test_env_beats_default(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
path = svc.config_path(tmp_path)
svc.add_service(
"railiance",
activity_core_url="https://activity.coulomb.social",
make_default=True,
path=path,
)
monkeypatch.setenv("ACTIVITY_CORE_URL", "http://env-only:8010")
ep = svc.resolve_endpoints(config_path_override=path)
assert ep["source"] == "env"
assert ep["activity_core_url"] == "http://env-only:8010"
def test_service_flag_beats_env(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
path = svc.config_path(tmp_path)
svc.add_service(
"railiance",
activity_core_url="https://activity.coulomb.social",
path=path,
)
monkeypatch.setenv("ACTIVITY_CORE_URL", "http://env-only:8010")
ep = svc.resolve_endpoints(service="railiance", config_path_override=path)
assert ep["source"] == "service"
assert ep["activity_core_url"] == "https://activity.coulomb.social"
def test_apply_endpoint_overrides() -> None:
clear_endpoint_overrides()
apply_endpoint_overrides("http://x:1", "http://y:2")
assert activity_core_url() == "http://x:1"
assert state_hub_url() == "http://y:2"
clear_endpoint_overrides()
def test_cli_service_add_and_which(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
monkeypatch.setenv("ACTIVITY_CONFIG_DIR", str(tmp_path))
code = main(
[
"service",
"add",
"railiance",
"--url",
"https://activity.coulomb.social",
"--hub-url",
"http://127.0.0.1:18000",
"--make-default",
]
)
assert code == 0
capsys.readouterr() # drop add text
code = main(["service", "list", "--format", "json"])
assert code == 0
data = json.loads(capsys.readouterr().out)
assert data["default"] == "railiance"
assert "railiance" in data["services"]
code = main(
["service", "which", "--service", "railiance", "--format", "json"]
)
assert code == 0
which = json.loads(capsys.readouterr().out)
assert which["activity_core_url"] == "https://activity.coulomb.social"
assert which["source"] == "service"