kind is a deployment property, not a program property
A program has no single kind — it HAS deployments, each with its own kind (a
program can be a tool AND a job, e.g. protonmail). Remove program-level kind:
- core: drop ProgramSpec.kind; CastleConfig.kind_of → deployments_of(name) →
[(deployment-name, kind)]; tools property derives from a tool deployment.
- api: ProgramSummary drops kind/services/jobs → deployments: [{name, kind}];
/programs?kind= filters by deployment-kind membership; a program's legacy
DeploymentSummary carries kind=None.
- cli: list/info show a program's set of deployment kinds; --kind filters by
membership.
Also: Services page now covers statics — /services returns kind in
{service, static} (both are exposed, URL-reachable 'services', caddy vs systemd),
and ServiceSummary gains kind + manager to distinguish them.
Suites: core 124, cli 25, castle-api 58.
This commit is contained in:
@@ -45,12 +45,18 @@ class DeploymentDetail(DeploymentSummary):
|
||||
|
||||
|
||||
class ServiceSummary(BaseModel):
|
||||
"""Summary of a service (long-running daemon)."""
|
||||
"""Summary of a service — a systemd daemon OR a caddy-served static site.
|
||||
|
||||
Both are "services" (exposed, URL-reachable things); `kind`/`manager`
|
||||
distinguish them (service+systemd vs static+caddy).
|
||||
"""
|
||||
|
||||
id: str
|
||||
description: str | None = None
|
||||
stack: str | None = None
|
||||
launcher: str | None = None # python|command|container|compose|node
|
||||
kind: str | None = None # service | static
|
||||
manager: str | None = None # systemd | caddy
|
||||
launcher: str | None = None # python|command|container|compose|node (systemd only)
|
||||
run_target: str | None = None # what it runs: program name, argv, image, …
|
||||
port: int | None = None
|
||||
health_path: str | None = None
|
||||
@@ -90,12 +96,22 @@ class JobDetail(JobSummary):
|
||||
manifest: dict
|
||||
|
||||
|
||||
class DeploymentRef(BaseModel):
|
||||
"""A reference to one of a program's deployments (name + its derived kind)."""
|
||||
|
||||
name: str
|
||||
kind: str # service | job | tool | static | reference
|
||||
|
||||
|
||||
class ProgramSummary(BaseModel):
|
||||
"""Summary of a program (software catalog entry)."""
|
||||
"""Summary of a program (software catalog entry).
|
||||
|
||||
A program has NO kind of its own — it *has deployments*, each with a kind
|
||||
(a program can be a tool AND a job). `deployments` is that list.
|
||||
"""
|
||||
|
||||
id: str
|
||||
description: str | None = None
|
||||
kind: str | None = None # derived: service|job|tool|static|reference
|
||||
stack: str | None = None
|
||||
version: str | None = None
|
||||
source: str | None = None
|
||||
@@ -106,8 +122,7 @@ class ProgramSummary(BaseModel):
|
||||
installed: bool | None = None
|
||||
active: bool | None = None # uniform lifecycle state (on PATH / running / served)
|
||||
actions: list[str] = []
|
||||
services: list[str] = [] # services that deploy this program
|
||||
jobs: list[str] = [] # jobs that deploy this program
|
||||
deployments: list[DeploymentRef] = [] # this program's deployments (name + kind)
|
||||
node: str | None = None
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ from castle_api.mesh import mesh_state
|
||||
from castle_api.health import check_all_health
|
||||
from castle_api.models import (
|
||||
DeploymentDetail,
|
||||
DeploymentRef,
|
||||
DeploymentSummary,
|
||||
GatewayConfigRequest,
|
||||
GatewayInfo,
|
||||
@@ -187,7 +188,11 @@ def _summary_from_job(name: str, job: SystemdDeployment, config: object) -> Depl
|
||||
def _summary_from_program(
|
||||
name: str, comp: ProgramSpec, root: Path
|
||||
) -> DeploymentSummary:
|
||||
"""Build a DeploymentSummary from a ProgramSpec (its derived kind)."""
|
||||
"""Build a DeploymentSummary from a ProgramSpec (legacy unified view).
|
||||
|
||||
A program has no single kind (kind is a deployment property), so the legacy
|
||||
entry carries none — the typed /programs view exposes its deployment list.
|
||||
"""
|
||||
source = comp.source
|
||||
|
||||
installed: bool | None = None
|
||||
@@ -198,7 +203,7 @@ def _summary_from_program(
|
||||
id=name,
|
||||
category="program",
|
||||
description=comp.description,
|
||||
kind=comp.kind,
|
||||
kind=None,
|
||||
stack=comp.stack,
|
||||
version=comp.version,
|
||||
source=source,
|
||||
@@ -257,6 +262,8 @@ def _service_from_deployed(name: str, deployed: object) -> ServiceSummary:
|
||||
id=name,
|
||||
description=deployed.description,
|
||||
stack=deployed.stack,
|
||||
kind=deployed.kind,
|
||||
manager=deployed.manager,
|
||||
launcher=deployed.launcher,
|
||||
run_target=run_target,
|
||||
port=deployed.port,
|
||||
@@ -294,6 +301,8 @@ def _service_from_spec(name: str, svc: SystemdDeployment, config: object) -> Ser
|
||||
id=name,
|
||||
description=description,
|
||||
stack=stack,
|
||||
kind="service",
|
||||
manager="systemd",
|
||||
launcher=svc.run.launcher,
|
||||
run_target=_run_target(svc.run),
|
||||
port=port,
|
||||
@@ -363,20 +372,20 @@ def _program_from_spec(
|
||||
|
||||
# Uniform lifecycle state (on PATH / running / served) — needs full config.
|
||||
active: bool | None = None
|
||||
services: list[str] = []
|
||||
jobs: list[str] = []
|
||||
deployments: list[DeploymentRef] = []
|
||||
if config is not None:
|
||||
from castle_core.lifecycle import is_active
|
||||
|
||||
active = is_active(name, config)
|
||||
# Deployments that reference this program (a program → 0-N services/jobs).
|
||||
services = [s for s, spec in config.services.items() if spec.program == name]
|
||||
jobs = [j for j, spec in config.jobs.items() if spec.program == name]
|
||||
# A program → 0-N deployments, each with its own kind.
|
||||
deployments = [
|
||||
DeploymentRef(name=dname, kind=kind)
|
||||
for dname, kind in config.deployments_of(name)
|
||||
]
|
||||
|
||||
return ProgramSummary(
|
||||
id=name,
|
||||
description=comp.description,
|
||||
kind=comp.kind,
|
||||
stack=comp.stack,
|
||||
version=comp.version,
|
||||
source=source,
|
||||
@@ -387,8 +396,7 @@ def _program_from_spec(
|
||||
installed=installed,
|
||||
active=active,
|
||||
actions=available_actions(comp),
|
||||
services=services,
|
||||
jobs=jobs,
|
||||
deployments=deployments,
|
||||
)
|
||||
|
||||
|
||||
@@ -405,9 +413,10 @@ def list_services(include_remote: bool = False) -> list[ServiceSummary]:
|
||||
summaries: list[ServiceSummary] = []
|
||||
seen: set[str] = set()
|
||||
|
||||
# Deployed services only — not jobs, tools (path), statics (caddy), or remotes.
|
||||
# Services page shows services (systemd) AND statics (caddy) — both are
|
||||
# exposed, URL-reachable "services". Not jobs, tools, or remotes.
|
||||
for name, deployed in registry.deployed.items():
|
||||
if deployed.kind != "service":
|
||||
if deployed.kind not in ("service", "static"):
|
||||
continue
|
||||
s = _service_from_deployed(name, deployed)
|
||||
s.node = hostname
|
||||
@@ -631,9 +640,8 @@ def list_programs(kind: str | None = None) -> list[ProgramSummary]:
|
||||
|
||||
for name, comp in config.programs.items():
|
||||
summary = _program_from_spec(name, comp, root, config)
|
||||
if summary.kind is None:
|
||||
continue
|
||||
if kind and summary.kind != kind:
|
||||
# A program's kinds are the kinds of its deployments; filter by membership.
|
||||
if kind and kind not in {d.kind for d in summary.deployments}:
|
||||
continue
|
||||
summary.node = hostname
|
||||
summaries.append(summary)
|
||||
@@ -722,11 +730,9 @@ def list_components(include_remote: bool = False) -> list[DeploymentSummary]:
|
||||
if ref and ref in config.programs:
|
||||
s.source = config.programs[ref].source
|
||||
|
||||
# Programs from the software catalog
|
||||
# Programs from the software catalog (legacy unified view)
|
||||
for name, comp in config.programs.items():
|
||||
summary = _summary_from_program(name, comp, root)
|
||||
if summary.kind is None:
|
||||
continue
|
||||
summary.node = local_hostname
|
||||
summaries.append(summary)
|
||||
except FileNotFoundError:
|
||||
|
||||
@@ -203,12 +203,14 @@ class TestProgramsList:
|
||||
names = [p["id"] for p in data]
|
||||
assert "test-tool" in names
|
||||
|
||||
def test_program_has_kind(self, client: TestClient) -> None:
|
||||
"""Program summary includes the derived kind."""
|
||||
def test_program_lists_deployments(self, client: TestClient) -> None:
|
||||
"""Program summary lists its deployments (name + kind), not a single kind."""
|
||||
response = client.get("/programs")
|
||||
data = response.json()
|
||||
tool = next(p for p in data if p["id"] == "test-tool")
|
||||
assert tool["kind"] == "tool"
|
||||
assert "kind" not in tool
|
||||
kinds = {d["kind"] for d in tool["deployments"]}
|
||||
assert "tool" in kinds
|
||||
|
||||
def test_no_port_field(self, client: TestClient) -> None:
|
||||
"""ProgramSummary does not have port field."""
|
||||
@@ -235,7 +237,7 @@ class TestProgramDetail:
|
||||
data = response.json()
|
||||
assert data["id"] == "test-tool"
|
||||
assert "manifest" in data
|
||||
assert data["kind"] == "tool"
|
||||
assert {d["kind"] for d in data["deployments"]} == {"tool"}
|
||||
|
||||
def test_not_found(self, client: TestClient) -> None:
|
||||
"""Returns 404 for unknown program."""
|
||||
|
||||
Reference in New Issue
Block a user