Files
wild-pc/cli/tests/test_list.py
Paul Payne 05b28cb584 Rename Castle -> Wild PC across the repo
Repo-side rename only (Phases 1-3 of the migration plan); the live box
(~/.castle, systemd units, /data/castle, domains) is a separate cutover.

- Slug `castle` -> `wildpc`: CLI command, module names (wildpc_core/cli/api),
  dist names, entry point `wildpc = wildpc_cli.main:main`.
- Identifiers: CastleConfig/NATSClient/DirError/MDNS -> Wildpc*.
- Env/constants: CASTLE_* -> WILDPC_*; ~/.castle -> ~/.wildpc, castle.yaml ->
  wildpc.yaml, /data/castle -> /data/wildpc.
- Systemd UNIT_PREFIX castle- -> wildpc-; own programs castle-api/gateway/etc.
- Display prose "Castle" -> "Wild PC" in docs, agent-guide files, README, frontend.
- Package dirs and bootstrap yaml renamed via git mv; lockfiles regenerated;
  redundant nested uv.lock files dropped (workspace root lock is authoritative).

Tests: core 273, cli 47, wildpc-api 120 all pass. Frontend type-checks + builds.
Fixed a stale test fixture (secret_env_path kind arg) broken pre-rename.
2026-07-18 22:55:08 -07:00

96 lines
4.1 KiB
Python

"""Tests for wildpc list command."""
from __future__ import annotations
import json
from argparse import Namespace
from pathlib import Path
from unittest.mock import patch
from wildpc_cli.commands.list_cmd import run_list
class TestListCommand:
"""Tests for the list command."""
def test_list_all(self, wildpc_root: Path, capsys: object) -> None:
"""List all components."""
with patch("wildpc_cli.commands.list_cmd.load_config") as mock_load:
from wildpc_cli.config import load_config
mock_load.return_value = load_config(wildpc_root)
args = Namespace(kind=None, stack=None, json=False)
result = run_list(args)
assert result == 0
captured = capsys.readouterr() # type: ignore[attr-defined]
assert "test-svc" in captured.out
assert "test-tool" in captured.out
def test_list_filter_daemon(self, wildpc_root: Path, capsys: object) -> None:
"""--behavior filters the program catalog by its real behavior field."""
with patch("wildpc_cli.commands.list_cmd.load_config") as mock_load:
from wildpc_cli.config import load_config
mock_load.return_value = load_config(wildpc_root)
args = Namespace(kind="service", stack=None, json=False)
result = run_list(args)
assert result == 0
captured = capsys.readouterr() # type: ignore[attr-defined]
assert "test-daemon" in captured.out
assert "test-tool" not in captured.out
# Services/jobs are deployment views, not behaviors — hidden under a filter.
assert "test-svc" not in captured.out
def test_list_filter_tool(self, wildpc_root: Path, capsys: object) -> None:
"""List filtered to tools."""
with patch("wildpc_cli.commands.list_cmd.load_config") as mock_load:
from wildpc_cli.config import load_config
mock_load.return_value = load_config(wildpc_root)
args = Namespace(kind="tool", stack=None, json=False)
result = run_list(args)
assert result == 0
captured = capsys.readouterr() # type: ignore[attr-defined]
assert "test-tool" in captured.out
assert "test-svc" not in captured.out
def test_list_jobs_are_deployments(self, wildpc_root: Path, capsys: object) -> None:
"""Jobs are a deployment view: shown unfiltered, hidden under a behavior filter."""
with patch("wildpc_cli.commands.list_cmd.load_config") as mock_load:
from wildpc_cli.config import load_config
mock_load.return_value = load_config(wildpc_root)
# Unfiltered: the job appears.
run_list(Namespace(kind=None, stack=None, json=False))
assert "test-job" in capsys.readouterr().out # type: ignore[attr-defined]
# Behavior filter targets the catalog, so jobs drop out.
run_list(Namespace(kind="tool", stack=None, json=False))
out = capsys.readouterr().out # type: ignore[attr-defined]
assert "test-job" not in out
assert "test-svc" not in out
assert "test-tool" in out
def test_list_json(self, wildpc_root: Path, capsys: object) -> None:
"""JSON output tags each entry with its derived kind."""
with patch("wildpc_cli.commands.list_cmd.load_config") as mock_load:
from wildpc_cli.config import load_config
mock_load.return_value = load_config(wildpc_root)
args = Namespace(kind=None, stack=None, json=True)
result = run_list(args)
assert result == 0
captured = capsys.readouterr() # type: ignore[attr-defined]
data = json.loads(captured.out)
names = [p["name"] for p in data]
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" # 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" in tool["kinds"]