test: cover manager behavior without live Gitea

This commit is contained in:
2026-05-06 15:24:56 +08:00
parent ba2c9d9f88
commit bd24a18c18
5 changed files with 518 additions and 0 deletions

90
tests/test_config.py Normal file
View File

@@ -0,0 +1,90 @@
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"