feat: migrate config to pydantic-settings (#65)

This commit is contained in:
banteg
2026-01-08 11:20:10 +04:00
committed by GitHub
parent 26df1c8ac0
commit d606833603
18 changed files with 937 additions and 131 deletions
+28 -5
View File
@@ -4,14 +4,15 @@ import pytest
from typer.testing import CliRunner
from takopi import cli
from takopi.config import ConfigError, parse_projects_config
from takopi.config import ConfigError
from takopi.settings import TakopiSettings
def test_parse_projects_rejects_engine_alias() -> None:
config = {"projects": {"codex": {"path": "/tmp/repo"}}}
with pytest.raises(ConfigError, match="aliases must not match engine ids"):
parse_projects_config(
config,
settings = TakopiSettings.model_validate(config)
settings.to_projects_config(
config_path=Path("takopi.toml"),
engine_ids=["codex"],
reserved=("cancel",),
@@ -21,8 +22,8 @@ def test_parse_projects_rejects_engine_alias() -> None:
def test_parse_projects_default_project_must_exist() -> None:
config = {"default_project": "z80", "projects": {}}
with pytest.raises(ConfigError, match="default_project"):
parse_projects_config(
config,
settings = TakopiSettings.model_validate(config)
settings.to_projects_config(
config_path=Path("takopi.toml"),
engine_ids=["codex"],
reserved=("cancel",),
@@ -47,3 +48,25 @@ def test_init_writes_project(monkeypatch, tmp_path) -> None:
assert 'worktrees_dir = ".worktrees"' in saved
assert 'default_engine = "codex"' in saved
assert 'worktree_base = "main"' in saved
def test_projects_default_engine_unknown() -> None:
config = {"projects": {"z80": {"path": "/tmp/repo", "default_engine": "nope"}}}
settings = TakopiSettings.model_validate(config)
with pytest.raises(ConfigError, match="projects.z80.default_engine"):
settings.to_projects_config(
config_path=Path("takopi.toml"),
engine_ids=["codex"],
reserved=("cancel",),
)
def test_projects_relative_path_resolves(tmp_path: Path) -> None:
config_path = tmp_path / "takopi.toml"
settings = TakopiSettings.model_validate({"projects": {"z80": {"path": "repo"}}})
projects = settings.to_projects_config(
config_path=config_path,
engine_ids=["codex"],
reserved=("cancel",),
)
assert projects.projects["z80"].path == config_path.parent / "repo"