91 lines
2.4 KiB
Python
91 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
import textwrap
|
|
|
|
import pytest
|
|
|
|
from agent_gitea.config import load_config
|
|
|
|
|
|
def test_load_config_validates_and_filters_enabled_repos(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("GITEA_TOKEN", "secret")
|
|
config_path = tmp_path / "config.yaml"
|
|
config_path.write_text(
|
|
textwrap.dedent(
|
|
"""
|
|
gitea:
|
|
base_url: https://gitea.test
|
|
token_env: GITEA_TOKEN
|
|
agents:
|
|
implementer:
|
|
command: ["codex", "{prompt_path}"]
|
|
reviewer:
|
|
command: ["codex", "{prompt_path}"]
|
|
repositories:
|
|
- owner: acme
|
|
name: enabled
|
|
enabled: true
|
|
- owner: acme
|
|
name: disabled
|
|
enabled: false
|
|
"""
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
config = load_config(config_path)
|
|
|
|
assert config.gitea.token == "secret"
|
|
assert [repo.full_name for repo in config.enabled_repositories] == ["acme/enabled"]
|
|
|
|
|
|
def test_load_config_rejects_duplicate_repositories(tmp_path):
|
|
config_path = tmp_path / "config.yaml"
|
|
config_path.write_text(
|
|
textwrap.dedent(
|
|
"""
|
|
gitea:
|
|
base_url: https://gitea.test
|
|
agents:
|
|
implementer:
|
|
command: ["agent"]
|
|
reviewer:
|
|
command: ["agent"]
|
|
repositories:
|
|
- owner: acme
|
|
name: service
|
|
- owner: acme
|
|
name: service
|
|
"""
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
with pytest.raises(ValueError, match="duplicate repository"):
|
|
load_config(config_path)
|
|
|
|
|
|
def test_load_config_reads_dotenv_next_to_config(tmp_path, monkeypatch):
|
|
monkeypatch.delenv("GITEA_TOKEN", raising=False)
|
|
(tmp_path / ".env").write_text("GITEA_TOKEN=from-dotenv\n", encoding="utf-8")
|
|
config_path = tmp_path / "config.yaml"
|
|
config_path.write_text(
|
|
textwrap.dedent(
|
|
"""
|
|
gitea:
|
|
base_url: https://gitea.test
|
|
agents:
|
|
implementer:
|
|
command: ["agent"]
|
|
reviewer:
|
|
command: ["agent"]
|
|
"""
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
config = load_config(config_path)
|
|
|
|
assert config.repositories == []
|
|
assert config.gitea.token == "from-dotenv"
|