"""Unit tests for devx.tools.check_config.""" from pathlib import Path from click.testing import CliRunner from devx.tools.check_config import cli class TestCheckConfig: def test_valid_config(self, tmp_path: Path) -> None: """A valid [tool.devx] section with consistent versions passes.""" runner = CliRunner() with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs: Path(fs, "pyproject.toml").write_text( '[project]\nname = "test"\n' '[project.optional-dependencies]\nci = ["devx>=0.15.0"]\ndev = ["devx>=0.15.0"]\n' '[tool.devx]\ntask_prefix = "TEST"\nvikunja_project_id = 1\nrepo_owner = "owner"\nrepo_name = "test"\n' ) result = runner.invoke(cli) assert result.exit_code == 0 assert "Configuration OK" in result.output def test_missing_tool_devx_section(self, tmp_path: Path) -> None: """Missing [tool.devx] section fails with error.""" runner = CliRunner() with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs: Path(fs, "pyproject.toml").write_text('[project]\nname = "test"\n') result = runner.invoke(cli) assert result.exit_code == 1 assert "missing required keys" in result.output def test_partial_tool_devx_section(self, tmp_path: Path) -> None: """Partial [tool.devx] section fails with missing keys.""" runner = CliRunner() with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs: Path(fs, "pyproject.toml").write_text('[project]\nname = "test"\n[tool.devx]\ntask_prefix = "TEST"\n') result = runner.invoke(cli) assert result.exit_code == 1 assert "missing required keys" in result.output assert "vikunja_project_id" in result.output assert "repo_owner" in result.output assert "repo_name" in result.output def test_version_mismatch(self, tmp_path: Path) -> None: """Version mismatch across extras fails.""" runner = CliRunner() with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs: Path(fs, "pyproject.toml").write_text( '[project]\nname = "test"\n' "[project.optional-dependencies]\n" 'ci = ["devx>=0.15.0"]\n' 'dev = ["devx>=0.14.2"]\n' '[tool.devx]\ntask_prefix = "TEST"\nvikunja_project_id = 1\nrepo_owner = "owner"\nrepo_name = "test"\n' ) result = runner.invoke(cli) assert result.exit_code == 1 assert "version mismatch" in result.output def test_no_pyproject_file(self, tmp_path: Path) -> None: """Missing pyproject.toml fails.""" runner = CliRunner() with runner.isolated_filesystem(temp_dir=str(tmp_path)): result = runner.invoke(cli) assert result.exit_code == 1 assert "not found" in result.output def test_no_extras_passes(self, tmp_path: Path) -> None: """No optional-dependencies with devx is fine (no versions to compare).""" runner = CliRunner() with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs: Path(fs, "pyproject.toml").write_text( '[project]\nname = "test"\n' '[tool.devx]\ntask_prefix = "TEST"\nvikunja_project_id = 1\nrepo_owner = "owner"\nrepo_name = "test"\n' ) result = runner.invoke(cli) assert result.exit_code == 0 assert "Configuration OK" in result.output def test_single_extra_passes(self, tmp_path: Path) -> None: """Single extra with devx version is fine (no mismatch possible).""" runner = CliRunner() with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs: Path(fs, "pyproject.toml").write_text( '[project]\nname = "test"\n' '[project.optional-dependencies]\nci = ["devx>=0.15.0", "pytest"]\n' '[tool.devx]\ntask_prefix = "TEST"\nvikunja_project_id = 1\nrepo_owner = "owner"\nrepo_name = "test"\n' ) result = runner.invoke(cli) assert result.exit_code == 0