Files
wild-pc/cli/tests/test_mesh.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

68 lines
2.4 KiB
Python

"""Tests for the wildpc mesh command (API calls mocked)."""
from __future__ import annotations
import urllib.error
from argparse import Namespace
from unittest.mock import patch
from wildpc_cli.commands.mesh import run_mesh
class TestMeshCommand:
def test_status(self, capsys: object) -> None:
data = {
"enabled": True, "connected": True, "nats_url": "tls://x:4222",
"peer_count": 1, "peers": ["primer"],
}
with patch("wildpc_cli.commands.mesh._get", return_value=data):
rc = run_mesh(Namespace(mesh_command="status"))
assert rc == 0
out = capsys.readouterr().out # type: ignore[attr-defined]
assert "connected" in out and "primer" in out
def test_nodes(self, capsys: object) -> None:
data = [
{"hostname": "civil", "online": True, "is_stale": False,
"deployed_count": 5, "is_local": True},
{"hostname": "primer", "online": True, "is_stale": False,
"deployed_count": 3, "is_local": False},
]
with patch("wildpc_cli.commands.mesh._get", return_value=data):
rc = run_mesh(Namespace(mesh_command="nodes"))
assert rc == 0
out = capsys.readouterr().out # type: ignore[attr-defined]
assert "civil" in out and "primer" in out
def test_config_list(self, capsys: object) -> None:
data = {"role": "authority", "keys": ["fleet/motd"]}
with patch("wildpc_cli.commands.mesh._get", return_value=data):
rc = run_mesh(
Namespace(mesh_command="config", mesh_config_command="list")
)
assert rc == 0
assert "fleet/motd" in capsys.readouterr().out # type: ignore[attr-defined]
def test_config_set_calls_put(self) -> None:
with patch(
"wildpc_cli.commands.mesh._put", return_value={"ok": True}
) as put:
rc = run_mesh(
Namespace(
mesh_command="config",
mesh_config_command="set",
key="fleet/x",
value="v",
)
)
assert rc == 0
put.assert_called_once()
def test_api_unreachable_returns_1(self, capsys: object) -> None:
with patch(
"wildpc_cli.commands.mesh._get",
side_effect=urllib.error.URLError("refused"),
):
rc = run_mesh(Namespace(mesh_command="status"))
assert rc == 1