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:
@@ -144,10 +144,6 @@ def run_create(args: argparse.Namespace) -> int:
|
||||
),
|
||||
)
|
||||
|
||||
# Populate the derived kind on the in-memory program so readers see the live
|
||||
# value immediately (it's excluded from disk — kind_of recomputes on load).
|
||||
config.programs[name].kind = config.kind_of(name)
|
||||
|
||||
save_config(config)
|
||||
|
||||
label = f"{stack} program" if stack else "bare program"
|
||||
|
||||
@@ -53,16 +53,18 @@ def run_info(args: argparse.Namespace) -> int:
|
||||
print(f"\n{BOLD}{name}{RESET}")
|
||||
print(f"{'─' * 40}")
|
||||
|
||||
# Determine kind (derived)
|
||||
kind = None
|
||||
if program and program.kind:
|
||||
kind = program.kind
|
||||
# Determine kind(s) — for a program, the kinds of its deployments; for a
|
||||
# single deployment, its own kind.
|
||||
kinds: list[str] = []
|
||||
if program:
|
||||
kinds = sorted({k for _, k in config.deployments_of(name)})
|
||||
elif service:
|
||||
kind = "service"
|
||||
kinds = ["service"]
|
||||
elif job:
|
||||
kind = "job"
|
||||
if kind:
|
||||
print(f" {BOLD}kind{RESET}: {kind}")
|
||||
kinds = ["job"]
|
||||
if kinds:
|
||||
label = "kind" if len(kinds) == 1 else "kinds"
|
||||
print(f" {BOLD}{label}{RESET}: {', '.join(kinds)}")
|
||||
|
||||
# Show stack
|
||||
stack = None
|
||||
@@ -182,8 +184,8 @@ def _info_json(
|
||||
data["service"] = service.model_dump(exclude_none=True, exclude={"id"})
|
||||
if job:
|
||||
data["job"] = job.model_dump(exclude_none=True, exclude={"id"})
|
||||
if program and program.kind:
|
||||
data["kind"] = program.kind
|
||||
if program:
|
||||
data["kinds"] = sorted({k for _, k in config.deployments_of(name)})
|
||||
elif service:
|
||||
data["kind"] = "service"
|
||||
elif job:
|
||||
|
||||
@@ -84,12 +84,17 @@ def run_list(args: argparse.Namespace) -> int:
|
||||
|
||||
any_output = False
|
||||
|
||||
# Programs (the catalog) — filtered by real behavior + stack
|
||||
# A program's kinds are the kinds of its deployments (a program has no kind
|
||||
# of its own). Sorted, de-duplicated.
|
||||
def prog_kinds(name: str) -> list[str]:
|
||||
return sorted({kind for _, kind in config.deployments_of(name)})
|
||||
|
||||
# Programs (the catalog) — filtered by a deployment kind + stack.
|
||||
progs = (
|
||||
{
|
||||
name: comp
|
||||
for name, comp in config.programs.items()
|
||||
if (not filter_kind or comp.kind == filter_kind)
|
||||
if (not filter_kind or filter_kind in prog_kinds(name))
|
||||
and (not filter_stack or comp.stack == filter_stack)
|
||||
}
|
||||
if resource in (None, "program")
|
||||
@@ -100,12 +105,13 @@ def run_list(args: argparse.Namespace) -> int:
|
||||
print(f"\n{BOLD}{CYAN}Programs{RESET}")
|
||||
print(f"{CYAN}{'─' * 40}{RESET}")
|
||||
for name, comp in progs.items():
|
||||
kind = comp.kind or "program"
|
||||
bcolor = KIND_COLORS.get(kind, "")
|
||||
behavior_str = f" {bcolor}{kind}{RESET}"
|
||||
kinds = prog_kinds(name)
|
||||
kinds_str = "".join(
|
||||
f" {KIND_COLORS.get(k, '')}{k}{RESET}" for k in kinds
|
||||
)
|
||||
stack_str = f" {DIM}{comp.stack}{RESET}" if comp.stack else ""
|
||||
desc = f" {DIM}{comp.description}{RESET}" if comp.description else ""
|
||||
print(f" {dot(name)} {BOLD}{name}{RESET}{behavior_str}{stack_str}{desc}")
|
||||
print(f" {dot(name)} {BOLD}{name}{RESET}{kinds_str}{stack_str}{desc}")
|
||||
|
||||
# Services + Jobs (deployment views) — independent of behavior, so only shown
|
||||
# when no behavior filter is applied. Each gated by its own resource scope.
|
||||
@@ -168,15 +174,16 @@ def _list_json(
|
||||
|
||||
output = []
|
||||
|
||||
# Programs (catalog) — filtered by derived kind + stack
|
||||
# Programs (catalog) — a program's kinds are its deployments' kinds.
|
||||
for name, comp in config.programs.items():
|
||||
if filter_kind and comp.kind != filter_kind:
|
||||
kinds = sorted({kind for _, kind in config.deployments_of(name)})
|
||||
if filter_kind and filter_kind not in kinds:
|
||||
continue
|
||||
if filter_stack and comp.stack != filter_stack:
|
||||
continue
|
||||
entry: dict = {
|
||||
"name": name,
|
||||
"kind": comp.kind,
|
||||
"kinds": kinds,
|
||||
"active": is_active(name, config),
|
||||
}
|
||||
if comp.stack:
|
||||
|
||||
@@ -183,7 +183,9 @@ def run_status(args: argparse.Namespace) -> int:
|
||||
on = is_active(name, config)
|
||||
color = "\033[92m" if on else "\033[90m"
|
||||
label = "active" if on else "inactive"
|
||||
print(f" {color}{label:10s}\033[0m {name} ({comp.kind or 'program'})")
|
||||
kinds = sorted({k for _, k in config.deployments_of(name)})
|
||||
tag = ", ".join(kinds) if kinds else "program"
|
||||
print(f" {color}{label:10s}\033[0m {name} ({tag})")
|
||||
print()
|
||||
return 0
|
||||
|
||||
|
||||
@@ -42,10 +42,10 @@ class TestAdd:
|
||||
)
|
||||
rc, config = _run_add(castle_root, target=str(repo))
|
||||
assert rc == 0
|
||||
# `add` adopts source only (kind is derived from a deployment declared
|
||||
# later); a fastapi project is detected as the python-fastapi stack.
|
||||
# `add` adopts source only — no deployment yet (kind is a deployment
|
||||
# property); a fastapi project is detected as the python-fastapi stack.
|
||||
assert config.programs["svc"].stack == "python-fastapi"
|
||||
assert config.programs["svc"].kind is None
|
||||
assert config.deployments_of("svc") == []
|
||||
|
||||
def test_adopt_rust_declares_commands(self, castle_root: Path, tmp_path: Path) -> None:
|
||||
repo = tmp_path / "rusty"
|
||||
|
||||
@@ -73,10 +73,9 @@ class TestCreateCommand:
|
||||
assert (project_dir / "src" / "my_tool2" / "main.py").exists()
|
||||
assert (project_dir / "CLAUDE.md").exists()
|
||||
assert "my-tool2" in config.programs
|
||||
comp = config.programs["my-tool2"]
|
||||
assert comp.kind == "tool"
|
||||
# A tool is a PATH deployment: manager=path.
|
||||
# A tool is a PATH deployment: manager=path, derived kind=tool.
|
||||
assert config.deployments["my-tool2"].manager == "path"
|
||||
assert config.deployments_of("my-tool2") == [("my-tool2", "tool")]
|
||||
|
||||
def test_create_supabase_app(self, castle_root: Path, tmp_path: Path) -> None:
|
||||
"""A supabase app scaffolds a Patch-shaped project registered as a static
|
||||
@@ -106,12 +105,12 @@ class TestCreateCommand:
|
||||
|
||||
# Registered as a program + a caddy (static) deployment serving public/
|
||||
comp = config.programs["guestbook"]
|
||||
assert comp.kind == "static"
|
||||
assert comp.stack == "supabase"
|
||||
assert comp.build is not None and comp.build.outputs == ["public"]
|
||||
dep = config.deployments["guestbook"]
|
||||
assert dep.manager == "caddy"
|
||||
assert dep.root == "public"
|
||||
assert config.deployments_of("guestbook") == [("guestbook", "static")]
|
||||
|
||||
def test_create_duplicate_fails(self, castle_root: Path, capsys: object) -> None:
|
||||
"""Creating a project with existing name fails."""
|
||||
|
||||
@@ -89,7 +89,7 @@ class TestListCommand:
|
||||
assert "test-svc" in names
|
||||
assert "test-tool" in names
|
||||
svc = next(p for p in data if p["name"] == "test-svc")
|
||||
assert svc["kind"] == "service"
|
||||
# test-tool is a program deployed on PATH → its derived kind is `tool`.
|
||||
assert svc["kind"] == "service" # a service deployment entry (singular)
|
||||
# test-tool is a program with a PATH deployment → kinds includes `tool`.
|
||||
tool = next(p for p in data if p["name"] == "test-tool")
|
||||
assert tool["kind"] == "tool"
|
||||
assert "tool" in tool["kinds"]
|
||||
|
||||
Reference in New Issue
Block a user