- Introduced `uv.lock` for dependency management with various packages including `pytest`, `colorama`, and `pluggy`. - Added `pyrightconfig.json` for Python type checking configuration. - Expanded `recommendations.md` with detailed scaling recommendations and project management strategies. - Created shared `ruff.toml` for consistent linting across projects. - Developed `Castle Tools` with various utilities including Android backup, browser automation, document conversion, and search tools. - Implemented `backup-collect` and `schedule` tools for system administration tasks. - Enhanced `search` functionality with indexing and querying capabilities using Tantivy. - Added comprehensive documentation for each tool, including usage examples and installation instructions.
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
"""Tests for castle service command."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from castle_cli.commands.service import _generate_unit, _unit_name
|
|
from castle_cli.config import load_config
|
|
|
|
|
|
class TestUnitName:
|
|
"""Tests for systemd unit naming."""
|
|
|
|
def test_unit_name_format(self) -> None:
|
|
"""Unit names follow castle-<name>.service pattern."""
|
|
assert _unit_name("central-context") == "castle-central-context.service"
|
|
assert _unit_name("my-svc") == "castle-my-svc.service"
|
|
|
|
|
|
class TestUnitGeneration:
|
|
"""Tests for systemd unit file generation."""
|
|
|
|
def test_contains_description(self, castle_root: Path) -> None:
|
|
"""Unit file has service description."""
|
|
config = load_config(castle_root)
|
|
manifest = config.components["test-svc"]
|
|
unit = _generate_unit(config, "test-svc", manifest)
|
|
assert "Description=Castle: Test service" in unit
|
|
|
|
def test_contains_working_dir(self, castle_root: Path) -> None:
|
|
"""Unit file has correct working directory."""
|
|
config = load_config(castle_root)
|
|
manifest = config.components["test-svc"]
|
|
unit = _generate_unit(config, "test-svc", manifest)
|
|
assert f"WorkingDirectory={castle_root / 'test-svc'}" in unit
|
|
|
|
def test_contains_environment(self, castle_root: Path) -> None:
|
|
"""Unit file has environment variables."""
|
|
config = load_config(castle_root)
|
|
manifest = config.components["test-svc"]
|
|
unit = _generate_unit(config, "test-svc", manifest)
|
|
expected_data_dir = str(castle_root / "data" / "test-svc")
|
|
assert f"Environment=TEST_SVC_DATA_DIR={expected_data_dir}" in unit
|
|
|
|
def test_contains_restart_policy(self, castle_root: Path) -> None:
|
|
"""Unit file has restart configuration."""
|
|
config = load_config(castle_root)
|
|
manifest = config.components["test-svc"]
|
|
unit = _generate_unit(config, "test-svc", manifest)
|
|
assert "Restart=on-failure" in unit
|
|
|
|
def test_uses_uv_run(self, castle_root: Path) -> None:
|
|
"""Unit file ExecStart uses uv run for python_uv_tool."""
|
|
config = load_config(castle_root)
|
|
manifest = config.components["test-svc"]
|
|
unit = _generate_unit(config, "test-svc", manifest)
|
|
assert "run test-svc" in unit
|