refactor: Align vocabulary — component → program / deployment
Canonical terms (see docs/registry.md glossary): - program: any catalog entry (tool/daemon/frontend) — the software - service / job: how a program is deployed (systemd .service / .timer) - deployment: umbrella for the unified service+job+program view Changes: - core: ServiceSpec/JobSpec component: → program: (component accepted as back-compat validation_alias); DeployedComponent → Deployment. - api: ComponentSummary/Detail → DeploymentSummary/Detail; GET /components → /deployments; GatewayRoute.component → program; GatewayInfo .component_count → deployment_count; ServiceActionResponse/action keys component → program. - app: matching type renames, /components → /deployments hook, route /component/:name → /deployment/:name, GatewayRoute.program. - docs: component-registry.md → registry.md (+ canonical glossary); CLAUDE.md endpoint list refreshed (drop removed /tools, add typed program/service/job + config routes). Tests: core 92, cli 24, api 52 green; app build clean; ruff clean.
This commit is contained in:
@@ -23,7 +23,7 @@ def castle_root(tmp_path: Path) -> Generator[Path, None, None]:
|
||||
},
|
||||
"services": {
|
||||
"test-svc": {
|
||||
"component": "test-svc-comp",
|
||||
"program": "test-svc-comp",
|
||||
"description": "Test service",
|
||||
"run": {
|
||||
"runner": "python",
|
||||
|
||||
@@ -6,7 +6,7 @@ from __future__ import annotations
|
||||
import pytest
|
||||
|
||||
from castle_core.generators.caddyfile import generate_caddyfile_from_registry
|
||||
from castle_core.registry import DeployedComponent, NodeConfig, NodeRegistry
|
||||
from castle_core.registry import Deployment, NodeConfig, NodeRegistry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -22,7 +22,7 @@ def _isolate_config(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
|
||||
|
||||
def _make_registry(
|
||||
deployed: dict[str, DeployedComponent] | None = None,
|
||||
deployed: dict[str, Deployment] | None = None,
|
||||
gateway_port: int = 9000,
|
||||
) -> NodeRegistry:
|
||||
"""Create a test registry."""
|
||||
@@ -45,7 +45,7 @@ class TestCaddyfileFromRegistry:
|
||||
"""Caddyfile has reverse proxy routes for deployed services."""
|
||||
registry = _make_registry(
|
||||
deployed={
|
||||
"test-svc": DeployedComponent(
|
||||
"test-svc": Deployment(
|
||||
runner="python",
|
||||
run_cmd=["uv", "run", "test-svc"],
|
||||
port=19000,
|
||||
@@ -61,7 +61,7 @@ class TestCaddyfileFromRegistry:
|
||||
"""Components without proxy_path are not in Caddyfile."""
|
||||
registry = _make_registry(
|
||||
deployed={
|
||||
"test-tool": DeployedComponent(
|
||||
"test-tool": Deployment(
|
||||
runner="command",
|
||||
run_cmd=["test-tool"],
|
||||
),
|
||||
@@ -81,7 +81,7 @@ class TestCaddyfileFromRegistry:
|
||||
"""Service proxy routes appear before the dashboard catch-all."""
|
||||
registry = _make_registry(
|
||||
deployed={
|
||||
"test-svc": DeployedComponent(
|
||||
"test-svc": Deployment(
|
||||
runner="python",
|
||||
run_cmd=["uv", "run", "test-svc"],
|
||||
port=19000,
|
||||
@@ -98,13 +98,13 @@ class TestCaddyfileFromRegistry:
|
||||
"""Multiple services get separate proxy routes."""
|
||||
registry = _make_registry(
|
||||
deployed={
|
||||
"svc-a": DeployedComponent(
|
||||
"svc-a": Deployment(
|
||||
runner="python",
|
||||
run_cmd=["uv", "run", "svc-a"],
|
||||
port=9001,
|
||||
proxy_path="/svc-a",
|
||||
),
|
||||
"svc-b": DeployedComponent(
|
||||
"svc-b": Deployment(
|
||||
runner="python",
|
||||
run_cmd=["uv", "run", "svc-b"],
|
||||
port=9002,
|
||||
@@ -126,14 +126,14 @@ class TestCaddyfileRemoteRegistries:
|
||||
"""Remote services get reverse_proxy entries to their hostname."""
|
||||
local = _make_registry(
|
||||
deployed={
|
||||
"local-svc": DeployedComponent(
|
||||
"local-svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9001, proxy_path="/local"
|
||||
),
|
||||
}
|
||||
)
|
||||
remote = _make_registry(
|
||||
deployed={
|
||||
"remote-svc": DeployedComponent(
|
||||
"remote-svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9050, proxy_path="/remote"
|
||||
),
|
||||
}
|
||||
@@ -148,14 +148,14 @@ class TestCaddyfileRemoteRegistries:
|
||||
"""If local and remote use the same path, local wins."""
|
||||
local = _make_registry(
|
||||
deployed={
|
||||
"svc": DeployedComponent(
|
||||
"svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9001, proxy_path="/api"
|
||||
),
|
||||
}
|
||||
)
|
||||
remote = _make_registry(
|
||||
deployed={
|
||||
"svc": DeployedComponent(
|
||||
"svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9001, proxy_path="/api"
|
||||
),
|
||||
}
|
||||
@@ -169,7 +169,7 @@ class TestCaddyfileRemoteRegistries:
|
||||
"""No remote routes when remote_registries is None."""
|
||||
local = _make_registry(
|
||||
deployed={
|
||||
"svc": DeployedComponent(
|
||||
"svc": Deployment(
|
||||
runner="python", run_cmd=["svc"], port=9001, proxy_path="/api"
|
||||
),
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class TestLoadConfig:
|
||||
"""Service references a component."""
|
||||
config = load_config(castle_root)
|
||||
svc = config.services["test-svc"]
|
||||
assert svc.component == "test-svc-comp"
|
||||
assert svc.program == "test-svc-comp"
|
||||
|
||||
def test_job_schedule(self, castle_root: Path) -> None:
|
||||
"""Job has correct schedule."""
|
||||
|
||||
@@ -7,11 +7,11 @@ from unittest.mock import patch
|
||||
|
||||
from castle_core import deploy as deploy_mod
|
||||
from castle_core.deploy import _desired_unit_files, _prune_orphans
|
||||
from castle_core.registry import DeployedComponent, NodeConfig, NodeRegistry
|
||||
from castle_core.registry import Deployment, NodeConfig, NodeRegistry
|
||||
|
||||
|
||||
def _svc(managed: bool = True, schedule: str | None = None) -> DeployedComponent:
|
||||
return DeployedComponent(
|
||||
def _svc(managed: bool = True, schedule: str | None = None) -> Deployment:
|
||||
return Deployment(
|
||||
runner="python",
|
||||
run_cmd=["x"],
|
||||
env={},
|
||||
@@ -20,7 +20,7 @@ def _svc(managed: bool = True, schedule: str | None = None) -> DeployedComponent
|
||||
)
|
||||
|
||||
|
||||
def _registry(**deployed: DeployedComponent) -> NodeRegistry:
|
||||
def _registry(**deployed: Deployment) -> NodeRegistry:
|
||||
return NodeRegistry(node=NodeConfig(castle_root="/x", gateway_port=9000), deployed=dict(deployed))
|
||||
|
||||
|
||||
|
||||
@@ -82,10 +82,10 @@ class TestServiceSpec:
|
||||
"""Service can reference a component."""
|
||||
s = ServiceSpec(
|
||||
id="svc",
|
||||
component="my-component",
|
||||
program="my-component",
|
||||
run=RunPython(runner="python", program="svc"),
|
||||
)
|
||||
assert s.component == "my-component"
|
||||
assert s.program == "my-component"
|
||||
|
||||
def test_service_with_proxy(self) -> None:
|
||||
"""Service with proxy spec."""
|
||||
@@ -139,11 +139,11 @@ class TestJobSpec:
|
||||
"""Job can reference a component."""
|
||||
j = JobSpec(
|
||||
id="sync",
|
||||
component="protonmail",
|
||||
program="protonmail",
|
||||
run=RunCommand(runner="command", argv=["protonmail", "sync"]),
|
||||
schedule="*/5 * * * *",
|
||||
)
|
||||
assert j.component == "protonmail"
|
||||
assert j.program == "protonmail"
|
||||
|
||||
def test_job_requires_schedule(self) -> None:
|
||||
"""Job without schedule is invalid."""
|
||||
|
||||
@@ -7,7 +7,7 @@ from castle_core.generators.systemd import (
|
||||
generate_unit_from_deployed,
|
||||
unit_name,
|
||||
)
|
||||
from castle_core.registry import DeployedComponent
|
||||
from castle_core.registry import Deployment
|
||||
|
||||
|
||||
class TestUnitName:
|
||||
@@ -24,7 +24,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_contains_description(self) -> None:
|
||||
"""Unit file has service description."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={"TEST_SVC_PORT": "19000"},
|
||||
@@ -35,7 +35,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_no_working_directory(self) -> None:
|
||||
"""Unit file has no WorkingDirectory (source/runtime separation)."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={},
|
||||
@@ -46,7 +46,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_contains_environment(self) -> None:
|
||||
"""Unit file has environment variables from deployed config."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={"TEST_SVC_DATA_DIR": "/home/user/.castle/data/test-svc"},
|
||||
@@ -57,7 +57,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_contains_restart_policy(self) -> None:
|
||||
"""Unit file has restart configuration."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={},
|
||||
@@ -68,7 +68,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_exec_start_from_run_cmd(self) -> None:
|
||||
"""Unit file ExecStart uses resolved run_cmd."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "test-svc"],
|
||||
env={},
|
||||
@@ -79,7 +79,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_basic_service(self) -> None:
|
||||
"""Generate a unit from a deployed component."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "my-svc"],
|
||||
env={"MY_SVC_PORT": "9001", "MY_SVC_DATA_DIR": "/home/user/.castle/data/my-svc"},
|
||||
@@ -95,7 +95,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_scheduled_job(self) -> None:
|
||||
"""Scheduled component generates oneshot unit."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="command",
|
||||
run_cmd=["/home/user/.local/bin/my-job"],
|
||||
env={},
|
||||
@@ -108,7 +108,7 @@ class TestUnitFromDeployed:
|
||||
|
||||
def test_no_repo_paths(self) -> None:
|
||||
"""Generated units must not reference repo paths."""
|
||||
deployed = DeployedComponent(
|
||||
deployed = Deployment(
|
||||
runner="python",
|
||||
run_cmd=["/home/user/.local/bin/uv", "run", "my-svc"],
|
||||
env={"DATA_DIR": "/home/user/.castle/data/my-svc"},
|
||||
|
||||
@@ -76,7 +76,7 @@ class TestUnitExpansion:
|
||||
assert svc.expose.http.health_path == "/health"
|
||||
assert svc.proxy.caddy.path_prefix == "/my-svc"
|
||||
assert svc.manage.systemd is not None
|
||||
assert svc.component == "my-svc"
|
||||
assert svc.program == "my-svc"
|
||||
|
||||
def test_tool_creates_program_only(self, units_root: Path) -> None:
|
||||
config = load_config(units_root)
|
||||
@@ -108,7 +108,7 @@ class TestUnitExpansion:
|
||||
assert job.run.runner == "command"
|
||||
assert job.run.argv == ["my-job", "run"]
|
||||
assert job.defaults.env["DATA_DIR"] == "/tmp/data"
|
||||
assert job.component == "my-job"
|
||||
assert job.program == "my-job"
|
||||
|
||||
def test_service_without_path_prefix(self, tmp_path: Path) -> None:
|
||||
config_data = {
|
||||
|
||||
Reference in New Issue
Block a user