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.
73 lines
2.9 KiB
Python
73 lines
2.9 KiB
Python
"""Tests for wildpc add — adopting existing repos as programs."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from argparse import Namespace
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from wildpc_cli.config import load_config
|
|
|
|
|
|
def _run_add(wildpc_root: Path, **kwargs: object) -> object:
|
|
with (
|
|
patch("wildpc_cli.commands.add.load_config") as mock_load,
|
|
patch("wildpc_cli.commands.add.save_config"),
|
|
):
|
|
config = load_config(wildpc_root)
|
|
mock_load.return_value = config
|
|
from wildpc_cli.commands.add import run_add
|
|
|
|
args = Namespace(name=None, description="", **kwargs)
|
|
rc = run_add(args)
|
|
return rc, config
|
|
|
|
|
|
class TestAdd:
|
|
def test_adopt_python_path_assigns_stack(self, wildpc_root: Path, tmp_path: Path) -> None:
|
|
repo = tmp_path / "mytool"
|
|
repo.mkdir()
|
|
(repo / "pyproject.toml").write_text('[project]\nname = "mytool"\ndependencies = []\n')
|
|
rc, config = _run_add(wildpc_root, target=str(repo))
|
|
assert rc == 0
|
|
prog = config.programs["mytool"]
|
|
assert prog.stack == "python-cli" # detected
|
|
assert prog.source == str(repo.resolve())
|
|
|
|
def test_adopt_fastapi_detects_daemon(self, wildpc_root: Path, tmp_path: Path) -> None:
|
|
repo = tmp_path / "svc"
|
|
repo.mkdir()
|
|
(repo / "pyproject.toml").write_text(
|
|
'[project]\nname = "svc"\ndependencies = ["fastapi>=0.1"]\n'
|
|
)
|
|
rc, config = _run_add(wildpc_root, target=str(repo))
|
|
assert rc == 0
|
|
# `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.deployments_of("svc") == []
|
|
|
|
def test_adopt_rust_declares_commands(self, wildpc_root: Path, tmp_path: Path) -> None:
|
|
repo = tmp_path / "rusty"
|
|
repo.mkdir()
|
|
(repo / "Cargo.toml").write_text('[package]\nname = "rusty"\n')
|
|
rc, config = _run_add(wildpc_root, target=str(repo))
|
|
assert rc == 0
|
|
prog = config.programs["rusty"]
|
|
assert prog.stack is None # no wildpc stack for rust
|
|
# build lands in BuildSpec; other verbs in CommandsSpec
|
|
assert prog.build is not None
|
|
assert prog.build.commands == [["cargo", "build", "--release"]]
|
|
assert prog.commands is not None
|
|
assert prog.commands.run == [["cargo", "run"]]
|
|
|
|
def test_adopt_git_url_records_repo(self, wildpc_root: Path) -> None:
|
|
rc, config = _run_add(wildpc_root, target="https://github.com/someone/widget.git")
|
|
assert rc == 0
|
|
prog = config.programs["widget"]
|
|
assert prog.repo == "https://github.com/someone/widget.git"
|
|
|
|
def test_missing_path_fails(self, wildpc_root: Path, tmp_path: Path) -> None:
|
|
rc, _ = _run_add(wildpc_root, target=str(tmp_path / "nope"))
|
|
assert rc == 1
|